Track SMS sent counts by type (mass, singular, auth, auto, admin).

Charge/refund bump the matching counter plus total; expose smsSentByType on business APIs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-09-09 11:31:17 +03:30
co-authored by Cursor
parent 717a203d48
commit a2dacfdc97
9 changed files with 156 additions and 22 deletions
+11 -2
View File
@@ -728,7 +728,12 @@ export class CustomersService {
},
);
const charged = await this.smsBilling.charge(businessId, resolved.message);
const charged = await this.smsBilling.charge(
businessId,
resolved.message,
1,
'singular',
);
try {
const result = await this.sms.sendMessage(
@@ -745,7 +750,7 @@ export class CustomersService {
templateVerified: resolved.templateVerified,
};
} catch (err) {
await this.smsBilling.refund(businessId, charged);
await this.smsBilling.refund(businessId, charged, 1, 'singular');
if (
err instanceof BadRequestException ||
err instanceof ServiceUnavailableException
@@ -883,6 +888,7 @@ export class CustomersService {
businessId,
sample.message,
recipients.length,
'mass',
);
} else {
personalizedPayloads = [];
@@ -912,6 +918,7 @@ export class CustomersService {
businessId,
totalCost,
personalizedPayloads.length,
'mass',
);
}
@@ -950,6 +957,7 @@ export class CustomersService {
businessId,
refundAmount,
remaining.length,
'mass',
);
charged = 0;
throw err;
@@ -971,6 +979,7 @@ export class CustomersService {
businessId,
charged,
personalized ? personalizedPayloads.length : recipients.length,
'mass',
);
}
if (