@flopay/shared 1.14.15 → 1.16.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/instrument-dispatch.d.ts +2 -0
- package/dist/instruments.d.ts +2 -0
- package/dist/payment-method-layout.d.ts +127 -0
- package/package.json +1 -1
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
* The groups behind "More payment options" for these countries. Left out,
|
|
22
|
+
* the default `moreOptions` applies; `[]` shows every group.
|
|
23
|
+
*/
|
|
24
|
+
moreOptions?: PaymentMethodGroup[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The merchant's payment method layout rules. The billing API applies them to
|
|
28
|
+
* each buyer: the session's country picks the rule, or the buyer's IP country
|
|
29
|
+
* when the session has none, and the IP country never leaves the server.
|
|
30
|
+
*/
|
|
31
|
+
export interface PaymentMethodLayoutRules {
|
|
32
|
+
/**
|
|
33
|
+
* The default order. Listed groups come first; the rest follow in the order
|
|
34
|
+
* PayPal, wallets, APMs, card. Unknown or repeated values are ignored with a
|
|
35
|
+
* console warning.
|
|
36
|
+
*/
|
|
37
|
+
order?: PaymentMethodGroup[];
|
|
38
|
+
/**
|
|
39
|
+
* The groups shown only after the buyer opens a closed "More payment
|
|
40
|
+
* options" link. In the default layout the card form always stays in view,
|
|
41
|
+
* so `'card'` there applies to the buttons layout only.
|
|
42
|
+
*/
|
|
43
|
+
moreOptions?: PaymentMethodGroup[];
|
|
44
|
+
/** Rules for buyers in particular countries, at most 50. The first rule naming the buyer country applies. */
|
|
45
|
+
countryRules?: PaymentMethodCountryRule[];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Where the country that picked the layout rule came from: the session's
|
|
49
|
+
* address country, the buyer's IP country, or none (the default rule applied).
|
|
50
|
+
*/
|
|
51
|
+
export type PaymentMethodLayoutCountrySource = 'session' | 'ip' | 'none';
|
|
52
|
+
/** The layout the billing API resolved for one buyer. */
|
|
53
|
+
export interface PaymentMethodLayout {
|
|
54
|
+
/** Every group, in the order to show them. */
|
|
55
|
+
order: PaymentMethodGroup[];
|
|
56
|
+
/** The groups behind a closed "More payment options" link, in `order` order. */
|
|
57
|
+
moreOptions: PaymentMethodGroup[];
|
|
58
|
+
countrySource: PaymentMethodLayoutCountrySource;
|
|
59
|
+
/** The session country that picked the rule; `null` unless `countrySource` is `'session'`. */
|
|
60
|
+
country: string | null;
|
|
61
|
+
/** What the billing API dropped from the rules, and why. */
|
|
62
|
+
warnings: string[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Reads a layout response defensively: `null` when it carries no order, so
|
|
66
|
+
* the caller falls back to the merchant's default order. An order missing a
|
|
67
|
+
* group is completed in the default order, so every group is always placed.
|
|
68
|
+
*/
|
|
69
|
+
export declare function normalizePaymentMethodLayout(raw: unknown): PaymentMethodLayout | null;
|
|
70
|
+
/**
|
|
71
|
+
* The merchant's default order, resolved without the billing API. Listed
|
|
72
|
+
* groups come first, in the merchant's order; groups left out follow in the
|
|
73
|
+
* default order. Unknown and repeated values are dropped with a console
|
|
74
|
+
* warning (once per distinct value), and anything that is not an array gives
|
|
75
|
+
* the default order.
|
|
76
|
+
*/
|
|
77
|
+
export declare function resolvePaymentMethodOrder(order: unknown): PaymentMethodGroup[];
|
|
78
|
+
/** The order to render the groups in, and the ones behind "More payment options". */
|
|
79
|
+
export type PaymentMethodGroupLayout = Pick<PaymentMethodLayout, 'order' | 'moreOptions'>;
|
|
80
|
+
/**
|
|
81
|
+
* The merchant's default rule, resolved without the billing API: the fallback
|
|
82
|
+
* when the API returns no layout (an older API, a network failure or a slow
|
|
83
|
+
* answer). It applies no country rules. `moreOptions` comes back in the
|
|
84
|
+
* resolved order.
|
|
85
|
+
*/
|
|
86
|
+
export declare function resolveDefaultPaymentMethodLayout(rules: PaymentMethodLayoutRules): PaymentMethodGroupLayout;
|
|
87
|
+
/** Where a layout's groups render: in view, or behind "More payment options". */
|
|
88
|
+
export interface PaymentMethodGroupPlacement {
|
|
89
|
+
/** The groups in view, in the resolved order. */
|
|
90
|
+
inView: PaymentMethodGroup[];
|
|
91
|
+
/** The groups behind the link, in the resolved order. */
|
|
92
|
+
behindLink: PaymentMethodGroup[];
|
|
93
|
+
/** Whether to show the link: something behind it is available. */
|
|
94
|
+
showLink: boolean;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Splits a resolved layout between the groups in view and the groups behind
|
|
98
|
+
* the "More payment options" link. `canHide` says which groups this layout
|
|
99
|
+
* may put behind the link (the default layout keeps its card form in view),
|
|
100
|
+
* and `available` which groups can show a payment method. When nothing
|
|
101
|
+
* available would stay in view, every group shows and there is no link; when
|
|
102
|
+
* nothing behind the link is available, there is no link.
|
|
103
|
+
*/
|
|
104
|
+
export declare function placePaymentMethodGroups(layout: PaymentMethodGroupLayout, { canHide, available, }: {
|
|
105
|
+
canHide: (group: PaymentMethodGroup) => boolean;
|
|
106
|
+
available: (group: PaymentMethodGroup) => boolean;
|
|
107
|
+
}): PaymentMethodGroupPlacement;
|
|
108
|
+
/**
|
|
109
|
+
* Whether the default layout puts its card form above the buttons. Only when
|
|
110
|
+
* Card is listed first: the card form is one block, so anywhere else it keeps
|
|
111
|
+
* its usual place below the buttons.
|
|
112
|
+
*/
|
|
113
|
+
export declare function isCardFormFirst(order: readonly PaymentMethodGroup[]): boolean;
|
|
114
|
+
/** A group with the render key a UI binding gives it. */
|
|
115
|
+
export interface KeyedPaymentMethodGroup {
|
|
116
|
+
group: PaymentMethodGroup;
|
|
117
|
+
key: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The render keys for an order. PayPal, wallets and APMs host provider
|
|
121
|
+
* iframes, which reload (and lose their provider connection) when a
|
|
122
|
+
* framework moves their DOM node. Keying each one by its place among those
|
|
123
|
+
* three means a reorder never moves a live iframe: a group whose place
|
|
124
|
+
* changes is mounted fresh, and the rest stay where they are. Card is keyed
|
|
125
|
+
* by its place in the full order, so moving only Card remounts only Card.
|
|
126
|
+
*/
|
|
127
|
+
export declare function keyPaymentMethodOrder(order: readonly PaymentMethodGroup[]): KeyedPaymentMethodGroup[];
|