Skip to content

Commit 91ffc01

Browse files
Merge pull request #510 from codex-team/fix/payment-tg-messages
fix(payments): Improve telegram notifications
2 parents 5eb4f34 + 2ba5d72 commit 91ffc01

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
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.28",
3+
"version": "1.1.29",
44
"main": "index.ts",
55
"license": "UNLICENSED",
66
"scripts": {

src/billing/cloudpayments.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,26 @@ plan monthly charge: ${data.cloudPayments?.recurrent.amount} ${body.Currency}`
557557

558558
await this.sendReceipt(workspace, tariffPlan, userEmail);
559559

560-
this.handleSendingToTelegramError(telegram.sendMessage(`✅ [Billing / Pay] New payment
560+
let messageText = '';
561+
562+
if (data.cloudPayments?.recurrent.startDate) {
563+
messageText = `✅ [Billing / Pay] New payment
561564
562565
amount: ${+body.Amount} ${body.Currency}
563566
next payment date: ${data.cloudPayments?.recurrent.startDate}
564567
workspace id: ${workspace._id}
565568
date of operation: ${body.DateTime}
566-
subscription id: ${body.SubscriptionId}`
567-
, TelegramBotURLs.Money));
569+
subscription id: ${body.SubscriptionId}`;
570+
} else {
571+
messageText = `✅ [Billing / Pay] New Recurrent payment
572+
573+
amount: ${+body.Amount} ${body.Currency}
574+
workspace id: ${workspace._id}
575+
date of operation: ${body.DateTime}
576+
subscription id: ${body.SubscriptionId}`;
577+
}
578+
579+
this.handleSendingToTelegramError(telegram.sendMessage(messageText, TelegramBotURLs.Money));
568580
}
569581
} catch (e) {
570582
const error = e as Error;
@@ -676,14 +688,17 @@ subscription id: ${body.SubscriptionId}`
676688

677689
console.log('💎 CloudPayments /recurrent request', body);
678690

679-
this.handleSendingToTelegramError(telegram.sendMessage(`✅ [Billing / Recurrent] New recurrent transaction
691+
const emoji = [SubscriptionStatus.CANCELLED, SubscriptionStatus.REJECTED].includes(body.Status) ? '❌' : '✅';
692+
693+
this.handleSendingToTelegramError(telegram.sendMessage(`${emoji} [Billing / Recurrent] New recurrent event
680694
681695
amount: ${+body.Amount} ${body.Currency}
682696
next payment date: ${body.NextTransactionDate}
683697
workspace id: ${body.AccountId}
684698
subscription id: ${body.Id}
685699
status: ${body.Status}`
686700
, TelegramBotURLs.Money));
701+
687702
HawkCatcher.send(new Error(`[Billing / Recurrent] New recurrent event with ${body.Status} status`), req.body);
688703

689704
switch (body.Status) {

0 commit comments

Comments
 (0)