online order notif after success
This commit is contained in:
@@ -10,6 +10,8 @@ import { OrderPaymentContext } from '../interface/payment';
|
||||
import { OrderStatus } from 'src/modules/orders/interface/order.interface';
|
||||
import { ChartPeriodEnum, PaymentChartDto } from '../dto/payment-chart.dto';
|
||||
import { PaymentMessage, OrderMessage } from 'src/common/enums/message.enum';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import { onlinePaymentSucceedEvent, paymentSucceedEvent } from '../events/payment.events';
|
||||
|
||||
@Injectable()
|
||||
export class PaymentsService {
|
||||
@@ -18,6 +20,7 @@ export class PaymentsService {
|
||||
constructor(
|
||||
private readonly em: EntityManager,
|
||||
private readonly gatewayManager: GatewayManager,
|
||||
private readonly eventEmitter: EventEmitter2,
|
||||
) { }
|
||||
|
||||
async payOrder(orderId: string): Promise<{ paymentUrl: string | null }> {
|
||||
@@ -127,6 +130,10 @@ export class PaymentsService {
|
||||
em.persist([wallet, payment, order]);
|
||||
await em.flush();
|
||||
});
|
||||
this.eventEmitter.emit(
|
||||
paymentSucceedEvent.name,
|
||||
new paymentSucceedEvent(ctx.order.id, ctx.order.restaurant.id, String(ctx.order?.orderNumber) || '', ctx.method, ctx.amount),
|
||||
);
|
||||
}
|
||||
|
||||
private async handleOnlinePayment(ctx: OrderPaymentContext): Promise<{ paymentUrl: string }> {
|
||||
@@ -162,7 +169,7 @@ export class PaymentsService {
|
||||
}
|
||||
|
||||
async verifyPayment(transactionId: string, orderId: string): Promise<Payment> {
|
||||
return this.em.transactional(async em => {
|
||||
const payment =await this.em.transactional(async em => {
|
||||
const payment = await em.findOne(
|
||||
Payment,
|
||||
{ transactionId, order: { id: orderId } },
|
||||
@@ -202,6 +209,11 @@ export class PaymentsService {
|
||||
await em.flush();
|
||||
return payment;
|
||||
});
|
||||
this.eventEmitter.emit(
|
||||
onlinePaymentSucceedEvent.name ,
|
||||
new onlinePaymentSucceedEvent(payment.id, payment.order.restaurant.id, String(payment.order?.orderNumber) || '', payment.amount),
|
||||
);
|
||||
return payment;
|
||||
}
|
||||
|
||||
findAllByRestaurantId(restId: string, userId: string) {
|
||||
|
||||
Reference in New Issue
Block a user