feat: add POST payment/admin/inquiry endpoint for instant zibal inquiry
All checks were successful
Deploy Canina / deploy (push) Successful in 32s
All checks were successful
Deploy Canina / deploy (push) Successful in 32s
This commit is contained in:
parent
ebdc27e190
commit
ee4ee7d842
@ -546,6 +546,26 @@ export class PaymentController {
|
||||
return this.paymentService.reconcilePendingTransactions();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@ApiBearerAuth()
|
||||
@Post('admin/inquiry')
|
||||
@ApiOperation({ summary: 'استعلام زنده وضعیت تراکنش با trackId یا transactionId' })
|
||||
async liveInquiryPost(@Body() body: { trackId?: string | number; transactionId?: string }) {
|
||||
if (body.transactionId) {
|
||||
return this.paymentService.adminLiveInquiry(body.transactionId);
|
||||
}
|
||||
if (body.trackId) {
|
||||
const tx = await this.paymentService.getTransactionByTrackId(String(body.trackId));
|
||||
if (tx) {
|
||||
return this.paymentService.adminLiveInquiry(tx.id);
|
||||
}
|
||||
// Direct Zibal inquiry fallback if transaction record not found
|
||||
return this.paymentService.inquiryDirectZibal(String(body.trackId));
|
||||
}
|
||||
throw new BadRequestException('trackId یا transactionId الزامی است');
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@ApiBearerAuth()
|
||||
@ -555,6 +575,7 @@ export class PaymentController {
|
||||
return this.paymentService.adminLiveInquiry(id);
|
||||
}
|
||||
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@ApiBearerAuth()
|
||||
|
||||
@ -893,6 +893,31 @@ export class PaymentService {
|
||||
};
|
||||
}
|
||||
|
||||
async getTransactionByTrackId(trackId: string) {
|
||||
return this.prisma.paymentTransaction.findFirst({
|
||||
where: { trackId },
|
||||
});
|
||||
}
|
||||
|
||||
async inquiryDirectZibal(trackId: string) {
|
||||
const inquiryRes = await this.zibalService.inquiryPayment(trackId);
|
||||
const statusMsg = this.zibalService.getStatusMessage(inquiryRes.status ?? 3);
|
||||
const resultMsg = this.zibalService.getResultMessage(inquiryRes.result);
|
||||
return {
|
||||
trackId,
|
||||
status: inquiryRes.status,
|
||||
statusMessage: statusMsg,
|
||||
result: inquiryRes.result,
|
||||
resultMessage: resultMsg,
|
||||
amount: inquiryRes.amount,
|
||||
refNumber: inquiryRes.refNumber,
|
||||
cardNumber: inquiryRes.cardNumber,
|
||||
paidAt: inquiryRes.paidAt,
|
||||
rawInquiryResponse: inquiryRes,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 9. Admin: Manually Approve / Verify a Transaction (e.g. Card-to-Card receipt or bank transfer)
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user