feat(sms): add WALLET_CHARGED sms trigger for online topup, manual admin credit, refund, and cashback
This commit is contained in:
1 parent
7093978e27
commit
e15c25dae1
5 files changed
+168
-3
No files matched your search
@@ -984,6 +984,32 @@ export class AdminService {
|
||||
});
|
||||
});
|
||||
|
||||
// Send SMS notification for wallet refund
|
||||
if (this.smsService && order.user?.mobile) {
|
||||
try {
|
||||
const user = await this.prisma.user.findUnique({
|
||||
where: { id: order.userId },
|
||||
});
|
||||
const customerFullName = (
|
||||
order.user.firstName
|
||||
? `${order.user.firstName} ${order.user.lastName || ''}`
|
||||
: 'کاربر گرامی'
|
||||
).trim();
|
||||
const refundData = {
|
||||
customerName: customerFullName,
|
||||
customerPhone: order.user.mobile,
|
||||
amount: Number(refundAmount || 0).toLocaleString('fa-IR'),
|
||||
balance: Number(user?.walletBalance || 0).toLocaleString('fa-IR'),
|
||||
reason: reason || `استرداد وجه سفارش #${order.trackingNumber || order.id.slice(0, 8)}`,
|
||||
date: new Date().toLocaleDateString('fa-IR'),
|
||||
};
|
||||
|
||||
this.smsService.triggerEvent('WALLET_CHARGED', refundData).catch(() => {});
|
||||
} catch (err) {
|
||||
// Silently catch SMS errors
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `مبلغ ${refundAmount.toLocaleString('fa-IR')} تومان با موفقیت به کیف پول کاربر بازگردانده شد.`,
|
||||
@@ -1243,7 +1269,7 @@ export class AdminService {
|
||||
});
|
||||
|
||||
const isIncrement = type === 'deposit' || type === 'refund';
|
||||
await this.prisma.user.update({
|
||||
const updatedUser = await this.prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: {
|
||||
walletBalance: isIncrement
|
||||
@@ -1252,6 +1278,31 @@ export class AdminService {
|
||||
},
|
||||
});
|
||||
|
||||
// Send SMS notification if wallet is topped up or refunded
|
||||
if (isIncrement && this.smsService && updatedUser.mobile) {
|
||||
try {
|
||||
const customerFullName = (
|
||||
updatedUser.firstName
|
||||
? `${updatedUser.firstName} ${updatedUser.lastName || ''}`
|
||||
: 'کاربر گرامی'
|
||||
).trim();
|
||||
const topupData = {
|
||||
customerName: customerFullName,
|
||||
customerPhone: updatedUser.mobile,
|
||||
amount: Number(amount || 0).toLocaleString('fa-IR'),
|
||||
balance: Number(updatedUser.walletBalance || 0).toLocaleString('fa-IR'),
|
||||
reason: description || (type === 'refund' ? 'استرداد وجه به کیف پول' : 'شارژ کیف پول توسط مدیریت'),
|
||||
date: new Date().toLocaleDateString('fa-IR'),
|
||||
};
|
||||
|
||||
this.smsService
|
||||
.triggerEvent('WALLET_CHARGED', topupData)
|
||||
.catch(() => {});
|
||||
} catch (err) {
|
||||
// Silently catch SMS errors
|
||||
}
|
||||
}
|
||||
|
||||
return transaction;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user