Skip to content

Commit

Permalink
Merge pull request #463 from codex-team/master
Browse files Browse the repository at this point in the history
Update prod
  • Loading branch information
TatianaFomina authored Jan 28, 2025
2 parents 26224d5 + 24b7136 commit 86f5840
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawk.api",
"version": "1.1.7",
"version": "1.1.8",
"main": "index.ts",
"license": "UNLICENSED",
"scripts": {
Expand Down
53 changes: 36 additions & 17 deletions src/billing/cloudpayments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,36 @@ export default class CloudPaymentsWebhooks {
return `${workspace.name} ${now.getDate()}/${now.getMonth() + 1} ${tariffPlan.name}`;
}

/**
* Confirms the correctness of a user's payment for card linking
* @param req - express request
* @param res - express response
* @param data - payment data receinved from checksum and request payload
*/
private async checkCardLinkOperation(req: express.Request, res: express.Response, data: PaymentData): Promise<void> {
if (data.isCardLinkOperation && (!data.userId || !data.workspaceId)) {
this.sendError(res, CheckCodes.PAYMENT_COULD_NOT_BE_ACCEPTED, '[Billing / Check] Card linking – invalid data', req.body);

return;
}

try {
const workspace = await this.getWorkspace(req, data.workspaceId);

telegram
.sendMessage(`✅ [Billing / Check] Card linked for subscription workspace «${workspace.name}»`, TelegramBotURLs.Money)
.catch(e => console.error('Error while sending message to Telegram: ' + e));

res.json({
code: CheckCodes.SUCCESS,
} as CheckResponse);
} catch (e) {
const error = e as Error;

this.sendError(res, CheckCodes.PAYMENT_COULD_NOT_BE_ACCEPTED, `[Billing / Check] ${error.toString()}`, req.body);
}
}

/**
* Route to confirm the correctness of a user's payment
* https://developers.cloudpayments.ru/#check
Expand All @@ -227,15 +257,16 @@ export default class CloudPaymentsWebhooks {
return;
}

if (data.isCardLinkOperation) {
this.checkCardLinkOperation(req, res, data);

return;
}

let workspace: WorkspaceModel;
let member: ConfirmedMemberDBScheme;
let plan: PlanDBScheme;

if (data.isCardLinkOperation && (!data.userId || !data.workspaceId)) {
this.sendError(res, CheckCodes.PAYMENT_COULD_NOT_BE_ACCEPTED, '[Billing / Check] Card linking – invalid data', body);

return;
}

if (!data.isCardLinkOperation && (!data.userId || !data.workspaceId || !data.tariffPlanId)) {
this.sendError(res, CheckCodes.PAYMENT_COULD_NOT_BE_ACCEPTED, '[Billing / Check] There is no necessary data in the request', body);
Expand Down Expand Up @@ -271,18 +302,6 @@ export default class CloudPaymentsWebhooks {
return;
}

if (data.isCardLinkOperation) {
telegram
.sendMessage(`✅ [Billing / Check] Card linked for subscription workspace «${workspace.name}»`, TelegramBotURLs.Money)
.catch(e => console.error('Error while sending message to Telegram: ' + e));

res.json({
code: CheckCodes.SUCCESS,
} as CheckResponse);

return;
}

/**
* Create business operation about creation of subscription
*/
Expand Down

0 comments on commit 86f5840

Please sign in to comment.