Skip to content

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:

  1. Validasi input (package, periode, metode bayar: xendit | manual).
  2. Opsional: buat relay Zimbra + domain (bila namaDomain ada).
  3. Buat/update contact Zoho (zoho.createZohoContact / updateZohoContact).
  4. Batalkan invoice belum lunas sebelumnya (zoho.markDeclinedEstimate).
  5. Buat Zoho estimate (zoho.createEstimateInvoice) → PDF proforma.
  6. Buat Xendit recurring payment (RecurringPayment.createPayment, externalID: 'AKTV-SMTP').
  7. Simpan invoice di DB (TransCompanyInvoices) dengan ID estimate Zoho + URL Xendit.
  8. Buat record subscription (TransCompanySubscriptions, status inactive).
  9. 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)

  1. Verifikasi status === 'PAID'.
  2. Cek apakah renewal recurring (recurring-xendit.service.jsrenewTransaction).
  3. Reschedule tanggal charge Xendit berikutnya.
  4. Tandai estimate Zoho accepted (zoho.markPaidEstimate).
  5. Buat tax invoice Zoho (zoho.createInvoice) dari estimate.
  6. Tandai invoice paid (zoho.markPaidInvoice).
  7. Download PDF invoice, update record DB.
  8. Aktifkan subscription, set periode billing.
  9. Update file .cf paket (pindahkan relay antar paket bila upgrade).
  10. Reset penghitung kuota email.
  11. Reaktivasi relay Zimbra yang suspended bila perlu.
  12. 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 / CronFile
GET /api/v1/auth-zohocontrollers/zoho/authorizeZoho/authorizeZohoController.js
GET /api/v1/get-tokencontrollers/zoho/getToken/getTokenController.js
Cron refresh tokencron/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.