feat: complete tickets & vet consultation, fix wallet balance overflow, b2b toggle, and transaction manual verification
Deploy Canina / deploy (push) Successful in 1m51s
Deploy Canina / deploy (push) Successful in 1m51s
This commit is contained in:
1 parent
1aa9d6e34d
commit
42707c04cf
24 files changed
+1856
-139
No files matched your search
@@ -212,6 +212,30 @@ export class PaymentController {
|
||||
return this.paymentService.adminLiveInquiry(id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@ApiBearerAuth()
|
||||
@Post('admin/manual-verify/:id')
|
||||
@ApiOperation({ summary: 'تایید دستی تراکنش یا فیش واریزی کارتبهکارت توسط ادمین' })
|
||||
async manualVerify(
|
||||
@Param('id') id: string,
|
||||
@Body() body: { adminNote?: string },
|
||||
) {
|
||||
return this.paymentService.adminManualVerify(id, body.adminNote);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@ApiBearerAuth()
|
||||
@Post('admin/manual-reject/:id')
|
||||
@ApiOperation({ summary: 'رد دستی تراکنش پرداخت توسط ادمین' })
|
||||
async manualReject(
|
||||
@Param('id') id: string,
|
||||
@Body() body: { reason?: string },
|
||||
) {
|
||||
return this.paymentService.adminManualReject(id, body.reason);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@ApiBearerAuth()
|
||||
|
||||
@@ -478,16 +478,22 @@ export class PaymentService {
|
||||
});
|
||||
|
||||
// Send SMS notification if order payment
|
||||
if (transaction.type === 'ORDER' && transaction.order?.user?.mobile) {
|
||||
const mobile = transaction.order.user.mobile;
|
||||
const customerMobile =
|
||||
transaction.order?.user?.mobile ||
|
||||
transaction.user?.mobile ||
|
||||
(transaction.rawRequest as { mobile?: string })?.mobile;
|
||||
|
||||
if (transaction.type === 'ORDER' && customerMobile) {
|
||||
const trackingNum =
|
||||
transaction.order.trackingNumber || transaction.order.id;
|
||||
transaction.order?.trackingNumber ||
|
||||
transaction.orderId ||
|
||||
transaction.id;
|
||||
const formattedAmount = Number(transaction.amount).toLocaleString(
|
||||
'fa-IR',
|
||||
);
|
||||
|
||||
this.smsService
|
||||
.sendOrderConfirmation(mobile, trackingNum, formattedAmount)
|
||||
.sendOrderConfirmation(customerMobile, trackingNum, formattedAmount)
|
||||
.catch((err) => {
|
||||
this.logger.warn(`Could not send SMS confirmation: ${err}`);
|
||||
});
|
||||
@@ -842,16 +848,101 @@ export class PaymentService {
|
||||
return {
|
||||
transactionId: transaction.id,
|
||||
trackId: transaction.trackId,
|
||||
currentDbStatus: transaction.status,
|
||||
gatewayResponse: inquiryRes,
|
||||
status: inquiryRes.status,
|
||||
statusMessage: statusMsg,
|
||||
result: inquiryRes.result,
|
||||
resultMessage: resultMsg,
|
||||
inquiredAt: new Date(),
|
||||
amount: inquiryRes.amount,
|
||||
refNumber: inquiryRes.refNumber,
|
||||
cardNumber: inquiryRes.cardNumber,
|
||||
paidAt: inquiryRes.paidAt,
|
||||
rawInquiryResponse: inquiryRes,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 9. Gateway Health Check for Admin
|
||||
* 9. Admin: Manually Approve / Verify a Transaction (e.g. Card-to-Card receipt or bank transfer)
|
||||
*/
|
||||
async adminManualVerify(transactionId: string, adminNote?: string) {
|
||||
const transaction = await this.prisma.paymentTransaction.findUnique({
|
||||
where: { id: transactionId },
|
||||
include: { order: true, user: true },
|
||||
});
|
||||
|
||||
if (!transaction) {
|
||||
throw new NotFoundException('تراکنش یافت نشد');
|
||||
}
|
||||
|
||||
if (transaction.status === 'VERIFIED') {
|
||||
throw new BadRequestException('این تراکنش قبلاً تایید شده است');
|
||||
}
|
||||
|
||||
await this.prisma.$transaction(async (tx) => {
|
||||
await tx.paymentTransaction.update({
|
||||
where: { id: transactionId },
|
||||
data: {
|
||||
status: 'VERIFIED',
|
||||
message: adminNote || 'تایید دستی توسط مدیر سیستم (کارت به کارت / فیش بانکی)',
|
||||
paidAt: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
if (transaction.type === 'WALLET_TOPUP') {
|
||||
await tx.user.update({
|
||||
where: { id: transaction.userId },
|
||||
data: {
|
||||
walletBalance: { increment: Number(transaction.amount) },
|
||||
},
|
||||
});
|
||||
|
||||
await tx.walletTransaction.create({
|
||||
data: {
|
||||
userId: transaction.userId,
|
||||
amount: transaction.amount,
|
||||
type: 'deposit',
|
||||
status: 'completed',
|
||||
description: `افزایش موجودی دستی تایید شده توسط ادمین (${adminNote || 'کارت به کارت'})`,
|
||||
},
|
||||
});
|
||||
} else if (transaction.type === 'ORDER' && transaction.orderId) {
|
||||
await tx.order.update({
|
||||
where: { id: transaction.orderId },
|
||||
data: {
|
||||
status: 'processing',
|
||||
paymentMethod: 'card_to_card',
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return { success: true, message: 'تراکنش با موفقیت به صورت دستی تایید و اعمال شد' };
|
||||
}
|
||||
|
||||
/**
|
||||
* 10. Admin: Manually Reject a Transaction
|
||||
*/
|
||||
async adminManualReject(transactionId: string, reason?: string) {
|
||||
const transaction = await this.prisma.paymentTransaction.findUnique({
|
||||
where: { id: transactionId },
|
||||
});
|
||||
|
||||
if (!transaction) {
|
||||
throw new NotFoundException('تراکنش یافت نشد');
|
||||
}
|
||||
|
||||
await this.prisma.paymentTransaction.update({
|
||||
where: { id: transactionId },
|
||||
data: {
|
||||
status: 'FAILED',
|
||||
message: reason || 'رد شده توسط ادمین سیستم',
|
||||
},
|
||||
});
|
||||
|
||||
return { success: true, message: 'تراکنش به عنوان ناموفق/رد شده علامتگذاری شد' };
|
||||
}
|
||||
|
||||
/**
|
||||
* 11. Gateway Health Check for Admin
|
||||
*/
|
||||
async checkGatewayHealth() {
|
||||
return this.zibalService.checkHealth();
|
||||
|
||||
Reference in new issue
Block a user