@flopay/shared 1.14.5 → 1.14.6
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/dist/before-button-click.d.ts +11 -0
- package/dist/card-setup-overlay-theme.d.ts +34 -0
- package/dist/card-setup-surface.d.ts +24 -0
- package/dist/card-setup-theme.d.ts +62 -0
- package/dist/card-setup.d.ts +7 -0
- package/dist/checkout-gateway-rules.d.ts +50 -0
- package/dist/checkout-outcomes.d.ts +14 -0
- package/dist/checkout-payload.d.ts +86 -0
- package/dist/checkout-process-request.d.ts +57 -0
- package/dist/config.d.ts +29 -0
- package/dist/constants.d.ts +452 -0
- package/dist/display.d.ts +64 -0
- package/dist/email-validation.d.ts +2 -0
- package/dist/errors.d.ts +53 -0
- package/dist/external-method-recovery.d.ts +24 -0
- package/dist/friendly-message.d.ts +5 -0
- package/dist/future-use.d.ts +24 -0
- package/dist/idempotency.d.ts +55 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +67 -3739
- package/dist/index.mjs +1 -1
- package/dist/inline-session-cache.d.ts +20 -0
- package/dist/instrument-dispatch.d.ts +28 -0
- package/dist/instruments.d.ts +51 -0
- package/dist/payment-logos.generated.d.ts +1 -0
- package/dist/payment-method-setup-advertisement.d.ts +67 -0
- package/dist/paypal-buyer-identity.d.ts +46 -0
- package/dist/paypal-channel.d.ts +77 -0
- package/dist/paypal-environment.d.ts +14 -0
- package/dist/postal-code-lookup.d.ts +19 -0
- package/dist/postal-code-validation.d.ts +46 -0
- package/dist/primary-tile-style.d.ts +46 -0
- package/dist/recent-completion.d.ts +2 -0
- package/dist/saved-payment-methods.d.ts +96 -0
- package/dist/sentry-filter.d.ts +21 -0
- package/dist/stripe-appearance.d.ts +19 -0
- package/dist/stripe-paypal-presentation.d.ts +42 -0
- package/dist/telemetry-failure.d.ts +14 -0
- package/dist/telemetry.d.ts +161 -0
- package/dist/types.d.ts +1747 -0
- package/dist/uuid.d.ts +19 -0
- package/dist/validation.d.ts +19 -0
- package/dist/vault-submit-theme.d.ts +22 -0
- package/dist/vault-theme.d.ts +28 -0
- package/dist/vault-verification.d.ts +45 -0
- package/dist/wallet-elements-mode.d.ts +27 -0
- package/dist/wallet-sheet-window.d.ts +44 -0
- package/package.json +4 -3
- package/dist/index.d.cts +0 -3739
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import type { AVSFieldConfig, ButtonsLayoutStyles, ButtonsLayoutTheme, CountryOption, CurrencyInfo, FloPayAppearance, ThemeBundle, ThemeBundleId, ThemeId } from './types.js';
|
|
2
|
+
/** Current SDK version. */
|
|
3
|
+
export declare const SDK_VERSION = "1.14.6";
|
|
4
|
+
/**
|
|
5
|
+
* HTTP header the SDK sends on checkout-session create/read requests so the
|
|
6
|
+
* backend can observe compatibility. Version 1.4.9 is the first release that
|
|
7
|
+
* can discover hosted card capture from an explicit Stripe `card` capability
|
|
8
|
+
* and recover the widget lazily when `session.vault` is omitted. The backend
|
|
9
|
+
* also uses this value to suppress the Flo-owned PayPal advertisement fields
|
|
10
|
+
* (`gateways.paypal.providerObjectType` and the `paypal_vaulted` entry in
|
|
11
|
+
* `enabledPaymentMethods`) for readers older than 1.6.0 — advertisement only,
|
|
12
|
+
* never request routing.
|
|
13
|
+
*
|
|
14
|
+
* @see SDK_VERSION — the value sent in this header.
|
|
15
|
+
*/
|
|
16
|
+
export declare const FLO_SDK_VERSION_HEADER = "x-flo-sdk-version";
|
|
17
|
+
/** Generic SDK response-shape negotiation header; never a gateway selector. */
|
|
18
|
+
export declare const FLO_SDK_CAPABILITIES_HEADER = "x-flo-sdk-capabilities";
|
|
19
|
+
/** Opts Auto session creation into the billing API's asynchronous `202` envelope. */
|
|
20
|
+
export declare const ASYNC_AUTO_CHECKOUT_CAPABILITY = "async-auto-checkout-v1";
|
|
21
|
+
/** Shared buyer-interaction window for saved-card and hosted-vault 3DS challenges. */
|
|
22
|
+
export declare const THREE_DS_CHALLENGE_WINDOW_MS = 300000;
|
|
23
|
+
/**
|
|
24
|
+
* In-band payment-method CHANNEL for Flo-owned PayPal continuations.
|
|
25
|
+
*
|
|
26
|
+
* The payment-method type sent to `POST /v1/checkouts/sessions/{id}/intents`
|
|
27
|
+
* is the channel selector: requesting `paypal_vaulted` opts a single request
|
|
28
|
+
* into the Flo-owned channel (an Order for `intentKind: 'payment'`, a vault
|
|
29
|
+
* setup token for `intentKind: 'setup'`), while the legacy `paypal` type keeps
|
|
30
|
+
* the released provider-managed semantics byte-identical — even when the
|
|
31
|
+
* backend feature flag is on. Sessions advertise availability via
|
|
32
|
+
* `gateways.paypal.providerObjectType` and an informational `paypal_vaulted`
|
|
33
|
+
* entry in `gateways.paypal.enabledPaymentMethods`; there is no capability
|
|
34
|
+
* header and no version-gated routing.
|
|
35
|
+
*/
|
|
36
|
+
export declare const PAYPAL_VAULTED_PAYMENT_METHOD_TYPE = "paypal_vaulted";
|
|
37
|
+
/** Stable provider-neutral saved-method outcome published by the billing API. */
|
|
38
|
+
export declare const STORED_PAYMENT_METHOD_UNSUPPORTED_CODE = "stored_payment_method_unsupported";
|
|
39
|
+
/** Buyer-safe recovery copy paired with {@link STORED_PAYMENT_METHOD_UNSUPPORTED_CODE}. */
|
|
40
|
+
export declare const STORED_PAYMENT_METHOD_UNSUPPORTED_MESSAGE = "This saved payment method can\u2019t be used for this payment. Choose another payment method.";
|
|
41
|
+
/**
|
|
42
|
+
* Buyer-facing copy for `checkout_processing_timeout`. The SDK could not confirm
|
|
43
|
+
* the outcome in time and the payment may still complete, so the buyer must
|
|
44
|
+
* never be invited to pay again (TeamFloPay/sdk#395).
|
|
45
|
+
*/
|
|
46
|
+
export declare const CHECKOUT_PROCESSING_TIMEOUT_MESSAGE = "We\u2019re still confirming your payment. Please don\u2019t pay again.";
|
|
47
|
+
/** Billing API URL for staging environment. */
|
|
48
|
+
export declare const BILLING_API_URL_STAGING = "https://api.stage.flopay.com";
|
|
49
|
+
/** Billing API URL for production environment. */
|
|
50
|
+
export declare const BILLING_API_URL_PRODUCTION = "https://api.flopay.com";
|
|
51
|
+
/**
|
|
52
|
+
* Default FloPay API base URL (used by @flopay/node). Alias for staging.
|
|
53
|
+
*
|
|
54
|
+
* @alias
|
|
55
|
+
*/
|
|
56
|
+
export declare const DEFAULT_API_BASE_URL = "https://api.stage.flopay.com";
|
|
57
|
+
/**
|
|
58
|
+
* Default billing API base URL. Alias for staging — prefer `resolveBillingApiUrl()`.
|
|
59
|
+
*
|
|
60
|
+
* @alias
|
|
61
|
+
*/
|
|
62
|
+
export declare const BILLING_API_URL = "https://api.stage.flopay.com";
|
|
63
|
+
/**
|
|
64
|
+
* Resolve the billing API URL from available configuration.
|
|
65
|
+
*
|
|
66
|
+
* Priority:
|
|
67
|
+
* 1. Explicit `billingApiUrl` (prop/param override)
|
|
68
|
+
* 2. `NEXT_PUBLIC_FLOPAY_ENV` environment variable (`'staging'` | `'production'`)
|
|
69
|
+
* 3. `configureFlopay()` global environment setting
|
|
70
|
+
* 4. Fallback: staging URL
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { resolveBillingApiUrl } from '@flopay/shared';
|
|
75
|
+
*
|
|
76
|
+
* // Reads from env var or configureFlopay() — no args needed
|
|
77
|
+
* const url = resolveBillingApiUrl();
|
|
78
|
+
*
|
|
79
|
+
* // Explicit override takes priority
|
|
80
|
+
* const url = resolveBillingApiUrl('https://custom.example.com');
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function resolveBillingApiUrl(billingApiUrl?: string): string;
|
|
84
|
+
/** Default API version header value. */
|
|
85
|
+
export declare const DEFAULT_API_VERSION = "2024-01-01";
|
|
86
|
+
/** The default appearance applied when no custom appearance is provided. */
|
|
87
|
+
export declare const DEFAULT_APPEARANCE: FloPayAppearance;
|
|
88
|
+
/** Flat theme — minimal borders and shadows. */
|
|
89
|
+
export declare const FLAT_APPEARANCE: FloPayAppearance;
|
|
90
|
+
/** Night theme — dark background. */
|
|
91
|
+
export declare const NIGHT_APPEARANCE: FloPayAppearance;
|
|
92
|
+
/** Modern light — clean & airy: Inter, soft shadows, generous spacing, 12px radius. */
|
|
93
|
+
export declare const MODERN_LIGHT_APPEARANCE: FloPayAppearance;
|
|
94
|
+
/** Modern dark — clean & airy on a deep-blue surface, 12px radius. */
|
|
95
|
+
export declare const MODERN_DARK_APPEARANCE: FloPayAppearance;
|
|
96
|
+
/** Bold light — vibrant: saturated primary, gradient submit, heavier weights. */
|
|
97
|
+
export declare const BOLD_LIGHT_APPEARANCE: FloPayAppearance;
|
|
98
|
+
/** Bold dark — saturated deep-blue surface, gradient submit. */
|
|
99
|
+
export declare const BOLD_DARK_APPEARANCE: FloPayAppearance;
|
|
100
|
+
/** Glass light — translucent surfaces with backdrop blur over a pastel blue gradient. */
|
|
101
|
+
export declare const GLASS_LIGHT_APPEARANCE: FloPayAppearance;
|
|
102
|
+
/** Glass dark — translucent surfaces with backdrop blur over a deep-blue gradient. */
|
|
103
|
+
export declare const GLASS_DARK_APPEARANCE: FloPayAppearance;
|
|
104
|
+
/** Default buttons layout — white card button, neutral borders. */
|
|
105
|
+
export declare const BUTTONS_LAYOUT_DEFAULT: ButtonsLayoutStyles;
|
|
106
|
+
/** Minimal buttons layout — borderless, subtle hover. */
|
|
107
|
+
export declare const BUTTONS_LAYOUT_MINIMAL: ButtonsLayoutStyles;
|
|
108
|
+
/** Rounded buttons layout — large border radius, soft shadows. */
|
|
109
|
+
export declare const BUTTONS_LAYOUT_ROUNDED: ButtonsLayoutStyles;
|
|
110
|
+
/** Dark buttons layout — dark backgrounds, light text. */
|
|
111
|
+
export declare const BUTTONS_LAYOUT_DARK: ButtonsLayoutStyles;
|
|
112
|
+
/** Modern light — soft surface, 14px radius, FloPay-blue submit with subtle shadow. */
|
|
113
|
+
export declare const BUTTONS_LAYOUT_MODERN_LIGHT: ButtonsLayoutStyles;
|
|
114
|
+
/** Modern dark — deep surface, 14px radius, sky-blue submit. */
|
|
115
|
+
export declare const BUTTONS_LAYOUT_MODERN_DARK: ButtonsLayoutStyles;
|
|
116
|
+
/** Bold light — blue-tint backdrop, primary-bordered card, gradient pill submit. */
|
|
117
|
+
export declare const BUTTONS_LAYOUT_BOLD_LIGHT: ButtonsLayoutStyles;
|
|
118
|
+
/** Bold dark — saturated deep-blue surface, accented borders, gradient pill submit. */
|
|
119
|
+
export declare const BUTTONS_LAYOUT_BOLD_DARK: ButtonsLayoutStyles;
|
|
120
|
+
/** Glass light — translucent surfaces with backdrop blur over a pastel blue gradient. */
|
|
121
|
+
export declare const BUTTONS_LAYOUT_GLASS_LIGHT: ButtonsLayoutStyles;
|
|
122
|
+
/** Glass dark — translucent surfaces with backdrop blur over a deep-blue gradient. */
|
|
123
|
+
export declare const BUTTONS_LAYOUT_GLASS_DARK: ButtonsLayoutStyles;
|
|
124
|
+
/** Resolve a buttons layout theme name to its style preset. */
|
|
125
|
+
export declare function resolveButtonsLayoutTheme(theme?: ButtonsLayoutTheme): ButtonsLayoutStyles;
|
|
126
|
+
/**
|
|
127
|
+
* First-class theme bundles. Each entry pairs a `FloPayAppearance` (for Stripe
|
|
128
|
+
* Elements) with a `ButtonsLayoutStyles` (for the FloPay wrapper) so the look
|
|
129
|
+
* is coherent across both halves. Consumers can pick by id without having to
|
|
130
|
+
* import the two halves separately.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```tsx
|
|
134
|
+
* import { THEMES } from '@flopay/shared';
|
|
135
|
+
*
|
|
136
|
+
* const { appearance, buttonsLayout } = THEMES['glass-dark'];
|
|
137
|
+
* <FloPayCheckout appearance={appearance} buttonsLayoutStyles={buttonsLayout} />
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare const THEMES: Record<ThemeBundleId, ThemeBundle>;
|
|
141
|
+
/**
|
|
142
|
+
* Resolve a {@link ThemeId} to its {@link ThemeBundle}, or `undefined` for
|
|
143
|
+
* `'classic'` / a missing id (the historic FloPay look with no bundle applied).
|
|
144
|
+
*
|
|
145
|
+
* Used by FloPay React components when consumers pass the high-level `theme`
|
|
146
|
+
* prop instead of supplying `appearance` + `buttonsStyles` manually. Explicit
|
|
147
|
+
* `appearance` / `buttonsStyles` props still override the resolved bundle.
|
|
148
|
+
*/
|
|
149
|
+
export declare function resolveTheme(id?: ThemeId | null): ThemeBundle | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* Map Stripe wire identifiers (`apple_pay`, `google_pay`, `amazon_pay`) to the
|
|
152
|
+
* camelCase keys that `ExpressCheckoutElement`'s `paymentMethods` options
|
|
153
|
+
* map expects. Everything not in this map is already camelCase compatible.
|
|
154
|
+
*/
|
|
155
|
+
export declare function stripeExpressMethodToOptionKey(method: string): string;
|
|
156
|
+
/**
|
|
157
|
+
* Per-method metadata for every Stripe payment-method type the SDK
|
|
158
|
+
* recognises. One source of truth instead of half a dozen disjoint maps —
|
|
159
|
+
* `STRIPE_METHOD_CURRENCIES`, `STRIPE_METHOD_AMOUNT_LIMITS`, the React
|
|
160
|
+
* package's display-name table, and the inline-form heuristic all derive
|
|
161
|
+
* from entries here.
|
|
162
|
+
*
|
|
163
|
+
* Source: Stripe payment-method support matrices at
|
|
164
|
+
* <https://docs.stripe.com/payments/payment-methods/integration-options>.
|
|
165
|
+
* Update entries when Stripe ships a new currency / amount limit / method
|
|
166
|
+
* — the SDK falls back to safe defaults for any wire identifier not listed.
|
|
167
|
+
*/
|
|
168
|
+
export interface StripeMethodEntry {
|
|
169
|
+
/**
|
|
170
|
+
* Human-readable label, used by consumers for "Pay with X" buttons and
|
|
171
|
+
* other UI surfaces that need the brand name.
|
|
172
|
+
*/
|
|
173
|
+
displayName: string;
|
|
174
|
+
/**
|
|
175
|
+
* Lowercase ISO-4217 currency codes Stripe accepts for this method. The
|
|
176
|
+
* sentinel `'*'` means "currency-agnostic" — only the universal big-button
|
|
177
|
+
* wallets (Apple Pay / Google Pay) use this today.
|
|
178
|
+
*/
|
|
179
|
+
currencies: readonly string[];
|
|
180
|
+
/**
|
|
181
|
+
* Uppercase ISO 3166-1 alpha-2 codes for the buyer countries Stripe makes
|
|
182
|
+
* this method available to (matched against the session customer's
|
|
183
|
+
* country). Many local APMs are country-gated independently of currency —
|
|
184
|
+
* Bancontact is Belgium-only, EPS Austria-only, iDEAL Netherlands-only,
|
|
185
|
+
* SEPA Debit the whole SEPA zone — so a EUR cart still must not offer
|
|
186
|
+
* Bancontact to a Dutch buyer.
|
|
187
|
+
*
|
|
188
|
+
* **Omit** for methods with no meaningful country restriction (the global
|
|
189
|
+
* wallets, Alipay, Klarna, …) — a missing list means "no country gate", so
|
|
190
|
+
* the method passes {@link filterStripeMethodsByCountry} for every buyer.
|
|
191
|
+
*/
|
|
192
|
+
countries?: readonly string[];
|
|
193
|
+
/**
|
|
194
|
+
* Per-currency amount min/max in the smallest currency unit (cents for USD,
|
|
195
|
+
* pence for GBP, etc.). Omit when there is no notable limit. Stripe's
|
|
196
|
+
* `/v1/elements/sessions` rejects the whole accordion when an entry is in
|
|
197
|
+
* `paymentMethodTypes` and the deferred-intent amount falls outside its
|
|
198
|
+
* advertised range, so filtering here matches Stripe's reality.
|
|
199
|
+
*/
|
|
200
|
+
amounts?: Record<string, {
|
|
201
|
+
min?: number;
|
|
202
|
+
max?: number;
|
|
203
|
+
}>;
|
|
204
|
+
/**
|
|
205
|
+
* True when this method renders inside Stripe's `ExpressCheckoutElement`
|
|
206
|
+
* (apple_pay, google_pay, paypal, link, amazon_pay, klarna). Everything
|
|
207
|
+
* else lives in the `PaymentElement` accordion.
|
|
208
|
+
*/
|
|
209
|
+
express?: boolean;
|
|
210
|
+
/**
|
|
211
|
+
* When `false`, the SDK auto-submits the moment the buyer clicks the
|
|
212
|
+
* method card — the buyer is taken straight to Stripe's authorization UI
|
|
213
|
+
* (popup / redirect) without an intermediate confirm step. Only set this
|
|
214
|
+
* for *pure* redirect-only methods that have no inline data collection
|
|
215
|
+
* (Cash App, Affirm).
|
|
216
|
+
*
|
|
217
|
+
* **Default `true`**: render an explicit "Pay with X" button at the
|
|
218
|
+
* bottom of the accordion. Safer-by-default — any new/unknown APM, or
|
|
219
|
+
* any method whose Stripe UI changes to add inline inputs, will surface
|
|
220
|
+
* a deliberate confirm action instead of silently auto-submitting on a
|
|
221
|
+
* stray keystroke. Bancontact / Giropay are theoretically redirect-only
|
|
222
|
+
* but ship with a Name input by default, so they stay on the default
|
|
223
|
+
* (button) path.
|
|
224
|
+
*/
|
|
225
|
+
needsExplicitConfirm?: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* Per-mode brand styling for the method tile button. The SDK looks up
|
|
228
|
+
* `theme.dark` when the active FloPay theme is one of the `*-dark`
|
|
229
|
+
* bundles, otherwise `theme.light` (also used for `classic`, since
|
|
230
|
+
* brand assets are designed primarily against light surfaces).
|
|
231
|
+
*
|
|
232
|
+
* Entries are optional — methods without a `theme` fall back to the
|
|
233
|
+
* neutral tile styling derived from the theme's `buttonsStyles.cardButton`
|
|
234
|
+
* + `derivePrimaryTileStyle`. Consumers can override per-tile via
|
|
235
|
+
* `buttonAppearance` on the inner component.
|
|
236
|
+
*/
|
|
237
|
+
theme?: {
|
|
238
|
+
light?: StripeMethodThemeVariant;
|
|
239
|
+
dark?: StripeMethodThemeVariant;
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Per-mode visual treatment for a Stripe method tile button. Applies brand
|
|
244
|
+
* colors and (optionally) an inline mark so each APM tile reads
|
|
245
|
+
* unmistakably as itself.
|
|
246
|
+
*
|
|
247
|
+
* `logoSvg` is an inline SVG string rendered at ~22px tall inside the
|
|
248
|
+
* button before the label. The SDK ships a small generic placeholder mark
|
|
249
|
+
* per method (a colored disc + initial) authored as original geometry —
|
|
250
|
+
* **not** a reproduction of any official trademarked logo. Consumers who
|
|
251
|
+
* have rights to a brand's artwork can replace these per-entry by
|
|
252
|
+
* overriding the matrix in their own deployment.
|
|
253
|
+
*/
|
|
254
|
+
export interface StripeMethodThemeVariant {
|
|
255
|
+
backgroundColor?: string;
|
|
256
|
+
borderColor?: string;
|
|
257
|
+
textColor?: string;
|
|
258
|
+
/**
|
|
259
|
+
* Inline SVG markup, e.g. `'<svg viewBox="0 0 24 24">…</svg>'`. Trusted
|
|
260
|
+
* by the renderer (mounted via `dangerouslySetInnerHTML`) — only edit
|
|
261
|
+
* via this matrix or a controlled override; never wire user input here.
|
|
262
|
+
*/
|
|
263
|
+
logoSvg?: string;
|
|
264
|
+
}
|
|
265
|
+
export declare const STRIPE_METHOD_MATRIX: Record<string, StripeMethodEntry>;
|
|
266
|
+
/**
|
|
267
|
+
* Whether a method's `logoSvg` is a vendored real brand logo (from
|
|
268
|
+
* `fetch:logos`) rather than the SDK's generated placeholder mark. Tile
|
|
269
|
+
* buttons use this to size the gap between logo and label: the real logos
|
|
270
|
+
* are self-contained cards that read as a separate mark (8px gap), whereas
|
|
271
|
+
* the generated placeholder monogram reads as part of the label (0px gap).
|
|
272
|
+
*/
|
|
273
|
+
export declare function hasVendoredStripeMethodLogo(type: string | null | undefined): boolean;
|
|
274
|
+
/**
|
|
275
|
+
* Stripe payment method types that render as native big buttons in the
|
|
276
|
+
* `ExpressCheckoutElement`. Everything else falls into the `PaymentElement`
|
|
277
|
+
* accordion. Derived from {@link STRIPE_METHOD_MATRIX} entries flagged
|
|
278
|
+
* `express: true` — insertion order in the matrix dictates the wallet-row
|
|
279
|
+
* ordering (apple_pay → google_pay → paypal → link → amazon_pay → klarna).
|
|
280
|
+
*/
|
|
281
|
+
export declare const STRIPE_EXPRESS_METHODS: readonly string[];
|
|
282
|
+
/**
|
|
283
|
+
* Stripe payment-method → supported-currencies map. Derived from
|
|
284
|
+
* {@link STRIPE_METHOD_MATRIX} — kept as a separate export for callers that
|
|
285
|
+
* just want the currency list without the rest of the entry.
|
|
286
|
+
*
|
|
287
|
+
* Stripe rejects the entire `PaymentElement` mount with an `IntegrationError`
|
|
288
|
+
* when `paymentMethodTypes` contains a method that doesn't support the session
|
|
289
|
+
* currency (e.g. `bancontact` on a USD session). The SDK drops those methods
|
|
290
|
+
* before forwarding them to Stripe so a single mis-matched method doesn't
|
|
291
|
+
* blank out the whole accordion.
|
|
292
|
+
*
|
|
293
|
+
* Unknown methods (anything not in the matrix) pass through unchanged so a
|
|
294
|
+
* brand-new Stripe APM keeps working until the matrix is refreshed.
|
|
295
|
+
*/
|
|
296
|
+
export declare const STRIPE_METHOD_CURRENCIES: Record<string, readonly string[]>;
|
|
297
|
+
/**
|
|
298
|
+
* Stripe payment-method → supported-buyer-countries map (uppercase ISO
|
|
299
|
+
* 3166-1 alpha-2). Derived from {@link STRIPE_METHOD_MATRIX}; only methods
|
|
300
|
+
* that declared a `countries` list appear here. Methods absent from this map
|
|
301
|
+
* have no country gate and are offered to every buyer (subject to the
|
|
302
|
+
* currency / amount filters).
|
|
303
|
+
*
|
|
304
|
+
* Local APMs like Bancontact (BE), EPS (AT) and iDEAL (NL) are available
|
|
305
|
+
* only to buyers in their home country even on a EUR cart, so the SDK drops
|
|
306
|
+
* them when the session customer's country doesn't match — mirroring what
|
|
307
|
+
* Stripe's `PaymentElement` would do from the buyer's locale anyway.
|
|
308
|
+
*/
|
|
309
|
+
export declare const STRIPE_METHOD_COUNTRIES: Record<string, readonly string[]>;
|
|
310
|
+
/**
|
|
311
|
+
* Display-name lookup. Falls back to a title-cased version of the wire id
|
|
312
|
+
* (e.g. `au_becs_debit` → `Au Becs Debit`) for methods not in the matrix so
|
|
313
|
+
* a brand-new APM still produces a legible label until the matrix catches up.
|
|
314
|
+
*/
|
|
315
|
+
export declare function getStripeMethodDisplayName(type: string | null | undefined): string;
|
|
316
|
+
/**
|
|
317
|
+
* Whether the SDK should render an explicit "Pay with X" button for this
|
|
318
|
+
* method rather than auto-submitting on click. Defaults to `true` (safer for
|
|
319
|
+
* unknown methods) — only methods explicitly flagged `needsExplicitConfirm:
|
|
320
|
+
* false` in the matrix (Cash App, Affirm) auto-submit.
|
|
321
|
+
*/
|
|
322
|
+
export declare function needsStripeMethodExplicitConfirm(type: string | null | undefined): boolean;
|
|
323
|
+
/**
|
|
324
|
+
* Resolve the per-mode brand styling for a method tile button, given the
|
|
325
|
+
* active FloPay theme id. Returns `null` when the method has no `theme`
|
|
326
|
+
* entry in the matrix — callers fall back to the neutral tile styling
|
|
327
|
+
* derived from `buttonsStyles.cardButton`.
|
|
328
|
+
*
|
|
329
|
+
* Theme-id → variant rule:
|
|
330
|
+
* - `*-dark` themes get `theme.dark` (then `theme.light` as fallback).
|
|
331
|
+
* - Everything else (`classic`, `*-light`, undefined) gets `theme.light`.
|
|
332
|
+
*/
|
|
333
|
+
export declare function resolveStripeMethodBrandVariant(type: string | null | undefined, themeId: ThemeId | null | undefined): StripeMethodThemeVariant | null;
|
|
334
|
+
/**
|
|
335
|
+
* Filter a Stripe payment-method wire-identifier list down to those that
|
|
336
|
+
* support the supplied ISO-4217 currency code. Unknown methods (anything not
|
|
337
|
+
* in {@link STRIPE_METHOD_CURRENCIES}) pass through unchanged so a brand-new
|
|
338
|
+
* Stripe APM keeps working until the SDK ships an updated map.
|
|
339
|
+
*
|
|
340
|
+
* The currency comparison is case-insensitive (`USD` and `usd` both match).
|
|
341
|
+
* An empty / missing currency disables filtering entirely (returns the input
|
|
342
|
+
* list as-is) — callers that don't know the currency are still better off
|
|
343
|
+
* letting Stripe fail loudly than dropping everything to silence.
|
|
344
|
+
*/
|
|
345
|
+
export declare function filterStripeMethodsByCurrency(methods: readonly string[] | undefined, currency: string | undefined): string[];
|
|
346
|
+
/**
|
|
347
|
+
* Filter a Stripe payment-method wire-identifier list down to those available
|
|
348
|
+
* to the supplied buyer country (ISO 3166-1 alpha-2). Methods with no country
|
|
349
|
+
* gate in {@link STRIPE_METHOD_COUNTRIES} — the global wallets, Alipay,
|
|
350
|
+
* Klarna, unknown methods — pass through unchanged.
|
|
351
|
+
*
|
|
352
|
+
* The country comparison is case-insensitive (`be` and `BE` both match). An
|
|
353
|
+
* empty / missing country disables filtering entirely (returns the input list
|
|
354
|
+
* as-is) — when the session doesn't know the buyer's country we'd rather let
|
|
355
|
+
* Stripe make the final call than drop every country-gated method.
|
|
356
|
+
*/
|
|
357
|
+
export declare function filterStripeMethodsByCountry(methods: readonly string[] | undefined, country: string | undefined): string[];
|
|
358
|
+
/**
|
|
359
|
+
* Per-method amount limits (in the smallest currency unit, e.g. cents for USD)
|
|
360
|
+
* keyed by Stripe wire identifier and then currency code. Derived from
|
|
361
|
+
* {@link STRIPE_METHOD_MATRIX} — kept as a separate export for callers that
|
|
362
|
+
* just want the amount limits without the rest of the entry.
|
|
363
|
+
*
|
|
364
|
+
* Stripe's `/v1/elements/sessions` endpoint hard-400's when
|
|
365
|
+
* `paymentMethodTypes` contains a method whose per-currency minimum or
|
|
366
|
+
* maximum is violated by the deferred-intent amount — and a single rejected
|
|
367
|
+
* method blanks out the entire `PaymentElement` accordion ("Frame not
|
|
368
|
+
* initialized" / empty `<div class="">` shell). Filtering here matches
|
|
369
|
+
* Stripe's reality so an incompatible amount silently drops the offending
|
|
370
|
+
* method instead of poisoning the whole mount.
|
|
371
|
+
*/
|
|
372
|
+
export declare const STRIPE_METHOD_AMOUNT_LIMITS: Record<string, Record<string, {
|
|
373
|
+
min?: number;
|
|
374
|
+
max?: number;
|
|
375
|
+
}>>;
|
|
376
|
+
/**
|
|
377
|
+
* Filter a Stripe payment-method wire-identifier list down to those whose
|
|
378
|
+
* per-currency amount range accepts {@link amountInMinorUnits}. Unknown methods
|
|
379
|
+
* (anything not in {@link STRIPE_METHOD_AMOUNT_LIMITS}) pass through unchanged
|
|
380
|
+
* so a brand-new Stripe APM keeps working without an SDK update.
|
|
381
|
+
*
|
|
382
|
+
* Currency comparison is case-insensitive. Missing currency / amount disables
|
|
383
|
+
* filtering — callers that don't know the cart yet should pass through the
|
|
384
|
+
* full list rather than silently dropping everything.
|
|
385
|
+
*/
|
|
386
|
+
export declare function filterStripeMethodsByAmount(methods: readonly string[] | undefined, currency: string | undefined, amountInMinorUnits: number | undefined): string[];
|
|
387
|
+
/**
|
|
388
|
+
* Partition the backend's `enabledPaymentMethods` list into the two SDK
|
|
389
|
+
* regions inside `SplitCardForm`:
|
|
390
|
+
*
|
|
391
|
+
* - `expressMethods` — intersected with {@link STRIPE_EXPRESS_METHODS} so
|
|
392
|
+
* only `ExpressCheckoutElement`-supported methods land in the big-button
|
|
393
|
+
* row.
|
|
394
|
+
* - `paymentElementMethods` — every remaining method (Cash App Pay, Affirm,
|
|
395
|
+
* iDEAL, Bancontact, SEPA debit, …) for the `PaymentElement` accordion.
|
|
396
|
+
*
|
|
397
|
+
* `card` is dropped from both lists — the card path stays on the split
|
|
398
|
+
* fields. When `options.excludePaypal` is `true`, the SDK is rendering
|
|
399
|
+
* `DirectPayPalButton` separately and PayPal is also pulled out of the
|
|
400
|
+
* express list to avoid double-rendering.
|
|
401
|
+
*/
|
|
402
|
+
export declare function partitionStripeMethods(enabledPaymentMethods: readonly string[] | undefined, options?: {
|
|
403
|
+
excludePaypal?: boolean;
|
|
404
|
+
}): {
|
|
405
|
+
expressMethods: string[];
|
|
406
|
+
paymentElementMethods: string[];
|
|
407
|
+
};
|
|
408
|
+
export declare const SUPPORTED_CARD_BRANDS: readonly ['visa', 'mastercard', 'mastercard_debit', 'amex', 'discover'];
|
|
409
|
+
/** Country code to currency information mapping. */
|
|
410
|
+
export declare const CURRENCY_MAP: Record<string, CurrencyInfo>;
|
|
411
|
+
/** Default currency info when country is unknown. */
|
|
412
|
+
export declare const DEFAULT_CURRENCY: CurrencyInfo;
|
|
413
|
+
/** Returns the correct postal code label for a country code (ISO 3166-1 alpha-2). */
|
|
414
|
+
export declare function getPostalCodeLabel(countryCode: string): string;
|
|
415
|
+
/** All countries for dropdown select, priority countries first. */
|
|
416
|
+
export declare const COUNTRY_OPTIONS: CountryOption[];
|
|
417
|
+
/** Look up a country option by ISO 3166-1 alpha-2 code. */
|
|
418
|
+
export declare function getCountryByCode(code: string): CountryOption | undefined;
|
|
419
|
+
/**
|
|
420
|
+
* Normalize `enableAVS` to a resolved config object.
|
|
421
|
+
* - `false` / `undefined` → `null` (AVS disabled)
|
|
422
|
+
* - `true` → default config (country + postal_code)
|
|
423
|
+
* - `AVSFieldConfig` → returned as-is
|
|
424
|
+
*/
|
|
425
|
+
export declare function resolveAVSConfig(enableAVS?: boolean | AVSFieldConfig): AVSFieldConfig | null;
|
|
426
|
+
/**
|
|
427
|
+
* Check if an AVS field should be visible for the given country.
|
|
428
|
+
* - `undefined` / `false` → hidden
|
|
429
|
+
* - `true` → visible for all countries
|
|
430
|
+
* - `string[]` (non-empty) → visible only for listed country codes
|
|
431
|
+
* - `[]` (empty) → visible for no countries; use `true` to show everywhere.
|
|
432
|
+
* A UI that wants "clear the country list = show everywhere" must normalize
|
|
433
|
+
* the cleared list to `true` before persisting — preserves the historical
|
|
434
|
+
* `[]` = "off" semantics so existing configs don't start rendering AVS
|
|
435
|
+
* globally.
|
|
436
|
+
*/
|
|
437
|
+
export declare function isAVSFieldVisible(field: boolean | string[] | undefined, country: string): boolean;
|
|
438
|
+
/** Returns true if any AVS field is meaningfully configured (at least one field is truthy). */
|
|
439
|
+
export declare function isAVSEnabled(enableAVS?: boolean | AVSFieldConfig): boolean;
|
|
440
|
+
export interface StateOption {
|
|
441
|
+
code: string;
|
|
442
|
+
name: string;
|
|
443
|
+
}
|
|
444
|
+
export declare const US_STATES: StateOption[];
|
|
445
|
+
export declare const CA_PROVINCES: StateOption[];
|
|
446
|
+
/**
|
|
447
|
+
* Get state/province options for a country.
|
|
448
|
+
* Returns a list for US and CA, or `null` for countries where a free-text input is appropriate.
|
|
449
|
+
*/
|
|
450
|
+
export declare function getStateOptions(country: string): StateOption[] | null;
|
|
451
|
+
/** Returns the appropriate label for the state/province field based on country. */
|
|
452
|
+
export declare function getStateLabel(countryCode: string): string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { CheckoutSession } from './types.js';
|
|
2
|
+
/** A single line item formatted for display in the checkout UI. */
|
|
3
|
+
export interface DisplayLineItem {
|
|
4
|
+
name: string;
|
|
5
|
+
quantity: number;
|
|
6
|
+
/** Price per unit in the session's currency (major units, e.g. 24.95). */
|
|
7
|
+
price: number;
|
|
8
|
+
/** Original price per unit before any discount (major units). */
|
|
9
|
+
originalPrice: number;
|
|
10
|
+
}
|
|
11
|
+
/** Computed display data for rendering an order summary. */
|
|
12
|
+
export interface CheckoutDisplayData {
|
|
13
|
+
/** Individual items/subscriptions with names, prices, and quantities. */
|
|
14
|
+
items: DisplayLineItem[];
|
|
15
|
+
/** ISO 4217 currency code (uppercase). */
|
|
16
|
+
currency: string;
|
|
17
|
+
/** Total amount due after discounts (major units, e.g. 24.95). */
|
|
18
|
+
total: number;
|
|
19
|
+
/** Sum of original prices before discounts (major units). */
|
|
20
|
+
originalTotal: number;
|
|
21
|
+
/** Total savings (originalTotal - total), clamped to >= 0. */
|
|
22
|
+
totalSave: number;
|
|
23
|
+
/** Discount percentage (0–100). */
|
|
24
|
+
discountPercent: number;
|
|
25
|
+
/**
|
|
26
|
+
* Coupon discount reported by the backend (cart-currency major units),
|
|
27
|
+
* when available. Populated from `session.discountAmount` (billing
|
|
28
|
+
* API ≥ v1.1.2); `undefined` on older backends. Use this to render an
|
|
29
|
+
* explicit "coupon" line without recomputing per-item math.
|
|
30
|
+
*/
|
|
31
|
+
couponDiscount?: number;
|
|
32
|
+
}
|
|
33
|
+
/** Options for {@link buildCheckoutDisplayData}. */
|
|
34
|
+
export interface BuildCheckoutDisplayDataOptions {
|
|
35
|
+
/**
|
|
36
|
+
* When `true`, items are hidden from the order summary if the session also
|
|
37
|
+
* contains subscriptions (matches the legacy checkout/CheckoutModal
|
|
38
|
+
* behavior). Defaults to `false` — items are always shown.
|
|
39
|
+
*/
|
|
40
|
+
hideBundledItems?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Builds display data from a `CheckoutSession` for rendering an order summary.
|
|
44
|
+
*
|
|
45
|
+
* - Subscriptions are always shown
|
|
46
|
+
* - Items are shown by default; pass `{ hideBundledItems: true }` to suppress
|
|
47
|
+
* them when the session also contains subscriptions (legacy behavior)
|
|
48
|
+
* - `overrideAmount` (when not null/undefined) is the discounted price
|
|
49
|
+
* - Plan name "4-WEEK PLAN" with price <= 1 is renamed to "7-DAY TRIAL: FULL ACCESS"
|
|
50
|
+
* - Discount percentage and savings are computed from the difference
|
|
51
|
+
*
|
|
52
|
+
* All amounts are in **major currency units** (dollars, not cents).
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { buildCheckoutDisplayData } from '@flopay/shared';
|
|
57
|
+
*
|
|
58
|
+
* const display = buildCheckoutDisplayData(session);
|
|
59
|
+
* // display.items → [{ name: 'Starter', price: 24.95, originalPrice: 24.95, quantity: 1 }]
|
|
60
|
+
* // display.total → 24.95
|
|
61
|
+
* // display.currency → 'EUR'
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function buildCheckoutDisplayData(session: CheckoutSession, options?: BuildCheckoutDisplayDataOptions): CheckoutDisplayData;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { TelemetryAppFamily, TelemetryPopupCapability, TelemetryPresentationMode } from './telemetry.js';
|
|
2
|
+
/** Discriminated error types returned by the FloPay SDK. */
|
|
3
|
+
export type FloPayErrorType = 'validation_error' | 'api_error' | 'authentication_error' | 'rate_limit_error' | 'network_error';
|
|
4
|
+
/** Privacy-bounded diagnostics for an external wallet or PayPal failure. */
|
|
5
|
+
export interface ExternalMethodFailureDetails {
|
|
6
|
+
providerCode: string;
|
|
7
|
+
popupBlocked: boolean;
|
|
8
|
+
inAppBrowser: boolean;
|
|
9
|
+
appFamily: TelemetryAppFamily;
|
|
10
|
+
popupCapability: TelemetryPopupCapability;
|
|
11
|
+
presentationMode?: TelemetryPresentationMode;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Custom error class for all FloPay SDK errors.
|
|
15
|
+
*
|
|
16
|
+
* Extends the native `Error` and adds structured fields that mirror
|
|
17
|
+
* Stripe-style error responses for familiarity.
|
|
18
|
+
*/
|
|
19
|
+
export declare class FloPayError extends Error {
|
|
20
|
+
readonly type: FloPayErrorType;
|
|
21
|
+
readonly code?: string;
|
|
22
|
+
readonly declineCode?: string;
|
|
23
|
+
readonly param?: string;
|
|
24
|
+
readonly statusCode?: number;
|
|
25
|
+
readonly details?: ExternalMethodFailureDetails;
|
|
26
|
+
/**
|
|
27
|
+
* The checkout session the failure belongs to, when one exists: for matching
|
|
28
|
+
* it to `payment.*` webhooks, the dashboard, or a support request. Never the
|
|
29
|
+
* session nonce.
|
|
30
|
+
*/
|
|
31
|
+
readonly sessionId?: string;
|
|
32
|
+
/** The underlying error when this one wraps another (the standard `Error.cause` slot). */
|
|
33
|
+
readonly cause?: unknown;
|
|
34
|
+
constructor(message: string, type: FloPayErrorType, options?: {
|
|
35
|
+
code?: string;
|
|
36
|
+
declineCode?: string;
|
|
37
|
+
param?: string;
|
|
38
|
+
statusCode?: number;
|
|
39
|
+
details?: ExternalMethodFailureDetails;
|
|
40
|
+
sessionId?: string;
|
|
41
|
+
cause?: unknown;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** Create a validation error (e.g. missing required field). */
|
|
45
|
+
export declare function validationError(message: string, param?: string): FloPayError;
|
|
46
|
+
/** Create an API error (e.g. upstream provider returned an error). */
|
|
47
|
+
export declare function apiError(message: string, code?: string, statusCode?: number): FloPayError;
|
|
48
|
+
/** Create an authentication error (e.g. invalid publishable key). */
|
|
49
|
+
export declare function authenticationError(message: string): FloPayError;
|
|
50
|
+
/** Create a rate limit error. */
|
|
51
|
+
export declare function rateLimitError(message: string): FloPayError;
|
|
52
|
+
/** Create a network error (e.g. fetch failed). */
|
|
53
|
+
export declare function networkError(message: string): FloPayError;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TelemetryTerminalReason } from './telemetry.js';
|
|
2
|
+
export declare const EXTERNAL_METHOD_CALLBACK_GRACE_MS = 600;
|
|
3
|
+
export interface ExternalMethodFailureContext {
|
|
4
|
+
inAppBrowser: boolean;
|
|
5
|
+
handoffObserved: boolean;
|
|
6
|
+
/** May corroborate a recognized signal, but never determines classification. */
|
|
7
|
+
elapsedMs?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ExternalMethodFailureClassification {
|
|
10
|
+
errorCode: 'POPUP_BLOCKED' | 'PROVIDER_RUNTIME_FAILED';
|
|
11
|
+
popupBlocked: boolean;
|
|
12
|
+
providerDeclined: boolean;
|
|
13
|
+
terminalReason: TelemetryTerminalReason;
|
|
14
|
+
}
|
|
15
|
+
/** One buyer-copy contract shared by wallets and both PayPal integrations. */
|
|
16
|
+
export declare function buildExternalMethodRecoveryMessage(displayName: string, popupBlocked: boolean, inAppBrowser: boolean): string;
|
|
17
|
+
export declare function sanitizeExternalFailureCode(value: unknown): string | undefined;
|
|
18
|
+
export declare function getProviderErrorCode(err: unknown): string | undefined;
|
|
19
|
+
export declare function getProviderDeclineCode(err: unknown): string | undefined;
|
|
20
|
+
export declare function isProviderDecline(err: unknown): boolean;
|
|
21
|
+
export declare function isPayPalAcknowledgementDeadWindow(err: unknown): boolean;
|
|
22
|
+
/** Classifies only bounded, positive evidence; time by itself is never evidence. */
|
|
23
|
+
export declare function classifyExternalMethodFailure(err: unknown, context: ExternalMethodFailureContext): ExternalMethodFailureClassification;
|
|
24
|
+
export declare function isPopupBlockedError(err: unknown): boolean;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The buyer-facing copy for a raw failure message: a known backend message is
|
|
3
|
+
* replaced, anything else is returned unchanged (`undefined` for a non-string).
|
|
4
|
+
*/
|
|
5
|
+
export declare function applyFriendlyMessageOverride(message: string | undefined | null): string | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CardSetupFutureUse, CheckoutSession } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The Stripe Elements group asking for a usage. It only selects which of
|
|
4
|
+
* today's values a legacy read (one without `futureUse`) keeps.
|
|
5
|
+
*/
|
|
6
|
+
export type FutureUseSurface = 'wallet' | 'paypal' | 'inline_apm' | 'setup';
|
|
7
|
+
/** The session fields the platform future-use policy is read from. */
|
|
8
|
+
export type FutureUseSessionFields = Pick<CheckoutSession, 'futureUse' | 'futureUseUnsupported'>;
|
|
9
|
+
/**
|
|
10
|
+
* The one place every Stripe Elements group gets its `setupFutureUsage`.
|
|
11
|
+
*
|
|
12
|
+
* Future use is platform policy, decided by the billing API. When the session
|
|
13
|
+
* read carries `futureUse`, the group declares exactly that value, unless one
|
|
14
|
+
* of the methods it collects is listed in `futureUseUnsupported`, in which
|
|
15
|
+
* case it declares none (the method stays payable one-off). The SDK never
|
|
16
|
+
* coerces or defaults the read's value.
|
|
17
|
+
*
|
|
18
|
+
* A legacy read (no known `futureUse`) keeps each group's historic value:
|
|
19
|
+
* wallets and PayPal `off_session`, inline APMs their historic list, and the
|
|
20
|
+
* setup surface nothing.
|
|
21
|
+
*
|
|
22
|
+
* @returns the usage to declare, or `undefined` to declare none.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveSetupFutureUsage(session: FutureUseSessionFields | null | undefined, methods: string | readonly string[], surface: FutureUseSurface): CardSetupFutureUse | undefined;
|