verify cash paymnt
This commit is contained in:
@@ -9,6 +9,7 @@ import { UserWallet } from 'src/modules/users/entities/user-wallet.entity';
|
||||
import { OrderPaymentContext } from '../interface/payment';
|
||||
import { InventoryService } from 'src/modules/inventory/inventory.service';
|
||||
import { OrderStatus } from 'src/modules/orders/interface/order.interface';
|
||||
import { PaymentMethod } from '../entities/payment-method.entity';
|
||||
|
||||
@Injectable()
|
||||
export class PaymentsService {
|
||||
@@ -212,6 +213,29 @@ export class PaymentsService {
|
||||
);
|
||||
}
|
||||
|
||||
async verifyCashPayment(id: string): Promise<Payment> {
|
||||
const payment = await this.em.transactional(async em => {
|
||||
const payment = await em.findOne(Payment, id, { populate: ['order'] });
|
||||
if (!payment) {
|
||||
throw new NotFoundException('Payment not found');
|
||||
}
|
||||
if (payment.method !== PaymentMethodEnum.Cash) {
|
||||
throw new BadRequestException('Payment method is not cash');
|
||||
}
|
||||
if (payment.status === PaymentStatusEnum.Paid) {
|
||||
throw new BadRequestException('Payment already paid');
|
||||
}
|
||||
payment.order.status = OrderStatus.PAID;
|
||||
payment.status = PaymentStatusEnum.Paid;
|
||||
payment.paidAt = new Date();
|
||||
em.persist(payment);
|
||||
em.persist(payment.order);
|
||||
await em.flush();
|
||||
return payment;
|
||||
});
|
||||
return payment;
|
||||
}
|
||||
|
||||
private markPaid(payment: Payment, referenceId: string) {
|
||||
payment.status = PaymentStatusEnum.Paid;
|
||||
payment.paidAt = new Date();
|
||||
|
||||
Reference in New Issue
Block a user