fix: resolve wallet topup callback and verify flow, fix admin orders BigInt serialization 500 error, and fix reactive B2B settings toggle
Deploy Canina / deploy (push) Successful in 1m41s
Deploy Canina / deploy (push) Successful in 1m41s
This commit is contained in:
1 parent
42707c04cf
commit
b527befe4a
10 files changed
+176
-29
No files matched your search
@@ -11,6 +11,7 @@ import {
|
||||
HttpStatus,
|
||||
Headers,
|
||||
Ip,
|
||||
BadRequestException,
|
||||
} from '@nestjs/common';
|
||||
import type { Request, Response } from 'express';
|
||||
import { PaymentService } from './payment.service';
|
||||
@@ -138,6 +139,25 @@ export class PaymentController {
|
||||
}
|
||||
}
|
||||
|
||||
@Get('zibal/verify')
|
||||
@ApiOperation({ summary: 'استعلام و تایید تراکنش زیبال توسط کلاینت' })
|
||||
async verifyPaymentDirect(
|
||||
@Query('trackId') trackId: string,
|
||||
@Query('success') success?: string,
|
||||
@Query('status') status?: string,
|
||||
@Query('orderId') orderId?: string,
|
||||
@Ip() ip?: string,
|
||||
@Headers('user-agent') userAgent?: string,
|
||||
) {
|
||||
if (!trackId) {
|
||||
throw new BadRequestException('trackId is required');
|
||||
}
|
||||
return this.paymentService.verifyAndProcess(trackId, success, status, orderId, {
|
||||
ipAddress: ip,
|
||||
userAgent,
|
||||
});
|
||||
}
|
||||
|
||||
@Post('zibal/callback')
|
||||
@ApiOperation({ summary: 'دریافت وبهوک / کالبک لِیزی زیبال' })
|
||||
async handleZibalLazyCallback(
|
||||
|
||||
@@ -56,9 +56,9 @@ export class PaymentService {
|
||||
);
|
||||
}
|
||||
|
||||
const frontendUrl = await this.zibalService.getFrontendUrl();
|
||||
const backendUrl = await this.zibalService.getBackendUrl();
|
||||
const callbackUrl =
|
||||
customCallbackUrl || `${frontendUrl}/payment/verify?orderId=${order.id}`;
|
||||
customCallbackUrl || `${backendUrl}/payment/zibal/callback?orderId=${order.id}`;
|
||||
|
||||
const requestPayload = {
|
||||
amountRials,
|
||||
@@ -151,9 +151,9 @@ export class PaymentService {
|
||||
}
|
||||
|
||||
const amountRials = Math.round(amountTomans * 10);
|
||||
const frontendUrl = await this.zibalService.getFrontendUrl();
|
||||
const backendUrl = await this.zibalService.getBackendUrl();
|
||||
const callbackUrl =
|
||||
customCallbackUrl || `${frontendUrl}/payment/verify?type=wallet`;
|
||||
customCallbackUrl || `${backendUrl}/payment/zibal/callback?type=WALLET_TOPUP`;
|
||||
|
||||
const requestPayload = {
|
||||
amountRials,
|
||||
|
||||
@@ -122,6 +122,31 @@ export class ZibalService implements IPaymentGateway {
|
||||
return envUrl ? envUrl.replace(/\/+$/, '') : 'https://canina.ir';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves base backend API URL for Zibal callbacks
|
||||
*/
|
||||
async getBackendUrl(): Promise<string> {
|
||||
try {
|
||||
const setting = await this.prisma.uiText.findUnique({
|
||||
where: { key: 'BACKEND_URL' },
|
||||
});
|
||||
if (setting && setting.value && setting.value.trim() !== '') {
|
||||
return setting.value.trim().replace(/\/+$/, '');
|
||||
}
|
||||
} catch (e) {
|
||||
this.logger.warn(`Could not read BACKEND_URL from db: ${e}`);
|
||||
}
|
||||
|
||||
const envUrl = process.env.BACKEND_URL || process.env.API_URL;
|
||||
if (envUrl) return envUrl.replace(/\/+$/, '');
|
||||
|
||||
const frontendUrl = await this.getFrontendUrl();
|
||||
if (frontendUrl.includes('stage')) {
|
||||
return 'https://stageapi.canina.ir/api';
|
||||
}
|
||||
return 'https://api.canina.ir/api';
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Request Payment (درخواست پرداخت با قابلیت Retry)
|
||||
* Amount must be in Rials.
|
||||
|
||||
Reference in new issue
Block a user