chore: implenet the external invoice 2
This commit is contained in:
@@ -562,7 +562,7 @@ export class InvoicesService {
|
||||
|
||||
await queryRunner.manager.save(Wallet, userWallet);
|
||||
|
||||
if (invoice.items[0]?.subscriptionPlan) {
|
||||
if (invoice.items[0]?.subscriptionPlan && !invoice.isExternal) {
|
||||
const userSubscription = invoice.items[0].subscriptionPlan;
|
||||
userSubscription.status = SubscriptionStatus.ACTIVE;
|
||||
|
||||
@@ -573,7 +573,7 @@ export class InvoicesService {
|
||||
await this.addNotifyAdminForSubscriptionPaymentToQueue(invoice);
|
||||
|
||||
//
|
||||
} else if (invoice.items[0]?.supportPlan) {
|
||||
} else if (invoice.items[0]?.supportPlan && !invoice.isExternal) {
|
||||
const oldUserSupportPlan = await queryRunner.manager.findOne(UserSupportPlan, {
|
||||
where: { user: { id: user.id }, status: UserSupportPlanStatus.ACTIVE },
|
||||
});
|
||||
@@ -594,6 +594,11 @@ export class InvoicesService {
|
||||
await this.addNotifyForWalletDeduction(invoice, user, userWallet, WalletMessage.INVOICE_WALLET_TRANSFER);
|
||||
}
|
||||
|
||||
invoice.status = InvoiceStatus.PAID;
|
||||
invoice.paidAt = dayjs().toDate();
|
||||
|
||||
await queryRunner.manager.save(Invoice, invoice);
|
||||
|
||||
if (invoice.isExternal && invoice.items?.[0]?.subscriptionPlan) {
|
||||
const externalInvoiceJobData: IExternalInvoiceJob = {
|
||||
invoice,
|
||||
@@ -604,18 +609,14 @@ export class InvoicesService {
|
||||
};
|
||||
|
||||
await this.externalInvoiceQueue.add(INVOICE.EXTERNAL_CALLBACK_JOB_NAME, externalInvoiceJobData, {
|
||||
delay: dayjs().add(5000, "millisecond").diff(dayjs()),
|
||||
// delay: dayjs().add(10000, "millisecond").diff(dayjs()),
|
||||
delay: 5000,
|
||||
attempts: INVOICE.EXTERNAL_JOB_ATTEMPTS,
|
||||
backoff: { type: "exponential", delay: INVOICE.EXTERNAL_JOB_BACKOFF },
|
||||
priority: INVOICE.EXTERNAL_JOB_PRIORITY,
|
||||
});
|
||||
}
|
||||
|
||||
invoice.status = InvoiceStatus.PAID;
|
||||
invoice.paidAt = dayjs().toDate();
|
||||
|
||||
await queryRunner.manager.save(Invoice, invoice);
|
||||
|
||||
await this.notificationQueue.addBillInvoiceNotification(userId, {
|
||||
invoiceId: invoice.numericId.toString(),
|
||||
dueDate: invoice.dueDate,
|
||||
@@ -816,7 +817,7 @@ export class InvoicesService {
|
||||
items: invoiceItems,
|
||||
tax: tax.toNumber(),
|
||||
dueDate,
|
||||
status: InvoiceStatus.PENDING,
|
||||
status: InvoiceStatus.WAIT_PAYMENT,
|
||||
isRecurring: createDto.isRecurring,
|
||||
recurringPeriod: createDto.recurringPeriod,
|
||||
maxRecurringCycles: createDto.maxRecurringCycles,
|
||||
|
||||
@@ -6,7 +6,7 @@ import { catchError, firstValueFrom } from "rxjs";
|
||||
import { SmsMessage } from "../../../common/enums/message.enum";
|
||||
import { ISmsConfigs } from "../../../configs/sms.config";
|
||||
import { SMS_CONFIG } from "../constants";
|
||||
import { numberFormat } from "./international.utils";
|
||||
import { dateFormat, numberFormat } from "./international.utils";
|
||||
import { truncateIfLong } from "./string.utils";
|
||||
import { ISmsGetLineResponse, ISmsVerifyBody, ISmsVerifyResponse } from "../interfaces/ISms";
|
||||
|
||||
@@ -341,7 +341,7 @@ export class SmsService {
|
||||
const smsData: ISmsVerifyBody = {
|
||||
Parameters: [
|
||||
{ name: "invoiceId", value: invoiceId },
|
||||
{ name: "price", value: Intl.NumberFormat("fa-IR").format(price) },
|
||||
{ name: "price", value: numberFormat(price) },
|
||||
{ name: "dueDate", value: dueDate },
|
||||
],
|
||||
Mobile: mobile,
|
||||
@@ -368,12 +368,12 @@ export class SmsService {
|
||||
}
|
||||
}
|
||||
//************************************************* */
|
||||
async sendInvoicePaidSms(mobile: string, invoiceId: string, amount: number, paidDate: string) {
|
||||
async sendInvoicePaidSms(mobile: string, invoiceId: string, price: number, paidDate: string) {
|
||||
const smsData: ISmsVerifyBody = {
|
||||
Parameters: [
|
||||
{ name: "invoiceId", value: invoiceId },
|
||||
{ name: "amount", value: numberFormat(amount) },
|
||||
{ name: "paidDate", value: paidDate },
|
||||
{ name: "price", value: numberFormat(price) },
|
||||
{ name: "date", value: dateFormat(paidDate) },
|
||||
],
|
||||
Mobile: mobile,
|
||||
TemplateId: this.smsConfigs.SMS_PATTERN_INVOICE_PAID,
|
||||
@@ -401,11 +401,11 @@ export class SmsService {
|
||||
|
||||
//************************************************* */
|
||||
|
||||
async sendInvoicePaymentReminderSms(mobile: string, invoiceId: string, amount: number, dueDate: string) {
|
||||
async sendInvoicePaymentReminderSms(mobile: string, invoiceId: string, price: number, dueDate: string) {
|
||||
const smsData: ISmsVerifyBody = {
|
||||
Parameters: [
|
||||
{ name: "invoiceId", value: invoiceId },
|
||||
{ name: "amount", value: numberFormat(amount) },
|
||||
{ name: "price", value: numberFormat(price) },
|
||||
{ name: "dueDate", value: dueDate },
|
||||
],
|
||||
Mobile: mobile,
|
||||
|
||||
Reference in New Issue
Block a user