feat(payment): fix zibal refund api, add maskable fields, receipt modal, standardized buttons and order refund options
Deploy Canina / deploy (push) Successful in 41s
Deploy Canina / deploy (push) Successful in 41s
This commit is contained in:
1 parent
f9e40564cf
commit
d62787cd99
22 files changed
+10934
-9318
No files matched your search
@@ -172,6 +172,21 @@ export class AdminController {
|
||||
return { success: true, data: order };
|
||||
}
|
||||
|
||||
@Post('orders/:id/refund-wallet')
|
||||
@ApiOperation({ summary: 'استرداد مستقیم مبلغ سفارش به کیف پول کاربر' })
|
||||
async refundOrderToWallet(
|
||||
@Param('id') id: string,
|
||||
@Body('amount') amount?: number,
|
||||
@Body('reason') reason?: string,
|
||||
) {
|
||||
const result = await this.adminService.refundOrderToWallet(
|
||||
id,
|
||||
amount ? Number(amount) : undefined,
|
||||
reason,
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Get('coupons')
|
||||
@ApiOperation({ summary: 'لیست کد تخفیفها' })
|
||||
@ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' })
|
||||
|
||||
@@ -615,6 +615,65 @@ export class AdminService {
|
||||
});
|
||||
}
|
||||
|
||||
async refundOrderToWallet(orderId: string, customAmount?: number, reason?: string) {
|
||||
const order = await this.prisma.order.findUnique({
|
||||
where: { id: orderId },
|
||||
include: { user: true },
|
||||
});
|
||||
|
||||
if (!order) {
|
||||
throw new NotFoundException('سفارش مورد نظر یافت نشد');
|
||||
}
|
||||
|
||||
if (!order.userId || !order.user) {
|
||||
throw new BadRequestException('این سفارش به کاربر ثبتنامشدهای متصل نیست');
|
||||
}
|
||||
|
||||
const refundAmount = customAmount !== undefined && customAmount > 0
|
||||
? customAmount
|
||||
: Number(order.totalAmount || 0);
|
||||
|
||||
if (refundAmount <= 0) {
|
||||
throw new BadRequestException('مبلغ استرداد باید بیشتر از صفر باشد');
|
||||
}
|
||||
|
||||
await this.prisma.$transaction(async (tx) => {
|
||||
// 1. Increment user wallet balance
|
||||
await tx.user.update({
|
||||
where: { id: order.userId },
|
||||
data: {
|
||||
walletBalance: { increment: refundAmount },
|
||||
},
|
||||
});
|
||||
|
||||
// 2. Create wallet transaction entry
|
||||
await tx.walletTransaction.create({
|
||||
data: {
|
||||
userId: order.userId,
|
||||
amount: refundAmount,
|
||||
type: 'deposit',
|
||||
status: 'completed',
|
||||
description: reason || `استرداد وجه سفارش لغو شده #${order.trackingNumber || order.id.slice(0, 8)} به کیف پول`,
|
||||
},
|
||||
});
|
||||
|
||||
// 3. Mark order as cancelled and note refund
|
||||
await tx.order.update({
|
||||
where: { id: order.id },
|
||||
data: {
|
||||
status: 'cancelled',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `مبلغ ${refundAmount.toLocaleString('fa-IR')} تومان با موفقیت به کیف پول کاربر بازگردانده شد.`,
|
||||
refundAmount,
|
||||
userId: order.userId,
|
||||
};
|
||||
}
|
||||
|
||||
async getCoupons(query: PaginationQuery = {}) {
|
||||
const page = Number(query.page) || 1;
|
||||
const limit = Number(query.limit) || 10;
|
||||
|
||||
Reference in new issue
Block a user