Skip to content

feat(flutterwave): Flutterwave payment provider package - #107

Open
alexasomba wants to merge 75 commits into
emdashCommerce:mainfrom
alexasomba:feat/flutterwave-provider
Open

alexasomba wants to merge 75 commits into
emdashCommerce:mainfrom
alexasomba:feat/flutterwave-provider

Conversation

@alexasomba

@alexasomba alexasomba commented Nov 24, 2026 •

Copy link
Copy Markdown

One review for the Flutterwave package. Supersedes #98, #100, #102, #104 and #106, which were the same package built in five stacked PRs. Part of the set in #97.

Builds on the core PRs: #99 (public key, independent), #101 (split allocations, the base), #103 and #105 (both build on #101; #105 includes split refunds), plus #114 (provider-neutral subscription seam) and #115 (tax guard + refund idempotency). Review those first; this branch contains their commits until they merge. It does not depend on Paystack.

What

packages/flutterwave: a PaymentProvider for Flutterwave v3. It registers itself on import "@dashcommerce/flutterwave".

Area Behaviour
Hosted checkout POST /v3/payments → redirect to the hosted link; reference dc-<draftId>
On-page Flutterwave Inline over the store's checkout via ./checkout-client; v3.js loads only on Pay; orders still come only from the webhook
Subscriptions Payment Plans, card-only. One plan per checkout (the plan id is the subscription key); payment_plan on hosted and Inline; renewals recorded from the plan field as idempotent invoices; cancel/resume through the plan
Amounts Core minor units ↔ Flutterwave major units, converted once at the boundary
Webhooks Constant-time verif-hash; charge.completed both outcomes; event-id dedupe; confirmation-failure release
Refunds POST /v3/transactions/:id/refund, duplicate guard via (refundRequestId=…), refund webhook → refund.updated
Splits Core allocations → subaccounts with flat_subaccount + the exact amount, hosted and Inline
Vendor onboarding List banks, verify the account name, create the subaccount, store the masked result
Discounts capabilities.coupons: true; the discount is applied to the amount Flutterwave charges
Reconciliation Parses meta.split_settlement_info + app_fee into core's splitSettlement; the order records what each subaccount earned
Connection check Read-only GET /v3/balances, test/live mode

Currencies: NGN, USD, GBP, EUR, KES, GHS, ZAR, UGX, TZS, RWF, XOF, XAF, ZMW, MWK, EGP.

API facts checked, not assumed

  • Flutterwave subaccounts: default split_type is percentage or flat; the transaction override supports flat_subaccount, flat and percentage. DashCommerce uses flat_subaccount with the exact vendor amount so the shares never drift; the default is only a fallback.
  • GET /v3/banks/{country} → { code, name }; POST /v3/accounts/resolve → account_name; POST /v3/subaccounts requires the bank, account, business name, country, mobile and split_value (and email in practice).
  • Paystack's docs define type: percentage|flat and share but not the flat share unit; that remains an open question for its own PR.
  • Payment Plans: POST /v3/payment-plans with interval (monthly, every 3 months, …), amount, currency and duration: 0; pass payment_plan on the first charge. verify returns plan, which is how a charge is tied to the plan. GET /v3/subscriptions answered 400 "Service error" on the test account, so the package uses the plan id and cancels via PUT /v3/payment-plans/{id}/cancel.

Live test-mode evidence (24 Nov 2026)

Check Result
Hosted link creation 200, real link
Real KES 1,500 M-Pesa payment via Inline Succeeded, transaction 10633614; callback → finished
Verify by id and tx_ref succeeded, 150000 minor, KES
Two-vendor split (KES 1,500) 900 to RS_CD57…, 450 to RS_A075…, 76.5 platform after the 73.5 fee; confirmed in meta.split_settlement_info
Payout onboarding 598 NG banks; 0690000033 resolved to Bale Gary; created RS_043B…, then deleted the probe
Partial + settled-max refunds Succeeded; verify still reports successful (documented)
Split refund Flutterwave returned 400 with Refund request successfully logged and no id; treated as a failure and surfaced, not claimed as success
Subscription plan + first charge Plan 254811 (KES 100/month); real test-card payment 10634465 through Inline; verify returned plan: 254811
Package-level plan creation initCheckout created plan 254812 and opened Inline with payment_plan; plan cancelled after the probe

Tests

  • 113 package tests, including checkout → webhook → order → refund through core's real routes, real verify/refund/split fixtures, on-page client, onboarding, idempotent onboarding, settlement and Payment Plans.
  • 373 core tests in this branch, covering the core PRs, including the non-Stripe vendor fix, the coupon rule, the optional payout verification, explicit split refunds and provider-managed subscriptions.
  • Typecheck clean; build emits both entries; one consolidated package changeset (minor).

Review fixes included

#103's review is merged in: verification is optional when a provider cannot resolve names, an active-but-unverified account is stored with verified: false (Paystack's is_verified: false), the onboarding form starts on the store's default-currency country, and the bank picker accepts mobile-money channels such as M-PESA. Onboarding is also idempotent here: re-adding the same bank account returns Flutterwave's existing subaccount, matched by account number and bank rather than the error text.

Deliberately not included

  • Country-specific subaccount meta (SWIFT/routing/branch) in the form. The docs conflict between the create reference and the split guide, and there are no test accounts for those countries; the README says to create those accounts in the dashboard/API for now.
  • API-driven split refunds: Flutterwave's split-refund response has no refund id, so the package surfaces the message and points to the dashboard.
  • Subscription trials, pausing, in-place upgrades and multiple subscription lines per checkout. All fail loudly; cancel and resume are supported.

…able

Real test-mode run (24 Nov 2026): GET /v3/refunds answers 400
unauthorized on a key that can create refunds. Degrade the duplicate
check to a logged warning for that case, log a failed disbursement, and
add fixtures from the real verify and refund responses.
createVendor stored stripeAccountId: "" and the field has a unique
index, so the second vendor failed. The field is now optional and
omitted when there is no Stripe account; a missing field is NULL.

Also documents the coupon rule for split allocations (the platform
absorbs a cart-wide discount; a larger one is a 409) and makes the
allocation comments generic for Paystack.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant