verify payment
This commit is contained in:
@@ -257,17 +257,14 @@ export class PaymentsService {
|
||||
);
|
||||
}
|
||||
|
||||
async verifyCashPayment(id: string): Promise<Payment> {
|
||||
return this.verifyManualPayment(id, PaymentMethodEnum.Cash, PaymentMessage.PAYMENT_METHOD_NOT_CASH);
|
||||
async verifyCashAnCreditPayment(id: string): Promise<Payment> {
|
||||
return this.verifyManualPayment(id, [PaymentMethodEnum.Cash, PaymentMethodEnum.CreditCard], PaymentMessage.PAYMENT_METHOD_NOT_CASH);
|
||||
}
|
||||
|
||||
async verifyCreditCardPayment(id: string): Promise<Payment> {
|
||||
return this.verifyManualPayment(id, PaymentMethodEnum.CreditCard, PaymentMessage.PAYMENT_METHOD_NOT_CREDIT_CARD);
|
||||
}
|
||||
|
||||
private async verifyManualPayment(
|
||||
id: string,
|
||||
expectedMethod: PaymentMethodEnum,
|
||||
expectedMethods: PaymentMethodEnum[],
|
||||
wrongMethodMessage: PaymentMessage,
|
||||
): Promise<Payment> {
|
||||
const payment = await this.em.transactional(async em => {
|
||||
@@ -275,7 +272,7 @@ export class PaymentsService {
|
||||
if (!payment) {
|
||||
throw new NotFoundException(PaymentMessage.PAYMENT_NOT_FOUND);
|
||||
}
|
||||
if (payment.method !== expectedMethod) {
|
||||
if (!expectedMethods.includes(payment.method)) {
|
||||
throw new BadRequestException(wrongMethodMessage);
|
||||
}
|
||||
if (payment.status === PaymentStatusEnum.Paid) {
|
||||
|
||||
Reference in New Issue
Block a user