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.8",
"version": "1.1.9",
"main": "index.ts",
"license": "UNLICENSED",
"scripts": {
Expand Down
18 changes: 13 additions & 5 deletions src/billing/cloudpayments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import { ComposePaymentPayload } from './types/composePaymentPayload';

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

Check warning on line 49 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 @@ -173,7 +173,7 @@
});
}

/**

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

View workflow job for this annotation

GitHub Actions / ESlint

Missing JSDoc @returns for function
* Returns true if workspace's plan is expired
* @param workspace - workspace to check
*/
Expand All @@ -193,7 +193,7 @@
return isPlanExpired;
}

/**

Check warning on line 196 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 @@ -267,8 +267,7 @@
let member: ConfirmedMemberDBScheme;
let plan: PlanDBScheme;


if (!data.isCardLinkOperation && (!data.userId || !data.workspaceId || !data.tariffPlanId)) {
if (!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);

return;
Expand Down Expand Up @@ -334,7 +333,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 336 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 @@ -362,7 +361,13 @@
return;
}

if (!data.workspaceId || !data.tariffPlanId || !data.userId) {
if (data.isCardLinkOperation && (!data.userId || !data.workspaceId)) {
this.sendError(res, PayCodes.SUCCESS, '[Billing / Pay] No workspace or user id in request body', req.body);

return;
}

if (!data.isCardLinkOperation && (!data.workspaceId || !data.tariffPlanId || !data.userId)) {
this.sendError(res, PayCodes.SUCCESS, `[Billing / Pay] No workspace, tariff plan or user id in request body`, body);

return;
Expand All @@ -372,12 +377,15 @@
let workspace;
let tariffPlan;
let user;
let planId;

try {
businessOperation = await this.getBusinessOperation(req, body.TransactionId.toString());
workspace = await this.getWorkspace(req, data.workspaceId);
tariffPlan = await this.getPlan(req, data.tariffPlanId);
user = await this.getUser(req, data.userId);
planId = data.isCardLinkOperation ? workspace.tariffPlanId.toString() : data.tariffPlanId;

tariffPlan = await this.getPlan(req, planId);
} catch (e) {
const error = e as Error;

Expand Down Expand Up @@ -475,7 +483,7 @@
type: SenderWorkerTaskType.PaymentSuccess,
payload: {
workspaceId: data.workspaceId,
tariffPlanId: data.tariffPlanId,
tariffPlanId: planId,
userId: data.userId,
},
};
Expand Down Expand Up @@ -612,7 +620,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 623 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 Down Expand Up @@ -773,7 +781,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 784 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 @@ -835,7 +843,7 @@
promise.catch(e => console.error('Error while sending message to Telegram: ' + e));
}

/**

Check warning on line 846 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