Skip to content

feat(flutterwave): on-page checkout with Flutterwave Inline - #100

Closed
alexasomba wants to merge 5 commits into
emdashCommerce:mainfrom
alexasomba:feat/flutterwave-on-page
Closed

alexasomba wants to merge 5 commits into
emdashCommerce:mainfrom
alexasomba:feat/flutterwave-on-page

Conversation

@alexasomba

Copy link
Copy Markdown
Contributor

Part of the Flutterwave set described in #97. Item 3. Builds on #98 (the package) and #99 (the public-key credential) — review those first; this branch contains their commits until they merge.

What

Flutterwave Inline as the store's on-page checkout, the same shape as Stripe Elements and Paystack's Popup:

  • The provider declares checkoutStyles: ["hosted", "on_page"] and a publicKey credential (FLWPUBK_TEST-… / FLWPUBK-…), saved by core as settings:flutterwavePublicKey.
  • With checkout set to "On your page", initCheckout returns on_page with the browser data: { publicKey, txRef, amount, currency, customerEmail, customerName?, customerPhone?, paymentOptions?, orderDraftId }. No server-side /payments call is made; Inline creates the transaction in the browser.
  • New ./checkout-client entry registers window.DashCommerceCheckoutClients.flutterwave. It loads https://checkout.flutterwave.com/v3.js only when the customer presses Pay, then calls FlutterwaveCheckout with the public key, tx_ref, amount in major units and the customer.
  • callback → onFinished(); onclose → onClosed(). A single settled guard stops onclose from firing after a successful callback.
  • Hosted checkout is unchanged.

Deliberate choices

  • No redirect_url. Flutterwave gives redirect_url precedence over callback, so passing both would navigate away before the callback could move the customer. The form's returnUrl is used instead.
  • Orders still come only from the signed webhook + live verify. The browser callback only moves the customer; a forged callback cannot create an order.
  • A missing public key fails loudly with a message naming the setting, rather than opening an Inline modal that cannot start.
  • Script loaded on demand, never on page load, so stores without on-page checkout pay nothing.

Evidence — real Flutterwave test mode (24 Nov 2026)

Check Result
./checkout-client on a local page Registered DashCommerceCheckoutClients.flutterwave; no script until Pay
Pay pressed checkout.flutterwave.com/v3.js loaded; Inline modal opened on checkout-v3.flutterwave.com
Real KES 1,500 M-Pesa payment Completed; callback fired and the page showed finished (transaction 10633614)
getPaymentStatus on the result succeeded, 150000 minor units, KES
KES 100 partial refund Succeeded (refund 115045); the disburse-status warning fired as designed
Embedded create-session without a public key Refused with "needs the public key"

Tests

  • 82 tests, including a new on-page.test.ts covering script loading on demand, the exact Inline options, callback/onclose ordering, load failure and retry, a throw from Inline, missing client data, and registration beside other providers.
  • Integration through core's real routes: embedded create-session returns on_page, the webhook still creates the order, and a missing public key is refused.
  • Provider units: on-page returns without calling the API, passes name/phone/channel hints, and still validates the cart first.
  • tsc --noEmit clean; Biome clean on the touched files; build emits both index and checkout-client entries.

Review notes

  • The public key is not a secret, but it is saved and masked through the same credential plumbing as the others (item 2). The provider reads it server-side and hands it to the browser in the create-session response.
  • The client payload is public by design; it contains no secret and no amount the webhook does not re-check.

…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.
@alexasomba

Copy link
Copy Markdown
Contributor Author

Superseded by #107 — the Flutterwave package is now reviewed as one PR. The commits are preserved on the consolidated branch, and the core PRs (#99, #101, #103, #105) stay separate.

@alexasomba alexasomba closed this Nov 24, 2026
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.
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