@@ -205,6 +205,36 @@ export default class CloudPaymentsWebhooks {
205205 return `${ workspace . name } ${ now . getDate ( ) } /${ now . getMonth ( ) + 1 } ${ tariffPlan . name } ` ;
206206 }
207207
208+ /**
209+ * Confirms the correctness of a user's payment for card linking
210+ * @param req - express request
211+ * @param res - express response
212+ * @param data - payment data receinved from checksum and request payload
213+ */
214+ private async checkCardLinkOperation ( req : express . Request , res : express . Response , data : PaymentData ) : Promise < void > {
215+ if ( data . isCardLinkOperation && ( ! data . userId || ! data . workspaceId ) ) {
216+ this . sendError ( res , CheckCodes . PAYMENT_COULD_NOT_BE_ACCEPTED , '[Billing / Check] Card linking – invalid data' , req . body ) ;
217+
218+ return ;
219+ }
220+
221+ try {
222+ const workspace = await this . getWorkspace ( req , data . workspaceId ) ;
223+
224+ telegram
225+ . sendMessage ( `✅ [Billing / Check] Card linked for subscription workspace «${ workspace . name } »` , TelegramBotURLs . Money )
226+ . catch ( e => console . error ( 'Error while sending message to Telegram: ' + e ) ) ;
227+
228+ res . json ( {
229+ code : CheckCodes . SUCCESS ,
230+ } as CheckResponse ) ;
231+ } catch ( e ) {
232+ const error = e as Error ;
233+
234+ this . sendError ( res , CheckCodes . PAYMENT_COULD_NOT_BE_ACCEPTED , `[Billing / Check] ${ error . toString ( ) } ` , req . body ) ;
235+ }
236+ }
237+
208238 /**
209239 * Route to confirm the correctness of a user's payment
210240 * https://developers.cloudpayments.ru/#check
@@ -227,15 +257,16 @@ export default class CloudPaymentsWebhooks {
227257 return ;
228258 }
229259
260+ if ( data . isCardLinkOperation ) {
261+ this . checkCardLinkOperation ( req , res , data ) ;
262+
263+ return ;
264+ }
265+
230266 let workspace : WorkspaceModel ;
231267 let member : ConfirmedMemberDBScheme ;
232268 let plan : PlanDBScheme ;
233269
234- if ( data . isCardLinkOperation && ( ! data . userId || ! data . workspaceId ) ) {
235- this . sendError ( res , CheckCodes . PAYMENT_COULD_NOT_BE_ACCEPTED , '[Billing / Check] Card linking – invalid data' , body ) ;
236-
237- return ;
238- }
239270
240271 if ( ! data . isCardLinkOperation && ( ! data . userId || ! data . workspaceId || ! data . tariffPlanId ) ) {
241272 this . sendError ( res , CheckCodes . PAYMENT_COULD_NOT_BE_ACCEPTED , '[Billing / Check] There is no necessary data in the request' , body ) ;
@@ -271,18 +302,6 @@ export default class CloudPaymentsWebhooks {
271302 return ;
272303 }
273304
274- if ( data . isCardLinkOperation ) {
275- telegram
276- . sendMessage ( `✅ [Billing / Check] Card linked for subscription workspace «${ workspace . name } »` , TelegramBotURLs . Money )
277- . catch ( e => console . error ( 'Error while sending message to Telegram: ' + e ) ) ;
278-
279- res . json ( {
280- code : CheckCodes . SUCCESS ,
281- } as CheckResponse ) ;
282-
283- return ;
284- }
285-
286305 /**
287306 * Create business operation about creation of subscription
288307 */
0 commit comments