Integrate · 04
Payments
Payments are provider-specific but share one rule: the order is recorded first, the provider is verified server-side, and the order state changes only after a trusted signal.

Provider selection
| Provider | Environment | Checkout mode |
|---|---|---|
| Stripe | STRIPE_PUBLIC_KEY, STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET | Stripe Checkout redirect and signed webhook. |
| Flutterwave v4 | FLW_CLIENT_ID, FLW_CLIENT_SECRET, FLW_ENCRYPTION_KEY, FLW_SECRET_HASH | Direct charge, 3DS/OTP/PIN/AVS and webhook re-query. |
| PayPal | PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PAYPAL_WEBHOOK_ID | Orders v2 create/capture and signed verification. |
| Cash on delivery | Site Settings cod_enabled | No provider; staff mark paid/fulfilled. |
PAYMENT_PROVIDER selects the default surface. The checkout only exposes providers that are fully configured.
Webhook endpoints
/payments/stripe/webhook/
/payments/flutterwave/webhook/
/payments/paypal/webhook/Each endpoint verifies the provider signature or secret before changing an order. Flutterwave and PayPal also re-query the provider where the flow requires it. A webhook failure is logged; a retry can be replayed from the provider dashboard.
Never mark an order paid from a browser redirect alone. The redirect is a user experience; the verified webhook or server-side capture is the source of truth.
Order state and refunds
Payment status and fulfilment status are independent. A paid order can be unfulfilled; a cancelled order can have a refund pending. Provider refunds update the refunded total and payment status. A fully refunded or cancelled order reverses affiliate commission and restores stock when configured.
| Signal | Action |
|---|---|
| Payment succeeded | Set payment status paid, write order event, send confirmation. |
| Payment failed | Keep the order unpaid, record the provider error, allow retry. |
| Refund issued | Update refunded total/status, reverse affiliate commission on full refund. |
| Chargeback / dispute | Treat as a reversal, preserve provider evidence and audit the order. |
Test mode and launch
Site Settings has a test-mode flag and each provider has its own sandbox/production environment. Use sandbox keys and a test card flow first, then switch both the environment and the keys together. Re-run a real low-value order after launch and reconcile it against the provider dashboard.
FLW_ENV=production
PAYPAL_ENV=production
# Stripe live keys replace the test keys in .env
sudo systemctl restart perfumz
curl -fsS http://127.0.0.1:8007/health/ready/
Reconciliation checklist
- The provider webhook is reachable over public HTTPS.
- The webhook secret matches the environment.
- Paid orders in the dashboard match provider captures.
- Refunds in the dashboard match provider refunds.
- Affiliate commissions are reversed for fully refunded orders.
- Failed payments are visible and retryable.