Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.22",
"version": "1.1.23",
"main": "index.ts",
"license": "UNLICENSED",
"scripts": {
Expand Down
29 changes: 23 additions & 6 deletions src/billing/cloudpayments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
const PENNY_MULTIPLIER = 100;

interface ComposePaymentRequest extends express.Request {
query: ComposePaymentPayload & { [key: string]: any };

Check warning on line 50 in src/billing/cloudpayments.ts

View workflow job for this annotation

GitHub Actions / ESlint

Unexpected any. Specify a different type
context: import('../types/graphql').ResolverContextBase;
};

Expand Down Expand Up @@ -185,6 +185,16 @@
return;
}

this.handleSendingToTelegramError(telegram.sendMessage(`✅ [Billing / Compose payment]

card link operation: ${isCardLinkOperation}
amount: ${+tariffPlan.monthlyCharge} RUB
last charge date: ${workspace.lastChargeDate?.toISOString()}
next payment date: ${nextPaymentDate.toISOString()}
workspace id: ${workspace._id.toString()}
debug: ${Boolean(workspace.isDebug)}`
, TelegramBotURLs.Money));

res.send({
invoiceId,
plan: {
Expand All @@ -199,7 +209,7 @@
});
}

/**

Check warning on line 212 in src/billing/cloudpayments.ts

View workflow job for this annotation

GitHub Actions / ESlint

Missing JSDoc @returns for function
* Generates invoice id for payment
*
* @param tariffPlan - tariff plan to generate invoice id
Expand Down Expand Up @@ -294,7 +304,7 @@
status: BusinessOperationStatus.Pending,
payload: {
workspaceId: workspace._id,
amount: +body.Amount,
amount: +body.Amount * PENNY_MULTIPLIER,
currency: body.Currency,
userId: member._id,
tariffPlanId: plan._id,
Expand All @@ -316,7 +326,7 @@
telegram.sendMessage(`✅ [Billing / Check] All checks passed successfully «${workspace.name}»`, TelegramBotURLs.Money)
.catch(e => console.error('Error while sending message to Telegram: ' + e));

HawkCatcher.send(new Error('[Billing / Check] All checks passed successfully'), body as any);

Check warning on line 329 in src/billing/cloudpayments.ts

View workflow job for this annotation

GitHub Actions / ESlint

Unexpected any. Specify a different type

res.json({
code: CheckCodes.SUCCESS,
Expand Down Expand Up @@ -531,7 +541,8 @@
workspace id: ${workspace._id}
date of operation: ${body.DateTime}
first payment date: ${data.cloudPayments?.recurrent.startDate}
sum: ${data.cloudPayments?.recurrent.amount}${body.Currency}`
card link charge: ${+body.Amount} ${body.Currency}
plan monthly charge: ${data.cloudPayments?.recurrent.amount} ${body.Currency}`
, TelegramBotURLs.Money));
} else {
/**
Expand Down Expand Up @@ -645,7 +656,7 @@

this.handleSendingToTelegramError(telegram.sendMessage(`❌ [Billing / Fail] Transaction failed for «${workspace.name}»`, TelegramBotURLs.Money));

HawkCatcher.send(new Error('[Billing / Fail] Transaction failed'), body as any);

Check warning on line 659 in src/billing/cloudpayments.ts

View workflow job for this annotation

GitHub Actions / ESlint

Unexpected any. Specify a different type

res.json({
code: FailCodes.SUCCESS,
Expand All @@ -670,7 +681,8 @@
amount: ${+body.Amount} ${body.Currency}
next payment date: ${body.NextTransactionDate}
workspace id: ${body.AccountId}
subscription id: ${body.Id}`
subscription id: ${body.Id}
status: ${body.Status}`
, TelegramBotURLs.Money));
HawkCatcher.send(new Error(`[Billing / Recurrent] New recurrent event with ${body.Status} status`), req.body);

Expand All @@ -680,6 +692,10 @@
let workspace;

try {
/**
* If there is a workspace with subscription id then subscription was cancelled via CloudPayments admin panel (or other no garage way)
* We need to remove subscription id from workspace
*/
workspace = await context.factories.workspacesFactory.findBySubscriptionId(body.Id);
} catch (e) {
const error = e as Error;
Expand All @@ -693,9 +709,10 @@
}

if (!workspace) {
this.sendError(res, RecurrentCodes.SUCCESS, `[Billing / Recurrent] Workspace with subscription id ${body.Id} not found`, {
body,
});
/**
* If no workspace found by subscription id then subscription is cancelled via garage and subscription id was set to null in mutation before this hook executed
* No need to send error
*/

return;
}
Expand Down Expand Up @@ -814,7 +831,7 @@
* @param errorText - error description
* @param backtrace - request data and error data
*/
private sendError(res: express.Response, errorCode: CheckCodes | PayCodes | FailCodes | RecurrentCodes, errorText: string, backtrace: { [key: string]: any }): void {

Check warning on line 834 in src/billing/cloudpayments.ts

View workflow job for this annotation

GitHub Actions / ESlint

Unexpected any. Specify a different type
res.json({
code: errorCode,
});
Expand Down Expand Up @@ -879,7 +896,7 @@
promise.catch(e => console.error('Error while sending message to Telegram: ' + e));
}

/**

Check warning on line 899 in src/billing/cloudpayments.ts

View workflow job for this annotation

GitHub Actions / ESlint

Missing JSDoc @returns for function
* Parses body and returns card data
* @param request - request body to parse
*/
Expand Down
Loading