Skip to content

Commit 19a1b48

Browse files
committed
Fix subscription
1 parent 9439c45 commit 19a1b48

1 file changed

Lines changed: 16 additions & 21 deletions

File tree

src/billing/cloudpayments.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export default class CloudPaymentsWebhooks {
135135
}
136136
const invoiceId = this.generateInvoiceId(tariffPlan, workspace);
137137

138-
const isCardLinkOperation = workspace.tariffPlanId.toString() === tariffPlanId && !this.isPlanExpired(workspace);
138+
const isCardLinkOperation = workspace.tariffPlanId.toString() === tariffPlanId && !workspace.isTariffPlanExpired();
139139

140140
let checksum;
141141

@@ -173,26 +173,6 @@ export default class CloudPaymentsWebhooks {
173173
});
174174
}
175175

176-
/**
177-
* Returns true if workspace's plan is expired
178-
* @param workspace - workspace to check
179-
*/
180-
private isPlanExpired(workspace: WorkspaceModel): boolean {
181-
const lastChargeDate = new Date(workspace.lastChargeDate);
182-
183-
let planExpiracyDate;
184-
185-
if (workspace.isDebug) {
186-
planExpiracyDate = lastChargeDate.setDate(lastChargeDate.getDate() + 1);
187-
} else {
188-
planExpiracyDate = lastChargeDate.setMonth(lastChargeDate.getMonth() + 1);
189-
}
190-
191-
const isPlanExpired = planExpiracyDate < Date.now();
192-
193-
return isPlanExpired;
194-
}
195-
196176
/**
197177
* Generates invoice id for payment
198178
*
@@ -216,6 +196,8 @@ export default class CloudPaymentsWebhooks {
216196
const context = req.context;
217197
const body: CheckRequest = req.body;
218198
let data;
199+
200+
console.log('💎 CloudPayments /check request', body);
219201

220202
try {
221203
data = await this.getDataFromRequest(req);
@@ -326,6 +308,8 @@ export default class CloudPaymentsWebhooks {
326308
const body: PayRequest = req.body;
327309
let data;
328310

311+
console.log('💎 CloudPayments /pay request', body);
312+
329313
try {
330314
data = await this.getDataFromRequest(req);
331315
} catch (e) {
@@ -559,6 +543,8 @@ export default class CloudPaymentsWebhooks {
559543
const body: FailRequest = req.body;
560544
let data: PlanProlongationPayload;
561545

546+
console.log('💎 CloudPayments /fail request', body);
547+
562548
try {
563549
data = await this.getDataFromRequest(req);
564550
} catch (e) {
@@ -571,6 +557,10 @@ export default class CloudPaymentsWebhooks {
571557
let workspace;
572558
let user;
573559

560+
/**
561+
* @todo handle card linking and update business operation status
562+
*/
563+
574564
if (!data.workspaceId || !data.userId || !data.tariffPlanId) {
575565
this.sendError(res, FailCodes.SUCCESS, `[Billing / Fail] No workspace or user id or plan id in request body`, body);
576566

@@ -637,6 +627,8 @@ export default class CloudPaymentsWebhooks {
637627
const body: RecurrentRequest = req.body;
638628
const context = req.context;
639629

630+
console.log('💎 CloudPayments /recurrent request', body);
631+
640632
this.handleSendingToTelegramError(telegram.sendMessage(`[Billing / Recurrent] New recurrent event with ${body.Status} status`, TelegramBotURLs.Money));
641633
HawkCatcher.send(new Error(`[Billing / Recurrent] New recurrent event with ${body.Status} status`), req.body);
642634

@@ -785,6 +777,9 @@ export default class CloudPaymentsWebhooks {
785777
code: errorCode,
786778
});
787779

780+
console.log(errorText, backtrace);
781+
console.log('We responded with an error code to CloudPayments: ' + errorCode);
782+
788783
this.handleSendingToTelegramError(telegram.sendMessage(`❌ ${errorText}`, TelegramBotURLs.Money));
789784

790785
HawkCatcher.send(new Error(errorText), backtrace);

0 commit comments

Comments
 (0)