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

+59
View File
@@ -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;