Repository navigation
feat(flutterwave): Flutterwave payment provider package - #98
Closed
alexasomba wants to merge 2 commits into
Closed
alexasomba wants to merge 2 commits into
alexasomba wants to merge 2 commits into
Conversation
…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.
This was referenced Nov 24, 2026
Contributor
Author
cavewebs
added a commit
that referenced
this pull request
Nov 27, 2026
Part of the Flutterwave set described in #97. **Item 2** — a generic core seam, independent of #85 (Paystack) and #98 (the Flutterwave package). No Flutterwave code in core. ## Why Flutterwave Inline, its on-page checkout, is a browser SDK initialised with the account's **public** key (`FLWPUBK-…`). Core's provider settings stored only `secretKey` and `webhookSecret`, and a provider has no KV access, so the server could not hand the browser client the key it needs. The shortcut — deriving the public key from the secret key — is not available. I checked a real test pair: `FLWPUBK_TEST-991d…` and `FLWSECK_TEST-03d5…` have different hash segments. ## What - `PaymentProviderCredentials.publicKey` and `credentialFields.publicKey` (label, prefixes, help). - `settings:<id>PublicKey` in the settings schema, `providerCredentialSetting` and `GET admin/settings` `_providers`, validated against the prefixes the provider declares and masked like the other credentials. - A third field in Settings → Payment provider, rendered **only** for a provider that declares one. - `loadPaymentProviderCredentials` returns `publicKey` when set. ## What does not change - Stripe's fields, keys and behaviour. - Providers that do not declare a public key: their settings row is byte-for-byte the same, and a `publicKey` value is refused for them (so a typo cannot save a key nothing reads). - The secret key and webhook secret are still offered for every provider, as before. ## Tests - `provider-credentials-settings.test.ts`: saves and loads the public key, validates its prefix, refuses one for a provider that does not declare it, never returns the value (only set/hint), and omits the row entirely for such a provider. - 12 tests in that file, 58 across the provider/credentials/webhook-header files, `tsc --noEmit` clean. - Changeset: minor for `@dashcommerce/core`. ## Next Item 3 is [#100](#100): the provider declares the field, returns `on_page` with `{ publicKey, txRef, amount, currency, customer… }`, and ships a `./checkout-client` that loads `checkout.flutterwave.com/v3.js` only when the customer presses Pay. The split seams are [#101](#101) (core) and [#102](#102) (Flutterwave). All are open.
cavewebs
added a commit
that referenced
this pull request
Dec 3, 2026
This PR brings the Flutterwave adapter and the Core changes it needs into one review. - Integration roadmap in #97 ## Superseded package PRs The changes from these five stacked PRs are included here. - #98 - #100 - #102 - #104 - #106 ## Review and merge order Core support for provider public keys, split allocations, and checkout and refund safety has merged in the following PRs. - #99 - #101 - #115 This branch also includes the current heads of the following PRs. Review their changes here if we merge the combined PR. Keep the original threads open until the changes are confirmed on `main`. - #103 - #105 - #114 A merge commit can preserve those PR heads and let GitHub mark them merged indirectly. If this PR is squash-merged and any companions remain open, verify their changes on `main` before closing them with a link here. moset15’s earlier draft [Stripe subscription checkout and customer linking #138](#138) overlaps with this PR in `storage-collections.ts`. When either PR lands, bring the other up to date with `main` and preserve the draft’s customer lookup index alongside this PR’s refund dispatch storage. ## Release Changesets plans Flutterwave 0.1.0 with Core 0.6.0 when this PR is included in the release. Flutterwave declares a Core peer range of `>=0.6.0 <1.0.0`. The minimum release must contain its provider interfaces and currency helper. If the release in [Core release PR #120](#120) ships before these changes land, update the Flutterwave peer floor to the next Core release that actually includes them. ## What `packages/flutterwave`: a `PaymentProvider` for Flutterwave v3. It registers itself on `import "@dashcommerce/flutterwave"`. | Area | Behaviour | |---|---| | Hosted checkout | Validate the hosted redirect URL, allow the sandbox host with test credentials, and return the verified checkout reference alongside the charge ID for [Verify hosted payments on return #126](#126) | | 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; record verified renewals once after matching transaction, plan, amount, and currency; late payments preserve cancellation; cancel/resume through the plan | | Amounts | Core minor units ↔ Flutterwave major units, converted once at the boundary | | Webhooks | Constant-time `verif-hash`, event deduplication, and provider verification before settling. Preserve the customer email saved at checkout when it is present | | Refunds | Reserve the request before dispatch, reconcile retries by the request tag and verified original charge, and keep acceptance pending until Flutterwave reports disbursement or failure | | 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 | ## Validation - Frozen install, workspace typecheck, and workspace build passed locally. All 789 workspace tests passed, including 398 Core and 137 Flutterwave tests. - An isolated merge preview with #126 passed 14 focused tests, including a verified Flutterwave checkout reference with a distinct numeric capture ID. - [GitHub checks for the review follow-up commit](https://github.com/emdashCommerce/dashcommerce/actions/runs/47085699551). The Flutterwave test-mode results above are historical. The refund-retry and renewal edge cases use fixtures. ## Review fixes included - The Flutterwave peer range covers Core 0.6.0 through the rest of the 0.x series, matching Paystack’s range pattern. The lockfile mirrors the current workspace versions and peer declarations. - The subscriptions table uses labels from the provider registry. Legacy Stripe rows still show Stripe, and rows for removed providers show their stored provider ID. - Removed the duplicated provider doc-comment opener and kept a single checkout guard for subscription carts with vendor-owned items. This branch includes the changes requested on [Provider-managed payout onboarding #103](#103): 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the Flutterwave set described in #97. Builds on the merged provider seam (#81–#84, #90); no core changes. Independent of #85 (Paystack): both packages sit on the same merged core seam, and either can merge first.
What
packages/flutterwave: aPaymentProviderfor Flutterwave on core's provider interface. It covers card, M-Pesa and mobile money through Flutterwave's hosted checkout, in NGN, USD, GBP, EUR, KES, GHS, ZAR, UGX, TZS, RWF, XOF, XAF, ZMW, MWK and EGP. It registers itself onimport "@dashcommerce/flutterwave". The README covers setup:allowedHosts: ["api.flutterwave.com"], keys, the secret hash, and the webhook URL.How it behaves
1500, and Flutterwave's1500comes back as150000. Unit-tested in both directions, including string amounts.charge.completedwithdata.status = successful, confirmed withGET /v3/transactions/:id/verifybefore core writes the order.failed/cancelledbecomecharge.failedand release the stock lock;pendingcreates nothing. The order stores the numeric transaction id aspaymentReference(refunds need it) andtx_refascheckoutReference.verif-hash, not an HMAC. The package compares it in constant time, trims whitespace, and explains the fix when it does not match. There is no timestamp, so replay protection is core's event-id dedupe plus the live verify; a replay cannot create a second order or an order Flutterwave does not confirm.charge.completed:<transaction id>:<status>andrefund:<refund id>:<status>. A repeat or overlapping delivery runs once. When confirmation fails, core releases the record, so Flutterwave's retry still creates the order.POST /v3/transactions/:id/refundwith(refundRequestId=<id>)at the end ofcomments. Flutterwave takes no idempotency key, so the package lists refunds and returns any non-failed refund already tagged with that request id instead of creating another. A reason cannot pose as a tag (brackets are stripped and the tag is anchored at the end). Atx_refis resolved to the numeric id first. Everycompleted*status maps to succeeded,pending-*/processingto pending,failedto failed.eventfield and capitalisedAmountRefunded/FlwRef/TransactionId. That maps torefund.updatedby the refund id, with each status a separate event id sopendingnever blockscompleted.GET /v3/balancescall and reports test or live mode from the key prefix.mobile_moneyresolves by currency (KES→mpesa,GHS→mobilemoneyghana, …). With no hint, Flutterwave shows what the account has enabled.Deliberately not included
FLWPUBK-…); core stores onlysecretKey/webhookSecretand gives providers no KV access. The public and secret keys do not share a hash segment (checked with a real pair), so the key cannot be derived. Hosted checkout is the equivalent flow today; Inline needs a core credential field first. The package declarescheckoutStyles: ["hosted"]rather than shipping a dead client.connect: falsemakes checkout refuse rather than silently drop a split.falsefor the same reason.Package
publishConfig.access: public, author "DashCommerce contributors". A minor changeset takes it to 0.1.0 beside core 0.4.0.bun.lockgains only the new workspace entry.Tests
charge.completedoutcomes, metadata as object and JSON string, draft recovery fromtx_ref, wrongverif-hash, amount mismatch (order held withpaymentAmountMismatch), verification outage then a successful retry, pending verification (no order), replay, refund retry guard, a failed refund retried, a new request id creating a new refund, the refund webhook moving a pending row to succeeded, and the settings API acceptingFLWSECK_TEST-while refusingFLWPUBK_.bun run typecheckpasses across the monorepo;biome checkis clean on the new files.End to end in Flutterwave test mode (24 Nov 2026)
Nigerian test account, KES wallet, test keys only.
GET /v3/balancesviacheckConnectionPOST /v3/paymentsviainitCheckoutdc-<draftId>;{CHECKOUT_SESSION_ID}strippedcheckout-v3.flutterwave.com;callbackreturnedsuccessful, transaction id10633588tx_refgetPaymentStatusreportedsucceeded,150000minor units, KESstatus: "completed"; the(refundRequestId=…)comment came back exactly as sent115050); verify still reportssuccessful400 "A partial refund is currently processing on this transaction"; surfaced, not swallowedGET /v3/refunds400 {"message":"unauthorized"}on this key, while refund creation worksWhat the run changed: the refund duplicate check now degrades to a logged warning when refund history is not available to the key, instead of blocking every refund;
meta.disburse_status: "failed"is logged becausecompletedcan mean "accepted, not yet paid out"; Flutterwave's one-partial-at-a-time rule is documented; and the README records that verify stayssuccessfulafter a refund.Still to run before release: the real webhook delivery (a real KES 100 payment and two
resend-hookcalls were accepted on 24 Nov 2026, but nothing reached the test tunnel yet — the dashboard configuration is under review), a declined payment, and the replay/verif-hashmatrix against the starter.Review notes
GET /v3/refunds) and not filterable by transaction, so the duplicate guard walks up to 20 pages (400 recent refunds) and logs when it stops. A retry is always near the top because the list is newest-first. On keys where the endpoint answersunauthorized, the guard is skipped with a warning, so a retried refund can duplicate there.data.idis the refund id or the transaction id; the OpenAPI example, the list endpoint and the refund webhook all treat it as the refund id, which is what the package relies on.