Skip to content

Commit 9247ff5

Browse files
Merge pull request #464 from codex-team/fix/card-linking-2
fix(payments): card linking error
2 parents 24b7136 + 189c799 commit 9247ff5

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hawk.api",
3-
"version": "1.1.8",
3+
"version": "1.1.9",
44
"main": "index.ts",
55
"license": "UNLICENSED",
66
"scripts": {

src/billing/cloudpayments.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ export default class CloudPaymentsWebhooks {
267267
let member: ConfirmedMemberDBScheme;
268268
let plan: PlanDBScheme;
269269

270-
271-
if (!data.isCardLinkOperation && (!data.userId || !data.workspaceId || !data.tariffPlanId)) {
270+
if (!data.userId || !data.workspaceId || !data.tariffPlanId) {
272271
this.sendError(res, CheckCodes.PAYMENT_COULD_NOT_BE_ACCEPTED, '[Billing / Check] There is no necessary data in the request', body);
273272

274273
return;
@@ -362,7 +361,13 @@ export default class CloudPaymentsWebhooks {
362361
return;
363362
}
364363

365-
if (!data.workspaceId || !data.tariffPlanId || !data.userId) {
364+
if (data.isCardLinkOperation && (!data.userId || !data.workspaceId)) {
365+
this.sendError(res, PayCodes.SUCCESS, '[Billing / Pay] No workspace or user id in request body', req.body);
366+
367+
return;
368+
}
369+
370+
if (!data.isCardLinkOperation && (!data.workspaceId || !data.tariffPlanId || !data.userId)) {
366371
this.sendError(res, PayCodes.SUCCESS, `[Billing / Pay] No workspace, tariff plan or user id in request body`, body);
367372

368373
return;
@@ -372,12 +377,15 @@ export default class CloudPaymentsWebhooks {
372377
let workspace;
373378
let tariffPlan;
374379
let user;
380+
let planId;
375381

376382
try {
377383
businessOperation = await this.getBusinessOperation(req, body.TransactionId.toString());
378384
workspace = await this.getWorkspace(req, data.workspaceId);
379-
tariffPlan = await this.getPlan(req, data.tariffPlanId);
380385
user = await this.getUser(req, data.userId);
386+
planId = data.isCardLinkOperation ? workspace.tariffPlanId.toString() : data.tariffPlanId;
387+
388+
tariffPlan = await this.getPlan(req, planId);
381389
} catch (e) {
382390
const error = e as Error;
383391

@@ -475,7 +483,7 @@ export default class CloudPaymentsWebhooks {
475483
type: SenderWorkerTaskType.PaymentSuccess,
476484
payload: {
477485
workspaceId: data.workspaceId,
478-
tariffPlanId: data.tariffPlanId,
486+
tariffPlanId: planId,
479487
userId: data.userId,
480488
},
481489
};

0 commit comments

Comments
 (0)