@@ -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