fix(wa): notifikasi LUNAS lewat gateway aktif + approve APK
All checks were successful
CI / test (push) Successful in 2m26s
All checks were successful
CI / test (push) Successful in 2m26s
- isConnected GOWA: tangani /devices array (state connected) - app-customer payment-notif: pakai waNotify, bukan Baileys - customerAPI approve kolektor + payment-unmatched: kirim WA lunas - versi 0.5.13
This commit is contained in:
@@ -4925,6 +4925,29 @@ router.post('/payment-unmatched/:id/match', requireAdminSession, express.urlenco
|
||||
if (!unpaid) await customerSvc.activateCustomer(inv.customer_id);
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
// Notifikasi WA lunas ke pelanggan
|
||||
try {
|
||||
const cust = customerSvc.getCustomerById(inv.customer_id);
|
||||
if (cust && cust.phone) {
|
||||
const pkg = cust.package_id ? customerSvc.getPackageById(cust.package_id) : null;
|
||||
await sendPaymentSuccessWA(
|
||||
cust.phone,
|
||||
cust.name,
|
||||
`${inv.period_month}/${inv.period_year}`,
|
||||
Number(inv.amount || 0).toLocaleString('id-ID'),
|
||||
'Manual (Webhook)',
|
||||
{
|
||||
customerId: cust.id,
|
||||
invoiceId: inv.id,
|
||||
username: cust.pppoe_username || cust.id,
|
||||
customerCode: cust.customer_code || '',
|
||||
packageName: pkg?.name || cust.package_name || '-',
|
||||
paidAt: new Date(), method: 'Manual (Webhook)'
|
||||
}
|
||||
);
|
||||
}
|
||||
} catch (e) {}
|
||||
req.session._msg = { type: 'success', text: 'Invoice #' + invId + ' ditandai LUNAS & notif dicocokkan.' };
|
||||
} catch (e) {
|
||||
req.session._msg = { type: 'error', text: 'Gagal cocokkan: ' + e.message };
|
||||
|
||||
@@ -2359,6 +2359,37 @@ router.post('/app/admin/collector-payments/approve', requireAdminApiAuth, async
|
||||
if (unpaidCount === 0) {
|
||||
try { await customerSvc.activateCustomer(pay.customer_id); } catch (_) {}
|
||||
}
|
||||
|
||||
// Notifikasi WA lunas ke pelanggan (gateway aktif)
|
||||
try {
|
||||
const customer = customerSvc.getCustomerById(pay.customer_id);
|
||||
const inv = billingSvc.getInvoiceById(pay.invoice_id);
|
||||
if (customer && customer.phone && inv) {
|
||||
const settings = getSettingsWithCache();
|
||||
const waNotify = require('../services/waNotifyService');
|
||||
const whatsappService = require('../services/whatsappService');
|
||||
const pkg = customer.package_id ? customerSvc.getPackageById(customer.package_id) : null;
|
||||
const appUrl = String(settings.public_base_url || '').replace(/\/$/, '');
|
||||
const template = db.getAppSetting('whatsapp_payment_success_message', '');
|
||||
const msg = whatsappService.formatPaymentSuccessMessage({
|
||||
customerName: customer.name,
|
||||
invoiceId: inv.id,
|
||||
customerUsername: customer.pppoe_username || customer.id || '-',
|
||||
customerCode: customer.customer_code || '',
|
||||
packageName: pkg?.name || customer.package_name || '-',
|
||||
periodMonth: inv.period_month,
|
||||
periodYear: inv.period_year,
|
||||
amount: inv.amount,
|
||||
paymentMethod: collectorLabel,
|
||||
paidAt: new Date(),
|
||||
companyName: settings.company_header || 'OPEN-ISP',
|
||||
companyPhone: settings.company_phone || '',
|
||||
portalUrl: appUrl ? appUrl + '/customer' : '',
|
||||
customTemplate: template
|
||||
});
|
||||
await waNotify.sendText(customer.phone, msg);
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
res.json({ success: true, message: 'Pembayaran berhasil di-approve dan tagihan ditandai LUNAS' });
|
||||
} catch (e) { res.status(500).json({ success: false, message: e.message }); }
|
||||
|
||||
Reference in New Issue
Block a user