farsi messages
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 { 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';
|
||||
|
||||
@Injectable()
|
||||
export class PaymentsService {
|
||||
@@ -40,7 +41,7 @@ export class PaymentsService {
|
||||
return this.handleOnlinePayment(ctx);
|
||||
|
||||
default:
|
||||
throw new BadRequestException('Unsupported payment method');
|
||||
throw new BadRequestException(PaymentMessage.UNSUPPORTED_PAYMENT_METHOD);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,22 +53,22 @@ export class PaymentsService {
|
||||
);
|
||||
|
||||
if (!order) {
|
||||
throw new NotFoundException('Order not found');
|
||||
throw new NotFoundException(OrderMessage.NOT_FOUND);
|
||||
}
|
||||
|
||||
if (order.total <= 0) {
|
||||
throw new BadRequestException('Amount must be greater than zero');
|
||||
throw new BadRequestException(PaymentMessage.AMOUNT_MUST_BE_GREATER_THAN_ZERO);
|
||||
}
|
||||
|
||||
const pm = order.paymentMethod;
|
||||
if (!pm) {
|
||||
throw new NotFoundException('Payment method not found');
|
||||
throw new NotFoundException(PaymentMessage.PAYMENT_METHOD_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (pm.method === PaymentMethodEnum.Online) {
|
||||
if (!pm.gateway) throw new BadRequestException('Gateway is required for online payment');
|
||||
if (!pm.merchantId) throw new BadRequestException('Merchant ID is required for online payment');
|
||||
if (!pm.restaurant?.domain) throw new BadRequestException('Restaurant domain is required for online payment');
|
||||
if (!pm.gateway) throw new BadRequestException(PaymentMessage.GATEWAY_REQUIRED);
|
||||
if (!pm.merchantId) throw new BadRequestException(PaymentMessage.MERCHANT_ID_REQUIRED);
|
||||
if (!pm.restaurant?.domain) throw new BadRequestException(PaymentMessage.RESTAURANT_DOMAIN_REQUIRED);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -91,7 +92,7 @@ export class PaymentsService {
|
||||
private async handleWalletPayment(ctx: OrderPaymentContext): Promise<void> {
|
||||
await this.em.transactional(async em => {
|
||||
const order = await em.findOne(Order, { id: ctx.order.id }, { populate: ['user', 'restaurant'] });
|
||||
if (!order) throw new NotFoundException('Order not found');
|
||||
if (!order) throw new NotFoundException(OrderMessage.NOT_FOUND);
|
||||
|
||||
if (order.status === OrderStatus.PAID) {
|
||||
return;
|
||||
@@ -169,7 +170,7 @@ export class PaymentsService {
|
||||
);
|
||||
|
||||
if (!payment) {
|
||||
throw new NotFoundException('Payment not found');
|
||||
throw new NotFoundException(PaymentMessage.PAYMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (payment.status === PaymentStatusEnum.Paid) {
|
||||
@@ -178,7 +179,7 @@ export class PaymentsService {
|
||||
|
||||
const pm = payment.order.paymentMethod;
|
||||
if (!pm?.merchantId || !payment.gateway) {
|
||||
throw new BadRequestException('Invalid payment configuration');
|
||||
throw new BadRequestException(PaymentMessage.INVALID_PAYMENT_CONFIGURATION);
|
||||
}
|
||||
|
||||
const gateway = this.gatewayManager.get(payment.gateway);
|
||||
@@ -215,13 +216,13 @@ export class PaymentsService {
|
||||
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');
|
||||
throw new NotFoundException(PaymentMessage.PAYMENT_NOT_FOUND);
|
||||
}
|
||||
if (payment.method !== PaymentMethodEnum.Cash) {
|
||||
throw new BadRequestException('Payment method is not cash');
|
||||
throw new BadRequestException(PaymentMessage.PAYMENT_METHOD_NOT_CASH);
|
||||
}
|
||||
if (payment.status === PaymentStatusEnum.Paid) {
|
||||
throw new BadRequestException('Payment already paid');
|
||||
throw new BadRequestException(PaymentMessage.PAYMENT_ALREADY_PAID);
|
||||
}
|
||||
payment.order.status = OrderStatus.PAID;
|
||||
payment.status = PaymentStatusEnum.Paid;
|
||||
@@ -269,7 +270,7 @@ export class PaymentsService {
|
||||
|
||||
if (existing) {
|
||||
if (existing.method !== params.method) {
|
||||
throw new BadRequestException('Existing pending payment method does not match order payment method');
|
||||
throw new BadRequestException(PaymentMessage.EXISTING_PENDING_PAYMENT_MISMATCH);
|
||||
}
|
||||
|
||||
return existing;
|
||||
|
||||
Reference in New Issue
Block a user