stripe-pwa-elements 4.0.0 → 4.0.2
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/cjs/factory-tenFFIul.js +1200 -0
- package/dist/cjs/{factory-da3xAKkz.js → i18n-FhEOc8vz.js} +6 -1131
- package/dist/cjs/ion-icon_2.cjs.entry.js +723 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/stripe-address-element.cjs.entry.js +12 -4
- package/dist/cjs/stripe-card-element-modal.cjs.entry.js +3 -2
- package/dist/cjs/{stripe-card-element_2.cjs.entry.js → stripe-card-element.cjs.entry.js} +15 -82
- package/dist/cjs/stripe-currency-selector.cjs.entry.js +11 -3
- package/dist/cjs/stripe-elements.cjs.js +1 -1
- package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +31 -5
- package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +11 -3
- package/dist/cjs/stripe-payment-element.cjs.entry.js +106 -161
- package/dist/cjs/stripe-payment-element.helpers-DukP33RI.js +122 -0
- package/dist/cjs/stripe-payment-request-button.cjs.entry.js +23 -16
- package/dist/cjs/stripe-payment-sheet.cjs.entry.js +506 -0
- package/dist/collection/collection-manifest.json +3 -2
- package/dist/collection/components/stripe-address-element/stripe-address-element.js +7 -0
- package/dist/collection/components/stripe-card-element/stripe-card-element.js +10 -2
- package/dist/collection/components/stripe-card-element-modal/stripe-card-element-modal.js +4 -3
- package/dist/collection/components/stripe-currency-selector/stripe-currency-selector.js +7 -0
- package/dist/collection/components/stripe-express-checkout-element/stripe-express-checkout-element.js +25 -0
- package/dist/collection/components/stripe-link-authentication-element/stripe-link-authentication-element.js +7 -0
- package/dist/collection/components/stripe-modal/stripe-modal.css +23 -1
- package/dist/collection/components/stripe-modal/stripe-modal.js +147 -6
- package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +94 -37
- package/dist/collection/components/stripe-payment-request-button/stripe-payment-request-button.js +17 -10
- package/dist/collection/components/stripe-payment-sheet/payment-sheet-state.js +179 -0
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.css +68 -0
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.helpers.js +90 -0
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +544 -0
- package/dist/collection/services/express-checkout-element-manager.js +36 -2
- package/dist/collection/services/stripe-service.js +37 -5
- package/dist/collection/utils/focus.js +76 -0
- package/dist/collection/utils/i18n.js +6 -0
- package/dist/components/factory.js +1 -1
- package/dist/components/i18n.js +1 -0
- package/dist/components/stripe-address-element.js +1 -1
- package/dist/components/stripe-card-element-modal.js +1 -1
- package/dist/components/stripe-card-element2.js +1 -1
- package/dist/components/stripe-currency-selector.js +1 -1
- package/dist/components/stripe-express-checkout-element.js +1 -1
- package/dist/components/stripe-link-authentication-element.js +1 -1
- package/dist/components/stripe-modal2.js +1 -1
- package/dist/components/stripe-payment-element.helpers.js +1 -0
- package/dist/components/stripe-payment-element.js +1 -1
- package/dist/components/stripe-payment-request-button2.js +1 -1
- package/dist/components/stripe-payment-sheet.d.ts +11 -0
- package/dist/components/stripe-payment-sheet.js +1 -0
- package/dist/esm/factory-Cd6OGTWN.js +1198 -0
- package/dist/esm/{factory-DeqoYLf_.js → i18n-B6JoQetF.js} +7 -1131
- package/dist/esm/ion-icon_2.entry.js +720 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/stripe-address-element.entry.js +9 -1
- package/dist/esm/stripe-card-element-modal.entry.js +3 -2
- package/dist/esm/{stripe-card-element_2.entry.js → stripe-card-element.entry.js} +13 -79
- package/dist/esm/stripe-currency-selector.entry.js +9 -1
- package/dist/esm/stripe-elements.js +1 -1
- package/dist/esm/stripe-express-checkout-element.entry.js +27 -1
- package/dist/esm/stripe-link-authentication-element.entry.js +9 -1
- package/dist/esm/stripe-payment-element.entry.js +98 -153
- package/dist/esm/stripe-payment-element.helpers-CipV87b8.js +117 -0
- package/dist/esm/stripe-payment-request-button.entry.js +18 -11
- package/dist/esm/stripe-payment-sheet.entry.js +504 -0
- package/dist/stripe-elements/{p-38e7b187.entry.js → p-4891edf0.entry.js} +1 -1
- package/dist/stripe-elements/p-5338bc5e.entry.js +1 -0
- package/dist/stripe-elements/p-6a9c8b7a.entry.js +1 -0
- package/dist/stripe-elements/p-7fe4a287.entry.js +1 -0
- package/dist/stripe-elements/p-915b86ed.entry.js +1 -0
- package/dist/stripe-elements/p-B6JoQetF.js +1 -0
- package/dist/stripe-elements/p-C7MQk9FK.js +1 -0
- package/dist/stripe-elements/p-DFAhQS0n.js +1 -0
- package/dist/stripe-elements/p-b06a254f.entry.js +1 -0
- package/dist/stripe-elements/p-b91c4fa7.entry.js +1 -0
- package/dist/stripe-elements/p-ba791c8f.entry.js +1 -0
- package/dist/stripe-elements/p-e7372ca7.entry.js +1 -0
- package/dist/stripe-elements/p-f892e375.entry.js +1 -0
- package/dist/stripe-elements/stripe-elements.esm.js +1 -1
- package/dist/types/components/stripe-address-element/stripe-address-element.d.ts +6 -0
- package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +8 -1
- package/dist/types/components/stripe-card-element-modal/stripe-card-element-modal.d.ts +2 -1
- package/dist/types/components/stripe-currency-selector/stripe-currency-selector.d.ts +6 -0
- package/dist/types/components/stripe-express-checkout-element/stripe-express-checkout-element.d.ts +11 -0
- package/dist/types/components/stripe-link-authentication-element/stripe-link-authentication-element.d.ts +6 -0
- package/dist/types/components/stripe-modal/stripe-modal.d.ts +44 -0
- package/dist/types/components/stripe-payment-element/stripe-payment-element.d.ts +18 -0
- package/dist/types/components/stripe-payment-request-button/stripe-payment-request-button.d.ts +7 -2
- package/dist/types/components/stripe-payment-sheet/payment-sheet-state.d.ts +104 -0
- package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.d.ts +112 -0
- package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.helpers.d.ts +95 -0
- package/dist/types/components.d.ts +169 -10
- package/dist/types/index.d.ts +2 -0
- package/dist/types/services/interfaces.d.ts +2 -0
- package/dist/types/services/stripe-service.d.ts +12 -3
- package/dist/types/utils/focus.d.ts +15 -0
- package/package.json +5 -3
- package/readme.md +46 -10
- package/dist/cjs/ion-icon.cjs.entry.js +0 -431
- package/dist/components/utils.js +0 -1
- package/dist/esm/ion-icon.entry.js +0 -429
- package/dist/stripe-elements/p--sA2m1ad.js +0 -1
- package/dist/stripe-elements/p-44495284.entry.js +0 -1
- package/dist/stripe-elements/p-4ba675fa.entry.js +0 -1
- package/dist/stripe-elements/p-5cf62945.entry.js +0 -1
- package/dist/stripe-elements/p-c24ae181.entry.js +0 -1
- package/dist/stripe-elements/p-d9e86451.entry.js +0 -1
- package/dist/stripe-elements/p-f09c86a0.entry.js +0 -1
- package/dist/stripe-elements/p-f64f394d.entry.js +0 -1
- package/dist/stripe-elements/p-f6d2425e.entry.js +0 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State machine behind `<stripe-payment-sheet>`.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions only: the component feeds events in and performs the returned effects
|
|
5
|
+
* (loading Stripe.js, showing the modal, confirming, emitting events, resolving `present()`).
|
|
6
|
+
* The same rules are model-checked in Quint; see the exhaustive test next to this file.
|
|
7
|
+
*/
|
|
8
|
+
export const initialSheetState = {
|
|
9
|
+
phase: 'idle',
|
|
10
|
+
generation: 0,
|
|
11
|
+
pendingPresent: false,
|
|
12
|
+
openRequested: false,
|
|
13
|
+
};
|
|
14
|
+
const CLIENT_SECRET_PATTERNS = [
|
|
15
|
+
[/^pi_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/, 'payment'],
|
|
16
|
+
[/^seti_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/, 'setup'],
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Tell whether a client secret belongs to a PaymentIntent or a SetupIntent from its prefix.
|
|
20
|
+
* @param clientSecret - The `client_secret` of a PaymentIntent (`pi_..._secret_...`) or SetupIntent (`seti_..._secret_...`)
|
|
21
|
+
* @returns The intent kind, or undefined when the format is not recognized
|
|
22
|
+
*/
|
|
23
|
+
export const intentKindFromClientSecret = (clientSecret) => {
|
|
24
|
+
const match = CLIENT_SECRET_PATTERNS.find(([pattern]) => pattern.test(clientSecret));
|
|
25
|
+
return match === null || match === void 0 ? void 0 : match[1];
|
|
26
|
+
};
|
|
27
|
+
const unchanged = (state) => ({ state, effects: [] });
|
|
28
|
+
/**
|
|
29
|
+
* Resolve the pending `present()` promise, if any.
|
|
30
|
+
*/
|
|
31
|
+
const resolvePending = (state, result) => {
|
|
32
|
+
if (!state.pendingPresent) {
|
|
33
|
+
return unchanged(state);
|
|
34
|
+
}
|
|
35
|
+
return { state: Object.assign(Object.assign({}, state), { pendingPresent: false }), effects: [{ type: 'resolvePresent', result }] };
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Close the sheet as canceled: hide it, emit the event and resolve `present()`.
|
|
39
|
+
*/
|
|
40
|
+
const cancel = (state) => {
|
|
41
|
+
const resolved = resolvePending(Object.assign(Object.assign({}, state), { openRequested: false }), 'paymentSheetCanceled');
|
|
42
|
+
const visible = state.phase === 'presented' || state.phase === 'confirming';
|
|
43
|
+
return {
|
|
44
|
+
state: resolved.state,
|
|
45
|
+
effects: [...(visible ? [{ type: 'hide' }] : []), { type: 'emit', event: 'paymentSheetCanceled' }, ...resolved.effects],
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const changeSecret = (state, clientSecret) => {
|
|
49
|
+
if (clientSecret === '') {
|
|
50
|
+
return unchanged(state);
|
|
51
|
+
}
|
|
52
|
+
// Never drop the result of a running confirmation; apply the new secret once it finishes
|
|
53
|
+
if (state.phase === 'confirming') {
|
|
54
|
+
return unchanged(Object.assign(Object.assign({}, state), { deferredClientSecret: clientSecret }));
|
|
55
|
+
}
|
|
56
|
+
const canceled = state.phase === 'presented' ? cancel(state) : unchanged(state);
|
|
57
|
+
const generation = state.generation + 1;
|
|
58
|
+
const intentKind = intentKindFromClientSecret(clientSecret);
|
|
59
|
+
if (intentKind == null) {
|
|
60
|
+
const resolved = resolvePending(Object.assign(Object.assign({}, canceled.state), { phase: 'loadFailed', generation, intentKind: undefined, openRequested: false }), 'paymentSheetFailed');
|
|
61
|
+
return {
|
|
62
|
+
state: resolved.state,
|
|
63
|
+
effects: [...canceled.effects, { type: 'emit', event: 'paymentSheetFailedToLoad' }, ...resolved.effects],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
state: Object.assign(Object.assign({}, canceled.state), { phase: 'loading', generation, intentKind }),
|
|
68
|
+
effects: [...canceled.effects, { type: 'load', generation, clientSecret, intentKind }],
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Apply a secret that arrived while confirming.
|
|
73
|
+
*/
|
|
74
|
+
const applyDeferredSecret = (result) => {
|
|
75
|
+
const { deferredClientSecret } = result.state;
|
|
76
|
+
if (deferredClientSecret == null) {
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
const next = changeSecret(Object.assign(Object.assign({}, result.state), { deferredClientSecret: undefined }), deferredClientSecret);
|
|
80
|
+
return { state: next.state, effects: [...result.effects, ...next.effects] };
|
|
81
|
+
};
|
|
82
|
+
const isCurrentConfirmation = (state, generation) => state.phase === 'confirming' && state.generation === generation;
|
|
83
|
+
/**
|
|
84
|
+
* Compute the next state and the effects to perform for an event.
|
|
85
|
+
* @param state - Current state
|
|
86
|
+
* @param event - Event to handle
|
|
87
|
+
*/
|
|
88
|
+
export const transition = (state, event) => {
|
|
89
|
+
switch (event.type) {
|
|
90
|
+
case 'secretChanged':
|
|
91
|
+
return changeSecret(state, event.clientSecret);
|
|
92
|
+
case 'loadSucceeded': {
|
|
93
|
+
if (event.generation !== state.generation || state.phase !== 'loading') {
|
|
94
|
+
return unchanged(state);
|
|
95
|
+
}
|
|
96
|
+
const open = state.openRequested;
|
|
97
|
+
return {
|
|
98
|
+
state: Object.assign(Object.assign({}, state), { phase: open ? 'presented' : 'ready', openRequested: false }),
|
|
99
|
+
effects: [{ type: 'emit', event: 'paymentSheetLoaded' }, ...(open ? [{ type: 'show' }] : [])],
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
case 'loadFailed': {
|
|
103
|
+
if (event.generation !== state.generation || state.phase !== 'loading') {
|
|
104
|
+
return unchanged(state);
|
|
105
|
+
}
|
|
106
|
+
const resolved = resolvePending(Object.assign(Object.assign({}, state), { phase: 'loadFailed', openRequested: false }), 'paymentSheetFailed');
|
|
107
|
+
return { state: resolved.state, effects: [{ type: 'emit', event: 'paymentSheetFailedToLoad' }, ...resolved.effects] };
|
|
108
|
+
}
|
|
109
|
+
case 'presentRequested':
|
|
110
|
+
if (state.pendingPresent) {
|
|
111
|
+
return unchanged(state);
|
|
112
|
+
}
|
|
113
|
+
switch (state.phase) {
|
|
114
|
+
case 'ready':
|
|
115
|
+
return { state: Object.assign(Object.assign({}, state), { phase: 'presented', pendingPresent: true }), effects: [{ type: 'show' }] };
|
|
116
|
+
case 'idle':
|
|
117
|
+
case 'loading':
|
|
118
|
+
return unchanged(Object.assign(Object.assign({}, state), { pendingPresent: true, openRequested: true }));
|
|
119
|
+
case 'presented':
|
|
120
|
+
case 'confirming':
|
|
121
|
+
// Already shown through the `open` attribute: wait for its result
|
|
122
|
+
return unchanged(Object.assign(Object.assign({}, state), { pendingPresent: true }));
|
|
123
|
+
default:
|
|
124
|
+
// loadFailed / completed / errored: nothing can be shown
|
|
125
|
+
return { state, effects: [{ type: 'resolvePresent', result: 'paymentSheetFailed' }] };
|
|
126
|
+
}
|
|
127
|
+
case 'openRequested':
|
|
128
|
+
if (state.phase === 'ready') {
|
|
129
|
+
return { state: Object.assign(Object.assign({}, state), { phase: 'presented' }), effects: [{ type: 'show' }] };
|
|
130
|
+
}
|
|
131
|
+
if (state.phase === 'idle' || state.phase === 'loading') {
|
|
132
|
+
return unchanged(Object.assign(Object.assign({}, state), { openRequested: true }));
|
|
133
|
+
}
|
|
134
|
+
return unchanged(state);
|
|
135
|
+
case 'closeRequested':
|
|
136
|
+
if (state.phase === 'presented') {
|
|
137
|
+
const canceled = cancel(state);
|
|
138
|
+
return { state: Object.assign(Object.assign({}, canceled.state), { phase: 'ready' }), effects: canceled.effects };
|
|
139
|
+
}
|
|
140
|
+
// Closing before the sheet was shown withdraws the request to open it
|
|
141
|
+
if ((state.phase === 'idle' || state.phase === 'loading') && state.openRequested) {
|
|
142
|
+
return cancel(state);
|
|
143
|
+
}
|
|
144
|
+
return unchanged(state);
|
|
145
|
+
case 'submitted':
|
|
146
|
+
if (state.phase !== 'presented' || state.intentKind == null) {
|
|
147
|
+
return unchanged(state);
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
state: Object.assign(Object.assign({}, state), { phase: 'confirming' }),
|
|
151
|
+
effects: [{ type: 'confirm', generation: state.generation, intentKind: state.intentKind }],
|
|
152
|
+
};
|
|
153
|
+
case 'confirmSucceeded': {
|
|
154
|
+
if (!isCurrentConfirmation(state, event.generation)) {
|
|
155
|
+
return unchanged(state);
|
|
156
|
+
}
|
|
157
|
+
const resolved = resolvePending(Object.assign(Object.assign({}, state), { phase: 'completed' }), 'paymentSheetCompleted');
|
|
158
|
+
return applyDeferredSecret({
|
|
159
|
+
state: resolved.state,
|
|
160
|
+
effects: [{ type: 'hide' }, { type: 'emit', event: 'paymentSheetCompleted' }, ...resolved.effects],
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
case 'confirmDeclined':
|
|
164
|
+
if (!isCurrentConfirmation(state, event.generation)) {
|
|
165
|
+
return unchanged(state);
|
|
166
|
+
}
|
|
167
|
+
return applyDeferredSecret({ state: Object.assign(Object.assign({}, state), { phase: 'presented' }), effects: [{ type: 'showError', message: event.message }] });
|
|
168
|
+
case 'confirmFailed': {
|
|
169
|
+
if (!isCurrentConfirmation(state, event.generation)) {
|
|
170
|
+
return unchanged(state);
|
|
171
|
+
}
|
|
172
|
+
const resolved = resolvePending(Object.assign(Object.assign({}, state), { phase: 'errored' }), 'paymentSheetFailed');
|
|
173
|
+
return applyDeferredSecret({
|
|
174
|
+
state: resolved.state,
|
|
175
|
+
effects: [{ type: 'hide' }, { type: 'emit', event: 'paymentSheetFailed' }, ...resolved.effects],
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--color-label: #565656;
|
|
3
|
+
--color-placeholder: #acacac;
|
|
4
|
+
--color-heading-text: #333;
|
|
5
|
+
--color-text-error: #ef4444;
|
|
6
|
+
--color-input-border: #e4e4e6;
|
|
7
|
+
--color-input-border-shadow: rgba(228, 228, 230, 0.6);
|
|
8
|
+
--color-button-text: rgba(255, 255, 255, 0.95);
|
|
9
|
+
--color-button-text-disabled: rgba(255, 255, 255, 0.4);
|
|
10
|
+
--color-primary: #0074d4;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/* Remove all the styles of the "User-Agent-Stylesheet", except for the 'display' property */
|
|
14
|
+
stripe-payment-sheet {
|
|
15
|
+
display: contents;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.stripe-payment-sheet-wrap {
|
|
19
|
+
box-sizing: border-box;
|
|
20
|
+
}
|
|
21
|
+
.stripe-payment-sheet-wrap *:where(:not(iframe, canvas, img, svg, video):not(svg *)) {
|
|
22
|
+
all: unset;
|
|
23
|
+
display: revert;
|
|
24
|
+
background: none;
|
|
25
|
+
border: none;
|
|
26
|
+
font-family: "Roboto", sans-serif;
|
|
27
|
+
box-sizing: border-box;
|
|
28
|
+
}
|
|
29
|
+
.stripe-payment-sheet-wrap button {
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
}
|
|
32
|
+
.stripe-payment-sheet-wrap {
|
|
33
|
+
display: block;
|
|
34
|
+
width: 100%;
|
|
35
|
+
background: #fff;
|
|
36
|
+
padding: 32px 16px;
|
|
37
|
+
}
|
|
38
|
+
.stripe-payment-sheet-wrap .stripe-heading {
|
|
39
|
+
font-size: 24px;
|
|
40
|
+
font-weight: bold;
|
|
41
|
+
color: var(--color-heading-text);
|
|
42
|
+
margin-bottom: 24px;
|
|
43
|
+
}
|
|
44
|
+
.stripe-payment-sheet-wrap .payment-info {
|
|
45
|
+
margin-top: 8px;
|
|
46
|
+
}
|
|
47
|
+
.stripe-payment-sheet-wrap .stripe-element-errors {
|
|
48
|
+
margin-top: 8px;
|
|
49
|
+
font-size: 14px;
|
|
50
|
+
color: var(--color-text-error);
|
|
51
|
+
}
|
|
52
|
+
.stripe-payment-sheet-wrap .stripe-submit {
|
|
53
|
+
margin-top: 32px;
|
|
54
|
+
}
|
|
55
|
+
.stripe-payment-sheet-wrap button {
|
|
56
|
+
display: block;
|
|
57
|
+
color: var(--color-button-text);
|
|
58
|
+
background-color: var(--color-primary);
|
|
59
|
+
width: 100%;
|
|
60
|
+
text-align: center;
|
|
61
|
+
padding: 16px 16px;
|
|
62
|
+
font-size: 18px;
|
|
63
|
+
border-radius: 6px;
|
|
64
|
+
min-height: 42px;
|
|
65
|
+
}
|
|
66
|
+
.stripe-payment-sheet-wrap button:disabled {
|
|
67
|
+
color: var(--color-button-text-disabled);
|
|
68
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s)
|
|
4
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
const SUPPORTED_OPTION_KEYS = ['merchantDisplayName', 'paymentMethodLayout', 'defaultBillingDetails', 'returnURL', 'style'];
|
|
14
|
+
const LAYOUTS = {
|
|
15
|
+
horizontal: 'tabs',
|
|
16
|
+
vertical: 'accordion',
|
|
17
|
+
automatic: 'auto',
|
|
18
|
+
};
|
|
19
|
+
const THEMES = {
|
|
20
|
+
alwaysLight: 'stripe',
|
|
21
|
+
alwaysDark: 'night',
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Drop keys whose value is undefined.
|
|
25
|
+
*/
|
|
26
|
+
const compact = (value) => Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
|
|
27
|
+
/**
|
|
28
|
+
* Build the Payment Element options from the payment sheet options.
|
|
29
|
+
* @param options - Payment sheet options
|
|
30
|
+
*/
|
|
31
|
+
export const toPaymentElementOptions = (options) => {
|
|
32
|
+
if (options == null) {
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
const { merchantDisplayName, paymentMethodLayout, defaultBillingDetails } = options;
|
|
36
|
+
const elementOptions = {};
|
|
37
|
+
if (merchantDisplayName != null) {
|
|
38
|
+
elementOptions.business = { name: merchantDisplayName };
|
|
39
|
+
}
|
|
40
|
+
if (paymentMethodLayout != null) {
|
|
41
|
+
elementOptions.layout = LAYOUTS[paymentMethodLayout];
|
|
42
|
+
}
|
|
43
|
+
if (defaultBillingDetails != null) {
|
|
44
|
+
const { address } = defaultBillingDetails, contact = __rest(defaultBillingDetails, ["address"]);
|
|
45
|
+
const billingDetails = compact(contact);
|
|
46
|
+
if (address != null) {
|
|
47
|
+
const { postalCode } = address, rest = __rest(address, ["postalCode"]);
|
|
48
|
+
billingDetails.address = compact(Object.assign(Object.assign({}, rest), { postal_code: postalCode }));
|
|
49
|
+
}
|
|
50
|
+
elementOptions.defaultValues = { billingDetails };
|
|
51
|
+
}
|
|
52
|
+
return elementOptions;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Build the Elements appearance from the payment sheet style.
|
|
56
|
+
* @param style - `alwaysLight` or `alwaysDark`
|
|
57
|
+
*/
|
|
58
|
+
export const toAppearance = (style) => {
|
|
59
|
+
if (style == null) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
return { theme: THEMES[style] };
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* List the given options that have no effect on the web (yet), sorted by name.
|
|
66
|
+
* @param options - Payment sheet options
|
|
67
|
+
*/
|
|
68
|
+
export const unsupportedOptionKeys = (options) => {
|
|
69
|
+
if (options == null) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
return Object.entries(options)
|
|
73
|
+
.filter(([key, value]) => value !== undefined && !SUPPORTED_OPTION_KEYS.includes(key))
|
|
74
|
+
.map(([key]) => key)
|
|
75
|
+
.sort();
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Stripe error types after which the customer can fix the input or simply try again.
|
|
79
|
+
* Types are listed at https://docs.stripe.com/api/errors and in `StripeErrorType` of @stripe/stripe-js.
|
|
80
|
+
*/
|
|
81
|
+
const RECOVERABLE_ERROR_TYPES = ['card_error', 'validation_error', 'api_connection_error', 'rate_limit_error', 'api_error'];
|
|
82
|
+
/**
|
|
83
|
+
* Tell whether a confirmation error lets the customer try again in the open sheet.
|
|
84
|
+
* Other errors (for example `invalid_request_error` for an intent that already succeeded) end the sheet with `paymentSheetFailed`.
|
|
85
|
+
* @param error - Error thrown while confirming
|
|
86
|
+
*/
|
|
87
|
+
export const isRecoverableConfirmError = (error) => {
|
|
88
|
+
const type = error === null || error === void 0 ? void 0 : error.type;
|
|
89
|
+
return typeof type === 'string' && RECOVERABLE_ERROR_TYPES.includes(type);
|
|
90
|
+
};
|