stripe-pwa-elements 4.0.2 → 4.0.4
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 → factory-Cm6zUD7R.js} +7 -1
- package/dist/cjs/{i18n-FhEOc8vz.js → i18n-lBbOeQt4.js} +6 -0
- package/dist/cjs/ion-icon_2.cjs.entry.js +5 -3
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/stripe-address-element.cjs.entry.js +2 -2
- package/dist/cjs/stripe-card-element.cjs.entry.js +13 -3
- package/dist/cjs/stripe-currency-selector.cjs.entry.js +2 -2
- package/dist/cjs/stripe-elements.cjs.js +1 -1
- package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +2 -2
- package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +2 -2
- package/dist/cjs/stripe-payment-element.cjs.entry.js +11 -3
- package/dist/cjs/{stripe-payment-element.helpers-DukP33RI.js → stripe-payment-element.helpers-lafmSRmb.js} +7 -8
- package/dist/cjs/stripe-payment-sheet.cjs.entry.js +516 -35
- package/dist/collection/components/stripe-address-element/stripe-address-element.js +2 -2
- package/dist/collection/components/stripe-card-element/stripe-card-element.js +11 -1
- package/dist/collection/components/stripe-modal/stripe-modal.css +4 -0
- package/dist/collection/components/stripe-modal/stripe-modal.js +3 -1
- package/dist/collection/components/stripe-payment-element/stripe-payment-element.helpers.js +7 -8
- package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +12 -4
- package/dist/collection/components/stripe-payment-sheet/payment-sheet-state.js +21 -7
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.checkout.js +94 -0
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.helpers.js +193 -9
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +240 -21
- package/dist/collection/services/link-authentication-element-manager.js +5 -0
- package/dist/collection/utils/i18n.js +6 -0
- package/dist/components/factory.js +1 -1
- package/dist/components/i18n.js +1 -1
- package/dist/components/stripe-card-element2.js +1 -1
- package/dist/components/stripe-modal2.js +1 -1
- package/dist/components/stripe-payment-element.helpers.js +1 -1
- package/dist/components/stripe-payment-element.js +1 -1
- package/dist/components/stripe-payment-sheet.js +1 -1
- package/dist/esm/{factory-Cd6OGTWN.js → factory-BaGv8K_i.js} +7 -2
- package/dist/esm/{i18n-B6JoQetF.js → i18n-CL5n3bOb.js} +6 -0
- package/dist/esm/ion-icon_2.entry.js +5 -3
- package/dist/esm/loader.js +1 -1
- package/dist/esm/stripe-address-element.entry.js +2 -2
- package/dist/esm/stripe-card-element.entry.js +13 -3
- package/dist/esm/stripe-currency-selector.entry.js +2 -2
- package/dist/esm/stripe-elements.js +1 -1
- package/dist/esm/stripe-express-checkout-element.entry.js +2 -2
- package/dist/esm/stripe-link-authentication-element.entry.js +2 -2
- package/dist/esm/stripe-payment-element.entry.js +11 -3
- package/dist/esm/{stripe-payment-element.helpers-CipV87b8.js → stripe-payment-element.helpers-CklK5RlF.js} +7 -8
- package/dist/esm/stripe-payment-sheet.entry.js +516 -35
- package/dist/stripe-elements/{p-f892e375.entry.js → p-2e41699e.entry.js} +1 -1
- package/dist/stripe-elements/{p-6a9c8b7a.entry.js → p-3fc4583a.entry.js} +1 -1
- package/dist/stripe-elements/p-5d3d93ec.entry.js +1 -0
- package/dist/stripe-elements/p-7a8f783c.entry.js +1 -0
- package/dist/stripe-elements/{p-915b86ed.entry.js → p-7e826964.entry.js} +1 -1
- package/dist/stripe-elements/p-BoZLkOAy.js +1 -0
- package/dist/stripe-elements/p-CL5n3bOb.js +1 -0
- package/dist/stripe-elements/{p-C7MQk9FK.js → p-DlMEZwSe.js} +1 -1
- package/dist/stripe-elements/{p-5338bc5e.entry.js → p-b62c9dae.entry.js} +1 -1
- package/dist/stripe-elements/p-b69f6103.entry.js +1 -0
- package/dist/stripe-elements/{p-7fe4a287.entry.js → p-f5552c81.entry.js} +1 -1
- package/dist/stripe-elements/stripe-elements.esm.js +1 -1
- package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +1 -0
- package/dist/types/components/stripe-payment-element/stripe-payment-element.helpers.d.ts +9 -2
- package/dist/types/components/stripe-payment-sheet/payment-sheet-state.d.ts +21 -4
- package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.checkout.d.ts +39 -0
- package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.d.ts +50 -5
- package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.helpers.d.ts +66 -8
- package/dist/types/components.d.ts +22 -9
- package/dist/types/services/interfaces.d.ts +2 -0
- package/package.json +4 -2
- package/readme.md +78 -27
- package/dist/stripe-elements/p-B6JoQetF.js +0 -1
- package/dist/stripe-elements/p-DFAhQS0n.js +0 -1
- package/dist/stripe-elements/p-b06a254f.entry.js +0 -1
- package/dist/stripe-elements/p-b91c4fa7.entry.js +0 -1
- package/dist/stripe-elements/p-e7372ca7.entry.js +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var index = require('./index-Dkb0SxZc.js');
|
|
4
|
-
var i18n = require('./i18n-
|
|
5
|
-
var factory = require('./factory-
|
|
6
|
-
var stripePaymentElement_helpers = require('./stripe-payment-element.helpers-
|
|
4
|
+
var i18n = require('./i18n-lBbOeQt4.js');
|
|
5
|
+
var factory = require('./factory-Cm6zUD7R.js');
|
|
6
|
+
var stripePaymentElement_helpers = require('./stripe-payment-element.helpers-lafmSRmb.js');
|
|
7
|
+
var error = require('./error-FFC4kSs5.js');
|
|
7
8
|
require('./index-CYbA1N_k.js');
|
|
8
|
-
require('./error-FFC4kSs5.js');
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* State machine behind `<stripe-payment-sheet>`.
|
|
@@ -33,6 +33,20 @@ const intentKindFromClientSecret = (clientSecret) => {
|
|
|
33
33
|
const match = CLIENT_SECRET_PATTERNS.find(([pattern]) => pattern.test(clientSecret));
|
|
34
34
|
return match === null || match === void 0 ? void 0 : match[1];
|
|
35
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* Tell what a client secret belongs to.
|
|
38
|
+
* A secret from `checkout-session-client-secret` is always a Checkout Session: Stripe does not document the format
|
|
39
|
+
* of a Checkout Session client secret, so it is never inspected. Intent secrets are told apart by their prefix.
|
|
40
|
+
* @param clientSecret - The client secret
|
|
41
|
+
* @param source - The attribute the secret was set through
|
|
42
|
+
* @returns The kind, or undefined when an intent secret has an unknown format
|
|
43
|
+
*/
|
|
44
|
+
const intentKindOf = (clientSecret, source) => {
|
|
45
|
+
if (source === 'checkoutSession') {
|
|
46
|
+
return 'checkoutSession';
|
|
47
|
+
}
|
|
48
|
+
return intentKindFromClientSecret(clientSecret);
|
|
49
|
+
};
|
|
36
50
|
const unchanged = (state) => ({ state, effects: [] });
|
|
37
51
|
/**
|
|
38
52
|
* Resolve the pending `present()` promise, if any.
|
|
@@ -54,17 +68,17 @@ const cancel = (state) => {
|
|
|
54
68
|
effects: [...(visible ? [{ type: 'hide' }] : []), { type: 'emit', event: 'paymentSheetCanceled' }, ...resolved.effects],
|
|
55
69
|
};
|
|
56
70
|
};
|
|
57
|
-
const changeSecret = (state, clientSecret) => {
|
|
71
|
+
const changeSecret = (state, clientSecret, source) => {
|
|
58
72
|
if (clientSecret === '') {
|
|
59
73
|
return unchanged(state);
|
|
60
74
|
}
|
|
61
75
|
// Never drop the result of a running confirmation; apply the new secret once it finishes
|
|
62
76
|
if (state.phase === 'confirming') {
|
|
63
|
-
return unchanged(Object.assign(Object.assign({}, state), {
|
|
77
|
+
return unchanged(Object.assign(Object.assign({}, state), { deferredSecret: { clientSecret, source } }));
|
|
64
78
|
}
|
|
65
79
|
const canceled = state.phase === 'presented' ? cancel(state) : unchanged(state);
|
|
66
80
|
const generation = state.generation + 1;
|
|
67
|
-
const intentKind =
|
|
81
|
+
const intentKind = intentKindOf(clientSecret, source);
|
|
68
82
|
if (intentKind == null) {
|
|
69
83
|
const resolved = resolvePending(Object.assign(Object.assign({}, canceled.state), { phase: 'loadFailed', generation, intentKind: undefined, openRequested: false }), 'paymentSheetFailed');
|
|
70
84
|
return {
|
|
@@ -81,11 +95,11 @@ const changeSecret = (state, clientSecret) => {
|
|
|
81
95
|
* Apply a secret that arrived while confirming.
|
|
82
96
|
*/
|
|
83
97
|
const applyDeferredSecret = (result) => {
|
|
84
|
-
const {
|
|
85
|
-
if (
|
|
98
|
+
const { deferredSecret } = result.state;
|
|
99
|
+
if (deferredSecret == null) {
|
|
86
100
|
return result;
|
|
87
101
|
}
|
|
88
|
-
const next = changeSecret(Object.assign(Object.assign({}, result.state), {
|
|
102
|
+
const next = changeSecret(Object.assign(Object.assign({}, result.state), { deferredSecret: undefined }), deferredSecret.clientSecret, deferredSecret.source);
|
|
89
103
|
return { state: next.state, effects: [...result.effects, ...next.effects] };
|
|
90
104
|
};
|
|
91
105
|
const isCurrentConfirmation = (state, generation) => state.phase === 'confirming' && state.generation === generation;
|
|
@@ -97,7 +111,7 @@ const isCurrentConfirmation = (state, generation) => state.phase === 'confirming
|
|
|
97
111
|
const transition = (state, event) => {
|
|
98
112
|
switch (event.type) {
|
|
99
113
|
case 'secretChanged':
|
|
100
|
-
return changeSecret(state, event.clientSecret);
|
|
114
|
+
return changeSecret(state, event.clientSecret, event.source);
|
|
101
115
|
case 'loadSucceeded': {
|
|
102
116
|
if (event.generation !== state.generation || state.phase !== 'loading') {
|
|
103
117
|
return unchanged(state);
|
|
@@ -199,7 +213,17 @@ var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
|
199
213
|
}
|
|
200
214
|
return t;
|
|
201
215
|
};
|
|
202
|
-
const SUPPORTED_OPTION_KEYS = [
|
|
216
|
+
const SUPPORTED_OPTION_KEYS = [
|
|
217
|
+
'merchantDisplayName',
|
|
218
|
+
'paymentMethodLayout',
|
|
219
|
+
'defaultBillingDetails',
|
|
220
|
+
'returnURL',
|
|
221
|
+
'style',
|
|
222
|
+
'billingDetailsCollectionConfiguration',
|
|
223
|
+
'shippingDetails',
|
|
224
|
+
'enableApplePay',
|
|
225
|
+
'enableGooglePay',
|
|
226
|
+
];
|
|
203
227
|
const LAYOUTS = {
|
|
204
228
|
horizontal: 'tabs',
|
|
205
229
|
vertical: 'accordion',
|
|
@@ -213,6 +237,34 @@ const THEMES = {
|
|
|
213
237
|
* Drop keys whose value is undefined.
|
|
214
238
|
*/
|
|
215
239
|
const compact = (value) => Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
|
|
240
|
+
/**
|
|
241
|
+
* Convert a Capacitor address to the Stripe shape (`postalCode` → `postal_code`), dropping keys that are not given.
|
|
242
|
+
*/
|
|
243
|
+
const toStripeAddress = (address) => {
|
|
244
|
+
const { postalCode } = address, rest = __rest(address, ["postalCode"]);
|
|
245
|
+
return compact(Object.assign(Object.assign({}, rest), { postal_code: postalCode }));
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* Payment Element billing fields to turn off: the `never` ones (passed from `defaultBillingDetails` at confirmation)
|
|
249
|
+
* and the ones collected by a separate element (email element, billing Address Element).
|
|
250
|
+
*/
|
|
251
|
+
const toBillingDetailsFields = (config) => {
|
|
252
|
+
if (config == null) {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
const { email, name, phone, address } = config;
|
|
256
|
+
const fields = compact({
|
|
257
|
+
email: email === 'never' || email === 'always' ? 'never' : undefined,
|
|
258
|
+
name: name === 'never' ? 'never' : undefined,
|
|
259
|
+
phone: phone === 'never' || (phone === 'always' && address === 'full') ? 'never' : undefined,
|
|
260
|
+
address: address === 'never' || address === 'full' ? 'never' : undefined,
|
|
261
|
+
});
|
|
262
|
+
return Object.keys(fields).length === 0 ? undefined : fields;
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* `true` → `auto` (shown when available), `false` → `never`, undefined → left to Stripe
|
|
266
|
+
*/
|
|
267
|
+
const toWalletOption = (enabled) => (enabled == null ? undefined : enabled ? 'auto' : 'never');
|
|
216
268
|
/**
|
|
217
269
|
* Build the Payment Element options from the payment sheet options.
|
|
218
270
|
* @param options - Payment sheet options
|
|
@@ -221,8 +273,16 @@ const toPaymentElementOptions = (options) => {
|
|
|
221
273
|
if (options == null) {
|
|
222
274
|
return {};
|
|
223
275
|
}
|
|
224
|
-
const { merchantDisplayName, paymentMethodLayout, defaultBillingDetails } = options;
|
|
276
|
+
const { merchantDisplayName, paymentMethodLayout, defaultBillingDetails, billingDetailsCollectionConfiguration, enableApplePay, enableGooglePay } = options;
|
|
225
277
|
const elementOptions = {};
|
|
278
|
+
const billingDetailsFields = toBillingDetailsFields(billingDetailsCollectionConfiguration);
|
|
279
|
+
const wallets = compact({ applePay: toWalletOption(enableApplePay), googlePay: toWalletOption(enableGooglePay) });
|
|
280
|
+
if (billingDetailsFields != null) {
|
|
281
|
+
elementOptions.fields = { billingDetails: billingDetailsFields };
|
|
282
|
+
}
|
|
283
|
+
if (Object.keys(wallets).length > 0) {
|
|
284
|
+
elementOptions.wallets = wallets;
|
|
285
|
+
}
|
|
226
286
|
if (merchantDisplayName != null) {
|
|
227
287
|
elementOptions.business = { name: merchantDisplayName };
|
|
228
288
|
}
|
|
@@ -233,8 +293,7 @@ const toPaymentElementOptions = (options) => {
|
|
|
233
293
|
const { address } = defaultBillingDetails, contact = __rest(defaultBillingDetails, ["address"]);
|
|
234
294
|
const billingDetails = compact(contact);
|
|
235
295
|
if (address != null) {
|
|
236
|
-
|
|
237
|
-
billingDetails.address = compact(Object.assign(Object.assign({}, rest), { postal_code: postalCode }));
|
|
296
|
+
billingDetails.address = toStripeAddress(address);
|
|
238
297
|
}
|
|
239
298
|
elementOptions.defaultValues = { billingDetails };
|
|
240
299
|
}
|
|
@@ -251,17 +310,156 @@ const toAppearance = (style) => {
|
|
|
251
310
|
return { theme: THEMES[style] };
|
|
252
311
|
};
|
|
253
312
|
/**
|
|
254
|
-
* List the given options that have no effect on the web (yet), sorted by name.
|
|
313
|
+
* List the given options (or option values, as `option.key`) that have no effect on the web (yet), sorted by name.
|
|
255
314
|
* @param options - Payment sheet options
|
|
315
|
+
* @param intentKind - Kind of the intent, when known
|
|
256
316
|
*/
|
|
257
|
-
const unsupportedOptionKeys = (options) => {
|
|
317
|
+
const unsupportedOptionKeys = (options, intentKind) => {
|
|
258
318
|
if (options == null) {
|
|
259
319
|
return [];
|
|
260
320
|
}
|
|
261
|
-
|
|
321
|
+
const keys = Object.entries(options)
|
|
262
322
|
.filter(([key, value]) => value !== undefined && !SUPPORTED_OPTION_KEYS.includes(key))
|
|
263
|
-
.map(([key]) => key)
|
|
264
|
-
|
|
323
|
+
.map(([key]) => key);
|
|
324
|
+
const config = options.billingDetailsCollectionConfiguration;
|
|
325
|
+
// `fields.billingDetails.name: 'always'` of the Payment Element requires Stripe beta access, so it is not sent
|
|
326
|
+
if ((config === null || config === void 0 ? void 0 : config.name) === 'always') {
|
|
327
|
+
keys.push('billingDetailsCollectionConfiguration.name');
|
|
328
|
+
}
|
|
329
|
+
// The phone can only be required through the billing Address Element
|
|
330
|
+
if ((config === null || config === void 0 ? void 0 : config.phone) === 'always' && config.address !== 'full') {
|
|
331
|
+
keys.push('billingDetailsCollectionConfiguration.phone');
|
|
332
|
+
}
|
|
333
|
+
// A SetupIntent has no shipping details
|
|
334
|
+
if (options.shippingDetails != null && intentKind === 'setup') {
|
|
335
|
+
keys.push('shippingDetails');
|
|
336
|
+
}
|
|
337
|
+
return keys.sort();
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* Prefill values of an Address Element. The address is left out without a country, which the Address Element requires.
|
|
341
|
+
*/
|
|
342
|
+
const toAddressDefaultValues = (details) => {
|
|
343
|
+
const { name, phone, address } = details;
|
|
344
|
+
const country = address === null || address === void 0 ? void 0 : address.country;
|
|
345
|
+
return compact({ name, phone, address: country == null || country === '' ? undefined : Object.assign(Object.assign({}, toStripeAddress(address)), { country }) });
|
|
346
|
+
};
|
|
347
|
+
const isBlank = (value) => value == null || value === '';
|
|
348
|
+
/**
|
|
349
|
+
* Loose email check, used only when the email element has not told whether its value is complete (a prefilled value nobody edited)
|
|
350
|
+
*/
|
|
351
|
+
const looksLikeEmail = (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
|
352
|
+
/**
|
|
353
|
+
* Error for a `never` field without a default value. Thrown while loading so that Stripe never rejects the confirmation.
|
|
354
|
+
*/
|
|
355
|
+
const missingDefaultError = (field, defaultKey) => new Error(`<stripe-payment-sheet>: billingDetailsCollectionConfiguration.${field} is 'never', so defaultBillingDetails.${defaultKey} is required`);
|
|
356
|
+
/**
|
|
357
|
+
* Error the customer can fix in the open sheet (handled like a Stripe `validation_error`).
|
|
358
|
+
* Its message is an English i18n key, translated when it is shown (see `isSheetValidationError`).
|
|
359
|
+
*/
|
|
360
|
+
const validationError = (message) => Object.assign(new Error(message), { type: 'validation_error', sheetValidation: true });
|
|
361
|
+
/**
|
|
362
|
+
* Tell whether an error was raised by this sheet's own validation (its message is an i18n key), rather than by Stripe (already localized).
|
|
363
|
+
* @param error - Error thrown while confirming
|
|
364
|
+
*/
|
|
365
|
+
const isSheetValidationError = (error) => (error === null || error === void 0 ? void 0 : error.sheetValidation) === true;
|
|
366
|
+
/**
|
|
367
|
+
* Decide which extra elements to show and which billing details to pass at confirmation (PaymentIntent / SetupIntent mode).
|
|
368
|
+
* @param options - Payment sheet options
|
|
369
|
+
* @param intentKind - Kind of the intent being confirmed
|
|
370
|
+
* @throws Error when a `never` field has no value in `defaultBillingDetails`
|
|
371
|
+
*/
|
|
372
|
+
const planBillingDetailsCollection = (options, intentKind) => {
|
|
373
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
374
|
+
const config = (_a = options === null || options === void 0 ? void 0 : options.billingDetailsCollectionConfiguration) !== null && _a !== void 0 ? _a : {};
|
|
375
|
+
const defaults = (_b = options === null || options === void 0 ? void 0 : options.defaultBillingDetails) !== null && _b !== void 0 ? _b : {};
|
|
376
|
+
const fixedBillingDetails = {};
|
|
377
|
+
['email', 'name', 'phone'].forEach(field => {
|
|
378
|
+
if (config[field] !== 'never') {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
if (isBlank(defaults[field])) {
|
|
382
|
+
throw missingDefaultError(field, field);
|
|
383
|
+
}
|
|
384
|
+
fixedBillingDetails[field] = defaults[field];
|
|
385
|
+
});
|
|
386
|
+
if (config.address === 'never') {
|
|
387
|
+
const address = defaults.address;
|
|
388
|
+
if (address == null || isBlank(address.country)) {
|
|
389
|
+
throw missingDefaultError('address', 'address.country');
|
|
390
|
+
}
|
|
391
|
+
// Every key is passed: the Payment Element does not collect any part of the address
|
|
392
|
+
fixedBillingDetails.address = {
|
|
393
|
+
line1: (_c = address.line1) !== null && _c !== void 0 ? _c : '',
|
|
394
|
+
line2: (_d = address.line2) !== null && _d !== void 0 ? _d : '',
|
|
395
|
+
city: (_e = address.city) !== null && _e !== void 0 ? _e : '',
|
|
396
|
+
state: (_f = address.state) !== null && _f !== void 0 ? _f : '',
|
|
397
|
+
postal_code: (_g = address.postalCode) !== null && _g !== void 0 ? _g : '',
|
|
398
|
+
country: address.country,
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
const collectPhoneFromAddress = config.address === 'full' && config.phone === 'always';
|
|
402
|
+
const plan = { fixedBillingDetails, collectPhoneFromAddress };
|
|
403
|
+
if (config.address === 'full') {
|
|
404
|
+
const billingAddressElement = { mode: 'billing', defaultValues: toAddressDefaultValues(defaults) };
|
|
405
|
+
if (collectPhoneFromAddress) {
|
|
406
|
+
billingAddressElement.fields = { phone: 'always' };
|
|
407
|
+
billingAddressElement.validation = { phone: { required: 'always' } };
|
|
408
|
+
}
|
|
409
|
+
else if (config.phone === 'never') {
|
|
410
|
+
billingAddressElement.fields = { phone: 'never' };
|
|
411
|
+
}
|
|
412
|
+
plan.billingAddressElement = billingAddressElement;
|
|
413
|
+
}
|
|
414
|
+
if (config.email === 'always') {
|
|
415
|
+
plan.emailElement = isBlank(defaults.email) ? {} : { defaultValues: { email: defaults.email } };
|
|
416
|
+
}
|
|
417
|
+
const shippingDetails = options === null || options === void 0 ? void 0 : options.shippingDetails;
|
|
418
|
+
if (shippingDetails != null && intentKind === 'payment') {
|
|
419
|
+
const shippingAddressElement = { mode: 'shipping', defaultValues: toAddressDefaultValues(shippingDetails) };
|
|
420
|
+
// The Address Element hides the phone field by default; show it so that the given phone is kept and editable
|
|
421
|
+
if (!isBlank(shippingDetails.phone)) {
|
|
422
|
+
shippingAddressElement.fields = { phone: 'always' };
|
|
423
|
+
}
|
|
424
|
+
plan.shippingAddressElement = shippingAddressElement;
|
|
425
|
+
}
|
|
426
|
+
return plan;
|
|
427
|
+
};
|
|
428
|
+
/**
|
|
429
|
+
* Build `payment_method_data.billing_details` for the confirmation.
|
|
430
|
+
* Values fixed by a `never` field win over the values typed into the extra elements.
|
|
431
|
+
* @param plan - Result of `planBillingDetailsCollection`
|
|
432
|
+
* @param collected - Values read from the extra elements
|
|
433
|
+
* @returns The billing details, or undefined when nothing has to be passed
|
|
434
|
+
* @throws Error with `type: 'validation_error'` when an extra element is not complete
|
|
435
|
+
*/
|
|
436
|
+
const collectedBillingDetails = (plan, collected) => {
|
|
437
|
+
var _a, _b;
|
|
438
|
+
const details = {};
|
|
439
|
+
if (plan.billingAddressElement != null) {
|
|
440
|
+
const billingAddress = collected.billingAddress;
|
|
441
|
+
if (billingAddress == null || !billingAddress.complete) {
|
|
442
|
+
throw validationError('Please complete your billing address.');
|
|
443
|
+
}
|
|
444
|
+
details.name = billingAddress.value.name;
|
|
445
|
+
details.address = billingAddress.value.address;
|
|
446
|
+
if (plan.collectPhoneFromAddress) {
|
|
447
|
+
details.phone = billingAddress.value.phone;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
if (plan.emailElement != null) {
|
|
451
|
+
// Before any change event the element shows its prefilled value
|
|
452
|
+
const email = (_a = collected.email) !== null && _a !== void 0 ? _a : (_b = plan.emailElement.defaultValues) === null || _b === void 0 ? void 0 : _b.email;
|
|
453
|
+
if (isBlank(email)) {
|
|
454
|
+
throw validationError('Please enter your email address.');
|
|
455
|
+
}
|
|
456
|
+
if (collected.emailComplete === false || (collected.emailComplete == null && !looksLikeEmail(email))) {
|
|
457
|
+
throw validationError('Please enter a valid email address.');
|
|
458
|
+
}
|
|
459
|
+
details.email = email;
|
|
460
|
+
}
|
|
461
|
+
Object.assign(details, plan.fixedBillingDetails);
|
|
462
|
+
return Object.keys(details).length === 0 ? undefined : details;
|
|
265
463
|
};
|
|
266
464
|
/**
|
|
267
465
|
* Stripe error types after which the customer can fix the input or simply try again.
|
|
@@ -278,8 +476,102 @@ const isRecoverableConfirmError = (error) => {
|
|
|
278
476
|
return typeof type === 'string' && RECOVERABLE_ERROR_TYPES.includes(type);
|
|
279
477
|
};
|
|
280
478
|
|
|
479
|
+
/**
|
|
480
|
+
* Build the Checkout Payment Element options from the payment sheet options.
|
|
481
|
+
* The Checkout Payment Element takes fewer options than the regular one: `business` and `defaultValues` are not
|
|
482
|
+
* available, so only the layout is passed.
|
|
483
|
+
* @param options - Payment sheet options
|
|
484
|
+
*/
|
|
485
|
+
const toCheckoutPaymentElementOptions = (options) => {
|
|
486
|
+
const { layout } = toPaymentElementOptions(options);
|
|
487
|
+
return layout == null ? {} : { layout };
|
|
488
|
+
};
|
|
489
|
+
/**
|
|
490
|
+
* List the given options that a Checkout Session does not use, sorted by name.
|
|
491
|
+
* Name, phone and address come from the session or from other Checkout elements; the email is passed to `confirm`.
|
|
492
|
+
* @param options - Payment sheet options
|
|
493
|
+
*/
|
|
494
|
+
const checkoutIgnoredOptionKeys = (options) => {
|
|
495
|
+
if (options == null) {
|
|
496
|
+
return [];
|
|
497
|
+
}
|
|
498
|
+
const { merchantDisplayName, defaultBillingDetails } = options;
|
|
499
|
+
const keys = ['name', 'phone', 'address'].filter(key => (defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails[key]) != null).map(key => `defaultBillingDetails.${key}`);
|
|
500
|
+
if (merchantDisplayName != null) {
|
|
501
|
+
keys.push('merchantDisplayName');
|
|
502
|
+
}
|
|
503
|
+
// The extra billing elements and the wallet mapping are implemented for PaymentIntent / SetupIntent mode only
|
|
504
|
+
['billingDetailsCollectionConfiguration', 'shippingDetails', 'enableApplePay', 'enableGooglePay']
|
|
505
|
+
.filter(key => options[key] !== undefined)
|
|
506
|
+
.forEach(key => keys.push(key));
|
|
507
|
+
return keys.sort();
|
|
508
|
+
};
|
|
509
|
+
/**
|
|
510
|
+
* Build the `elementsOptions` passed to `initCheckoutElementsSdk` from the payment sheet options.
|
|
511
|
+
* @param options - Payment sheet options
|
|
512
|
+
*/
|
|
513
|
+
const toCheckoutElementsOptions = (options) => {
|
|
514
|
+
const appearance = toAppearance(options === null || options === void 0 ? void 0 : options.style);
|
|
515
|
+
return appearance == null ? undefined : { appearance };
|
|
516
|
+
};
|
|
517
|
+
/**
|
|
518
|
+
* Throw when the session can no longer be paid. Stripe documents an `expired` session as "No further processing will occur",
|
|
519
|
+
* and a `complete` one is already paid or being paid, so confirming again cannot succeed.
|
|
520
|
+
* @param status - `session.status` from `getSession()`; undefined when it cannot be read
|
|
521
|
+
* @param message - Message of the confirm error, if any
|
|
522
|
+
* @throws StripeAPIError of type `invalid_request_error` (unrecoverable), with the code `checkout_session_expired` or `checkout_session_complete`
|
|
523
|
+
*/
|
|
524
|
+
const assertSessionOpen = (status, message) => {
|
|
525
|
+
if (status == null || status.type === 'open') {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
throw new error.StripeAPIError({
|
|
529
|
+
type: 'invalid_request_error',
|
|
530
|
+
code: `checkout_session_${status.type}`,
|
|
531
|
+
message: message !== null && message !== void 0 ? message : `The Checkout Session is ${status.type} and can no longer be paid.`,
|
|
532
|
+
});
|
|
533
|
+
};
|
|
534
|
+
/**
|
|
535
|
+
* Confirm a Checkout Session from the payment sheet.
|
|
536
|
+
*
|
|
537
|
+
* Unlike the default of `confirm`, which always redirects to `returnUrl`, this passes `redirect: 'if_required'`
|
|
538
|
+
* so that payment methods without a redirect finish in the page and can be reported as `paymentSheetCompleted`.
|
|
539
|
+
*
|
|
540
|
+
* Errors are thrown as `StripeAPIError` with a `type` that `isRecoverableConfirmError` understands.
|
|
541
|
+
* A confirm error only carries `code: 'paymentFailed'` or `code: null` (`StripeCheckoutConfirmResult` in @stripe/stripe-js),
|
|
542
|
+
* so whether the session can still be paid is read from `session.status`:
|
|
543
|
+
* - session `expired` or `complete` (before confirming or after a failed confirm): `invalid_request_error`, which ends the sheet
|
|
544
|
+
* - `paymentFailed` on an open session (a decline): `card_error`, which keeps the sheet open
|
|
545
|
+
* - any other confirm error on an open session, or a failure to load the actions: `api_error`, which keeps the sheet open
|
|
546
|
+
* @param checkout - The Checkout instance from `initCheckoutElementsSdk`
|
|
547
|
+
* @param returnUrl - Where Stripe redirects after a redirect-based payment method
|
|
548
|
+
* @param email - Customer email; needed when the session was created without `customer_email` or `customer`
|
|
549
|
+
* @returns The confirmation result
|
|
550
|
+
* @throws StripeAPIError when the actions cannot be loaded, the session can no longer be paid, or the confirmation fails
|
|
551
|
+
*/
|
|
552
|
+
const confirmCheckoutSessionSheet = async (checkout, returnUrl, email) => {
|
|
553
|
+
const loadActionsResult = await checkout.loadActions();
|
|
554
|
+
if (loadActionsResult.type === 'error') {
|
|
555
|
+
throw new error.StripeAPIError({ type: 'api_error', code: 'checkout_session_error', message: loadActionsResult.error.message });
|
|
556
|
+
}
|
|
557
|
+
const { actions } = loadActionsResult;
|
|
558
|
+
const sessionStatus = () => { var _a, _b; return (_b = (_a = actions.getSession) === null || _a === void 0 ? void 0 : _a.call(actions)) === null || _b === void 0 ? void 0 : _b.status; };
|
|
559
|
+
assertSessionOpen(sessionStatus());
|
|
560
|
+
const result = await actions.confirm(Object.assign({ returnUrl, redirect: 'if_required' }, (email != null && email !== '' ? { email } : {})));
|
|
561
|
+
if (result.type === 'error') {
|
|
562
|
+
const { code, message } = result.error;
|
|
563
|
+
assertSessionOpen(sessionStatus(), message);
|
|
564
|
+
if (code === 'paymentFailed') {
|
|
565
|
+
throw new error.StripeAPIError({ type: 'card_error', code, message });
|
|
566
|
+
}
|
|
567
|
+
throw new error.StripeAPIError({ type: 'api_error', code: 'checkout_session_error', message });
|
|
568
|
+
}
|
|
569
|
+
return result;
|
|
570
|
+
};
|
|
571
|
+
|
|
281
572
|
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
573
|
|
|
574
|
+
const nonEmpty = (value) => (value == null || value === '' ? undefined : value);
|
|
283
575
|
const StripePaymentSheet = class {
|
|
284
576
|
/**
|
|
285
577
|
* Show the sheet and wait for its result.
|
|
@@ -315,6 +607,7 @@ const StripePaymentSheet = class {
|
|
|
315
607
|
this.paymentSheetCanceled = index.createEvent(this, "paymentSheetCanceled", 7);
|
|
316
608
|
this.paymentSheetFailed = index.createEvent(this, "paymentSheetFailed", 7);
|
|
317
609
|
this.warnedUnsupportedOptions = false;
|
|
610
|
+
this.warnedCheckoutIgnoredOptions = false;
|
|
318
611
|
/**
|
|
319
612
|
* Whether the sheet is shown. Setting it to false closes the sheet as canceled.
|
|
320
613
|
*/
|
|
@@ -351,6 +644,9 @@ const StripePaymentSheet = class {
|
|
|
351
644
|
};
|
|
352
645
|
this.stripeService = factory.serviceFactory.createStripeService();
|
|
353
646
|
this.paymentElementManager = factory.serviceFactory.createPaymentElementManager(this.stripeService);
|
|
647
|
+
this.billingAddressElementManager = factory.serviceFactory.createAddressElementManager(this.stripeService);
|
|
648
|
+
this.shippingAddressElementManager = factory.serviceFactory.createAddressElementManager(this.stripeService);
|
|
649
|
+
this.emailElementManager = factory.serviceFactory.createLinkAuthenticationElementManager(this.stripeService);
|
|
354
650
|
}
|
|
355
651
|
/**
|
|
356
652
|
* Props are not yet populated inside the constructor with the custom-elements build,
|
|
@@ -367,12 +663,43 @@ const StripePaymentSheet = class {
|
|
|
367
663
|
}
|
|
368
664
|
disconnectedCallback() {
|
|
369
665
|
this.paymentElementManager.unmount();
|
|
666
|
+
this.unmountExtraElements();
|
|
667
|
+
}
|
|
668
|
+
unmountExtraElements() {
|
|
669
|
+
this.billingAddressElementManager.unmount();
|
|
670
|
+
this.shippingAddressElementManager.unmount();
|
|
671
|
+
this.emailElementManager.unmount();
|
|
370
672
|
}
|
|
673
|
+
/**
|
|
674
|
+
* Decide what to load from the attributes and load it only when it differs from the last load.
|
|
675
|
+
* A change that does not alter the result (the attribute that is not used, or an empty value that means unset)
|
|
676
|
+
* must neither reload Stripe.js nor cancel an open sheet.
|
|
677
|
+
*/
|
|
371
678
|
startLoading() {
|
|
372
|
-
|
|
679
|
+
const target = this.loadTarget();
|
|
680
|
+
if (target == null || target.key === this.lastLoadKey) {
|
|
373
681
|
return;
|
|
374
682
|
}
|
|
375
|
-
this.
|
|
683
|
+
this.lastLoadKey = target.key;
|
|
684
|
+
this.dispatch({ type: 'secretChanged', clientSecret: target.clientSecret, source: target.source });
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* The secret to load and a key of everything the load depends on, or undefined when nothing can be loaded.
|
|
688
|
+
* The Checkout Session wins when both secrets are set (the same rule as `stripe-payment-element`).
|
|
689
|
+
*/
|
|
690
|
+
loadTarget() {
|
|
691
|
+
var _a;
|
|
692
|
+
const publishableKey = nonEmpty(this.publishableKey);
|
|
693
|
+
if (publishableKey == null) {
|
|
694
|
+
return undefined;
|
|
695
|
+
}
|
|
696
|
+
const checkoutSessionClientSecret = nonEmpty(this.checkoutSessionClientSecret);
|
|
697
|
+
const intentClientSecret = nonEmpty(this.intentClientSecret);
|
|
698
|
+
const [clientSecret, source] = checkoutSessionClientSecret != null ? [checkoutSessionClientSecret, 'checkoutSession'] : [intentClientSecret, 'intent'];
|
|
699
|
+
if (clientSecret == null) {
|
|
700
|
+
return undefined;
|
|
701
|
+
}
|
|
702
|
+
return { key: JSON.stringify([publishableKey, (_a = nonEmpty(this.stripeAccount)) !== null && _a !== void 0 ? _a : null, source, clientSecret]), clientSecret, source };
|
|
376
703
|
}
|
|
377
704
|
dispatch(event) {
|
|
378
705
|
const { state, effects } = transition(this.sheet, event);
|
|
@@ -383,7 +710,12 @@ const StripePaymentSheet = class {
|
|
|
383
710
|
var _a;
|
|
384
711
|
switch (effect.type) {
|
|
385
712
|
case 'load':
|
|
386
|
-
|
|
713
|
+
if (effect.intentKind === 'checkoutSession') {
|
|
714
|
+
this.loadCheckoutSession(effect.generation, effect.clientSecret);
|
|
715
|
+
}
|
|
716
|
+
else {
|
|
717
|
+
this.load(effect.generation, effect.clientSecret, effect.intentKind);
|
|
718
|
+
}
|
|
387
719
|
break;
|
|
388
720
|
case 'show':
|
|
389
721
|
this.visible = true;
|
|
@@ -394,7 +726,12 @@ const StripePaymentSheet = class {
|
|
|
394
726
|
this.open = false;
|
|
395
727
|
break;
|
|
396
728
|
case 'confirm':
|
|
397
|
-
|
|
729
|
+
if (effect.intentKind === 'checkoutSession') {
|
|
730
|
+
this.confirmCheckoutSession(effect.generation);
|
|
731
|
+
}
|
|
732
|
+
else {
|
|
733
|
+
this.confirm(effect.generation, effect.intentKind);
|
|
734
|
+
}
|
|
398
735
|
break;
|
|
399
736
|
case 'showError':
|
|
400
737
|
this.errorMessage = effect.message;
|
|
@@ -409,16 +746,20 @@ const StripePaymentSheet = class {
|
|
|
409
746
|
break;
|
|
410
747
|
}
|
|
411
748
|
}
|
|
412
|
-
async load(generation, clientSecret) {
|
|
749
|
+
async load(generation, clientSecret, intentKind) {
|
|
413
750
|
var _a;
|
|
414
|
-
this.warnUnsupportedOptions();
|
|
751
|
+
this.warnUnsupportedOptions(intentKind);
|
|
752
|
+
// A newer load started while this one was waiting: stop before touching the elements, so that only the latest load mounts and emits
|
|
753
|
+
const superseded = () => generation !== this.sheet.generation;
|
|
415
754
|
try {
|
|
755
|
+
// Fails before loading Stripe.js when a `never` field has no default value, so that Stripe never rejects the confirmation
|
|
756
|
+
const collection = planBillingDetailsCollection(this.options, intentKind);
|
|
416
757
|
await this.stripeService.initialize(this.publishableKey, {
|
|
417
758
|
stripeAccount: this.stripeAccount,
|
|
418
759
|
applicationName: this.applicationName,
|
|
419
760
|
clientSecret,
|
|
420
761
|
});
|
|
421
|
-
if (
|
|
762
|
+
if (superseded()) {
|
|
422
763
|
return;
|
|
423
764
|
}
|
|
424
765
|
if (this.stripeService.state.loadStripeStatus !== 'success') {
|
|
@@ -427,24 +768,110 @@ const StripePaymentSheet = class {
|
|
|
427
768
|
const appearance = toAppearance((_a = this.options) === null || _a === void 0 ? void 0 : _a.style);
|
|
428
769
|
if (appearance != null) {
|
|
429
770
|
await this.stripeService.getElements().update({ appearance });
|
|
771
|
+
if (superseded()) {
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
if (!(await this.mountExtraElements(collection, superseded))) {
|
|
776
|
+
return;
|
|
430
777
|
}
|
|
431
778
|
await this.paymentElementManager.initialize(this.el, toPaymentElementOptions(this.options));
|
|
432
779
|
this.dispatch({ type: 'loadSucceeded', generation });
|
|
433
780
|
}
|
|
434
781
|
catch (e) {
|
|
782
|
+
if (superseded()) {
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
435
785
|
this.lastError = e;
|
|
436
786
|
this.dispatch({ type: 'loadFailed', generation });
|
|
437
787
|
}
|
|
438
788
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
789
|
+
/**
|
|
790
|
+
* Render the mount points of the plan's extra elements and mount them. Elements a previous load needed but this one does not are unmounted
|
|
791
|
+
* (the managers unmount their previous element themselves when initialized again).
|
|
792
|
+
*/
|
|
793
|
+
async mountExtraElements(collection, superseded) {
|
|
794
|
+
this.collection = collection;
|
|
795
|
+
const { emailElement, shippingAddressElement, billingAddressElement } = collection;
|
|
796
|
+
const extraElements = [
|
|
797
|
+
{
|
|
798
|
+
manager: this.emailElementManager,
|
|
799
|
+
selector: '.stripe-payment-sheet-email',
|
|
800
|
+
mount: emailElement && (container => this.emailElementManager.initialize(container, emailElement)),
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
manager: this.shippingAddressElementManager,
|
|
804
|
+
selector: '.stripe-payment-sheet-shipping-address',
|
|
805
|
+
mount: shippingAddressElement && (container => this.shippingAddressElementManager.initialize(container, shippingAddressElement)),
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
manager: this.billingAddressElementManager,
|
|
809
|
+
selector: '.stripe-payment-sheet-billing-address',
|
|
810
|
+
mount: billingAddressElement && (container => this.billingAddressElementManager.initialize(container, billingAddressElement)),
|
|
811
|
+
},
|
|
812
|
+
];
|
|
813
|
+
for (const { manager, selector, mount } of extraElements) {
|
|
814
|
+
if (mount == null) {
|
|
815
|
+
manager.unmount();
|
|
816
|
+
continue;
|
|
817
|
+
}
|
|
818
|
+
// The container is looked up with findElement, which waits for it in case the sheet has not rendered yet
|
|
819
|
+
const container = await factory.findElement(this.el, selector);
|
|
820
|
+
if (superseded()) {
|
|
821
|
+
return false;
|
|
822
|
+
}
|
|
823
|
+
await mount(container);
|
|
824
|
+
if (superseded()) {
|
|
825
|
+
return false;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
return true;
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Billing details read from the extra elements and the `never` fields, as extra confirm params
|
|
832
|
+
*/
|
|
833
|
+
async confirmParams() {
|
|
834
|
+
var _a;
|
|
835
|
+
const collection = this.collection;
|
|
836
|
+
if (collection == null) {
|
|
837
|
+
return undefined;
|
|
838
|
+
}
|
|
839
|
+
const billingAddress = collection.billingAddressElement != null ? await ((_a = this.billingAddressElementManager.getElement()) === null || _a === void 0 ? void 0 : _a.getValue()) : undefined;
|
|
840
|
+
const emailState = collection.emailElement != null ? this.emailElementManager.getState() : undefined;
|
|
841
|
+
const billingDetails = collectedBillingDetails(collection, { billingAddress, email: emailState === null || emailState === void 0 ? void 0 : emailState.email, emailComplete: emailState === null || emailState === void 0 ? void 0 : emailState.complete });
|
|
842
|
+
return billingDetails == null ? undefined : { payment_method_data: { billing_details: billingDetails } };
|
|
843
|
+
}
|
|
844
|
+
confirm(generation, intentKind) {
|
|
845
|
+
return this.runConfirm(generation, async () => {
|
|
846
|
+
var _a, _b;
|
|
847
|
+
const elements = this.stripeService.getElements();
|
|
848
|
+
// elements.submit() comes first, with nothing awaited before it, as in Stripe's submit handler examples:
|
|
849
|
+
// it validates the elements and collects what wallets (Apple Pay, Google Pay) need while the customer's click still counts,
|
|
850
|
+
// and other asynchronous work may follow once it has resolved
|
|
851
|
+
const { error: submitError } = await elements.submit();
|
|
852
|
+
if (submitError != null) {
|
|
853
|
+
throw submitError;
|
|
854
|
+
}
|
|
442
855
|
const returnUrl = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.returnURL) !== null && _b !== void 0 ? _b : window.location.href;
|
|
443
|
-
|
|
856
|
+
const extraConfirmParams = await this.confirmParams();
|
|
857
|
+
return stripePaymentElement_helpers.confirmPaymentOrSetup(this.stripeService.getStripe(), elements, intentKind, returnUrl, extraConfirmParams);
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Run a confirmation and report its result to the state machine.
|
|
862
|
+
* `confirm` is called synchronously, so that its first step still runs inside the customer's submit event.
|
|
863
|
+
* Errors the customer can fix or retry keep the sheet open; others end it with `paymentSheetFailed`.
|
|
864
|
+
*/
|
|
865
|
+
async runConfirm(generation, confirm) {
|
|
866
|
+
var _a;
|
|
867
|
+
try {
|
|
868
|
+
this.lastResult = await confirm();
|
|
444
869
|
this.dispatch({ type: 'confirmSucceeded', generation });
|
|
445
870
|
}
|
|
446
871
|
catch (e) {
|
|
447
|
-
const
|
|
872
|
+
const rawMessage = (_a = e.message) !== null && _a !== void 0 ? _a : String(e);
|
|
873
|
+
// Stripe's messages are already localized; the sheet's own validation messages are i18n keys
|
|
874
|
+
const message = isSheetValidationError(e) ? i18n.i18n.t(rawMessage) : rawMessage;
|
|
448
875
|
if (isRecoverableConfirmError(e)) {
|
|
449
876
|
this.dispatch({ type: 'confirmDeclined', generation, message });
|
|
450
877
|
return;
|
|
@@ -453,6 +880,48 @@ const StripePaymentSheet = class {
|
|
|
453
880
|
this.dispatch({ type: 'confirmFailed', generation, message });
|
|
454
881
|
}
|
|
455
882
|
}
|
|
883
|
+
async loadCheckoutSession(generation, clientSecret) {
|
|
884
|
+
this.warnUnsupportedOptions('checkoutSession');
|
|
885
|
+
this.warnCheckoutIgnoredOptions();
|
|
886
|
+
// The extra billing elements belong to intent mode; remove those of an earlier intent load
|
|
887
|
+
this.collection = undefined;
|
|
888
|
+
this.unmountExtraElements();
|
|
889
|
+
try {
|
|
890
|
+
await this.stripeService.initializeWithCheckoutSession(this.publishableKey, clientSecret, {
|
|
891
|
+
stripeAccount: this.stripeAccount,
|
|
892
|
+
applicationName: this.applicationName,
|
|
893
|
+
elementsOptions: toCheckoutElementsOptions(this.options),
|
|
894
|
+
});
|
|
895
|
+
if (generation !== this.sheet.generation) {
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
if (this.stripeService.state.loadStripeStatus !== 'success') {
|
|
899
|
+
throw new Error('Failed to load Stripe.js');
|
|
900
|
+
}
|
|
901
|
+
await this.paymentElementManager.initialize(this.el, toCheckoutPaymentElementOptions(this.options));
|
|
902
|
+
this.dispatch({ type: 'loadSucceeded', generation });
|
|
903
|
+
}
|
|
904
|
+
catch (e) {
|
|
905
|
+
// An error of a load that a newer load replaced is not reported
|
|
906
|
+
if (generation !== this.sheet.generation) {
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
this.lastError = e;
|
|
910
|
+
this.dispatch({ type: 'loadFailed', generation });
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
confirmCheckoutSession(generation) {
|
|
914
|
+
var _a, _b;
|
|
915
|
+
const returnUrl = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.returnURL) !== null && _b !== void 0 ? _b : window.location.href;
|
|
916
|
+
return this.runConfirm(generation, async () => {
|
|
917
|
+
var _a, _b;
|
|
918
|
+
const checkout = this.stripeService.getCheckout();
|
|
919
|
+
if (checkout == null) {
|
|
920
|
+
throw new Error('Checkout Session is not initialized');
|
|
921
|
+
}
|
|
922
|
+
return confirmCheckoutSessionSheet(checkout, returnUrl, (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.defaultBillingDetails) === null || _b === void 0 ? void 0 : _b.email);
|
|
923
|
+
});
|
|
924
|
+
}
|
|
456
925
|
emit(event) {
|
|
457
926
|
switch (event) {
|
|
458
927
|
case 'paymentSheetLoaded':
|
|
@@ -472,18 +941,27 @@ const StripePaymentSheet = class {
|
|
|
472
941
|
break;
|
|
473
942
|
}
|
|
474
943
|
}
|
|
475
|
-
warnUnsupportedOptions() {
|
|
476
|
-
const keys = unsupportedOptionKeys(this.options);
|
|
944
|
+
warnUnsupportedOptions(intentKind) {
|
|
945
|
+
const keys = unsupportedOptionKeys(this.options, intentKind);
|
|
477
946
|
if (this.warnedUnsupportedOptions || keys.length === 0) {
|
|
478
947
|
return;
|
|
479
948
|
}
|
|
480
949
|
this.warnedUnsupportedOptions = true;
|
|
481
950
|
console.warn(`<stripe-payment-sheet>: these options have no effect on the web yet: ${keys.join(', ')}`);
|
|
482
951
|
}
|
|
952
|
+
warnCheckoutIgnoredOptions() {
|
|
953
|
+
const keys = checkoutIgnoredOptionKeys(this.options);
|
|
954
|
+
if (this.warnedCheckoutIgnoredOptions || keys.length === 0) {
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
this.warnedCheckoutIgnoredOptions = true;
|
|
958
|
+
console.warn(`<stripe-payment-sheet>: these options have no effect with a Checkout Session: ${keys.join(', ')}`);
|
|
959
|
+
}
|
|
483
960
|
render() {
|
|
961
|
+
var _a, _b, _c;
|
|
484
962
|
const { phase } = this.sheet;
|
|
485
963
|
const confirming = phase === 'confirming';
|
|
486
|
-
return (index.h(index.Host, { key: '
|
|
964
|
+
return (index.h(index.Host, { key: 'e6b2c3cb168039eb428eaaee1dce598f534c18e7' }, index.h("stripe-modal", { key: 'ef1515b07cca402c4db8818e2e94ca80e4d954c2', open: this.visible, showCloseButton: !confirming, onClose: this.handleModalClose }, index.h("div", { key: '9252fa1653b206d211756c94325c73a8ec482a37', class: "stripe-payment-sheet-wrap" }, index.h("form", { key: '904a54f2439e0356c2cbf9227326efe446aa08ce', id: "stripe-payment-sheet", onSubmit: this.handleSubmit }, index.h("div", { key: '103d81e3c56cfba1c421e1bf140a49e2b392c6b5', class: "stripe-heading" }, i18n.i18n.t(this.sheetTitle)), index.h("div", { key: 'cda58a48db7b04af1981407b7100def815404e35', class: "payment-info visible" }, index.h("div", { key: 'cbe248666aa4807c25d492df1ab1de017bc78e2c', class: "stripe-payment-sheet-email" }, ((_a = this.collection) === null || _a === void 0 ? void 0 : _a.emailElement) != null && index.h("div", { key: 'b0210c6cce85d1affaa83e3fa30785158c9bab98', id: "link-authentication-element" })), index.h("div", { key: '2420956298e5b36c63f3fbea6b4e32429b7ace27', class: "stripe-payment-sheet-shipping-address" }, ((_b = this.collection) === null || _b === void 0 ? void 0 : _b.shippingAddressElement) != null && index.h("div", { key: 'ae41335a42c59598e1addbfdea0a13342c026456', id: "address-element" })), index.h("div", { key: '3196844c9396c40548a3c632733565027df3cea7', class: "stripe-payment-sheet-billing-address" }, ((_c = this.collection) === null || _c === void 0 ? void 0 : _c.billingAddressElement) != null && index.h("div", { key: '269a99368975db70722fc181a1c099859f23d3d6', id: "address-element" })), index.h("div", { key: '2a63173a607501ff08ac072956cdbe462a4400c1', id: "payment-element" })), index.h("div", { key: '7a72a86097aca2af6491c56b52258286ef820283', class: "stripe-element-errors", role: "alert" }, this.errorMessage), index.h("div", { key: '10f05d5ecfa53cde350f00acffd86e232e370fe7', class: "stripe-submit" }, index.h("button", { key: 'a7ad3e538b94403bd8c71b31bd405c1b0c59543c', type: "submit", disabled: phase !== 'presented' }, confirming ? i18n.i18n.t('Loading') : i18n.i18n.t(this.buttonLabel))))))));
|
|
487
965
|
}
|
|
488
966
|
get el() { return index.getElement(this); }
|
|
489
967
|
static get watchers() { return {
|
|
@@ -493,6 +971,9 @@ const StripePaymentSheet = class {
|
|
|
493
971
|
"intentClientSecret": [{
|
|
494
972
|
"handleSecretChange": 0
|
|
495
973
|
}],
|
|
974
|
+
"checkoutSessionClientSecret": [{
|
|
975
|
+
"handleSecretChange": 0
|
|
976
|
+
}],
|
|
496
977
|
"stripeAccount": [{
|
|
497
978
|
"handleSecretChange": 0
|
|
498
979
|
}],
|