@funnelfox/billing 0.8.0-ffb-758.54 → 0.8.0-ffb-805.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -0
- package/dist/chunk-index.cjs.js +839 -15
- package/dist/chunk-index.es.js +839 -16
- package/dist/funnelfox-billing.cjs.js +1 -0
- package/dist/funnelfox-billing.esm.js +1 -1
- package/dist/funnelfox-billing.js +839 -15
- package/dist/funnelfox-billing.min.js +1 -1
- package/package.json +2 -2
- package/src/types.d.ts +108 -5
package/README.md
CHANGED
|
@@ -140,6 +140,8 @@ const checkout = await createCheckout({
|
|
|
140
140
|
- `customer.externalId` (string, required) - Your user identifier
|
|
141
141
|
- `customer.email` (string, optional) - Customer email
|
|
142
142
|
- `customer.countryCode` (string, optional) - ISO country code
|
|
143
|
+
- `options.displayCurrency` (string, optional) - ISO 4217 currency the page showed the price in (from Billing's `price_points/resolve`). Billing charges it when the price point offers it, otherwise the price point's own currency. Also accepted by `initMethod`, `createClientSession`, the Stripe forms, and (currency only) `silentPurchase` and `mountWalletUpsell`.
|
|
144
|
+
- `options.displayCountry` (string, optional) - ISO 3166-1 alpha-2 country the page resolved that currency for.
|
|
143
145
|
- `options.container` (string, required) - CSS selector for checkout container
|
|
144
146
|
- `options.card.emailAddress.visible` (boolean, optional) - Shows an email field in the card form. Disabled by default.
|
|
145
147
|
- `options.card.emailAddress.template` (string, optional) - Wraps the entered email before it is sent with payment, for example `{{email}}`.
|
|
@@ -716,6 +718,64 @@ const headlessCheckout = await Primer.createHeadless(session.clientToken, {
|
|
|
716
718
|
await headlessCheckout.start();
|
|
717
719
|
```
|
|
718
720
|
|
|
721
|
+
## One-Click Upsell With Wallet Re-Authentication
|
|
722
|
+
|
|
723
|
+
### `Billing.mountWalletUpsell(container, options)`
|
|
724
|
+
|
|
725
|
+
A saved Apple Pay / Google Pay token must not be charged as a customer-initiated payment (Primer), so a buyer who paid with a wallet confirms the upsell in the wallet sheet again, and the upsell is charged with that fresh wallet payment. Call `mountWalletUpsell` when the upsell screen loads, not on tap: Apple Pay opens its sheet only from the tap itself, so the SDK prepares everything in advance and mounts Primer's native wallet button into `container`.
|
|
726
|
+
|
|
727
|
+
```javascript
|
|
728
|
+
const mount = await Billing.mountWalletUpsell(container, {
|
|
729
|
+
orgId: 'your-org-id',
|
|
730
|
+
priceId: 'upsell_price',
|
|
731
|
+
externalId: 'user_456',
|
|
732
|
+
clientMetadata: { ff_billing_reason: 'upsell' },
|
|
733
|
+
style: {
|
|
734
|
+
buttonType: 'plain',
|
|
735
|
+
buttonColor: 'black',
|
|
736
|
+
height: 54,
|
|
737
|
+
borderRadius: 28,
|
|
738
|
+
},
|
|
739
|
+
onStart: () => {},
|
|
740
|
+
onThreeDSStart: ({ orderId }) => {},
|
|
741
|
+
onThreeDSEnd: ({ result }) => {},
|
|
742
|
+
onResult: result => {
|
|
743
|
+
// result.outcome: 'succeeded' | 'declined' | '3ds_failed' | '3ds_abandoned'
|
|
744
|
+
// | 'error' | 'processing' | 'already_purchased' | 'cancelled'
|
|
745
|
+
},
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
if (mount.mounted) {
|
|
749
|
+
// The wallet button is shown: hide your own upsell button.
|
|
750
|
+
// mount.setDisabled(true | false), mount.destroy() when the screen goes away.
|
|
751
|
+
} else if (mount.reason === 'not_wallet' || mount.reason === 'error') {
|
|
752
|
+
// Keep your own button and use Billing.silentPurchase({ handle3DS: true }).
|
|
753
|
+
} else if (mount.reason === 'wallet_unavailable') {
|
|
754
|
+
// The buyer's wallet cannot be shown on this device: open the full checkout on tap.
|
|
755
|
+
}
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
Mount result:
|
|
759
|
+
|
|
760
|
+
- `mounted: true` with `wallet` (`APPLE_PAY` or `GOOGLE_PAY`): the native button is shown.
|
|
761
|
+
- `not_wallet`: the buyer's saved method is not a Primer wallet.
|
|
762
|
+
- `wallet_unavailable`: the device cannot show the buyer's wallet. The other wallet is never offered instead.
|
|
763
|
+
- `error` with `error`: a request failed (network, 5xx, `double_purchase`, `invalid_price`, `merchant_config_error`, rate limit) or the button could not be rendered.
|
|
764
|
+
- The promise rejects only with `ValidationError`. With `mounted: false` nothing is left in `container`.
|
|
765
|
+
|
|
766
|
+
`onResult` is called exactly once per attempt, with the same fields as `silentPurchase({ handle3DS: true })` plus the outcome `cancelled`: the buyer closed the wallet sheet and nothing was charged. After `cancelled` the button stays active and can be tapped again; after any other outcome it is disabled for good. 3DS, retries with an idempotency key and the meaning of each outcome are those of `silentPurchase({ handle3DS: true })`; `processing` carries the order id the charge was reserved under.
|
|
767
|
+
|
|
768
|
+
Handled by the SDK:
|
|
769
|
+
|
|
770
|
+
- A second tap while an attempt runs is ignored, for both wallets, and so is a `silentPurchase({ handle3DS: true })` for the same buyer.
|
|
771
|
+
- The wallet session is prepared again before it expires and when the tab becomes visible with little time left. A tap on a session about to expire is ignored and the button is replaced, so the next tap works.
|
|
772
|
+
- When the backend reports the wallet session as no longer valid (nothing charged), the SDK prepares a new one and retries once with the same wallet payment, but only if the amount is unchanged. Otherwise, and when the wallet payment itself is rejected, the result is `error`.
|
|
773
|
+
- If the session cannot be prepared again while the button is shown, `onResult` gets an `error` without a tap and the button is disabled.
|
|
774
|
+
|
|
775
|
+
Style: `buttonType` `plain` | `buy` | `pay` | `continue` (a type the wallet does not have becomes `plain`; Apple Pay `continue` is drawn with Apple's `<apple-pay-button>`), `buttonColor` `black` | `white` | `white-outline` (Google Pay shows `white-outline` as `white`), `height` and `borderRadius` in px (default 54 and 28).
|
|
776
|
+
|
|
777
|
+
Apple Pay needs the page's domain to be verified for Apple Pay in Primer, as for the checkout.
|
|
778
|
+
|
|
719
779
|
## Stripe Integration
|
|
720
780
|
|
|
721
781
|
The `Billing.stripe` namespace provides a Stripe-native checkout experience — no Primer dependency required. It supports card payments via Stripe Elements and native wallet payments (Apple Pay / Google Pay) via the Payment Request API.
|