@flopay/shared 1.14.15 → 1.15.0
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/constants.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +1 -1
- package/dist/payment-method-layout.d.ts +87 -0
- package/package.json +1 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A group of payment methods the checkout can put in order:
|
|
3
|
+
* - `'card'` — the hosted card form (the "Credit / Debit Card" button on the buttons layout)
|
|
4
|
+
* - `'paypal'` — PayPal
|
|
5
|
+
* - `'wallets'` — the express wallet row (Apple Pay, Google Pay)
|
|
6
|
+
* - `'apms'` — Stripe's alternative payment methods (Klarna, iDEAL, SEPA, …)
|
|
7
|
+
*/
|
|
8
|
+
export type PaymentMethodGroup = 'card' | 'paypal' | 'wallets' | 'apms';
|
|
9
|
+
/** The order the checkout uses when the merchant sets none: PayPal, wallets, APMs, then card. */
|
|
10
|
+
export declare const DEFAULT_PAYMENT_METHOD_ORDER: readonly PaymentMethodGroup[];
|
|
11
|
+
/** A layout rule for buyers in some countries. */
|
|
12
|
+
export interface PaymentMethodCountryRule {
|
|
13
|
+
/**
|
|
14
|
+
* ISO 3166-1 alpha-2 country codes, in any case. A country an earlier rule
|
|
15
|
+
* already names stays with that earlier rule.
|
|
16
|
+
*/
|
|
17
|
+
countries: string[];
|
|
18
|
+
/** The order for these countries. Left out, the default `order` applies. */
|
|
19
|
+
order?: PaymentMethodGroup[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The merchant's payment method layout rules. The billing API applies them to
|
|
23
|
+
* each buyer: the session's country picks the rule, or the buyer's IP country
|
|
24
|
+
* when the session has none, and the IP country never leaves the server.
|
|
25
|
+
*/
|
|
26
|
+
export interface PaymentMethodLayoutRules {
|
|
27
|
+
/**
|
|
28
|
+
* The default order. Listed groups come first; the rest follow in the order
|
|
29
|
+
* PayPal, wallets, APMs, card. Unknown or repeated values are ignored with a
|
|
30
|
+
* console warning.
|
|
31
|
+
*/
|
|
32
|
+
order?: PaymentMethodGroup[];
|
|
33
|
+
/** Rules for buyers in particular countries, at most 50. The first rule naming the buyer country applies. */
|
|
34
|
+
countryRules?: PaymentMethodCountryRule[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Where the country that picked the layout rule came from: the session's
|
|
38
|
+
* address country, the buyer's IP country, or none (the default rule applied).
|
|
39
|
+
*/
|
|
40
|
+
export type PaymentMethodLayoutCountrySource = 'session' | 'ip' | 'none';
|
|
41
|
+
/** The layout the billing API resolved for one buyer. */
|
|
42
|
+
export interface PaymentMethodLayout {
|
|
43
|
+
/** Every group, in the order to show them. */
|
|
44
|
+
order: PaymentMethodGroup[];
|
|
45
|
+
/** The groups behind a closed "More payment options" link, in `order` order. */
|
|
46
|
+
moreOptions: PaymentMethodGroup[];
|
|
47
|
+
countrySource: PaymentMethodLayoutCountrySource;
|
|
48
|
+
/** The session country that picked the rule; `null` unless `countrySource` is `'session'`. */
|
|
49
|
+
country: string | null;
|
|
50
|
+
/** What the billing API dropped from the rules, and why. */
|
|
51
|
+
warnings: string[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Reads a layout response defensively: `null` when it carries no order, so
|
|
55
|
+
* the caller falls back to the merchant's default order. An order missing a
|
|
56
|
+
* group is completed in the default order, so every group is always placed.
|
|
57
|
+
*/
|
|
58
|
+
export declare function normalizePaymentMethodLayout(raw: unknown): PaymentMethodLayout | null;
|
|
59
|
+
/**
|
|
60
|
+
* The merchant's default order, resolved without the billing API: the
|
|
61
|
+
* fallback when the API returns no layout (an older API, a network failure or
|
|
62
|
+
* a slow answer). It applies no country rules. Listed groups come first, in
|
|
63
|
+
* the merchant's order; groups left out follow in the default order. Unknown
|
|
64
|
+
* and repeated values are dropped with a console warning (once per distinct
|
|
65
|
+
* value), and anything that is not an array gives the default order.
|
|
66
|
+
*/
|
|
67
|
+
export declare function resolvePaymentMethodOrder(order: unknown): PaymentMethodGroup[];
|
|
68
|
+
/**
|
|
69
|
+
* Whether the default layout puts its card form above the buttons. Only when
|
|
70
|
+
* Card is listed first: the card form is one block, so anywhere else it keeps
|
|
71
|
+
* its usual place below the buttons.
|
|
72
|
+
*/
|
|
73
|
+
export declare function isCardFormFirst(order: readonly PaymentMethodGroup[]): boolean;
|
|
74
|
+
/** A group with the render key a UI binding gives it. */
|
|
75
|
+
export interface KeyedPaymentMethodGroup {
|
|
76
|
+
group: PaymentMethodGroup;
|
|
77
|
+
key: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The render keys for an order. PayPal, wallets and APMs host provider
|
|
81
|
+
* iframes, which reload (and lose their provider connection) when a
|
|
82
|
+
* framework moves their DOM node. Keying each one by its place among those
|
|
83
|
+
* three means a reorder never moves a live iframe: a group whose place
|
|
84
|
+
* changes is mounted fresh, and the rest stay where they are. Card is keyed
|
|
85
|
+
* by its place in the full order, so moving only Card remounts only Card.
|
|
86
|
+
*/
|
|
87
|
+
export declare function keyPaymentMethodOrder(order: readonly PaymentMethodGroup[]): KeyedPaymentMethodGroup[];
|