feat(payment): fix zibal refund api, add maskable fields, receipt modal, standardized buttons and order refund options
Deploy Canina / deploy (push) Successful in 41s

This commit is contained in:
parsa aghaei committed 2026-08-22 17:01:13 +03:30
1 parent f9e40564cf
commit d62787cd99
22 files changed
+10934 -9318

No files matched your search

+26 -5
View File
@@ -45,6 +45,23 @@ export class PaymentController {
private readonly zibalEBankService: ZibalEBankService,
) {}
private extractRealClientIp(req: Request, fallbackIp?: string): string {
const xForwardedFor = req.headers['x-forwarded-for'];
if (xForwardedFor) {
const forwardedIps = Array.isArray(xForwardedFor)
? xForwardedFor[0]
: xForwardedFor.split(',')[0];
if (forwardedIps && forwardedIps.trim()) {
return forwardedIps.trim().replace(/^::ffff:/, '');
}
}
const xRealIp = req.headers['x-real-ip'];
if (xRealIp && typeof xRealIp === 'string') {
return xRealIp.trim().replace(/^::ffff:/, '');
}
return (fallbackIp || req.ip || '').replace(/^::ffff:/, '');
}
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@Post('zibal/initiate')
@@ -56,16 +73,17 @@ export class PaymentController {
description: 'خطا در ایجاد تراکنش یا نامعتبر بودن سفارش',
})
async initiateOrderPayment(
@Req() req: { user: { id: string } },
@Req() req: Request & { user: { id: string } },
@Body() body: InitiatePaymentDto,
@Ip() ip: string,
@Headers('user-agent') userAgent?: string,
) {
const realIp = this.extractRealClientIp(req, ip);
return this.paymentService.initiateOrderPayment(
req.user.id,
body.orderId,
body.customCallbackUrl,
{ ipAddress: ip, userAgent },
{ ipAddress: realIp, userAgent },
);
}
@@ -77,16 +95,17 @@ export class PaymentController {
description: 'لینک هدایت به درگاه پرداخت برای شارژ کیف پول',
})
async initiateWalletTopup(
@Req() req: { user: { id: string } },
@Req() req: Request & { user: { id: string } },
@Body() body: InitiateWalletTopupDto,
@Ip() ip: string,
@Headers('user-agent') userAgent?: string,
) {
const realIp = this.extractRealClientIp(req, ip);
return this.paymentService.initiateWalletTopup(
req.user.id,
Number(body.amount),
body.customCallbackUrl,
{ ipAddress: ip, userAgent },
{ ipAddress: realIp, userAgent },
);
}
@@ -95,11 +114,13 @@ export class PaymentController {
summary: 'دریافت کال‌بک بازگشت از درگاه زیبال و تایید تراکنش',
})
async handleZibalCallback(
@Req() req: Request,
@Query() query: ZibalCallbackQueryDto,
@Res() res: Response,
@Ip() ip: string,
@Headers('user-agent') userAgent?: string,
) {
const realIp = this.extractRealClientIp(req, ip);
const trackId = query.trackId || '';
const success = query.success;
const status = query.status;
@@ -119,7 +140,7 @@ export class PaymentController {
success,
status,
orderId,
{ ipAddress: ip, userAgent },
{ ipAddress: realIp, userAgent },
);
const params = new URLSearchParams({
+21 -8
View File
@@ -540,19 +540,26 @@ export class ZibalService implements IPaymentGateway {
cardNumber?: string;
description?: string;
}) {
const accountId =
options.accountId ||
(await this.prisma.uiText.findUnique({ where: { key: 'ZIBAL_EBANK_ACCOUNT_ID' } }))?.value;
const merchant = await this.getMerchant();
const accountIdSetting = (
await this.prisma.uiText.findUnique({ where: { key: 'ZIBAL_EBANK_ACCOUNT_ID' } })
)?.value;
const payload = {
const payload: Record<string, any> = {
merchant: merchant || undefined,
merchantId: merchant || undefined,
trackId: Number(options.trackId),
accountId: accountId || 'default',
tryReverse: options.tryReverse ?? false,
amount: options.amount,
cardNumber: options.cardNumber,
amount: options.amount ? Number(options.amount) : undefined,
cardNumber: options.cardNumber || undefined,
description: options.description || 'استرداد وجه سفارش در کنینا',
};
const finalAccountId = options.accountId || accountIdSetting;
if (finalAccountId && finalAccountId.trim() !== '') {
payload.accountId = finalAccountId.trim();
}
return this.apiRequest<any>('/v1/account/refund', 'POST', payload);
}
@@ -563,7 +570,10 @@ export class ZibalService implements IPaymentGateway {
refundId?: number | string;
transactionTrackId?: number | string;
}) {
const merchant = await this.getMerchant();
return this.apiRequest<any>('/v1/account/refund/inquiry', 'POST', {
merchant: merchant || undefined,
merchantId: merchant || undefined,
refundId: params.refundId ? Number(params.refundId) : undefined,
transactionTrackId: params.transactionTrackId
? Number(params.transactionTrackId)
@@ -582,9 +592,12 @@ export class ZibalService implements IPaymentGateway {
fromDate?: string;
toDate?: string;
}) {
const merchant = await this.getMerchant();
return this.apiRequest<any>('/v1/account/refund/list', 'POST', {
merchant: merchant || undefined,
merchantId: merchant || undefined,
status: filter.status,
type: filter.type || 4,
type: filter.type,
page: filter.page || 1,
size: filter.size || 20,
fromDate: filter.fromDate,