stripe-pwa-elements 4.0.4 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/cjs/{factory-Cm6zUD7R.js → factory-yd5HDEZn.js} +2 -1
  2. package/dist/cjs/{i18n-lBbOeQt4.js → i18n-CWEsGqxV.js} +2 -2
  3. package/dist/cjs/ion-icon_2.cjs.entry.js +1 -1
  4. package/dist/cjs/loader.cjs.js +1 -1
  5. package/dist/cjs/stripe-address-element.cjs.entry.js +2 -2
  6. package/dist/cjs/stripe-card-element.cjs.entry.js +3 -3
  7. package/dist/cjs/stripe-currency-selector.cjs.entry.js +2 -2
  8. package/dist/cjs/stripe-elements.cjs.js +1 -1
  9. package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +2 -2
  10. package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +2 -2
  11. package/dist/cjs/stripe-payment-element.cjs.entry.js +19 -8
  12. package/dist/cjs/stripe-payment-element.helpers-D1JnhTa-.js +182 -0
  13. package/dist/cjs/stripe-payment-sheet.cjs.entry.js +73 -58
  14. package/dist/collection/components/stripe-card-element/stripe-card-element.js +2 -2
  15. package/dist/collection/components/stripe-payment-element/stripe-payment-element.helpers.js +9 -32
  16. package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +88 -6
  17. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.checkout.js +60 -48
  18. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +5 -2
  19. package/dist/collection/services/stripe-service.js +1 -0
  20. package/dist/collection/utils/checkout-confirm.js +84 -0
  21. package/dist/collection/utils/i18n.js +2 -2
  22. package/dist/components/factory.js +1 -1
  23. package/dist/components/i18n.js +1 -1
  24. package/dist/components/stripe-card-element2.js +1 -1
  25. package/dist/components/stripe-payment-element.helpers.js +1 -1
  26. package/dist/components/stripe-payment-element.js +1 -1
  27. package/dist/components/stripe-payment-sheet.js +1 -1
  28. package/dist/esm/{factory-BaGv8K_i.js → factory-B_WxdnxM.js} +2 -1
  29. package/dist/esm/{i18n-CL5n3bOb.js → i18n-HWdALSvT.js} +2 -2
  30. package/dist/esm/ion-icon_2.entry.js +1 -1
  31. package/dist/esm/loader.js +1 -1
  32. package/dist/esm/stripe-address-element.entry.js +2 -2
  33. package/dist/esm/stripe-card-element.entry.js +3 -3
  34. package/dist/esm/stripe-currency-selector.entry.js +2 -2
  35. package/dist/esm/stripe-elements.js +1 -1
  36. package/dist/esm/stripe-express-checkout-element.entry.js +2 -2
  37. package/dist/esm/stripe-link-authentication-element.entry.js +2 -2
  38. package/dist/esm/stripe-payment-element.entry.js +19 -8
  39. package/dist/esm/stripe-payment-element.helpers-PuWxhMNR.js +176 -0
  40. package/dist/esm/stripe-payment-sheet.entry.js +73 -58
  41. package/dist/stripe-elements/{p-f5552c81.entry.js → p-2e2bf0fe.entry.js} +1 -1
  42. package/dist/stripe-elements/{p-3fc4583a.entry.js → p-32a2d5a4.entry.js} +1 -1
  43. package/dist/stripe-elements/{p-b62c9dae.entry.js → p-84d45b48.entry.js} +1 -1
  44. package/dist/stripe-elements/{p-CL5n3bOb.js → p-HWdALSvT.js} +1 -1
  45. package/dist/stripe-elements/{p-5d3d93ec.entry.js → p-a266da6f.entry.js} +1 -1
  46. package/dist/stripe-elements/{p-7e826964.entry.js → p-b4faa9db.entry.js} +1 -1
  47. package/dist/stripe-elements/p-c4a0e310.entry.js +1 -0
  48. package/dist/stripe-elements/{p-2e41699e.entry.js → p-e660d76a.entry.js} +1 -1
  49. package/dist/stripe-elements/p-eeebfbbf.entry.js +1 -0
  50. package/dist/stripe-elements/p-n0XJSLU3.js +1 -0
  51. package/dist/stripe-elements/p-wrjrFokg.js +1 -0
  52. package/dist/stripe-elements/stripe-elements.esm.js +1 -1
  53. package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +5 -0
  54. package/dist/types/components/stripe-payment-element/stripe-payment-element.d.ts +38 -0
  55. package/dist/types/components/stripe-payment-element/stripe-payment-element.helpers.d.ts +8 -2
  56. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.checkout.d.ts +19 -11
  57. package/dist/types/components.d.ts +36 -4
  58. package/dist/types/services/interfaces.d.ts +3 -1
  59. package/dist/types/utils/checkout-confirm.d.ts +35 -0
  60. package/package.json +1 -1
  61. package/dist/cjs/stripe-payment-element.helpers-lafmSRmb.js +0 -121
  62. package/dist/esm/stripe-payment-element.helpers-CklK5RlF.js +0 -116
  63. package/dist/stripe-elements/p-7a8f783c.entry.js +0 -1
  64. package/dist/stripe-elements/p-BoZLkOAy.js +0 -1
  65. package/dist/stripe-elements/p-DlMEZwSe.js +0 -1
  66. package/dist/stripe-elements/p-b69f6103.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-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');
4
+ var i18n = require('./i18n-CWEsGqxV.js');
5
+ var factory = require('./factory-yd5HDEZn.js');
6
+ var stripePaymentElement_helpers = require('./stripe-payment-element.helpers-D1JnhTa-.js');
8
7
  require('./index-CYbA1N_k.js');
8
+ require('./error-FFC4kSs5.js');
9
9
 
10
10
  /**
11
11
  * State machine behind `<stripe-payment-sheet>`.
@@ -236,13 +236,13 @@ const THEMES = {
236
236
  /**
237
237
  * Drop keys whose value is undefined.
238
238
  */
239
- const compact = (value) => Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
239
+ const compact$1 = (value) => Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
240
240
  /**
241
241
  * Convert a Capacitor address to the Stripe shape (`postalCode` → `postal_code`), dropping keys that are not given.
242
242
  */
243
243
  const toStripeAddress = (address) => {
244
244
  const { postalCode } = address, rest = __rest(address, ["postalCode"]);
245
- return compact(Object.assign(Object.assign({}, rest), { postal_code: postalCode }));
245
+ return compact$1(Object.assign(Object.assign({}, rest), { postal_code: postalCode }));
246
246
  };
247
247
  /**
248
248
  * Payment Element billing fields to turn off: the `never` ones (passed from `defaultBillingDetails` at confirmation)
@@ -253,7 +253,7 @@ const toBillingDetailsFields = (config) => {
253
253
  return undefined;
254
254
  }
255
255
  const { email, name, phone, address } = config;
256
- const fields = compact({
256
+ const fields = compact$1({
257
257
  email: email === 'never' || email === 'always' ? 'never' : undefined,
258
258
  name: name === 'never' ? 'never' : undefined,
259
259
  phone: phone === 'never' || (phone === 'always' && address === 'full') ? 'never' : undefined,
@@ -276,7 +276,7 @@ const toPaymentElementOptions = (options) => {
276
276
  const { merchantDisplayName, paymentMethodLayout, defaultBillingDetails, billingDetailsCollectionConfiguration, enableApplePay, enableGooglePay } = options;
277
277
  const elementOptions = {};
278
278
  const billingDetailsFields = toBillingDetailsFields(billingDetailsCollectionConfiguration);
279
- const wallets = compact({ applePay: toWalletOption(enableApplePay), googlePay: toWalletOption(enableGooglePay) });
279
+ const wallets = compact$1({ applePay: toWalletOption(enableApplePay), googlePay: toWalletOption(enableGooglePay) });
280
280
  if (billingDetailsFields != null) {
281
281
  elementOptions.fields = { billingDetails: billingDetailsFields };
282
282
  }
@@ -291,7 +291,7 @@ const toPaymentElementOptions = (options) => {
291
291
  }
292
292
  if (defaultBillingDetails != null) {
293
293
  const { address } = defaultBillingDetails, contact = __rest(defaultBillingDetails, ["address"]);
294
- const billingDetails = compact(contact);
294
+ const billingDetails = compact$1(contact);
295
295
  if (address != null) {
296
296
  billingDetails.address = toStripeAddress(address);
297
297
  }
@@ -342,7 +342,7 @@ const unsupportedOptionKeys = (options, intentKind) => {
342
342
  const toAddressDefaultValues = (details) => {
343
343
  const { name, phone, address } = details;
344
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 }) });
345
+ return compact$1({ name, phone, address: country == null || country === '' ? undefined : Object.assign(Object.assign({}, toStripeAddress(address)), { country }) });
346
346
  };
347
347
  const isBlank = (value) => value == null || value === '';
348
348
  /**
@@ -486,17 +486,66 @@ const toCheckoutPaymentElementOptions = (options) => {
486
486
  const { layout } = toPaymentElementOptions(options);
487
487
  return layout == null ? {} : { layout };
488
488
  };
489
+ /**
490
+ * Drop keys whose value is undefined.
491
+ */
492
+ const compact = (value) => Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
493
+ /**
494
+ * Build the `defaultValues` passed to `initCheckoutElementsSdk` from the payment sheet options.
495
+ * The email and phone prefill the Checkout Elements; name and address are passed as `billingAddress`,
496
+ * which Stripe only accepts with a country, so a name or address without `country` cannot be prefilled.
497
+ * @param options - Payment sheet options
498
+ */
499
+ const toCheckoutDefaultValues = (options) => {
500
+ var _a, _b;
501
+ const details = options === null || options === void 0 ? void 0 : options.defaultBillingDetails;
502
+ if (details == null) {
503
+ return undefined;
504
+ }
505
+ const values = {};
506
+ if (details.email != null && details.email !== '') {
507
+ values.email = details.email;
508
+ }
509
+ if (details.phone != null && details.phone !== '') {
510
+ values.phoneNumber = details.phone;
511
+ }
512
+ const country = (_a = details.address) === null || _a === void 0 ? void 0 : _a.country;
513
+ if (country != null && country !== '') {
514
+ const address = details.address;
515
+ const checkoutAddress = compact({
516
+ country,
517
+ line1: address === null || address === void 0 ? void 0 : address.line1,
518
+ line2: address === null || address === void 0 ? void 0 : address.line2,
519
+ city: address === null || address === void 0 ? void 0 : address.city,
520
+ postal_code: address === null || address === void 0 ? void 0 : address.postalCode,
521
+ state: address === null || address === void 0 ? void 0 : address.state,
522
+ });
523
+ const contact = { name: (_b = details.name) !== null && _b !== void 0 ? _b : null, address: checkoutAddress };
524
+ values.billingAddress = contact;
525
+ }
526
+ return Object.keys(values).length === 0 ? undefined : values;
527
+ };
489
528
  /**
490
529
  * 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`.
530
+ * Name and address are prefilled through `defaultValues`, which Stripe only accepts with a country, so they are
531
+ * listed when they cannot be used. The email is passed to `confirm` and the phone prefilled through `defaultValues`.
492
532
  * @param options - Payment sheet options
493
533
  */
494
534
  const checkoutIgnoredOptionKeys = (options) => {
535
+ var _a;
495
536
  if (options == null) {
496
537
  return [];
497
538
  }
498
539
  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}`);
540
+ const keys = [];
541
+ const country = (_a = defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails.address) === null || _a === void 0 ? void 0 : _a.country;
542
+ if (((defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails.name) != null || (defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails.address) != null) && (country == null || country === '')) {
543
+ for (const key of ['name', 'address']) {
544
+ if ((defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails[key]) != null) {
545
+ keys.push(`defaultBillingDetails.${key}`);
546
+ }
547
+ }
548
+ }
500
549
  if (merchantDisplayName != null) {
501
550
  keys.push('merchantDisplayName');
502
551
  }
@@ -514,60 +563,23 @@ const toCheckoutElementsOptions = (options) => {
514
563
  const appearance = toAppearance(options === null || options === void 0 ? void 0 : options.style);
515
564
  return appearance == null ? undefined : { appearance };
516
565
  };
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
566
  /**
535
567
  * Confirm a Checkout Session from the payment sheet.
536
568
  *
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`.
569
+ * The shared implementation (see `confirmCheckoutActions`) retries without `returnUrl` when the session was
570
+ * created with `return_url`, and passes `redirect: 'if_required'` so that payment methods without a redirect
571
+ * finish in the page and can be reported as `paymentSheetCompleted`.
539
572
  *
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
573
+ * Errors are thrown as `StripeAPIError` with a `type` that `isRecoverableConfirmError` understands:
574
+ * an expired or complete session is an `invalid_request_error` (unrecoverable), a decline is a `card_error`,
575
+ * and any other failure is an `api_error` (both recoverable).
546
576
  * @param checkout - The Checkout instance from `initCheckoutElementsSdk`
547
- * @param returnUrl - Where Stripe redirects after a redirect-based payment method
577
+ * @param returnUrl - Where Stripe redirects after a redirect-based payment method, when the session has no `return_url`
548
578
  * @param email - Customer email; needed when the session was created without `customer_email` or `customer`
549
579
  * @returns The confirmation result
550
580
  * @throws StripeAPIError when the actions cannot be loaded, the session can no longer be paid, or the confirmation fails
551
581
  */
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
- };
582
+ const confirmCheckoutSessionSheet = async (checkout, returnUrl, email) => stripePaymentElement_helpers.confirmCheckoutActions(checkout, returnUrl, email);
571
583
 
572
584
  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)}`;
573
585
 
@@ -891,6 +903,7 @@ const StripePaymentSheet = class {
891
903
  stripeAccount: this.stripeAccount,
892
904
  applicationName: this.applicationName,
893
905
  elementsOptions: toCheckoutElementsOptions(this.options),
906
+ defaultValues: toCheckoutDefaultValues(this.options),
894
907
  });
895
908
  if (generation !== this.sheet.generation) {
896
909
  return;
@@ -912,6 +925,8 @@ const StripePaymentSheet = class {
912
925
  }
913
926
  confirmCheckoutSession(generation) {
914
927
  var _a, _b;
928
+ // returnUrl defaults to the current page; confirmCheckoutSessionSheet retries without it when the
929
+ // session was created with `return_url` (which rejects the argument before processing)
915
930
  const returnUrl = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.returnURL) !== null && _b !== void 0 ? _b : window.location.href;
916
931
  return this.runConfirm(generation, async () => {
917
932
  var _a, _b;
@@ -961,7 +976,7 @@ const StripePaymentSheet = class {
961
976
  var _a, _b, _c;
962
977
  const { phase } = this.sheet;
963
978
  const confirming = phase === 'confirming';
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))))))));
979
+ return (index.h(index.Host, { key: '52591afbd5af5ceb2530a37248e3bb1f410f880c' }, index.h("stripe-modal", { key: '607c26d28f381b5017f9714fca398c2f5eb9c066', open: this.visible, showCloseButton: !confirming, onClose: this.handleModalClose }, index.h("div", { key: '44cfb1929b178257878d5a42d8441b2f7f823436', class: "stripe-payment-sheet-wrap" }, index.h("form", { key: '20be8d4cb150883936241639c299a86d081c1903', id: "stripe-payment-sheet", onSubmit: this.handleSubmit }, index.h("div", { key: '14e5c98793de6d2ebb1a1cc755e501b427915d9f', class: "stripe-heading" }, i18n.i18n.t(this.sheetTitle)), index.h("div", { key: '235ac34c0c2260793756960caa75ef9f62e401fd', class: "payment-info visible" }, index.h("div", { key: '10ed4c9be02a08429b8bfd028f40be409613250b', class: "stripe-payment-sheet-email" }, ((_a = this.collection) === null || _a === void 0 ? void 0 : _a.emailElement) != null && index.h("div", { key: '5a21882fc11b839287bd499f9441b7a37b2f7e4d', id: "link-authentication-element" })), index.h("div", { key: 'd88e637fcecc62bba18fc25cdf674a03624ceb8a', class: "stripe-payment-sheet-shipping-address" }, ((_b = this.collection) === null || _b === void 0 ? void 0 : _b.shippingAddressElement) != null && index.h("div", { key: '934f6b59ce787c6452191f1df14b1848f847db4a', id: "address-element" })), index.h("div", { key: '1fe9f0371e0669c6b5485b19672ee02169312674', class: "stripe-payment-sheet-billing-address" }, ((_c = this.collection) === null || _c === void 0 ? void 0 : _c.billingAddressElement) != null && index.h("div", { key: 'fb548084588b34ffcd8534cc2b0a402e1af60d76', id: "address-element" })), index.h("div", { key: '8dec277132c63cc11c49962f136b67685e810ccb', id: "payment-element" })), index.h("div", { key: 'e0f20ba527fb9b941cc8d70d7631a03dcfc2c370', class: "stripe-element-errors", role: "alert" }, this.errorMessage), index.h("div", { key: 'db7357b49c141ff9272f1b4690f933ea54d9bfb3', class: "stripe-submit" }, index.h("button", { key: '9112ed21047df0b2fdfa5f8d6b7872f878062dc1', type: "submit", disabled: phase !== 'presented' }, confirming ? i18n.i18n.t('Loading') : i18n.i18n.t(this.buttonLabel))))))));
965
980
  }
966
981
  get el() { return index.getElement(this); }
967
982
  static get watchers() { return {
@@ -364,7 +364,7 @@ export class StripeCardElement {
364
364
  // NOTE: `stripe-payment-sheet-wrap` is a legacy class name (leftover from a former
365
365
  // component name). External consumers may target it in their own CSS, so it is a
366
366
  // public DOM contract that MUST be kept for backward compatibility. Do not remove it.
367
- h("div", { class: "stripe-payment-sheet-wrap" }, h("form", { id: "stripe-card-element" }, h("div", { class: "stripe-heading" }, i18n.t(this.sheetTitle)), h("div", { id: "stripe-payment-request-button" }), h("div", null, h("div", { class: "stripe-section-title" }, i18n.t('Card information'))), h("div", { class: "payment-info card visible" }, h("fieldset", { class: "stripe-input-box" }, h("div", null, h("label", null, this.showLabel ? h("lenged", null, i18n.t('Card Number')) : null, h("div", { id: "card-number" }))), h("div", { class: "stripe-input-column", style: { display: 'flex' } }, h("label", { style: { width: '50%' } }, this.showLabel ? h("lenged", null, i18n.t('MM / YY')) : null, h("div", { id: "card-expiry" })), h("label", { style: { width: '50%' } }, this.showLabel ? h("lenged", null, i18n.t('CVC')) : null, h("div", { id: "card-cvc" }))))), h("div", { id: "card-errors", class: "stripe-element-errors" }, errorMessage), this.zip ? (h("div", { style: { marginTop: '1.5rem' } }, h("div", { class: "stripe-section-title" }, i18n.t('Country or region')))) : null, this.zip ? (h("div", { class: "payment-info card visible" }, h("fieldset", { class: "stripe-input-box" }, h("div", null, h("label", null, this.showLabel ? h("lenged", null, i18n.t('Postal Code')) : null, h("input", { id: "zip", name: "zip", type: "text", inputmode: "numeric", class: "StripeElement", style: { width: '100%' }, placeholder: i18n.t('Postal Code'), value: this.zipCode, onInput: e => {
367
+ h("div", { class: "stripe-payment-sheet-wrap" }, h("form", { id: "stripe-card-element" }, h("div", { class: "stripe-heading" }, i18n.t(this.sheetTitle)), h("div", { id: "stripe-payment-request-button" }), h("div", null, h("div", { class: "stripe-section-title" }, i18n.t('Card information'))), h("div", { class: "payment-info card visible" }, h("fieldset", { class: "stripe-input-box" }, h("div", null, h("label", null, this.showLabel ? h("lenged", null, i18n.t('Card Number')) : null, h("div", { id: "card-number" }))), h("div", { class: "stripe-input-column", style: { display: 'flex' } }, h("label", { style: { width: '50%' } }, this.showLabel ? h("lenged", null, i18n.t('MM / YY')) : null, h("div", { id: "card-expiry" })), h("label", { style: { width: '50%' } }, this.showLabel ? h("lenged", null, i18n.t('CVC')) : null, h("div", { id: "card-cvc" }))))), h("div", { id: "card-errors", class: "stripe-element-errors" }, errorMessage), this.zip ? (h("div", { style: { marginTop: '1.5rem' } }, h("div", { class: "stripe-section-title" }, i18n.t('Postal Code')))) : null, this.zip ? (h("div", { class: "payment-info card visible" }, h("fieldset", { class: "stripe-input-box" }, h("div", null, h("label", null, this.showLabel ? h("lenged", null, i18n.t('Postal Code')) : null, h("input", { id: "zip", name: "zip", type: "text", inputmode: "numeric", class: "StripeElement", style: { width: '100%' }, placeholder: i18n.t('Postal Code'), value: this.zipCode, onInput: e => {
368
368
  this.zipCode = e.target.value;
369
369
  } })))))) : null, h("div", { style: { marginTop: '32px' } }, h("button", { type: "submit", disabled: disabled }, this.progress === 'loading' ? i18n.t('Loading') : i18n.t(this.buttonLabel))))));
370
370
  }
@@ -707,7 +707,7 @@ export class StripeCardElement {
707
707
  "name": "example",
708
708
  "text": "```\nconst stripeElement = document.createElement('stripe-card-element');\ncustomElements\n .whenDefined('stripe-card-element')\n .then(() => {\n stripeElement\n .addEventListener('formSubmit', async props => {\n const {\n detail: { stripe, cardNumber, event },\n } = props;\n const result = await stripe.createPaymentMethod({\n type: 'card',\n card: cardNumber,\n });\n console.log(result);\n })\n })\n```"
709
709
  }],
710
- "text": "Form submit event"
710
+ "text": "Form submit event\n\nNote: this event fires after the submit handling completes, not when the form is\nsubmitted. With the default submit action it is emitted only after the payment\nsucceeds; a declined payment shows an error inside the form and this event does\nnot fire. Listen to `defaultFormSubmitResult` for the outcome of the default action."
711
711
  },
712
712
  "complexType": {
713
713
  "original": "FormSubmitEvent",
@@ -1,3 +1,4 @@
1
+ import { confirmCheckoutActions } from "../../utils/checkout-confirm";
1
2
  import { StripeAPIError } from "../../utils/error";
2
3
  /**
3
4
  * Determine whether the submit button should be disabled.
@@ -46,42 +47,18 @@ export const confirmPaymentOrSetup = async (stripe, elements, intentType, return
46
47
  };
47
48
  /**
48
49
  * Confirm a Checkout Session payment using the checkout actions.
50
+ *
51
+ * Stripe requires exactly one of `returnUrl` (confirm argument) or the session's `return_url`, and the client
52
+ * cannot tell which one a session has (`getSession()` does not expose it). The shared implementation passes
53
+ * `returnUrl` first and retries without it when Stripe rejects it because the session already has
54
+ * `return_url`. See `confirmCheckoutActions` for the full behavior and error classification.
49
55
  * @param checkout the Stripe Checkout instance
50
- * @param returnUrl the URL Stripe should redirect back to when required
56
+ * @param returnUrl URL Stripe should redirect back to when the session has no `return_url`
57
+ * @param email customer email, required when the session was created without `customer_email` or `customer`
51
58
  * @returns the confirmation result
52
59
  * @throws StripeAPIError when loading actions or confirming fails
53
60
  */
54
- export const confirmCheckoutSession = async (checkout, returnUrl) => {
55
- var _a;
56
- // Load actions from the checkout session
57
- const loadActionsResult = await checkout.loadActions();
58
- if (loadActionsResult.type === 'error') {
59
- // Create a StripeError-compatible object from the Checkout Session error
60
- const stripeError = {
61
- type: 'api_error',
62
- code: loadActionsResult.error.code || 'checkout_session_error',
63
- message: loadActionsResult.error.message,
64
- };
65
- throw new StripeAPIError(stripeError);
66
- }
67
- const { actions } = loadActionsResult;
68
- // Confirm the payment using checkout session actions
69
- const result = await actions.confirm({
70
- returnUrl,
71
- redirect: 'if_required',
72
- });
73
- if (result.type === 'error') {
74
- // Create a StripeError-compatible object from the confirm error
75
- const stripeError = {
76
- type: 'card_error',
77
- code: result.error.code || 'payment_failed',
78
- message: result.error.message,
79
- decline_code: result.error.code === 'paymentFailed' ? (_a = result.error.paymentFailed) === null || _a === void 0 ? void 0 : _a.declineCode : undefined,
80
- };
81
- throw new StripeAPIError(stripeError);
82
- }
83
- return result;
84
- };
61
+ export const confirmCheckoutSession = async (checkout, returnUrl, email) => confirmCheckoutActions(checkout, returnUrl, email);
85
62
  /**
86
63
  * Resolve the mode-specific properties for a submit event.
87
64
  * Picks the Checkout or Elements payload depending on the active mode and
@@ -53,6 +53,7 @@ export class StripePaymentElement {
53
53
  stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
54
54
  applicationName: this.applicationName,
55
55
  elementsOptions: options === null || options === void 0 ? void 0 : options.elementsOptions,
56
+ defaultValues: options === null || options === void 0 ? void 0 : options.defaultValues,
56
57
  });
57
58
  await this.mountWhenLoaded(generation);
58
59
  }
@@ -97,14 +98,20 @@ export class StripePaymentElement {
97
98
  options.stripeAccount = this.stripeService.state.stripeAccount;
98
99
  const hasOptionValue = Object.values(options).filter(value => value != null && value !== '').length > 0;
99
100
  if (this.hasCheckoutSessionClientSecret()) {
100
- this.initStripeWithCheckoutSession(publishableKey, this.checkoutSessionClientSecret, { stripeAccount: options.stripeAccount });
101
+ this.initStripeWithCheckoutSession(publishableKey, this.checkoutSessionClientSecret, {
102
+ stripeAccount: options.stripeAccount,
103
+ defaultValues: this.checkoutSessionDefaultValues,
104
+ });
101
105
  return;
102
106
  }
103
107
  this.initStripe(publishableKey, hasOptionValue ? options : undefined);
104
108
  }
105
109
  updateStripeAccountId(stripeAccount) {
106
110
  if (this.hasCheckoutSessionClientSecret()) {
107
- this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey, this.checkoutSessionClientSecret, { stripeAccount });
111
+ this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey, this.checkoutSessionClientSecret, {
112
+ stripeAccount: stripeAccount,
113
+ defaultValues: this.checkoutSessionDefaultValues,
114
+ });
108
115
  return;
109
116
  }
110
117
  this.initStripe(this.stripeService.state.publishableKey, {
@@ -132,6 +139,7 @@ export class StripePaymentElement {
132
139
  if (this.publishableKey != null && this.publishableKey !== '' && newValue != null && newValue !== '') {
133
140
  await this.initStripeWithCheckoutSession(this.publishableKey, newValue, {
134
141
  stripeAccount: this.stripeAccount,
142
+ defaultValues: this.checkoutSessionDefaultValues,
135
143
  });
136
144
  // A new secret starts a fresh payment, so re-enable the submit button after a previous success
137
145
  if (this.progress === 'success') {
@@ -187,6 +195,7 @@ export class StripePaymentElement {
187
195
  if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
188
196
  this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey, this.checkoutSessionClientSecret, {
189
197
  stripeAccount: this.stripeService.state.stripeAccount,
198
+ defaultValues: this.checkoutSessionDefaultValues,
190
199
  });
191
200
  return;
192
201
  }
@@ -222,11 +231,12 @@ export class StripePaymentElement {
222
231
  * @param checkout - The Stripe Checkout instance
223
232
  */
224
233
  async checkoutSessionFormSubmitAction(event, checkout) {
234
+ var _a;
225
235
  event.preventDefault();
226
236
  try {
227
- // Get current page URL for return_url
228
- const returnUrl = window.location.href;
229
- const result = await confirmCheckoutSession(checkout, returnUrl);
237
+ // returnUrl defaults to the current page; confirmCheckoutSession retries without it when the
238
+ // session was created with `return_url` (which rejects the argument before processing)
239
+ const result = await confirmCheckoutSession(checkout, (_a = this.checkoutSessionReturnUrl) !== null && _a !== void 0 ? _a : window.location.href, this.checkoutSessionEmail);
230
240
  this.checkoutSessionConfirmResultHandler(result);
231
241
  }
232
242
  catch (e) {
@@ -338,6 +348,7 @@ export class StripePaymentElement {
338
348
  if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
339
349
  this.initStripeWithCheckoutSession(this.publishableKey, this.checkoutSessionClientSecret, {
340
350
  stripeAccount: this.stripeAccount,
351
+ defaultValues: this.checkoutSessionDefaultValues,
341
352
  });
342
353
  return;
343
354
  }
@@ -657,6 +668,77 @@ export class StripePaymentElement {
657
668
  "attribute": "should-use-default-form-submit-action",
658
669
  "defaultValue": "true"
659
670
  },
671
+ "checkoutSessionReturnUrl": {
672
+ "type": "string",
673
+ "mutable": false,
674
+ "complexType": {
675
+ "original": "string",
676
+ "resolved": "string",
677
+ "references": {}
678
+ },
679
+ "required": false,
680
+ "optional": true,
681
+ "docs": {
682
+ "tags": [{
683
+ "name": "example",
684
+ "text": "```\n<stripe-payment-element checkout-session-client-secret=\"cs_xxx_secret_xxx\" checkout-session-return-url=\"https://example.com/return\" />\n```"
685
+ }],
686
+ "text": "URL Stripe redirects to after a redirect-based payment method (Checkout Session mode only).\nUsed when the Checkout Session was created WITHOUT `return_url`. Defaults to the current page URL.\nA session created with `return_url` ignores this value: Stripe redirects there automatically."
687
+ },
688
+ "getter": false,
689
+ "setter": false,
690
+ "reflect": false,
691
+ "attribute": "checkout-session-return-url"
692
+ },
693
+ "checkoutSessionEmail": {
694
+ "type": "string",
695
+ "mutable": false,
696
+ "complexType": {
697
+ "original": "string",
698
+ "resolved": "string",
699
+ "references": {}
700
+ },
701
+ "required": false,
702
+ "optional": true,
703
+ "docs": {
704
+ "tags": [{
705
+ "name": "example",
706
+ "text": "```\n<stripe-payment-element checkout-session-client-secret=\"cs_xxx_secret_xxx\" checkout-session-email=\"customer@example.com\" />\n```"
707
+ }],
708
+ "text": "Customer email passed to `confirm()` (Checkout Session mode only).\nRequired when the Checkout Session was created without `customer_email` or `customer`,\nbecause confirming such a session fails with \"An email address is required\"."
709
+ },
710
+ "getter": false,
711
+ "setter": false,
712
+ "reflect": false,
713
+ "attribute": "checkout-session-email"
714
+ },
715
+ "checkoutSessionDefaultValues": {
716
+ "type": "unknown",
717
+ "mutable": false,
718
+ "complexType": {
719
+ "original": "CheckoutSessionOptions['defaultValues']",
720
+ "resolved": "{ billingAddress?: StripeCheckoutContact; shippingAddress?: StripeCheckoutContact; email?: string; phoneNumber?: string; }",
721
+ "references": {
722
+ "CheckoutSessionOptions": {
723
+ "location": "import",
724
+ "path": "../../services/interfaces",
725
+ "id": "src/services/interfaces.ts::CheckoutSessionOptions",
726
+ "referenceLocation": "CheckoutSessionOptions"
727
+ }
728
+ }
729
+ },
730
+ "required": false,
731
+ "optional": true,
732
+ "docs": {
733
+ "tags": [{
734
+ "name": "example",
735
+ "text": "```\nconst stripeElement = document.createElement('stripe-payment-element');\ncustomElements.whenDefined('stripe-payment-element').then(() => {\n stripeElement.checkoutSessionDefaultValues = { email: 'customer@example.com' };\n});\n```"
736
+ }],
737
+ "text": "Prefilled values of the Checkout Elements (Checkout Session mode only): `email`, `phoneNumber`,\n`billingAddress` and `shippingAddress` as supported by `initCheckoutElementsSdk`.\nJavaScript property only: it cannot be set through an HTML attribute."
738
+ },
739
+ "getter": false,
740
+ "setter": false
741
+ },
660
742
  "handleSubmit": {
661
743
  "type": "unknown",
662
744
  "mutable": true,
@@ -748,7 +830,7 @@ export class StripePaymentElement {
748
830
  "name": "example",
749
831
  "text": "```\nconst stripeElement = document.createElement('stripe-payment-element');\ncustomElements\n .whenDefined('stripe-payment-element')\n .then(() => {\n stripeElement\n .addEventListener('formSubmit', async props => {\n const { detail: { stripe, elements } } = props;\n console.log('Form submitted', stripe, elements);\n })\n })\n```"
750
832
  }],
751
- "text": "Form submit event"
833
+ "text": "Form submit event\n\nNote: this event fires after the submit handling completes, not when the form is\nsubmitted. With the default submit action it is emitted only after the payment\nsucceeds; a declined payment shows an error inside the form and this event does\nnot fire. Listen to `defaultFormSubmitResult` for the outcome of the default action."
752
834
  },
753
835
  "complexType": {
754
836
  "original": "PaymentElementSubmitEvent",
@@ -1,4 +1,4 @@
1
- import { StripeAPIError } from "../../utils/error";
1
+ import { confirmCheckoutActions } from "../../utils/checkout-confirm";
2
2
  import { toAppearance, toPaymentElementOptions } from "./stripe-payment-sheet.helpers";
3
3
  /**
4
4
  * Build the Checkout Payment Element options from the payment sheet options.
@@ -10,17 +10,66 @@ export const toCheckoutPaymentElementOptions = (options) => {
10
10
  const { layout } = toPaymentElementOptions(options);
11
11
  return layout == null ? {} : { layout };
12
12
  };
13
+ /**
14
+ * Drop keys whose value is undefined.
15
+ */
16
+ const compact = (value) => Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
17
+ /**
18
+ * Build the `defaultValues` passed to `initCheckoutElementsSdk` from the payment sheet options.
19
+ * The email and phone prefill the Checkout Elements; name and address are passed as `billingAddress`,
20
+ * which Stripe only accepts with a country, so a name or address without `country` cannot be prefilled.
21
+ * @param options - Payment sheet options
22
+ */
23
+ export const toCheckoutDefaultValues = (options) => {
24
+ var _a, _b;
25
+ const details = options === null || options === void 0 ? void 0 : options.defaultBillingDetails;
26
+ if (details == null) {
27
+ return undefined;
28
+ }
29
+ const values = {};
30
+ if (details.email != null && details.email !== '') {
31
+ values.email = details.email;
32
+ }
33
+ if (details.phone != null && details.phone !== '') {
34
+ values.phoneNumber = details.phone;
35
+ }
36
+ const country = (_a = details.address) === null || _a === void 0 ? void 0 : _a.country;
37
+ if (country != null && country !== '') {
38
+ const address = details.address;
39
+ const checkoutAddress = compact({
40
+ country,
41
+ line1: address === null || address === void 0 ? void 0 : address.line1,
42
+ line2: address === null || address === void 0 ? void 0 : address.line2,
43
+ city: address === null || address === void 0 ? void 0 : address.city,
44
+ postal_code: address === null || address === void 0 ? void 0 : address.postalCode,
45
+ state: address === null || address === void 0 ? void 0 : address.state,
46
+ });
47
+ const contact = { name: (_b = details.name) !== null && _b !== void 0 ? _b : null, address: checkoutAddress };
48
+ values.billingAddress = contact;
49
+ }
50
+ return Object.keys(values).length === 0 ? undefined : values;
51
+ };
13
52
  /**
14
53
  * List the given options that a Checkout Session does not use, sorted by name.
15
- * Name, phone and address come from the session or from other Checkout elements; the email is passed to `confirm`.
54
+ * Name and address are prefilled through `defaultValues`, which Stripe only accepts with a country, so they are
55
+ * listed when they cannot be used. The email is passed to `confirm` and the phone prefilled through `defaultValues`.
16
56
  * @param options - Payment sheet options
17
57
  */
18
58
  export const checkoutIgnoredOptionKeys = (options) => {
59
+ var _a;
19
60
  if (options == null) {
20
61
  return [];
21
62
  }
22
63
  const { merchantDisplayName, defaultBillingDetails } = options;
23
- const keys = ['name', 'phone', 'address'].filter(key => (defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails[key]) != null).map(key => `defaultBillingDetails.${key}`);
64
+ const keys = [];
65
+ const country = (_a = defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails.address) === null || _a === void 0 ? void 0 : _a.country;
66
+ if (((defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails.name) != null || (defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails.address) != null) && (country == null || country === '')) {
67
+ for (const key of ['name', 'address']) {
68
+ if ((defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails[key]) != null) {
69
+ keys.push(`defaultBillingDetails.${key}`);
70
+ }
71
+ }
72
+ }
24
73
  if (merchantDisplayName != null) {
25
74
  keys.push('merchantDisplayName');
26
75
  }
@@ -38,57 +87,20 @@ export const toCheckoutElementsOptions = (options) => {
38
87
  const appearance = toAppearance(options === null || options === void 0 ? void 0 : options.style);
39
88
  return appearance == null ? undefined : { appearance };
40
89
  };
41
- /**
42
- * Throw when the session can no longer be paid. Stripe documents an `expired` session as "No further processing will occur",
43
- * and a `complete` one is already paid or being paid, so confirming again cannot succeed.
44
- * @param status - `session.status` from `getSession()`; undefined when it cannot be read
45
- * @param message - Message of the confirm error, if any
46
- * @throws StripeAPIError of type `invalid_request_error` (unrecoverable), with the code `checkout_session_expired` or `checkout_session_complete`
47
- */
48
- const assertSessionOpen = (status, message) => {
49
- if (status == null || status.type === 'open') {
50
- return;
51
- }
52
- throw new StripeAPIError({
53
- type: 'invalid_request_error',
54
- code: `checkout_session_${status.type}`,
55
- message: message !== null && message !== void 0 ? message : `The Checkout Session is ${status.type} and can no longer be paid.`,
56
- });
57
- };
58
90
  /**
59
91
  * Confirm a Checkout Session from the payment sheet.
60
92
  *
61
- * Unlike the default of `confirm`, which always redirects to `returnUrl`, this passes `redirect: 'if_required'`
62
- * so that payment methods without a redirect finish in the page and can be reported as `paymentSheetCompleted`.
93
+ * The shared implementation (see `confirmCheckoutActions`) retries without `returnUrl` when the session was
94
+ * created with `return_url`, and passes `redirect: 'if_required'` so that payment methods without a redirect
95
+ * finish in the page and can be reported as `paymentSheetCompleted`.
63
96
  *
64
- * Errors are thrown as `StripeAPIError` with a `type` that `isRecoverableConfirmError` understands.
65
- * A confirm error only carries `code: 'paymentFailed'` or `code: null` (`StripeCheckoutConfirmResult` in @stripe/stripe-js),
66
- * so whether the session can still be paid is read from `session.status`:
67
- * - session `expired` or `complete` (before confirming or after a failed confirm): `invalid_request_error`, which ends the sheet
68
- * - `paymentFailed` on an open session (a decline): `card_error`, which keeps the sheet open
69
- * - any other confirm error on an open session, or a failure to load the actions: `api_error`, which keeps the sheet open
97
+ * Errors are thrown as `StripeAPIError` with a `type` that `isRecoverableConfirmError` understands:
98
+ * an expired or complete session is an `invalid_request_error` (unrecoverable), a decline is a `card_error`,
99
+ * and any other failure is an `api_error` (both recoverable).
70
100
  * @param checkout - The Checkout instance from `initCheckoutElementsSdk`
71
- * @param returnUrl - Where Stripe redirects after a redirect-based payment method
101
+ * @param returnUrl - Where Stripe redirects after a redirect-based payment method, when the session has no `return_url`
72
102
  * @param email - Customer email; needed when the session was created without `customer_email` or `customer`
73
103
  * @returns The confirmation result
74
104
  * @throws StripeAPIError when the actions cannot be loaded, the session can no longer be paid, or the confirmation fails
75
105
  */
76
- export const confirmCheckoutSessionSheet = async (checkout, returnUrl, email) => {
77
- const loadActionsResult = await checkout.loadActions();
78
- if (loadActionsResult.type === 'error') {
79
- throw new StripeAPIError({ type: 'api_error', code: 'checkout_session_error', message: loadActionsResult.error.message });
80
- }
81
- const { actions } = loadActionsResult;
82
- 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; };
83
- assertSessionOpen(sessionStatus());
84
- const result = await actions.confirm(Object.assign({ returnUrl, redirect: 'if_required' }, (email != null && email !== '' ? { email } : {})));
85
- if (result.type === 'error') {
86
- const { code, message } = result.error;
87
- assertSessionOpen(sessionStatus(), message);
88
- if (code === 'paymentFailed') {
89
- throw new StripeAPIError({ type: 'card_error', code, message });
90
- }
91
- throw new StripeAPIError({ type: 'api_error', code: 'checkout_session_error', message });
92
- }
93
- return result;
94
- };
106
+ export const confirmCheckoutSessionSheet = async (checkout, returnUrl, email) => confirmCheckoutActions(checkout, returnUrl, email);