register payment listener

This commit is contained in:
2025-12-24 23:57:16 +03:30
parent d78846fea9
commit 4716620a43
6 changed files with 17 additions and 11 deletions
@@ -64,7 +64,7 @@ export class PaymentsController {
@ApiBody({ type: VerifyPaymentDto })
@ApiNotFoundResponse({ description: 'Payment not found' })
verifyPayment(@Body() verifyPaymentDto: VerifyPaymentDto) {
return this.paymentsService.verifyPayment(verifyPaymentDto.authority, verifyPaymentDto.orderId);
return this.paymentsService.verifyOnlinePayment(verifyPaymentDto.authority, verifyPaymentDto.orderId);
}
/** admin routes */
@@ -15,6 +15,7 @@ export class paymentSucceedEvent {
export class onlinePaymentSucceedEvent {
constructor(
public readonly paymentId: string,
public readonly orderId: string,
public readonly restaurantId: string,
public readonly orderNumber: string,
public readonly total: number,
@@ -119,10 +119,10 @@ export class PaymentListeners {
},
});
const order = await this.orderService.findOne(event.paymentId, event.restaurantId);
const order = await this.orderService.findOne(event.orderId, event.restaurantId);
if (!order) {
this.logger.error(
`Order not found: ${event.paymentId} for restaurant: ${event.restaurantId}`,
`Order not found: ${event.orderId} for restaurant: ${event.restaurantId}`,
);
return;
}
+8 -3
View File
@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common';
import { Module, forwardRef } from '@nestjs/common';
import { PaymentsService } from './services/payments.service';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { PaymentMethod } from './entities/payment-method.entity';
@@ -13,13 +13,18 @@ import { ZarinpalGateway } from './gateways/zarinpal.gateway';
import { GatewayManager } from './gateways/gateway.manager';
import { PaymentRepository } from './repositories/payment.repository';
import { InventoryModule } from '../inventory/inventory.module';
import { PaymentListeners } from './listeners/payment.listeners';
import { AdminModule } from '../admin/admin.module';
import { NotificationsModule } from '../notifications/notifications.module';
import { OrdersModule } from '../orders/orders.module';
@Module({
imports: [MikroOrmModule.forFeature([PaymentMethod, Payment, Restaurant]),
AuthModule, JwtModule, InventoryModule],
AuthModule, JwtModule, InventoryModule, AdminModule, NotificationsModule,
forwardRef(() => OrdersModule)],
controllers: [PaymentsController],
providers: [PaymentsService, PaymentMethodService, PaymentMethodRepository,
PaymentRepository, ZarinpalGateway, GatewayManager],
PaymentRepository, ZarinpalGateway, GatewayManager, PaymentListeners],
exports: [
PaymentMethodRepository,
PaymentRepository,
@@ -168,7 +168,7 @@ export class PaymentsService {
};
}
async verifyPayment(transactionId: string, orderId: string): Promise<Payment> {
async verifyOnlinePayment(transactionId: string, orderId: string): Promise<Payment> {
const payment = await this.em.transactional(async em => {
const payment = await em.findOne(
Payment,
@@ -214,7 +214,7 @@ export class PaymentsService {
});
this.eventEmitter.emit(
onlinePaymentSucceedEvent.name,
new onlinePaymentSucceedEvent(payment.id, payment.order.restaurant.id, String(payment.order?.orderNumber) || '', payment.amount),
new onlinePaymentSucceedEvent(payment.id, payment.order.id, payment.order.restaurant.id, String(payment.order?.orderNumber) || '', payment.amount),
);
return payment;
}