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,506 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var index = require('./index-Dkb0SxZc.js');
|
|
4
|
+
var i18n = require('./i18n-FhEOc8vz.js');
|
|
5
|
+
var factory = require('./factory-tenFFIul.js');
|
|
6
|
+
var stripePaymentElement_helpers = require('./stripe-payment-element.helpers-DukP33RI.js');
|
|
7
|
+
require('./index-CYbA1N_k.js');
|
|
8
|
+
require('./error-FFC4kSs5.js');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* State machine behind `<stripe-payment-sheet>`.
|
|
12
|
+
*
|
|
13
|
+
* Pure functions only: the component feeds events in and performs the returned effects
|
|
14
|
+
* (loading Stripe.js, showing the modal, confirming, emitting events, resolving `present()`).
|
|
15
|
+
* The same rules are model-checked in Quint; see the exhaustive test next to this file.
|
|
16
|
+
*/
|
|
17
|
+
const initialSheetState = {
|
|
18
|
+
phase: 'idle',
|
|
19
|
+
generation: 0,
|
|
20
|
+
pendingPresent: false,
|
|
21
|
+
openRequested: false,
|
|
22
|
+
};
|
|
23
|
+
const CLIENT_SECRET_PATTERNS = [
|
|
24
|
+
[/^pi_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/, 'payment'],
|
|
25
|
+
[/^seti_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/, 'setup'],
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* Tell whether a client secret belongs to a PaymentIntent or a SetupIntent from its prefix.
|
|
29
|
+
* @param clientSecret - The `client_secret` of a PaymentIntent (`pi_..._secret_...`) or SetupIntent (`seti_..._secret_...`)
|
|
30
|
+
* @returns The intent kind, or undefined when the format is not recognized
|
|
31
|
+
*/
|
|
32
|
+
const intentKindFromClientSecret = (clientSecret) => {
|
|
33
|
+
const match = CLIENT_SECRET_PATTERNS.find(([pattern]) => pattern.test(clientSecret));
|
|
34
|
+
return match === null || match === void 0 ? void 0 : match[1];
|
|
35
|
+
};
|
|
36
|
+
const unchanged = (state) => ({ state, effects: [] });
|
|
37
|
+
/**
|
|
38
|
+
* Resolve the pending `present()` promise, if any.
|
|
39
|
+
*/
|
|
40
|
+
const resolvePending = (state, result) => {
|
|
41
|
+
if (!state.pendingPresent) {
|
|
42
|
+
return unchanged(state);
|
|
43
|
+
}
|
|
44
|
+
return { state: Object.assign(Object.assign({}, state), { pendingPresent: false }), effects: [{ type: 'resolvePresent', result }] };
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Close the sheet as canceled: hide it, emit the event and resolve `present()`.
|
|
48
|
+
*/
|
|
49
|
+
const cancel = (state) => {
|
|
50
|
+
const resolved = resolvePending(Object.assign(Object.assign({}, state), { openRequested: false }), 'paymentSheetCanceled');
|
|
51
|
+
const visible = state.phase === 'presented' || state.phase === 'confirming';
|
|
52
|
+
return {
|
|
53
|
+
state: resolved.state,
|
|
54
|
+
effects: [...(visible ? [{ type: 'hide' }] : []), { type: 'emit', event: 'paymentSheetCanceled' }, ...resolved.effects],
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const changeSecret = (state, clientSecret) => {
|
|
58
|
+
if (clientSecret === '') {
|
|
59
|
+
return unchanged(state);
|
|
60
|
+
}
|
|
61
|
+
// Never drop the result of a running confirmation; apply the new secret once it finishes
|
|
62
|
+
if (state.phase === 'confirming') {
|
|
63
|
+
return unchanged(Object.assign(Object.assign({}, state), { deferredClientSecret: clientSecret }));
|
|
64
|
+
}
|
|
65
|
+
const canceled = state.phase === 'presented' ? cancel(state) : unchanged(state);
|
|
66
|
+
const generation = state.generation + 1;
|
|
67
|
+
const intentKind = intentKindFromClientSecret(clientSecret);
|
|
68
|
+
if (intentKind == null) {
|
|
69
|
+
const resolved = resolvePending(Object.assign(Object.assign({}, canceled.state), { phase: 'loadFailed', generation, intentKind: undefined, openRequested: false }), 'paymentSheetFailed');
|
|
70
|
+
return {
|
|
71
|
+
state: resolved.state,
|
|
72
|
+
effects: [...canceled.effects, { type: 'emit', event: 'paymentSheetFailedToLoad' }, ...resolved.effects],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
state: Object.assign(Object.assign({}, canceled.state), { phase: 'loading', generation, intentKind }),
|
|
77
|
+
effects: [...canceled.effects, { type: 'load', generation, clientSecret, intentKind }],
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Apply a secret that arrived while confirming.
|
|
82
|
+
*/
|
|
83
|
+
const applyDeferredSecret = (result) => {
|
|
84
|
+
const { deferredClientSecret } = result.state;
|
|
85
|
+
if (deferredClientSecret == null) {
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
const next = changeSecret(Object.assign(Object.assign({}, result.state), { deferredClientSecret: undefined }), deferredClientSecret);
|
|
89
|
+
return { state: next.state, effects: [...result.effects, ...next.effects] };
|
|
90
|
+
};
|
|
91
|
+
const isCurrentConfirmation = (state, generation) => state.phase === 'confirming' && state.generation === generation;
|
|
92
|
+
/**
|
|
93
|
+
* Compute the next state and the effects to perform for an event.
|
|
94
|
+
* @param state - Current state
|
|
95
|
+
* @param event - Event to handle
|
|
96
|
+
*/
|
|
97
|
+
const transition = (state, event) => {
|
|
98
|
+
switch (event.type) {
|
|
99
|
+
case 'secretChanged':
|
|
100
|
+
return changeSecret(state, event.clientSecret);
|
|
101
|
+
case 'loadSucceeded': {
|
|
102
|
+
if (event.generation !== state.generation || state.phase !== 'loading') {
|
|
103
|
+
return unchanged(state);
|
|
104
|
+
}
|
|
105
|
+
const open = state.openRequested;
|
|
106
|
+
return {
|
|
107
|
+
state: Object.assign(Object.assign({}, state), { phase: open ? 'presented' : 'ready', openRequested: false }),
|
|
108
|
+
effects: [{ type: 'emit', event: 'paymentSheetLoaded' }, ...(open ? [{ type: 'show' }] : [])],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
case 'loadFailed': {
|
|
112
|
+
if (event.generation !== state.generation || state.phase !== 'loading') {
|
|
113
|
+
return unchanged(state);
|
|
114
|
+
}
|
|
115
|
+
const resolved = resolvePending(Object.assign(Object.assign({}, state), { phase: 'loadFailed', openRequested: false }), 'paymentSheetFailed');
|
|
116
|
+
return { state: resolved.state, effects: [{ type: 'emit', event: 'paymentSheetFailedToLoad' }, ...resolved.effects] };
|
|
117
|
+
}
|
|
118
|
+
case 'presentRequested':
|
|
119
|
+
if (state.pendingPresent) {
|
|
120
|
+
return unchanged(state);
|
|
121
|
+
}
|
|
122
|
+
switch (state.phase) {
|
|
123
|
+
case 'ready':
|
|
124
|
+
return { state: Object.assign(Object.assign({}, state), { phase: 'presented', pendingPresent: true }), effects: [{ type: 'show' }] };
|
|
125
|
+
case 'idle':
|
|
126
|
+
case 'loading':
|
|
127
|
+
return unchanged(Object.assign(Object.assign({}, state), { pendingPresent: true, openRequested: true }));
|
|
128
|
+
case 'presented':
|
|
129
|
+
case 'confirming':
|
|
130
|
+
// Already shown through the `open` attribute: wait for its result
|
|
131
|
+
return unchanged(Object.assign(Object.assign({}, state), { pendingPresent: true }));
|
|
132
|
+
default:
|
|
133
|
+
// loadFailed / completed / errored: nothing can be shown
|
|
134
|
+
return { state, effects: [{ type: 'resolvePresent', result: 'paymentSheetFailed' }] };
|
|
135
|
+
}
|
|
136
|
+
case 'openRequested':
|
|
137
|
+
if (state.phase === 'ready') {
|
|
138
|
+
return { state: Object.assign(Object.assign({}, state), { phase: 'presented' }), effects: [{ type: 'show' }] };
|
|
139
|
+
}
|
|
140
|
+
if (state.phase === 'idle' || state.phase === 'loading') {
|
|
141
|
+
return unchanged(Object.assign(Object.assign({}, state), { openRequested: true }));
|
|
142
|
+
}
|
|
143
|
+
return unchanged(state);
|
|
144
|
+
case 'closeRequested':
|
|
145
|
+
if (state.phase === 'presented') {
|
|
146
|
+
const canceled = cancel(state);
|
|
147
|
+
return { state: Object.assign(Object.assign({}, canceled.state), { phase: 'ready' }), effects: canceled.effects };
|
|
148
|
+
}
|
|
149
|
+
// Closing before the sheet was shown withdraws the request to open it
|
|
150
|
+
if ((state.phase === 'idle' || state.phase === 'loading') && state.openRequested) {
|
|
151
|
+
return cancel(state);
|
|
152
|
+
}
|
|
153
|
+
return unchanged(state);
|
|
154
|
+
case 'submitted':
|
|
155
|
+
if (state.phase !== 'presented' || state.intentKind == null) {
|
|
156
|
+
return unchanged(state);
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
state: Object.assign(Object.assign({}, state), { phase: 'confirming' }),
|
|
160
|
+
effects: [{ type: 'confirm', generation: state.generation, intentKind: state.intentKind }],
|
|
161
|
+
};
|
|
162
|
+
case 'confirmSucceeded': {
|
|
163
|
+
if (!isCurrentConfirmation(state, event.generation)) {
|
|
164
|
+
return unchanged(state);
|
|
165
|
+
}
|
|
166
|
+
const resolved = resolvePending(Object.assign(Object.assign({}, state), { phase: 'completed' }), 'paymentSheetCompleted');
|
|
167
|
+
return applyDeferredSecret({
|
|
168
|
+
state: resolved.state,
|
|
169
|
+
effects: [{ type: 'hide' }, { type: 'emit', event: 'paymentSheetCompleted' }, ...resolved.effects],
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
case 'confirmDeclined':
|
|
173
|
+
if (!isCurrentConfirmation(state, event.generation)) {
|
|
174
|
+
return unchanged(state);
|
|
175
|
+
}
|
|
176
|
+
return applyDeferredSecret({ state: Object.assign(Object.assign({}, state), { phase: 'presented' }), effects: [{ type: 'showError', message: event.message }] });
|
|
177
|
+
case 'confirmFailed': {
|
|
178
|
+
if (!isCurrentConfirmation(state, event.generation)) {
|
|
179
|
+
return unchanged(state);
|
|
180
|
+
}
|
|
181
|
+
const resolved = resolvePending(Object.assign(Object.assign({}, state), { phase: 'errored' }), 'paymentSheetFailed');
|
|
182
|
+
return applyDeferredSecret({
|
|
183
|
+
state: resolved.state,
|
|
184
|
+
effects: [{ type: 'hide' }, { type: 'emit', event: 'paymentSheetFailed' }, ...resolved.effects],
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
191
|
+
var t = {};
|
|
192
|
+
for (var p in s)
|
|
193
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
194
|
+
t[p] = s[p];
|
|
195
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
196
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
197
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
198
|
+
t[p[i]] = s[p[i]];
|
|
199
|
+
}
|
|
200
|
+
return t;
|
|
201
|
+
};
|
|
202
|
+
const SUPPORTED_OPTION_KEYS = ['merchantDisplayName', 'paymentMethodLayout', 'defaultBillingDetails', 'returnURL', 'style'];
|
|
203
|
+
const LAYOUTS = {
|
|
204
|
+
horizontal: 'tabs',
|
|
205
|
+
vertical: 'accordion',
|
|
206
|
+
automatic: 'auto',
|
|
207
|
+
};
|
|
208
|
+
const THEMES = {
|
|
209
|
+
alwaysLight: 'stripe',
|
|
210
|
+
alwaysDark: 'night',
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Drop keys whose value is undefined.
|
|
214
|
+
*/
|
|
215
|
+
const compact = (value) => Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
|
|
216
|
+
/**
|
|
217
|
+
* Build the Payment Element options from the payment sheet options.
|
|
218
|
+
* @param options - Payment sheet options
|
|
219
|
+
*/
|
|
220
|
+
const toPaymentElementOptions = (options) => {
|
|
221
|
+
if (options == null) {
|
|
222
|
+
return {};
|
|
223
|
+
}
|
|
224
|
+
const { merchantDisplayName, paymentMethodLayout, defaultBillingDetails } = options;
|
|
225
|
+
const elementOptions = {};
|
|
226
|
+
if (merchantDisplayName != null) {
|
|
227
|
+
elementOptions.business = { name: merchantDisplayName };
|
|
228
|
+
}
|
|
229
|
+
if (paymentMethodLayout != null) {
|
|
230
|
+
elementOptions.layout = LAYOUTS[paymentMethodLayout];
|
|
231
|
+
}
|
|
232
|
+
if (defaultBillingDetails != null) {
|
|
233
|
+
const { address } = defaultBillingDetails, contact = __rest(defaultBillingDetails, ["address"]);
|
|
234
|
+
const billingDetails = compact(contact);
|
|
235
|
+
if (address != null) {
|
|
236
|
+
const { postalCode } = address, rest = __rest(address, ["postalCode"]);
|
|
237
|
+
billingDetails.address = compact(Object.assign(Object.assign({}, rest), { postal_code: postalCode }));
|
|
238
|
+
}
|
|
239
|
+
elementOptions.defaultValues = { billingDetails };
|
|
240
|
+
}
|
|
241
|
+
return elementOptions;
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* Build the Elements appearance from the payment sheet style.
|
|
245
|
+
* @param style - `alwaysLight` or `alwaysDark`
|
|
246
|
+
*/
|
|
247
|
+
const toAppearance = (style) => {
|
|
248
|
+
if (style == null) {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
return { theme: THEMES[style] };
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* List the given options that have no effect on the web (yet), sorted by name.
|
|
255
|
+
* @param options - Payment sheet options
|
|
256
|
+
*/
|
|
257
|
+
const unsupportedOptionKeys = (options) => {
|
|
258
|
+
if (options == null) {
|
|
259
|
+
return [];
|
|
260
|
+
}
|
|
261
|
+
return Object.entries(options)
|
|
262
|
+
.filter(([key, value]) => value !== undefined && !SUPPORTED_OPTION_KEYS.includes(key))
|
|
263
|
+
.map(([key]) => key)
|
|
264
|
+
.sort();
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Stripe error types after which the customer can fix the input or simply try again.
|
|
268
|
+
* Types are listed at https://docs.stripe.com/api/errors and in `StripeErrorType` of @stripe/stripe-js.
|
|
269
|
+
*/
|
|
270
|
+
const RECOVERABLE_ERROR_TYPES = ['card_error', 'validation_error', 'api_connection_error', 'rate_limit_error', 'api_error'];
|
|
271
|
+
/**
|
|
272
|
+
* Tell whether a confirmation error lets the customer try again in the open sheet.
|
|
273
|
+
* Other errors (for example `invalid_request_error` for an intent that already succeeded) end the sheet with `paymentSheetFailed`.
|
|
274
|
+
* @param error - Error thrown while confirming
|
|
275
|
+
*/
|
|
276
|
+
const isRecoverableConfirmError = (error) => {
|
|
277
|
+
const type = error === null || error === void 0 ? void 0 : error.type;
|
|
278
|
+
return typeof type === 'string' && RECOVERABLE_ERROR_TYPES.includes(type);
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const stripePaymentSheetCss = () => `:root{--color-label:#565656;--color-placeholder:#acacac;--color-heading-text:#333;--color-text-error:#ef4444;--color-input-border:#e4e4e6;--color-input-border-shadow:rgba(228, 228, 230, 0.6);--color-button-text:rgba(255, 255, 255, 0.95);--color-button-text-disabled:rgba(255, 255, 255, 0.4);--color-primary:#0074d4}stripe-payment-sheet{display:contents}.stripe-payment-sheet-wrap{box-sizing:border-box}.stripe-payment-sheet-wrap *:where(:not(iframe,canvas,img,svg,video):not(svg *)){all:unset;display:revert;background:none;border:none;font-family:"Roboto", sans-serif;box-sizing:border-box}.stripe-payment-sheet-wrap button{cursor:pointer}.stripe-payment-sheet-wrap{display:block;width:100%;background:#fff;padding:32px 16px}.stripe-payment-sheet-wrap .stripe-heading{font-size:24px;font-weight:bold;color:var(--color-heading-text);margin-bottom:24px}.stripe-payment-sheet-wrap .payment-info{margin-top:8px}.stripe-payment-sheet-wrap .stripe-element-errors{margin-top:8px;font-size:14px;color:var(--color-text-error)}.stripe-payment-sheet-wrap .stripe-submit{margin-top:32px}.stripe-payment-sheet-wrap button{display:block;color:var(--color-button-text);background-color:var(--color-primary);width:100%;text-align:center;padding:16px 16px;font-size:18px;border-radius:6px;min-height:42px}.stripe-payment-sheet-wrap button:disabled{color:var(--color-button-text-disabled)}`;
|
|
282
|
+
|
|
283
|
+
const StripePaymentSheet = class {
|
|
284
|
+
/**
|
|
285
|
+
* Show the sheet and wait for its result.
|
|
286
|
+
* Calling it again while a result is pending returns the same promise.
|
|
287
|
+
* @returns `{ paymentResult }`, where `paymentResult` is `paymentSheetCompleted`, `paymentSheetCanceled` or `paymentSheetFailed`
|
|
288
|
+
* @example
|
|
289
|
+
* ```
|
|
290
|
+
* const sheet = document.querySelector('stripe-payment-sheet');
|
|
291
|
+
* const { paymentResult } = await sheet.present();
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
async present() {
|
|
295
|
+
if (this.presentPromise == null) {
|
|
296
|
+
this.presentPromise = new Promise(resolve => {
|
|
297
|
+
this.resolvePresent = resolve;
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
const promise = this.presentPromise;
|
|
301
|
+
this.dispatch({ type: 'presentRequested' });
|
|
302
|
+
return promise;
|
|
303
|
+
}
|
|
304
|
+
handleSecretChange() {
|
|
305
|
+
this.startLoading();
|
|
306
|
+
}
|
|
307
|
+
handleOpenChange(open) {
|
|
308
|
+
this.dispatch({ type: open ? 'openRequested' : 'closeRequested' });
|
|
309
|
+
}
|
|
310
|
+
constructor(hostRef) {
|
|
311
|
+
index.registerInstance(this, hostRef);
|
|
312
|
+
this.paymentSheetLoaded = index.createEvent(this, "paymentSheetLoaded", 7);
|
|
313
|
+
this.paymentSheetFailedToLoad = index.createEvent(this, "paymentSheetFailedToLoad", 7);
|
|
314
|
+
this.paymentSheetCompleted = index.createEvent(this, "paymentSheetCompleted", 7);
|
|
315
|
+
this.paymentSheetCanceled = index.createEvent(this, "paymentSheetCanceled", 7);
|
|
316
|
+
this.paymentSheetFailed = index.createEvent(this, "paymentSheetFailed", 7);
|
|
317
|
+
this.warnedUnsupportedOptions = false;
|
|
318
|
+
/**
|
|
319
|
+
* Whether the sheet is shown. Setting it to false closes the sheet as canceled.
|
|
320
|
+
*/
|
|
321
|
+
this.open = false;
|
|
322
|
+
/**
|
|
323
|
+
* Sheet title. Translated automatically by this library.
|
|
324
|
+
*/
|
|
325
|
+
this.sheetTitle = 'Add your payment information';
|
|
326
|
+
/**
|
|
327
|
+
* Submit button label. Translated automatically by this library.
|
|
328
|
+
*/
|
|
329
|
+
this.buttonLabel = 'Pay';
|
|
330
|
+
/**
|
|
331
|
+
* Application name registered to Stripe.js, for wrapper libraries such as `@capacitor-community/stripe`.
|
|
332
|
+
*/
|
|
333
|
+
this.applicationName = 'stripe-pwa-elements';
|
|
334
|
+
this.sheet = initialSheetState;
|
|
335
|
+
this.visible = false;
|
|
336
|
+
this.errorMessage = '';
|
|
337
|
+
this.handleSubmit = (e) => {
|
|
338
|
+
e.preventDefault();
|
|
339
|
+
this.errorMessage = '';
|
|
340
|
+
this.dispatch({ type: 'submitted' });
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* The modal closes itself on a backdrop or close button click. Keep it open when the sheet refuses to close (while confirming).
|
|
344
|
+
*/
|
|
345
|
+
this.handleModalClose = () => {
|
|
346
|
+
var _a;
|
|
347
|
+
this.dispatch({ type: 'closeRequested' });
|
|
348
|
+
if (this.visible) {
|
|
349
|
+
(_a = this.el.querySelector('stripe-modal')) === null || _a === void 0 ? void 0 : _a.openModal();
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
this.stripeService = factory.serviceFactory.createStripeService();
|
|
353
|
+
this.paymentElementManager = factory.serviceFactory.createPaymentElementManager(this.stripeService);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Props are not yet populated inside the constructor with the custom-elements build,
|
|
357
|
+
* so loading starts here.
|
|
358
|
+
*/
|
|
359
|
+
componentWillLoad() {
|
|
360
|
+
if (this.open) {
|
|
361
|
+
this.dispatch({ type: 'openRequested' });
|
|
362
|
+
}
|
|
363
|
+
this.startLoading();
|
|
364
|
+
}
|
|
365
|
+
componentDidLoad() {
|
|
366
|
+
this.el.classList.add(i18n.checkPlatform());
|
|
367
|
+
}
|
|
368
|
+
disconnectedCallback() {
|
|
369
|
+
this.paymentElementManager.unmount();
|
|
370
|
+
}
|
|
371
|
+
startLoading() {
|
|
372
|
+
if (this.publishableKey == null || this.publishableKey === '' || this.intentClientSecret == null) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
this.dispatch({ type: 'secretChanged', clientSecret: this.intentClientSecret });
|
|
376
|
+
}
|
|
377
|
+
dispatch(event) {
|
|
378
|
+
const { state, effects } = transition(this.sheet, event);
|
|
379
|
+
this.sheet = state;
|
|
380
|
+
effects.forEach(effect => this.perform(effect));
|
|
381
|
+
}
|
|
382
|
+
perform(effect) {
|
|
383
|
+
var _a;
|
|
384
|
+
switch (effect.type) {
|
|
385
|
+
case 'load':
|
|
386
|
+
this.load(effect.generation, effect.clientSecret);
|
|
387
|
+
break;
|
|
388
|
+
case 'show':
|
|
389
|
+
this.visible = true;
|
|
390
|
+
this.open = true;
|
|
391
|
+
break;
|
|
392
|
+
case 'hide':
|
|
393
|
+
this.visible = false;
|
|
394
|
+
this.open = false;
|
|
395
|
+
break;
|
|
396
|
+
case 'confirm':
|
|
397
|
+
this.confirm(effect.generation, effect.intentKind);
|
|
398
|
+
break;
|
|
399
|
+
case 'showError':
|
|
400
|
+
this.errorMessage = effect.message;
|
|
401
|
+
break;
|
|
402
|
+
case 'emit':
|
|
403
|
+
this.emit(effect.event);
|
|
404
|
+
break;
|
|
405
|
+
case 'resolvePresent':
|
|
406
|
+
(_a = this.resolvePresent) === null || _a === void 0 ? void 0 : _a.call(this, { paymentResult: effect.result });
|
|
407
|
+
this.presentPromise = undefined;
|
|
408
|
+
this.resolvePresent = undefined;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
async load(generation, clientSecret) {
|
|
413
|
+
var _a;
|
|
414
|
+
this.warnUnsupportedOptions();
|
|
415
|
+
try {
|
|
416
|
+
await this.stripeService.initialize(this.publishableKey, {
|
|
417
|
+
stripeAccount: this.stripeAccount,
|
|
418
|
+
applicationName: this.applicationName,
|
|
419
|
+
clientSecret,
|
|
420
|
+
});
|
|
421
|
+
if (generation !== this.sheet.generation) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (this.stripeService.state.loadStripeStatus !== 'success') {
|
|
425
|
+
throw new Error('Failed to load Stripe.js');
|
|
426
|
+
}
|
|
427
|
+
const appearance = toAppearance((_a = this.options) === null || _a === void 0 ? void 0 : _a.style);
|
|
428
|
+
if (appearance != null) {
|
|
429
|
+
await this.stripeService.getElements().update({ appearance });
|
|
430
|
+
}
|
|
431
|
+
await this.paymentElementManager.initialize(this.el, toPaymentElementOptions(this.options));
|
|
432
|
+
this.dispatch({ type: 'loadSucceeded', generation });
|
|
433
|
+
}
|
|
434
|
+
catch (e) {
|
|
435
|
+
this.lastError = e;
|
|
436
|
+
this.dispatch({ type: 'loadFailed', generation });
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
async confirm(generation, intentKind) {
|
|
440
|
+
var _a, _b, _c;
|
|
441
|
+
try {
|
|
442
|
+
const returnUrl = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.returnURL) !== null && _b !== void 0 ? _b : window.location.href;
|
|
443
|
+
this.lastResult = await stripePaymentElement_helpers.confirmPaymentOrSetup(this.stripeService.getStripe(), this.stripeService.getElements(), intentKind, returnUrl);
|
|
444
|
+
this.dispatch({ type: 'confirmSucceeded', generation });
|
|
445
|
+
}
|
|
446
|
+
catch (e) {
|
|
447
|
+
const message = (_c = e.message) !== null && _c !== void 0 ? _c : String(e);
|
|
448
|
+
if (isRecoverableConfirmError(e)) {
|
|
449
|
+
this.dispatch({ type: 'confirmDeclined', generation, message });
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
this.lastError = e;
|
|
453
|
+
this.dispatch({ type: 'confirmFailed', generation, message });
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
emit(event) {
|
|
457
|
+
switch (event) {
|
|
458
|
+
case 'paymentSheetLoaded':
|
|
459
|
+
this.paymentSheetLoaded.emit({ stripe: this.stripeService.getStripe() });
|
|
460
|
+
break;
|
|
461
|
+
case 'paymentSheetFailedToLoad':
|
|
462
|
+
this.paymentSheetFailedToLoad.emit(this.lastError);
|
|
463
|
+
break;
|
|
464
|
+
case 'paymentSheetCompleted':
|
|
465
|
+
this.paymentSheetCompleted.emit(this.lastResult);
|
|
466
|
+
break;
|
|
467
|
+
case 'paymentSheetCanceled':
|
|
468
|
+
this.paymentSheetCanceled.emit();
|
|
469
|
+
break;
|
|
470
|
+
case 'paymentSheetFailed':
|
|
471
|
+
this.paymentSheetFailed.emit(this.lastError);
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
warnUnsupportedOptions() {
|
|
476
|
+
const keys = unsupportedOptionKeys(this.options);
|
|
477
|
+
if (this.warnedUnsupportedOptions || keys.length === 0) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
this.warnedUnsupportedOptions = true;
|
|
481
|
+
console.warn(`<stripe-payment-sheet>: these options have no effect on the web yet: ${keys.join(', ')}`);
|
|
482
|
+
}
|
|
483
|
+
render() {
|
|
484
|
+
const { phase } = this.sheet;
|
|
485
|
+
const confirming = phase === 'confirming';
|
|
486
|
+
return (index.h(index.Host, { key: 'ecb6de4b0674af9f5ecf86acce93e092c3bee881' }, index.h("stripe-modal", { key: '137473608d8cc3c0833c34529f1dafb9fc0cba34', open: this.visible, showCloseButton: !confirming, onClose: this.handleModalClose }, index.h("div", { key: '0da153ef48ddc5464f050ea1921a69f975a7d8e1', class: "stripe-payment-sheet-wrap" }, index.h("form", { key: '6f6653aee9d0ad54c8bf935ace2f6d4fdc648e1f', id: "stripe-payment-sheet", onSubmit: this.handleSubmit }, index.h("div", { key: '85d3e28a20679051decdb02d590c2144e652f0bd', class: "stripe-heading" }, i18n.i18n.t(this.sheetTitle)), index.h("div", { key: 'f6b8d90a3731732c0b36af0512a5ace87a12f98d', class: "payment-info visible" }, index.h("div", { key: '813a1ad3a0db2efa650aceff828412999f34ff2b', id: "payment-element" })), index.h("div", { key: '63bd6a8c20dd7b8b92aa2171553c13570ab17808', class: "stripe-element-errors", role: "alert" }, this.errorMessage), index.h("div", { key: 'f70e9b353ae9eecd1300bbbd40ebb731ef44c344', class: "stripe-submit" }, index.h("button", { key: '6f32a7b94132091348680476b0e7292072800dbf', type: "submit", disabled: phase !== 'presented' }, confirming ? i18n.i18n.t('Loading') : i18n.i18n.t(this.buttonLabel))))))));
|
|
487
|
+
}
|
|
488
|
+
get el() { return index.getElement(this); }
|
|
489
|
+
static get watchers() { return {
|
|
490
|
+
"publishableKey": [{
|
|
491
|
+
"handleSecretChange": 0
|
|
492
|
+
}],
|
|
493
|
+
"intentClientSecret": [{
|
|
494
|
+
"handleSecretChange": 0
|
|
495
|
+
}],
|
|
496
|
+
"stripeAccount": [{
|
|
497
|
+
"handleSecretChange": 0
|
|
498
|
+
}],
|
|
499
|
+
"open": [{
|
|
500
|
+
"handleOpenChange": 0
|
|
501
|
+
}]
|
|
502
|
+
}; }
|
|
503
|
+
};
|
|
504
|
+
StripePaymentSheet.style = stripePaymentSheetCss();
|
|
505
|
+
|
|
506
|
+
exports.stripe_payment_sheet = StripePaymentSheet;
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
"components/stripe-address-element/stripe-address-element.js",
|
|
4
4
|
"components/stripe-payment-element/stripe-payment-element.js",
|
|
5
5
|
"components/stripe-card-element/stripe-card-element.js",
|
|
6
|
-
"components/stripe-card-element-modal/stripe-card-element-modal.js",
|
|
7
6
|
"components/stripe-currency-selector/stripe-currency-selector.js",
|
|
8
7
|
"components/stripe-express-checkout-element/stripe-express-checkout-element.js",
|
|
9
8
|
"components/stripe-link-authentication-element/stripe-link-authentication-element.js",
|
|
9
|
+
"components/stripe-payment-request-button/stripe-payment-request-button.js",
|
|
10
|
+
"components/stripe-card-element-modal/stripe-card-element-modal.js",
|
|
10
11
|
"components/stripe-modal/stripe-modal.js",
|
|
11
|
-
"components/stripe-payment-
|
|
12
|
+
"components/stripe-payment-sheet/stripe-payment-sheet.js"
|
|
12
13
|
],
|
|
13
14
|
"mixins": [],
|
|
14
15
|
"compiler": {
|
|
@@ -184,6 +184,13 @@ export class StripeAddressElement {
|
|
|
184
184
|
// Dependency Injection via factory
|
|
185
185
|
this.stripeService = serviceFactory.createStripeService();
|
|
186
186
|
this.addressElementManager = serviceFactory.createAddressElementManager(this.stripeService);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Props are not yet populated inside the constructor when the component is registered via
|
|
190
|
+
* the custom-elements build (`dist/components/*`), so initialization that depends on them
|
|
191
|
+
* must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
|
|
192
|
+
*/
|
|
193
|
+
componentWillLoad() {
|
|
187
194
|
if (this.publishableKey != null && this.publishableKey !== '') {
|
|
188
195
|
this.initStripe(this.publishableKey, {
|
|
189
196
|
stripeAccount: this.stripeAccount,
|
|
@@ -228,7 +228,8 @@ export class StripeCardElement {
|
|
|
228
228
|
*/
|
|
229
229
|
this.showLabel = false;
|
|
230
230
|
/**
|
|
231
|
-
* The component will
|
|
231
|
+
* The component will confirm the intent for you: `stripe.confirmCardPayment` when `intentType` is `'payment'`,
|
|
232
|
+
* `stripe.confirmCardSetup` when it is `'setup'`.
|
|
232
233
|
* If you want to customize the behavior, should set false.
|
|
233
234
|
* And listen the 'formSubmit' event on the element
|
|
234
235
|
*/
|
|
@@ -236,6 +237,13 @@ export class StripeCardElement {
|
|
|
236
237
|
// Dependency Injection via factory
|
|
237
238
|
this.stripeService = serviceFactory.createStripeService();
|
|
238
239
|
this.cardElementManager = serviceFactory.createCardElementManager(this.stripeService);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Props are not yet populated inside the constructor when the component is registered via
|
|
243
|
+
* the custom-elements build (`dist/components/*`), so initialization that depends on them
|
|
244
|
+
* must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
|
|
245
|
+
*/
|
|
246
|
+
componentWillLoad() {
|
|
239
247
|
if (this.publishableKey != null && this.publishableKey !== '') {
|
|
240
248
|
this.initStripe(this.publishableKey, buildInitStripeOptionsFromAccount(this.stripeAccount));
|
|
241
249
|
}
|
|
@@ -571,7 +579,7 @@ export class StripeCardElement {
|
|
|
571
579
|
"optional": false,
|
|
572
580
|
"docs": {
|
|
573
581
|
"tags": [],
|
|
574
|
-
"text": "The component will
|
|
582
|
+
"text": "The component will confirm the intent for you: `stripe.confirmCardPayment` when `intentType` is `'payment'`,\n`stripe.confirmCardSetup` when it is `'setup'`.\nIf you want to customize the behavior, should set false.\nAnd listen the 'formSubmit' event on the element"
|
|
575
583
|
},
|
|
576
584
|
"getter": false,
|
|
577
585
|
"setter": false,
|
|
@@ -6,7 +6,8 @@ export class StripeCardElementModal {
|
|
|
6
6
|
*/
|
|
7
7
|
this.showLabel = false;
|
|
8
8
|
/**
|
|
9
|
-
* The component will
|
|
9
|
+
* The component will confirm the intent for you: `stripe.confirmCardPayment` when `intentType` is `'payment'`,
|
|
10
|
+
* `stripe.confirmCardSetup` when it is `'setup'`.
|
|
10
11
|
* If you want to customize the behavior, should set false.
|
|
11
12
|
* And listen the 'formSubmit' event on the element
|
|
12
13
|
*/
|
|
@@ -94,7 +95,7 @@ export class StripeCardElementModal {
|
|
|
94
95
|
cardElement.setPaymentRequestOption(options);
|
|
95
96
|
}
|
|
96
97
|
render() {
|
|
97
|
-
return (h("stripe-modal", { key: '
|
|
98
|
+
return (h("stripe-modal", { key: '4904f57b562da9ce4fc348fb376f931cac707540', open: this.open, showCloseButton: this.showCloseButton }, h("stripe-card-element", { key: '8707fa6e32ca82b700f53fc2a257b8af1cc7b45c', showLabel: this.showLabel, publishableKey: this.publishableKey, intentClientSecret: this.intentClientSecret, shouldUseDefaultFormSubmitAction: this.shouldUseDefaultFormSubmitAction, handleSubmit: this.handleSubmit, stripeDidLoaded: this.stripeDidLoaded, intentType: this.intentType, zip: this.zip, buttonLabel: this.buttonLabel, sheetTitle: this.sheetTitle, applicationName: this.applicationName })));
|
|
98
99
|
}
|
|
99
100
|
static get is() { return "stripe-card-element-modal"; }
|
|
100
101
|
static get originalStyleUrls() {
|
|
@@ -264,7 +265,7 @@ export class StripeCardElementModal {
|
|
|
264
265
|
"optional": false,
|
|
265
266
|
"docs": {
|
|
266
267
|
"tags": [],
|
|
267
|
-
"text": "The component will
|
|
268
|
+
"text": "The component will confirm the intent for you: `stripe.confirmCardPayment` when `intentType` is `'payment'`,\n`stripe.confirmCardSetup` when it is `'setup'`.\nIf you want to customize the behavior, should set false.\nAnd listen the 'formSubmit' event on the element"
|
|
268
269
|
},
|
|
269
270
|
"getter": false,
|
|
270
271
|
"setter": false,
|
|
@@ -127,6 +127,13 @@ export class StripeCurrencySelector {
|
|
|
127
127
|
// Dependency Injection via factory
|
|
128
128
|
this.stripeService = serviceFactory.createStripeService();
|
|
129
129
|
this.currencySelectorElementManager = serviceFactory.createCurrencySelectorElementManager(this.stripeService);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Props are not yet populated inside the constructor when the component is registered via
|
|
133
|
+
* the custom-elements build (`dist/components/*`), so initialization that depends on them
|
|
134
|
+
* must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
|
|
135
|
+
*/
|
|
136
|
+
componentWillLoad() {
|
|
130
137
|
if (this.publishableKey) {
|
|
131
138
|
this.initStripe(this.publishableKey, {
|
|
132
139
|
stripeAccount: this.stripeAccount,
|
|
@@ -83,6 +83,8 @@ export class StripeExpressCheckoutElement {
|
|
|
83
83
|
await this.stripeService.initialize(publishableKey, {
|
|
84
84
|
stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
|
|
85
85
|
applicationName: this.applicationName,
|
|
86
|
+
clientSecret: this.clientSecret,
|
|
87
|
+
elementsOptions: this.buildElementsOptions(),
|
|
86
88
|
});
|
|
87
89
|
// If already successfully loaded, initialize elements immediately
|
|
88
90
|
if (this.stripeService.state.loadStripeStatus === 'success') {
|
|
@@ -101,6 +103,22 @@ export class StripeExpressCheckoutElement {
|
|
|
101
103
|
});
|
|
102
104
|
}
|
|
103
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Options for `stripe.elements()` when there is no client secret.
|
|
108
|
+
* Stripe.js reads mode / amount / currency from the Elements group, not from the element itself.
|
|
109
|
+
*/
|
|
110
|
+
buildElementsOptions() {
|
|
111
|
+
if (this.currency == null || this.currency === '') {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
if (this.intentType === 'setup') {
|
|
115
|
+
return { mode: 'setup', currency: this.currency };
|
|
116
|
+
}
|
|
117
|
+
if (this.amount === undefined) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
return { mode: 'payment', amount: this.amount, currency: this.currency };
|
|
121
|
+
}
|
|
104
122
|
/**
|
|
105
123
|
* Update element options dynamically
|
|
106
124
|
* @param options - Partial options to update
|
|
@@ -155,6 +173,13 @@ export class StripeExpressCheckoutElement {
|
|
|
155
173
|
// Dependency Injection via factory
|
|
156
174
|
this.stripeService = serviceFactory.createStripeService();
|
|
157
175
|
this.expressCheckoutManager = serviceFactory.createExpressCheckoutElementManager(this.stripeService);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Props are not yet populated inside the constructor when the component is registered via
|
|
179
|
+
* the custom-elements build (`dist/components/*`), so initialization that depends on them
|
|
180
|
+
* must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
|
|
181
|
+
*/
|
|
182
|
+
componentWillLoad() {
|
|
158
183
|
if (this.publishableKey != null && this.publishableKey !== '') {
|
|
159
184
|
this.initStripe(this.publishableKey, {
|
|
160
185
|
stripeAccount: this.stripeAccount,
|