Skip to content

Commit 24b7136

Browse files
Merge pull request #462 from codex-team/fix/card-linking
fix(payments): Fix card linking
2 parents 424edb0 + 0703a69 commit 24b7136

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
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.7",
3+
"version": "1.1.8",
44
"main": "index.ts",
55
"license": "UNLICENSED",
66
"scripts": {

src/billing/cloudpayments.ts

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)