chore: add recurring invoice proccesor logic

This commit is contained in:
mahyargdz
2025-03-11 11:52:46 +03:30
parent fdf1bc908c
commit 4503721b90
17 changed files with 310 additions and 36 deletions
+1
View File
@@ -42,4 +42,5 @@ export type TemplateParams =
| "dueDate"
| "user"
| "subject"
| "planName"
| "message";
@@ -429,6 +429,69 @@ export class SmsService {
// throw new InternalServerErrorException("error in sending sms");
}
}
// //************************************************* */
async sendRecurringInvoiceDraftSms(adminMobile: string, invoiceId: string, price: number) {
const smsData: ISmsVerifyBody = {
Parameters: [
{ name: "invoiceId", value: invoiceId },
{ name: "price", value: Intl.NumberFormat("fa-IR").format(price) },
],
Mobile: adminMobile,
TemplateId: this.smsConfigs.SMS_PATTERN_RECURRING_INVOICE_DRAFT,
};
try {
const { data } = await firstValueFrom(
this.httpService
.post<ISmsVerifyResponse>(`${this.smsConfigs.API_URL}/send/verify`, smsData, {
headers: { "X-API-KEY": this.smsConfigs.API_KEY },
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error("error in sending recurring invoice draft sms", err);
throw new InternalServerErrorException("error in sending recurring invoice draft sms");
}),
),
);
return data;
} catch (error) {
this.logger.error("error in sending sms", error);
throw new InternalServerErrorException("error in sending sms");
}
}
// //************************************************* */
async sendBlockServiceSms(mobile: string, invoiceId: string, planName: string) {
const smsData: ISmsVerifyBody = {
Parameters: [
{ name: "invoiceId", value: invoiceId },
{ name: "planName", value: planName },
],
Mobile: mobile,
TemplateId: this.smsConfigs.SMS_PATTERN_SUBSCRIPTION_CANCELLED,
};
try {
const { data } = await firstValueFrom(
this.httpService
.post<ISmsVerifyResponse>(`${this.smsConfigs.API_URL}/send/verify`, smsData, {
headers: { "X-API-KEY": this.smsConfigs.API_KEY },
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error("error in sending subscription cancelled sms", err);
throw new InternalServerErrorException("error in sending subscription cancelled sms");
}),
),
);
return data;
} catch (error) {
this.logger.error("error in sending sms", error);
throw new InternalServerErrorException("error in sending sms");
}
}
// //************************************************* */