mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { Service, Inject } from 'typedi';
|
|
import events from '@/subscribers/events';
|
|
import { PaymentReceiveNotifyBySms } from '@/services/Sales/PaymentReceived/PaymentReceivedSmsNotify';
|
|
import { IPaymentReceivedCreatedPayload } from '@/interfaces';
|
|
import { runAfterTransaction } from '@/services/UnitOfWork/TransactionsHooks';
|
|
|
|
@Service()
|
|
export default class SendSmsNotificationPaymentReceive {
|
|
@Inject()
|
|
private paymentReceiveSmsNotify: PaymentReceiveNotifyBySms;
|
|
|
|
/**
|
|
* Attach events.
|
|
*/
|
|
public attach(bus) {
|
|
bus.subscribe(
|
|
events.paymentReceive.onCreated,
|
|
this.handleNotifyViaSmsOncePaymentPublish
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Handles send SMS notification after payment transaction creation.
|
|
*/
|
|
private handleNotifyViaSmsOncePaymentPublish = ({
|
|
tenantId,
|
|
paymentReceiveId,
|
|
trx,
|
|
}: IPaymentReceivedCreatedPayload) => {
|
|
// Notify via Sms after transactions complete running.
|
|
runAfterTransaction(trx, async () => {
|
|
try {
|
|
await this.paymentReceiveSmsNotify.notifyViaSmsNotificationAfterCreation(
|
|
tenantId,
|
|
paymentReceiveId
|
|
);
|
|
} catch (error) { }
|
|
});
|
|
};
|
|
}
|