PayPal integration with 6-hop state machine and commission tracking
Full payment lifecycle management. Tracks from billing through collection with automated reminders. PayPal webhooks handle online payments; manual entry covers clinic payments. The system auto-calculates the 10% commission owed on Oshun revenue.
awaiting through completeExternal service: PayPal (sandbox + live modes)
Oshun deal: $500/mo base + 10% commission on all client revenue.
Required environment variables:
PAYPAL_CLIENT_ID — PayPal app client IDPAYPAL_SECRET — PayPal app secretPAYPAL_MODE — sandbox or livesrc/webhooks/billing.js — PayPal webhook route registration and event processing. Key exports: registerBillingRoutes() (line 12), processWebhookEvent() (line 198).src/actions/billing.js — Core billing action handlers: state transitions, reminder scheduling, commission calculation, and manual payment recording.awaiting — payment expected, no action yetgrace — grace period active, soft reminder sentstaff_prompted — staff notified to follow uppatient_prompted — patient directly remindedat_risk — escalation begins, account flaggedreconciliation — final resolution in progresscomplete — payment confirmed and recordedEscalation timeline: Day 3 warning → Day 7 suspend → Day 14 final → Day 30 cancel
payments — payment records and current statebilling_notifications — log of all reminder messages sentcommissions — commission calculations per payment eventaccounting_sync_log — audit trail of all accounting sync actionsaccounting_chart_of_accounts — chart of accounts for categorizationNone currently.