bugs
This commit is contained in:
+5
-5
@@ -1,5 +1,5 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Query } from '@nestjs/common';
|
||||
import { PaymentsService } from '../services/payments.service';
|
||||
import { PaymentService } from '../services/payments.service';
|
||||
import {
|
||||
ApiTags,
|
||||
ApiOperation,
|
||||
@@ -23,9 +23,9 @@ import { PayOrderDto } from '../dto/pay-order.dto';
|
||||
|
||||
@ApiTags('payments')
|
||||
@Controller()
|
||||
export class PaymentsController {
|
||||
export class PaymentController {
|
||||
constructor(
|
||||
private readonly paymentsService: PaymentsService,
|
||||
private readonly paymentsService: PaymentService,
|
||||
) { }
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ export class PaymentsController {
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Pay for an order' })
|
||||
payAnOrder(@Param('orderId') orderId: string,@Body() dto :PayOrderDto) {
|
||||
return this.paymentsService.payOrder(orderId,dto);
|
||||
payAnOrder(@Param('orderId') orderId: string, @Body() dto: PayOrderDto) {
|
||||
return this.paymentsService.payOrder(orderId, dto);
|
||||
}
|
||||
|
||||
// @Post('public/payments/verify')
|
||||
@@ -6,7 +6,7 @@ import { Permission } from 'src/common/enums/permission.enum';
|
||||
import { NotifTitleEnum } from 'src/modules/notification/interfaces/notification.interface';
|
||||
import { NotificationService } from 'src/modules/notification/services/notification.service';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { OrdersService } from 'src/modules/order/providers/orders.service';
|
||||
import { OrderService } from 'src/modules/order/providers/order.service';
|
||||
|
||||
@Injectable()
|
||||
export class PaymentListeners {
|
||||
@@ -17,7 +17,7 @@ export class PaymentListeners {
|
||||
private readonly adminService: AdminRepository,
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly orderService: OrdersService,
|
||||
private readonly orderService: OrderService,
|
||||
) {
|
||||
this.orderCreatedSmsTemplateId = this.configService.get<string>('SMS_PATTERN_ORDER_CREATED') ?? '123';
|
||||
this.paymentSucceedSmsTemplateId = this.configService.get<string>('SMS_PATTERN_ONLINE_PAYMENT_SUCCEED') ?? '123';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Module, forwardRef } from '@nestjs/common';
|
||||
import { PaymentsService } from './services/payments.service';
|
||||
import { PaymentService } from './services/payments.service';
|
||||
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
||||
import { PaymentsController } from './controllers/payments.controller';
|
||||
import { PaymentController } from './controllers/payment.controller';
|
||||
import { AuthModule } from '../auth/auth.module';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { Payment } from './entities/payment.entity';
|
||||
@@ -12,17 +12,29 @@ import { PaymentListeners } from './listeners/payment.listeners';
|
||||
import { AdminModule } from '../admin/admin.module';
|
||||
import { NotificationsModule } from '../notification/notifications.module';
|
||||
import { OrderModule } from '../order/order.module';
|
||||
import { UserModule } from '../user/user.module';
|
||||
|
||||
@Module({
|
||||
imports: [MikroOrmModule.forFeature([Payment]),
|
||||
AuthModule, JwtModule, AdminModule, NotificationsModule,
|
||||
forwardRef(() => OrderModule)],
|
||||
controllers: [PaymentsController],
|
||||
providers: [PaymentsService,
|
||||
PaymentRepository, ZarinpalGateway, GatewayManager, PaymentListeners],
|
||||
imports: [
|
||||
MikroOrmModule.forFeature([Payment]),
|
||||
AuthModule,
|
||||
JwtModule,
|
||||
AdminModule,
|
||||
NotificationsModule,
|
||||
forwardRef(() => OrderModule),
|
||||
UserModule
|
||||
],
|
||||
controllers: [PaymentController],
|
||||
providers: [
|
||||
PaymentService,
|
||||
PaymentRepository,
|
||||
ZarinpalGateway,
|
||||
GatewayManager,
|
||||
PaymentListeners
|
||||
],
|
||||
exports: [
|
||||
PaymentRepository,
|
||||
PaymentsService,
|
||||
PaymentService,
|
||||
// PaymentGatewayService,
|
||||
],
|
||||
})
|
||||
|
||||
@@ -19,8 +19,8 @@ import { Payment } from '../entities/payment.entity';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class PaymentsService {
|
||||
private readonly logger = new Logger(PaymentsService.name);
|
||||
export class PaymentService {
|
||||
private readonly logger = new Logger(PaymentService.name);
|
||||
|
||||
constructor(
|
||||
private readonly em: EntityManager,
|
||||
@@ -211,7 +211,6 @@ export class PaymentsService {
|
||||
// TODO : use decimal js
|
||||
// does need persist or not
|
||||
payment.order.paidAmount += payment.amount
|
||||
payment.order.balance = payment.order.total - payment.order.paidAmount
|
||||
|
||||
await em.flush();
|
||||
return payment;
|
||||
@@ -249,7 +248,6 @@ export class PaymentsService {
|
||||
|
||||
// TODO : use decimal js
|
||||
payment.order.paidAmount += payment.amount
|
||||
payment.order.balance = payment.order.total - payment.order.paidAmount
|
||||
|
||||
em.persist(payment);
|
||||
em.persist(payment.order);
|
||||
@@ -259,57 +257,5 @@ export class PaymentsService {
|
||||
return payment;
|
||||
}
|
||||
|
||||
// private markPaid(payment: Payment, referenceId: string) {
|
||||
// payment.status = PaymentStatusEnum.Paid;
|
||||
// payment.paidAt = new Date();
|
||||
// payment.referenceId = referenceId;
|
||||
// }
|
||||
|
||||
// private failPayment(payment: Payment) {
|
||||
// payment.status = PaymentStatusEnum.Failed;
|
||||
// payment.failedAt = new Date();
|
||||
// payment.order.status = OrderStatus.CANCELED;
|
||||
// }
|
||||
|
||||
|
||||
// private async getOrCreateLatestPendingPayment(
|
||||
// orderId: string,
|
||||
// params: {
|
||||
// amount: number;
|
||||
// method: PaymentMethodEnum;
|
||||
// gateway: PaymentGatewayEnum | null;
|
||||
// em?: EntityManager;
|
||||
// },
|
||||
// ): Promise<Payment> {
|
||||
// const em = params.em ?? this.em;
|
||||
|
||||
// const existing = await em.findOne(
|
||||
// Payment,
|
||||
// { order: { id: orderId }, status: PaymentStatusEnum.Pending },
|
||||
// { orderBy: { createdAt: 'DESC' } },
|
||||
// );
|
||||
|
||||
// if (existing) {
|
||||
// if (existing.method !== params.method) {
|
||||
// throw new BadRequestException(PaymentMessage.EXISTING_PENDING_PAYMENT_MISMATCH);
|
||||
// }
|
||||
|
||||
// return existing;
|
||||
// }
|
||||
|
||||
// const orderRef = em.getReference(Order, orderId);
|
||||
// const payment = em.create(Payment, {
|
||||
// amount: params.amount,
|
||||
// order: orderRef,
|
||||
// method: params.method,
|
||||
// gateway: params.gateway,
|
||||
// transactionId: null,
|
||||
// status: PaymentStatusEnum.Pending,
|
||||
// });
|
||||
|
||||
// em.persist(payment);
|
||||
// await em.flush();
|
||||
// return payment;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user