Tampilan
Billing & Pembayaran
Billing menggabungkan Zoho Books (estimate/invoice/faktur pajak) dan Xendit (payment gateway + recurring).
Alur checkout langganan baru
Route: POST /api/v1/billings/checkoutController: controllers/biliings/checkoutServicePackages/checkoutServicePackagesController.jsService: checkoutServicePackagesService.js
Langkah:
- Validasi input (package, periode, metode bayar:
xendit|manual). - Opsional: buat relay Zimbra + domain (bila
namaDomainada). - Buat/update contact Zoho (
zoho.createZohoContact/updateZohoContact). - Batalkan invoice belum lunas sebelumnya (
zoho.markDeclinedEstimate). - Buat Zoho estimate (
zoho.createEstimateInvoice) → PDF proforma. - Buat Xendit recurring payment (
RecurringPayment.createPayment,externalID: 'AKTV-SMTP'). - Simpan invoice di DB (
TransCompanyInvoices) dengan ID estimate Zoho + URL Xendit. - Buat record subscription (
TransCompanySubscriptions, statusinactive). - Kirim email proforma via nodemailer + template Pug (
inv-terbit-new/proforma-inv-manual).
Alur callback pembayaran
Route: POST /api/v1/callback-paymentController: controllers/callbackXendit.jsAuth: header x-callback-token harus cocok dengan CALLBACK_TOKEN_XENDIT.
Branch A — Over-quota payment (tanpa recurring_payment_id)
- Service:
controllers/services/overquota-xendit.service.js. - Tandai estimate Zoho paid → buat over-quota invoice → catat payment → update kuota.
Branch B — Subscription payment (ada recurring_payment_id)
- Verifikasi
status === 'PAID'. - Cek apakah renewal recurring (
recurring-xendit.service.js→renewTransaction). - Reschedule tanggal charge Xendit berikutnya.
- Tandai estimate Zoho accepted (
zoho.markPaidEstimate). - Buat tax invoice Zoho (
zoho.createInvoice) dari estimate. - Tandai invoice paid (
zoho.markPaidInvoice). - Download PDF invoice, update record DB.
- Aktifkan subscription, set periode billing.
- Update file
.cfpaket (pindahkan relay antar paket bila upgrade). - Reset penghitung kuota email.
- Reaktivasi relay Zimbra yang suspended bila perlu.
- Queue job notifikasi:
send-mail-invoice,send-mail-filling-data(reminder NPWP),send-notif-new-payment(notif admin),sync-domain-zmta, registrasi kontak MailWizz.
Recurring renewal
Service: controllers/services/recurring-xendit.service.js. Cron di cron/invoices/recurring-invoice/ menangani:
- Pembuatan proforma sebelum renewal.
- Reminder pembayaran (H-1/3/5/0, H+1..3).
- Notifikasi admin.
Lihat Background Jobs & Cron.
Pembayaran manual (admin)
Controller: controllers/admin/recordManualPayments/recordManualPaymentController.jsService: recordManualPaymentService.js
Memakai zoho.recordPaymentInvoice(bankId) untuk pembayaran transfer bank yang dicatat admin (route butuh role accounting).
Over-quota billing
Cron terkait: cron:overquota:reminder, cron:overquota:reminder-sender, cron:overquota:generate-billing, cron:overquota:send-billing (lihat Background Jobs).
Zoho OAuth
| Route / Cron | File |
|---|---|
GET /api/v1/auth-zoho | controllers/zoho/authorizeZoho/authorizeZohoController.js |
GET /api/v1/get-token | controllers/zoho/getToken/getTokenController.js |
| Cron refresh token | cron/job-update-access-token-zoho.js |
Refresh token Zoho disimpan via repositories/config.repository.js (getTokenZoho). Token Zoho biasanya kedaluwarsa ~1 jam, jadi cron refresh harus berjalan sesuai TTL.