This commit is contained in:
2025-12-03 23:07:36 +03:30
parent ccabe04b60
commit 4e2bf34ab4
3 changed files with 21 additions and 36 deletions
@@ -150,7 +150,7 @@ export class PaymentsService {
return null;
}
async verifyPayment(authority: string, amount: number | undefined, orderId: string): Promise<Payment> {
async verifyPayment(authority: string, orderId: string): Promise<Payment> {
// Find payment by authority and orderId
const payment = await this.em.findOne(
Payment,
@@ -177,12 +177,12 @@ export class PaymentsService {
}
// For non-online payments, mark as paid directly
if (paymentMethod.method !== PaymentMethodEnum.Online) {
payment.status = PaymentStatusEnum.Paid;
payment.paidAt = new Date();
await this.em.persistAndFlush(payment);
return payment;
}
// if (paymentMethod.method !== PaymentMethodEnum.Online) {
// payment.status = PaymentStatusEnum.Paid;
// payment.paidAt = new Date();
// await this.em.persistAndFlush(payment);
// return payment;
// }
// Online payments require gateway verification
if (!paymentMethod.merchantId) {
@@ -193,13 +193,12 @@ export class PaymentsService {
throw new BadRequestException('Payment gateway is required for online payment verification');
}
// Use provided amount or payment amount
const verifyAmount = amount || payment.amount;
// Use payment amount
const verifyAmount = payment.amount;
// Handle ZarinPal gateway verification
if (payment.gateway === PaymentGatewayEnum.ZarinPal) {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const verifyResponse = await this.verifyZarinPalPayment({
merchantId: paymentMethod.merchantId,
amount: verifyAmount,
@@ -211,18 +210,13 @@ export class PaymentsService {
throw new BadRequestException('Invalid verification response from payment gateway');
}
// Type assertion after type guard
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const response: IPaymentVerifyResponse = verifyResponse as IPaymentVerifyResponse;
const response = verifyResponse;
// Check verification response code (100 means success for ZarinPal)
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (response.code === 100) {
// Payment successful
payment.status = PaymentStatusEnum.Paid;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
payment.refId = String(response.refId);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
payment.cardPan = response.cardPan;
payment.verifyResponse = response as unknown as Record<string, any>;
payment.paidAt = new Date();