@@ -268,7 +268,7 @@ export default class CloudPaymentsWebhooks {
268268 let plan : PlanDBScheme ;
269269
270270
271- if ( ! data . isCardLinkOperation && ( ! data . userId || ! data . workspaceId || ! data . tariffPlanId ) ) {
271+ if ( ! data . userId || ! data . workspaceId || ! data . tariffPlanId ) {
272272 this . sendError ( res , CheckCodes . PAYMENT_COULD_NOT_BE_ACCEPTED , '[Billing / Check] There is no necessary data in the request' , body ) ;
273273
274274 return ;
@@ -362,7 +362,13 @@ export default class CloudPaymentsWebhooks {
362362 return ;
363363 }
364364
365- if ( ! data . workspaceId || ! data . tariffPlanId || ! data . userId ) {
365+ if ( data . isCardLinkOperation && ( ! data . userId || ! data . workspaceId ) ) {
366+ this . sendError ( res , PayCodes . SUCCESS , '[Billing / Pay] No workspace of user id in card linking request body' , req . body ) ;
367+
368+ return ;
369+ }
370+
371+ if ( ! data . isCardLinkOperation && ( ! data . workspaceId || ! data . tariffPlanId || ! data . userId ) ) {
366372 this . sendError ( res , PayCodes . SUCCESS , `[Billing / Pay] No workspace, tariff plan or user id in request body` , body ) ;
367373
368374 return ;
@@ -372,12 +378,16 @@ export default class CloudPaymentsWebhooks {
372378 let workspace ;
373379 let tariffPlan ;
374380 let user ;
381+ let planId ;
375382
376383 try {
377384 businessOperation = await this . getBusinessOperation ( req , body . TransactionId . toString ( ) ) ;
378385 workspace = await this . getWorkspace ( req , data . workspaceId ) ;
379- tariffPlan = await this . getPlan ( req , data . tariffPlanId ) ;
380386 user = await this . getUser ( req , data . userId ) ;
387+ planId = data . isCardLinkOperation ? workspace . tariffPlanId . toString ( ) : data . tariffPlanId ;
388+
389+
390+ tariffPlan = await this . getPlan ( req , planId ) ;
381391 } catch ( e ) {
382392 const error = e as Error ;
383393
@@ -475,7 +485,7 @@ export default class CloudPaymentsWebhooks {
475485 type : SenderWorkerTaskType . PaymentSuccess ,
476486 payload : {
477487 workspaceId : data . workspaceId ,
478- tariffPlanId : data . tariffPlanId ,
488+ tariffPlanId : planId ,
479489 userId : data . userId ,
480490 } ,
481491 } ;
0 commit comments