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.
Files changed (72) hide show
  1. package/dist/cjs/{factory-tenFFIul.js → factory-Cm6zUD7R.js} +7 -1
  2. package/dist/cjs/{i18n-FhEOc8vz.js → i18n-lBbOeQt4.js} +6 -0
  3. package/dist/cjs/ion-icon_2.cjs.entry.js +5 -3
  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 +13 -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 +11 -3
  12. package/dist/cjs/{stripe-payment-element.helpers-DukP33RI.js → stripe-payment-element.helpers-lafmSRmb.js} +7 -8
  13. package/dist/cjs/stripe-payment-sheet.cjs.entry.js +516 -35
  14. package/dist/collection/components/stripe-address-element/stripe-address-element.js +2 -2
  15. package/dist/collection/components/stripe-card-element/stripe-card-element.js +11 -1
  16. package/dist/collection/components/stripe-modal/stripe-modal.css +4 -0
  17. package/dist/collection/components/stripe-modal/stripe-modal.js +3 -1
  18. package/dist/collection/components/stripe-payment-element/stripe-payment-element.helpers.js +7 -8
  19. package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +12 -4
  20. package/dist/collection/components/stripe-payment-sheet/payment-sheet-state.js +21 -7
  21. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.checkout.js +94 -0
  22. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.helpers.js +193 -9
  23. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +240 -21
  24. package/dist/collection/services/link-authentication-element-manager.js +5 -0
  25. package/dist/collection/utils/i18n.js +6 -0
  26. package/dist/components/factory.js +1 -1
  27. package/dist/components/i18n.js +1 -1
  28. package/dist/components/stripe-card-element2.js +1 -1
  29. package/dist/components/stripe-modal2.js +1 -1
  30. package/dist/components/stripe-payment-element.helpers.js +1 -1
  31. package/dist/components/stripe-payment-element.js +1 -1
  32. package/dist/components/stripe-payment-sheet.js +1 -1
  33. package/dist/esm/{factory-Cd6OGTWN.js → factory-BaGv8K_i.js} +7 -2
  34. package/dist/esm/{i18n-B6JoQetF.js → i18n-CL5n3bOb.js} +6 -0
  35. package/dist/esm/ion-icon_2.entry.js +5 -3
  36. package/dist/esm/loader.js +1 -1
  37. package/dist/esm/stripe-address-element.entry.js +2 -2
  38. package/dist/esm/stripe-card-element.entry.js +13 -3
  39. package/dist/esm/stripe-currency-selector.entry.js +2 -2
  40. package/dist/esm/stripe-elements.js +1 -1
  41. package/dist/esm/stripe-express-checkout-element.entry.js +2 -2
  42. package/dist/esm/stripe-link-authentication-element.entry.js +2 -2
  43. package/dist/esm/stripe-payment-element.entry.js +11 -3
  44. package/dist/esm/{stripe-payment-element.helpers-CipV87b8.js → stripe-payment-element.helpers-CklK5RlF.js} +7 -8
  45. package/dist/esm/stripe-payment-sheet.entry.js +516 -35
  46. package/dist/stripe-elements/{p-f892e375.entry.js → p-2e41699e.entry.js} +1 -1
  47. package/dist/stripe-elements/{p-6a9c8b7a.entry.js → p-3fc4583a.entry.js} +1 -1
  48. package/dist/stripe-elements/p-5d3d93ec.entry.js +1 -0
  49. package/dist/stripe-elements/p-7a8f783c.entry.js +1 -0
  50. package/dist/stripe-elements/{p-915b86ed.entry.js → p-7e826964.entry.js} +1 -1
  51. package/dist/stripe-elements/p-BoZLkOAy.js +1 -0
  52. package/dist/stripe-elements/p-CL5n3bOb.js +1 -0
  53. package/dist/stripe-elements/{p-C7MQk9FK.js → p-DlMEZwSe.js} +1 -1
  54. package/dist/stripe-elements/{p-5338bc5e.entry.js → p-b62c9dae.entry.js} +1 -1
  55. package/dist/stripe-elements/p-b69f6103.entry.js +1 -0
  56. package/dist/stripe-elements/{p-7fe4a287.entry.js → p-f5552c81.entry.js} +1 -1
  57. package/dist/stripe-elements/stripe-elements.esm.js +1 -1
  58. package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +1 -0
  59. package/dist/types/components/stripe-payment-element/stripe-payment-element.helpers.d.ts +9 -2
  60. package/dist/types/components/stripe-payment-sheet/payment-sheet-state.d.ts +21 -4
  61. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.checkout.d.ts +39 -0
  62. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.d.ts +50 -5
  63. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.helpers.d.ts +66 -8
  64. package/dist/types/components.d.ts +22 -9
  65. package/dist/types/services/interfaces.d.ts +2 -0
  66. package/package.json +4 -2
  67. package/readme.md +78 -27
  68. package/dist/stripe-elements/p-B6JoQetF.js +0 -1
  69. package/dist/stripe-elements/p-DFAhQS0n.js +0 -1
  70. package/dist/stripe-elements/p-b06a254f.entry.js +0 -1
  71. package/dist/stripe-elements/p-b91c4fa7.entry.js +0 -1
  72. package/dist/stripe-elements/p-e7372ca7.entry.js +0 -1
@@ -483,7 +483,7 @@ export class StripeAddressElement {
483
483
  "references": {
484
484
  "AddressSubmitHandler": {
485
485
  "location": "local",
486
- "path": "/Users/okamotohidetaka/development/oss/stripe-pwa-elements/src/components/stripe-address-element/stripe-address-element.tsx",
486
+ "path": "/home/circleci/project/src/components/stripe-address-element/stripe-address-element.tsx",
487
487
  "id": "src/components/stripe-address-element/stripe-address-element.tsx::AddressSubmitHandler"
488
488
  }
489
489
  }
@@ -573,7 +573,7 @@ export class StripeAddressElement {
573
573
  "references": {
574
574
  "AddressSubmitEvent": {
575
575
  "location": "local",
576
- "path": "/Users/okamotohidetaka/development/oss/stripe-pwa-elements/src/components/stripe-address-element/stripe-address-element.tsx",
576
+ "path": "/home/circleci/project/src/components/stripe-address-element/stripe-address-element.tsx",
577
577
  "id": "src/components/stripe-address-element/stripe-address-element.tsx::AddressSubmitEvent"
578
578
  }
579
579
  }
@@ -113,6 +113,12 @@ export class StripeCardElement {
113
113
  stripeAccount,
114
114
  });
115
115
  }
116
+ updateIntentClientSecret() {
117
+ // Card Elements are not bound to the client secret, so a new secret starts a fresh payment
118
+ if (this.progress === 'success') {
119
+ this.progress = '';
120
+ }
121
+ }
116
122
  /**
117
123
  * @param option
118
124
  * @private
@@ -352,7 +358,8 @@ export class StripeCardElement {
352
358
  if (loadStripeStatus === 'failure') {
353
359
  return h("p", null, i18n.t('Failed to load Stripe'));
354
360
  }
355
- const disabled = this.progress === 'loading';
361
+ // A succeeded intent cannot be confirmed again, so the form must not accept a second submit
362
+ const disabled = this.progress === 'loading' || this.progress === 'success';
356
363
  return (
357
364
  // NOTE: `stripe-payment-sheet-wrap` is a legacy class name (leftover from a former
358
365
  // component name). External consumers may target it in their own CSS, so it is a
@@ -892,6 +899,9 @@ export class StripeCardElement {
892
899
  }, {
893
900
  "propName": "stripeAccount",
894
901
  "methodName": "updateStripeAccountId"
902
+ }, {
903
+ "propName": "intentClientSecret",
904
+ "methodName": "updateIntentClientSecret"
895
905
  }];
896
906
  }
897
907
  }
@@ -87,6 +87,10 @@
87
87
  padding: 16px 8px 24px;
88
88
  background-color: #fff;
89
89
  width: 100%;
90
+ max-height: 100vh;
91
+ max-height: 100dvh;
92
+ overflow-y: auto;
93
+ overscroll-behavior: contain;
90
94
  }
91
95
 
92
96
  .modal-close-button-wrap {
@@ -186,6 +186,8 @@ export class StripeModal {
186
186
  return;
187
187
  }
188
188
  const modalChild = this.el.shadowRoot.querySelector('.modal-child');
189
+ // The panel stays in the DOM while closed and keeps its scroll position; start each opening at the top (title, close button)
190
+ modalChild.scrollTop = 0;
189
191
  modalChild.classList.add('loading');
190
192
  modalChild.style.willChange = 'transform';
191
193
  modalChild.addEventListener('transitionend', () => {
@@ -200,7 +202,7 @@ export class StripeModal {
200
202
  render() {
201
203
  const { renderedOpen, showCloseButton } = this;
202
204
  const guardTabIndex = renderedOpen ? 0 : -1;
203
- return (h(Host, { key: '684539aa83388bec518e73bbd8aa19e73cfde07d', role: renderedOpen ? 'dialog' : undefined, "aria-modal": renderedOpen ? 'true' : undefined, onKeyDown: this.handleKeyDown, onFocusin: this.handleFocusIn }, h("div", { key: 'db6f1088c1ef7e35aefba06faaf3e9c2dcaa3419', class: `modal-row${renderedOpen ? ' open' : ''}`, onClick: () => this.closeModal() }, h("div", { key: '89c783c793261566b77ba962da730a973e8cbd8d', class: "modal-child", tabindex: "-1", ref: el => (this.dialogElement = el), onClick: e => e.stopPropagation() }, h("div", { key: '0e329b32c25509134f5a25adb266b03dd0bd71d8', class: "focus-guard", tabindex: guardTabIndex, onFocus: this.handleStartGuardFocus }), showCloseButton ? (h("div", { class: "modal-close-button-wrap" }, h("button", { type: "button", class: "modal-close-button", "aria-label": i18n.t('Close'), ref: el => (this.closeButtonElement = el), onClick: () => this.closeModal() }, h("ion-icon", { name: "close", size: "large", "aria-hidden": "true" })))) : null, h("div", { key: 'f2b5dcbc72ba3178dd920ceecd4fd339f69598d7', class: "modal-loading" }, h("svg", { key: '1f7afb6cc48be8fc84f9b69678f2c8ca1e2b145e', version: "1.1", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 2400 2400" }, h("g", { key: 'ed40edfeabe02bf198b194eb04777e1f4a6b203e', "stroke-width": "200", "stroke-linecap": "round", stroke: "currentColor", fill: "none", id: "spinner" }, h("line", { key: '03c9170ee9e566227fddcc9037a92c48ed954b89', x1: "1200", y1: "600", x2: "1200", y2: "100" }), h("line", { key: '302aec0abf20ee8afe66245ecbc9d5e2adbade82', opacity: "0.5", x1: "1200", y1: "2300", x2: "1200", y2: "1800" }), h("line", { key: 'd3bea8de4d689a5c5c423a72dd23a0fbc64c29dd', opacity: "0.917", x1: "900", y1: "680.4", x2: "650", y2: "247.4" }), h("line", { key: '543e33091e87bf85c3a0e4d4881babdffbe4b825', opacity: "0.417", x1: "1750", y1: "2152.6", x2: "1500", y2: "1719.6" }), h("line", { key: '5c2e0a3722955a8ee17b57f3061097f18681ba7e', opacity: "0.833", x1: "680.4", y1: "900", x2: "247.4", y2: "650" }), h("line", { key: '1100d48a500bfca6075243cf69be9e6f575bdae6', opacity: "0.333", x1: "2152.6", y1: "1750", x2: "1719.6", y2: "1500" }), h("line", { key: '6c3f7c309a5ed15c6ffce11925efe09dbc8e6f3b', opacity: "0.75", x1: "600", y1: "1200", x2: "100", y2: "1200" }), h("line", { key: '7708c31b141f3a151e8dc78c89b20442f34ce1e2', opacity: "0.25", x1: "2300", y1: "1200", x2: "1800", y2: "1200" }), h("line", { key: 'd419fc4006e8063f9bbc35b4cb2a9a88010c623a', opacity: "0.667", x1: "680.4", y1: "1500", x2: "247.4", y2: "1750" }), h("line", { key: '78ccaf11a6e7c3183d210b787ce9374bd7c4aff4', opacity: "0.167", x1: "2152.6", y1: "650", x2: "1719.6", y2: "900" }), h("line", { key: 'acb1444de9fcd9aa1a3182d759d3b8aeb0906284', opacity: "0.583", x1: "900", y1: "1719.6", x2: "650", y2: "2152.6" }), h("line", { key: '6adef9d6a54f302c8da7c84cae32851723ce25cc', opacity: "0.083", x1: "1750", y1: "247.4", x2: "1500", y2: "680.4" }), h("animateTransform", { key: '7acf982514091f6c3ec9bd4ddfc660f3286ddd4e', attributeName: "transform", attributeType: "XML", type: "rotate", keyTimes: "0;0.08333;0.16667;0.25;0.33333;0.41667;0.5;0.58333;0.66667;0.75;0.83333;0.91667", values: "0 1199 1199;30 1199 1199;60 1199 1199;90 1199 1199;120 1199 1199;150 1199 1199;180 1199 1199;210 1199 1199;240 1199 1199;270 1199 1199;300 1199 1199;330 1199 1199", dur: "0.83333s", begin: "0s", repeatCount: "indefinite", calcMode: "discrete" })))), h("div", { key: '120bebc59c0fc013cb2bfbaf8957ad3731e1ddf4', class: "modal-content", ref: el => (this.contentElement = el) }, h("slot", { key: '0f371823f8fddd61e2b0ce24a59477103d979875' })), h("div", { key: 'fa8436f70871d59055dab2cf0fcfe5d4577328c1', class: "focus-guard", tabindex: guardTabIndex, onFocus: this.handleEndGuardFocus })))));
205
+ return (h(Host, { key: '55e0d63b18df165313ea3dd8b8f17aa0e0d0a253', role: renderedOpen ? 'dialog' : undefined, "aria-modal": renderedOpen ? 'true' : undefined, onKeyDown: this.handleKeyDown, onFocusin: this.handleFocusIn }, h("div", { key: 'adb0b493c0ae525f275025c03e1b8f02b04de1af', class: `modal-row${renderedOpen ? ' open' : ''}`, onClick: () => this.closeModal() }, h("div", { key: '478bdad2ad481bfc2d8ffcf552788292fa93daed', class: "modal-child", tabindex: "-1", ref: el => (this.dialogElement = el), onClick: e => e.stopPropagation() }, h("div", { key: '8cc68ecefa37ec1db65f6c910d1da40f9144e722', class: "focus-guard", tabindex: guardTabIndex, onFocus: this.handleStartGuardFocus }), showCloseButton ? (h("div", { class: "modal-close-button-wrap" }, h("button", { type: "button", class: "modal-close-button", "aria-label": i18n.t('Close'), ref: el => (this.closeButtonElement = el), onClick: () => this.closeModal() }, h("ion-icon", { name: "close", size: "large", "aria-hidden": "true" })))) : null, h("div", { key: '26271a75906a72e9944599f98da007bfebc2e348', class: "modal-loading" }, h("svg", { key: 'bc6b1267e2f3b6b1dd7209db55be717fddf9acd4', version: "1.1", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 2400 2400" }, h("g", { key: '00ed54798ac376ed71f87a088fad2519cb1262dc', "stroke-width": "200", "stroke-linecap": "round", stroke: "currentColor", fill: "none", id: "spinner" }, h("line", { key: '98242d65eb9470430bd5cc656cbb479232782746', x1: "1200", y1: "600", x2: "1200", y2: "100" }), h("line", { key: '2e2f0538a6d048465ef5f8a3d5ed1932f6c59270', opacity: "0.5", x1: "1200", y1: "2300", x2: "1200", y2: "1800" }), h("line", { key: '11f850b0e7dc0d259f35f56aab17068d4d25ca95', opacity: "0.917", x1: "900", y1: "680.4", x2: "650", y2: "247.4" }), h("line", { key: '14c3226b5d2741902f428a208966adf016c1bb7e', opacity: "0.417", x1: "1750", y1: "2152.6", x2: "1500", y2: "1719.6" }), h("line", { key: 'd41da322484b62c1db1df72b9bd1bcc0dbb85a2c', opacity: "0.833", x1: "680.4", y1: "900", x2: "247.4", y2: "650" }), h("line", { key: '246dcdd4a011775dc8fea8a05cfcfc429d5bd03c', opacity: "0.333", x1: "2152.6", y1: "1750", x2: "1719.6", y2: "1500" }), h("line", { key: 'f0a2d217a33a8caa6995a30d840002cb8c076e8d', opacity: "0.75", x1: "600", y1: "1200", x2: "100", y2: "1200" }), h("line", { key: '7552fb2c04f85c54b8bcc2235a32690e4489177f', opacity: "0.25", x1: "2300", y1: "1200", x2: "1800", y2: "1200" }), h("line", { key: '7b5a62164a0ef759b057f9100c7c5af834c9f6b7', opacity: "0.667", x1: "680.4", y1: "1500", x2: "247.4", y2: "1750" }), h("line", { key: 'd36af9d23059da4ca91147084e47ba94e19f5ada', opacity: "0.167", x1: "2152.6", y1: "650", x2: "1719.6", y2: "900" }), h("line", { key: 'f8eed2a97d817b68e0b29f5b5037d34d46a79a46', opacity: "0.583", x1: "900", y1: "1719.6", x2: "650", y2: "2152.6" }), h("line", { key: '1641d577b703e213157bc553966e434a40ba7158', opacity: "0.083", x1: "1750", y1: "247.4", x2: "1500", y2: "680.4" }), h("animateTransform", { key: '60fb2d30c248db1b4195d6015dc96225a15e4010', attributeName: "transform", attributeType: "XML", type: "rotate", keyTimes: "0;0.08333;0.16667;0.25;0.33333;0.41667;0.5;0.58333;0.66667;0.75;0.83333;0.91667", values: "0 1199 1199;30 1199 1199;60 1199 1199;90 1199 1199;120 1199 1199;150 1199 1199;180 1199 1199;210 1199 1199;240 1199 1199;270 1199 1199;300 1199 1199;330 1199 1199", dur: "0.83333s", begin: "0s", repeatCount: "indefinite", calcMode: "discrete" })))), h("div", { key: '27d3b71da43e5935dff3eff2e1bc507a24261b70', class: "modal-content", ref: el => (this.contentElement = el) }, h("slot", { key: '641408238d3969b830d1f3e9398be6f05bc1f65b' })), h("div", { key: 'c6178542b98a99d6a50b74270adc273671d5cc19', class: "focus-guard", tabindex: guardTabIndex, onFocus: this.handleEndGuardFocus })))));
204
206
  }
205
207
  static get is() { return "stripe-modal"; }
206
208
  static get encapsulation() { return "shadow"; }
@@ -3,13 +3,15 @@ import { StripeAPIError } from "../../utils/error";
3
3
  * Determine whether the submit button should be disabled.
4
4
  * For Checkout Session mode: the checkout is ready once Stripe finished loading.
5
5
  * For Payment Intent / Setup Intent mode: an intent client secret must be present.
6
+ * The button stays disabled after a successful payment as well: the intent or
7
+ * checkout is already confirmed and cannot be submitted again.
6
8
  * @param params progress / loading state and the current mode information
7
9
  * @returns true when the submit button should be disabled
8
10
  */
9
11
  export const isSubmitButtonDisabled = (params) => {
10
12
  const { progress, isCheckoutSession, loadStripeStatus, intentClientSecret } = params;
11
13
  const hasValidSecret = isCheckoutSession ? loadStripeStatus === 'success' : intentClientSecret != null && intentClientSecret !== '';
12
- return progress === 'loading' || !hasValidSecret;
14
+ return progress === 'loading' || progress === 'success' || !hasValidSecret;
13
15
  };
14
16
  /**
15
17
  * Run the default Stripe confirmation flow for Payment Intent / Setup Intent mode.
@@ -18,25 +20,22 @@ export const isSubmitButtonDisabled = (params) => {
18
20
  * @param elements the Stripe Elements instance bound to the payment element
19
21
  * @param intentType the configured intent type
20
22
  * @param returnUrl the URL Stripe should redirect back to when required
23
+ * @param extraConfirmParams optional params merged into `confirmParams` (for example `payment_method_data.billing_details`)
21
24
  * @returns the confirmation result
22
25
  * @throws StripeAPIError when Stripe returns an error
23
26
  */
24
- export const confirmPaymentOrSetup = async (stripe, elements, intentType, returnUrl) => {
27
+ export const confirmPaymentOrSetup = async (stripe, elements, intentType, returnUrl, extraConfirmParams) => {
25
28
  const result = await (() => {
26
29
  if (intentType === 'payment') {
27
30
  return stripe.confirmPayment({
28
31
  elements,
29
- confirmParams: {
30
- return_url: returnUrl,
31
- },
32
+ confirmParams: Object.assign({ return_url: returnUrl }, extraConfirmParams),
32
33
  redirect: 'if_required',
33
34
  });
34
35
  }
35
36
  return stripe.confirmSetup({
36
37
  elements,
37
- confirmParams: {
38
- return_url: returnUrl,
39
- },
38
+ confirmParams: Object.assign({ return_url: returnUrl }, extraConfirmParams),
40
39
  redirect: 'if_required',
41
40
  });
42
41
  })();
@@ -122,6 +122,10 @@ export class StripePaymentElement {
122
122
  return;
123
123
  }
124
124
  await this.initStripe(publishableKey, { stripeAccount });
125
+ // A new secret starts a fresh payment, so re-enable the submit button after a previous success
126
+ if (this.progress === 'success') {
127
+ this.progress = '';
128
+ }
125
129
  }
126
130
  async updateCheckoutSessionClientSecret(newValue) {
127
131
  // Re-initialize with checkout session when client secret changes
@@ -129,6 +133,10 @@ export class StripePaymentElement {
129
133
  await this.initStripeWithCheckoutSession(this.publishableKey, newValue, {
130
134
  stripeAccount: this.stripeAccount,
131
135
  });
136
+ // A new secret starts a fresh payment, so re-enable the submit button after a previous success
137
+ if (this.progress === 'success') {
138
+ this.progress = '';
139
+ }
132
140
  }
133
141
  }
134
142
  stripeLoadedEventHandler() {
@@ -658,7 +666,7 @@ export class StripePaymentElement {
658
666
  "references": {
659
667
  "PaymentElementSubmitHandler": {
660
668
  "location": "local",
661
- "path": "/Users/okamotohidetaka/development/oss/stripe-pwa-elements/src/components/stripe-payment-element/stripe-payment-element.tsx",
669
+ "path": "/home/circleci/project/src/components/stripe-payment-element/stripe-payment-element.tsx",
662
670
  "id": "src/components/stripe-payment-element/stripe-payment-element.tsx::PaymentElementSubmitHandler"
663
671
  }
664
672
  }
@@ -748,7 +756,7 @@ export class StripePaymentElement {
748
756
  "references": {
749
757
  "PaymentElementSubmitEvent": {
750
758
  "location": "local",
751
- "path": "/Users/okamotohidetaka/development/oss/stripe-pwa-elements/src/components/stripe-payment-element/stripe-payment-element.tsx",
759
+ "path": "/home/circleci/project/src/components/stripe-payment-element/stripe-payment-element.tsx",
752
760
  "id": "src/components/stripe-payment-element/stripe-payment-element.tsx::PaymentElementSubmitEvent"
753
761
  }
754
762
  }
@@ -797,7 +805,7 @@ export class StripePaymentElement {
797
805
  "references": {
798
806
  "CheckoutSessionFormSubmitResult": {
799
807
  "location": "local",
800
- "path": "/Users/okamotohidetaka/development/oss/stripe-pwa-elements/src/components/stripe-payment-element/stripe-payment-element.tsx",
808
+ "path": "/home/circleci/project/src/components/stripe-payment-element/stripe-payment-element.tsx",
801
809
  "id": "src/components/stripe-payment-element/stripe-payment-element.tsx::CheckoutSessionFormSubmitResult"
802
810
  }
803
811
  }
@@ -869,7 +877,7 @@ export class StripePaymentElement {
869
877
  },
870
878
  "InitCheckoutSessionOptions": {
871
879
  "location": "local",
872
- "path": "/Users/okamotohidetaka/development/oss/stripe-pwa-elements/src/components/stripe-payment-element/stripe-payment-element.tsx",
880
+ "path": "/home/circleci/project/src/components/stripe-payment-element/stripe-payment-element.tsx",
873
881
  "id": "src/components/stripe-payment-element/stripe-payment-element.tsx::InitCheckoutSessionOptions"
874
882
  }
875
883
  },
@@ -24,6 +24,20 @@ export const intentKindFromClientSecret = (clientSecret) => {
24
24
  const match = CLIENT_SECRET_PATTERNS.find(([pattern]) => pattern.test(clientSecret));
25
25
  return match === null || match === void 0 ? void 0 : match[1];
26
26
  };
27
+ /**
28
+ * Tell what a client secret belongs to.
29
+ * A secret from `checkout-session-client-secret` is always a Checkout Session: Stripe does not document the format
30
+ * of a Checkout Session client secret, so it is never inspected. Intent secrets are told apart by their prefix.
31
+ * @param clientSecret - The client secret
32
+ * @param source - The attribute the secret was set through
33
+ * @returns The kind, or undefined when an intent secret has an unknown format
34
+ */
35
+ export const intentKindOf = (clientSecret, source) => {
36
+ if (source === 'checkoutSession') {
37
+ return 'checkoutSession';
38
+ }
39
+ return intentKindFromClientSecret(clientSecret);
40
+ };
27
41
  const unchanged = (state) => ({ state, effects: [] });
28
42
  /**
29
43
  * Resolve the pending `present()` promise, if any.
@@ -45,17 +59,17 @@ const cancel = (state) => {
45
59
  effects: [...(visible ? [{ type: 'hide' }] : []), { type: 'emit', event: 'paymentSheetCanceled' }, ...resolved.effects],
46
60
  };
47
61
  };
48
- const changeSecret = (state, clientSecret) => {
62
+ const changeSecret = (state, clientSecret, source) => {
49
63
  if (clientSecret === '') {
50
64
  return unchanged(state);
51
65
  }
52
66
  // Never drop the result of a running confirmation; apply the new secret once it finishes
53
67
  if (state.phase === 'confirming') {
54
- return unchanged(Object.assign(Object.assign({}, state), { deferredClientSecret: clientSecret }));
68
+ return unchanged(Object.assign(Object.assign({}, state), { deferredSecret: { clientSecret, source } }));
55
69
  }
56
70
  const canceled = state.phase === 'presented' ? cancel(state) : unchanged(state);
57
71
  const generation = state.generation + 1;
58
- const intentKind = intentKindFromClientSecret(clientSecret);
72
+ const intentKind = intentKindOf(clientSecret, source);
59
73
  if (intentKind == null) {
60
74
  const resolved = resolvePending(Object.assign(Object.assign({}, canceled.state), { phase: 'loadFailed', generation, intentKind: undefined, openRequested: false }), 'paymentSheetFailed');
61
75
  return {
@@ -72,11 +86,11 @@ const changeSecret = (state, clientSecret) => {
72
86
  * Apply a secret that arrived while confirming.
73
87
  */
74
88
  const applyDeferredSecret = (result) => {
75
- const { deferredClientSecret } = result.state;
76
- if (deferredClientSecret == null) {
89
+ const { deferredSecret } = result.state;
90
+ if (deferredSecret == null) {
77
91
  return result;
78
92
  }
79
- const next = changeSecret(Object.assign(Object.assign({}, result.state), { deferredClientSecret: undefined }), deferredClientSecret);
93
+ const next = changeSecret(Object.assign(Object.assign({}, result.state), { deferredSecret: undefined }), deferredSecret.clientSecret, deferredSecret.source);
80
94
  return { state: next.state, effects: [...result.effects, ...next.effects] };
81
95
  };
82
96
  const isCurrentConfirmation = (state, generation) => state.phase === 'confirming' && state.generation === generation;
@@ -88,7 +102,7 @@ const isCurrentConfirmation = (state, generation) => state.phase === 'confirming
88
102
  export const transition = (state, event) => {
89
103
  switch (event.type) {
90
104
  case 'secretChanged':
91
- return changeSecret(state, event.clientSecret);
105
+ return changeSecret(state, event.clientSecret, event.source);
92
106
  case 'loadSucceeded': {
93
107
  if (event.generation !== state.generation || state.phase !== 'loading') {
94
108
  return unchanged(state);
@@ -0,0 +1,94 @@
1
+ import { StripeAPIError } from "../../utils/error";
2
+ import { toAppearance, toPaymentElementOptions } from "./stripe-payment-sheet.helpers";
3
+ /**
4
+ * Build the Checkout Payment Element options from the payment sheet options.
5
+ * The Checkout Payment Element takes fewer options than the regular one: `business` and `defaultValues` are not
6
+ * available, so only the layout is passed.
7
+ * @param options - Payment sheet options
8
+ */
9
+ export const toCheckoutPaymentElementOptions = (options) => {
10
+ const { layout } = toPaymentElementOptions(options);
11
+ return layout == null ? {} : { layout };
12
+ };
13
+ /**
14
+ * 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`.
16
+ * @param options - Payment sheet options
17
+ */
18
+ export const checkoutIgnoredOptionKeys = (options) => {
19
+ if (options == null) {
20
+ return [];
21
+ }
22
+ 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}`);
24
+ if (merchantDisplayName != null) {
25
+ keys.push('merchantDisplayName');
26
+ }
27
+ // The extra billing elements and the wallet mapping are implemented for PaymentIntent / SetupIntent mode only
28
+ ['billingDetailsCollectionConfiguration', 'shippingDetails', 'enableApplePay', 'enableGooglePay']
29
+ .filter(key => options[key] !== undefined)
30
+ .forEach(key => keys.push(key));
31
+ return keys.sort();
32
+ };
33
+ /**
34
+ * Build the `elementsOptions` passed to `initCheckoutElementsSdk` from the payment sheet options.
35
+ * @param options - Payment sheet options
36
+ */
37
+ export const toCheckoutElementsOptions = (options) => {
38
+ const appearance = toAppearance(options === null || options === void 0 ? void 0 : options.style);
39
+ return appearance == null ? undefined : { appearance };
40
+ };
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
+ /**
59
+ * Confirm a Checkout Session from the payment sheet.
60
+ *
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`.
63
+ *
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
70
+ * @param checkout - The Checkout instance from `initCheckoutElementsSdk`
71
+ * @param returnUrl - Where Stripe redirects after a redirect-based payment method
72
+ * @param email - Customer email; needed when the session was created without `customer_email` or `customer`
73
+ * @returns The confirmation result
74
+ * @throws StripeAPIError when the actions cannot be loaded, the session can no longer be paid, or the confirmation fails
75
+ */
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
+ };
@@ -10,7 +10,17 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  }
11
11
  return t;
12
12
  };
13
- const SUPPORTED_OPTION_KEYS = ['merchantDisplayName', 'paymentMethodLayout', 'defaultBillingDetails', 'returnURL', 'style'];
13
+ const SUPPORTED_OPTION_KEYS = [
14
+ 'merchantDisplayName',
15
+ 'paymentMethodLayout',
16
+ 'defaultBillingDetails',
17
+ 'returnURL',
18
+ 'style',
19
+ 'billingDetailsCollectionConfiguration',
20
+ 'shippingDetails',
21
+ 'enableApplePay',
22
+ 'enableGooglePay',
23
+ ];
14
24
  const LAYOUTS = {
15
25
  horizontal: 'tabs',
16
26
  vertical: 'accordion',
@@ -24,6 +34,34 @@ const THEMES = {
24
34
  * Drop keys whose value is undefined.
25
35
  */
26
36
  const compact = (value) => Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
37
+ /**
38
+ * Convert a Capacitor address to the Stripe shape (`postalCode` → `postal_code`), dropping keys that are not given.
39
+ */
40
+ const toStripeAddress = (address) => {
41
+ const { postalCode } = address, rest = __rest(address, ["postalCode"]);
42
+ return compact(Object.assign(Object.assign({}, rest), { postal_code: postalCode }));
43
+ };
44
+ /**
45
+ * Payment Element billing fields to turn off: the `never` ones (passed from `defaultBillingDetails` at confirmation)
46
+ * and the ones collected by a separate element (email element, billing Address Element).
47
+ */
48
+ const toBillingDetailsFields = (config) => {
49
+ if (config == null) {
50
+ return undefined;
51
+ }
52
+ const { email, name, phone, address } = config;
53
+ const fields = compact({
54
+ email: email === 'never' || email === 'always' ? 'never' : undefined,
55
+ name: name === 'never' ? 'never' : undefined,
56
+ phone: phone === 'never' || (phone === 'always' && address === 'full') ? 'never' : undefined,
57
+ address: address === 'never' || address === 'full' ? 'never' : undefined,
58
+ });
59
+ return Object.keys(fields).length === 0 ? undefined : fields;
60
+ };
61
+ /**
62
+ * `true` → `auto` (shown when available), `false` → `never`, undefined → left to Stripe
63
+ */
64
+ const toWalletOption = (enabled) => (enabled == null ? undefined : enabled ? 'auto' : 'never');
27
65
  /**
28
66
  * Build the Payment Element options from the payment sheet options.
29
67
  * @param options - Payment sheet options
@@ -32,8 +70,16 @@ export const toPaymentElementOptions = (options) => {
32
70
  if (options == null) {
33
71
  return {};
34
72
  }
35
- const { merchantDisplayName, paymentMethodLayout, defaultBillingDetails } = options;
73
+ const { merchantDisplayName, paymentMethodLayout, defaultBillingDetails, billingDetailsCollectionConfiguration, enableApplePay, enableGooglePay } = options;
36
74
  const elementOptions = {};
75
+ const billingDetailsFields = toBillingDetailsFields(billingDetailsCollectionConfiguration);
76
+ const wallets = compact({ applePay: toWalletOption(enableApplePay), googlePay: toWalletOption(enableGooglePay) });
77
+ if (billingDetailsFields != null) {
78
+ elementOptions.fields = { billingDetails: billingDetailsFields };
79
+ }
80
+ if (Object.keys(wallets).length > 0) {
81
+ elementOptions.wallets = wallets;
82
+ }
37
83
  if (merchantDisplayName != null) {
38
84
  elementOptions.business = { name: merchantDisplayName };
39
85
  }
@@ -44,8 +90,7 @@ export const toPaymentElementOptions = (options) => {
44
90
  const { address } = defaultBillingDetails, contact = __rest(defaultBillingDetails, ["address"]);
45
91
  const billingDetails = compact(contact);
46
92
  if (address != null) {
47
- const { postalCode } = address, rest = __rest(address, ["postalCode"]);
48
- billingDetails.address = compact(Object.assign(Object.assign({}, rest), { postal_code: postalCode }));
93
+ billingDetails.address = toStripeAddress(address);
49
94
  }
50
95
  elementOptions.defaultValues = { billingDetails };
51
96
  }
@@ -62,17 +107,156 @@ export const toAppearance = (style) => {
62
107
  return { theme: THEMES[style] };
63
108
  };
64
109
  /**
65
- * List the given options that have no effect on the web (yet), sorted by name.
110
+ * List the given options (or option values, as `option.key`) that have no effect on the web (yet), sorted by name.
66
111
  * @param options - Payment sheet options
112
+ * @param intentKind - Kind of the intent, when known
67
113
  */
68
- export const unsupportedOptionKeys = (options) => {
114
+ export const unsupportedOptionKeys = (options, intentKind) => {
69
115
  if (options == null) {
70
116
  return [];
71
117
  }
72
- return Object.entries(options)
118
+ const keys = Object.entries(options)
73
119
  .filter(([key, value]) => value !== undefined && !SUPPORTED_OPTION_KEYS.includes(key))
74
- .map(([key]) => key)
75
- .sort();
120
+ .map(([key]) => key);
121
+ const config = options.billingDetailsCollectionConfiguration;
122
+ // `fields.billingDetails.name: 'always'` of the Payment Element requires Stripe beta access, so it is not sent
123
+ if ((config === null || config === void 0 ? void 0 : config.name) === 'always') {
124
+ keys.push('billingDetailsCollectionConfiguration.name');
125
+ }
126
+ // The phone can only be required through the billing Address Element
127
+ if ((config === null || config === void 0 ? void 0 : config.phone) === 'always' && config.address !== 'full') {
128
+ keys.push('billingDetailsCollectionConfiguration.phone');
129
+ }
130
+ // A SetupIntent has no shipping details
131
+ if (options.shippingDetails != null && intentKind === 'setup') {
132
+ keys.push('shippingDetails');
133
+ }
134
+ return keys.sort();
135
+ };
136
+ /**
137
+ * Prefill values of an Address Element. The address is left out without a country, which the Address Element requires.
138
+ */
139
+ const toAddressDefaultValues = (details) => {
140
+ const { name, phone, address } = details;
141
+ const country = address === null || address === void 0 ? void 0 : address.country;
142
+ return compact({ name, phone, address: country == null || country === '' ? undefined : Object.assign(Object.assign({}, toStripeAddress(address)), { country }) });
143
+ };
144
+ const isBlank = (value) => value == null || value === '';
145
+ /**
146
+ * Loose email check, used only when the email element has not told whether its value is complete (a prefilled value nobody edited)
147
+ */
148
+ const looksLikeEmail = (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
149
+ /**
150
+ * Error for a `never` field without a default value. Thrown while loading so that Stripe never rejects the confirmation.
151
+ */
152
+ const missingDefaultError = (field, defaultKey) => new Error(`<stripe-payment-sheet>: billingDetailsCollectionConfiguration.${field} is 'never', so defaultBillingDetails.${defaultKey} is required`);
153
+ /**
154
+ * Error the customer can fix in the open sheet (handled like a Stripe `validation_error`).
155
+ * Its message is an English i18n key, translated when it is shown (see `isSheetValidationError`).
156
+ */
157
+ const validationError = (message) => Object.assign(new Error(message), { type: 'validation_error', sheetValidation: true });
158
+ /**
159
+ * Tell whether an error was raised by this sheet's own validation (its message is an i18n key), rather than by Stripe (already localized).
160
+ * @param error - Error thrown while confirming
161
+ */
162
+ export const isSheetValidationError = (error) => (error === null || error === void 0 ? void 0 : error.sheetValidation) === true;
163
+ /**
164
+ * Decide which extra elements to show and which billing details to pass at confirmation (PaymentIntent / SetupIntent mode).
165
+ * @param options - Payment sheet options
166
+ * @param intentKind - Kind of the intent being confirmed
167
+ * @throws Error when a `never` field has no value in `defaultBillingDetails`
168
+ */
169
+ export const planBillingDetailsCollection = (options, intentKind) => {
170
+ var _a, _b, _c, _d, _e, _f, _g;
171
+ const config = (_a = options === null || options === void 0 ? void 0 : options.billingDetailsCollectionConfiguration) !== null && _a !== void 0 ? _a : {};
172
+ const defaults = (_b = options === null || options === void 0 ? void 0 : options.defaultBillingDetails) !== null && _b !== void 0 ? _b : {};
173
+ const fixedBillingDetails = {};
174
+ ['email', 'name', 'phone'].forEach(field => {
175
+ if (config[field] !== 'never') {
176
+ return;
177
+ }
178
+ if (isBlank(defaults[field])) {
179
+ throw missingDefaultError(field, field);
180
+ }
181
+ fixedBillingDetails[field] = defaults[field];
182
+ });
183
+ if (config.address === 'never') {
184
+ const address = defaults.address;
185
+ if (address == null || isBlank(address.country)) {
186
+ throw missingDefaultError('address', 'address.country');
187
+ }
188
+ // Every key is passed: the Payment Element does not collect any part of the address
189
+ fixedBillingDetails.address = {
190
+ line1: (_c = address.line1) !== null && _c !== void 0 ? _c : '',
191
+ line2: (_d = address.line2) !== null && _d !== void 0 ? _d : '',
192
+ city: (_e = address.city) !== null && _e !== void 0 ? _e : '',
193
+ state: (_f = address.state) !== null && _f !== void 0 ? _f : '',
194
+ postal_code: (_g = address.postalCode) !== null && _g !== void 0 ? _g : '',
195
+ country: address.country,
196
+ };
197
+ }
198
+ const collectPhoneFromAddress = config.address === 'full' && config.phone === 'always';
199
+ const plan = { fixedBillingDetails, collectPhoneFromAddress };
200
+ if (config.address === 'full') {
201
+ const billingAddressElement = { mode: 'billing', defaultValues: toAddressDefaultValues(defaults) };
202
+ if (collectPhoneFromAddress) {
203
+ billingAddressElement.fields = { phone: 'always' };
204
+ billingAddressElement.validation = { phone: { required: 'always' } };
205
+ }
206
+ else if (config.phone === 'never') {
207
+ billingAddressElement.fields = { phone: 'never' };
208
+ }
209
+ plan.billingAddressElement = billingAddressElement;
210
+ }
211
+ if (config.email === 'always') {
212
+ plan.emailElement = isBlank(defaults.email) ? {} : { defaultValues: { email: defaults.email } };
213
+ }
214
+ const shippingDetails = options === null || options === void 0 ? void 0 : options.shippingDetails;
215
+ if (shippingDetails != null && intentKind === 'payment') {
216
+ const shippingAddressElement = { mode: 'shipping', defaultValues: toAddressDefaultValues(shippingDetails) };
217
+ // The Address Element hides the phone field by default; show it so that the given phone is kept and editable
218
+ if (!isBlank(shippingDetails.phone)) {
219
+ shippingAddressElement.fields = { phone: 'always' };
220
+ }
221
+ plan.shippingAddressElement = shippingAddressElement;
222
+ }
223
+ return plan;
224
+ };
225
+ /**
226
+ * Build `payment_method_data.billing_details` for the confirmation.
227
+ * Values fixed by a `never` field win over the values typed into the extra elements.
228
+ * @param plan - Result of `planBillingDetailsCollection`
229
+ * @param collected - Values read from the extra elements
230
+ * @returns The billing details, or undefined when nothing has to be passed
231
+ * @throws Error with `type: 'validation_error'` when an extra element is not complete
232
+ */
233
+ export const collectedBillingDetails = (plan, collected) => {
234
+ var _a, _b;
235
+ const details = {};
236
+ if (plan.billingAddressElement != null) {
237
+ const billingAddress = collected.billingAddress;
238
+ if (billingAddress == null || !billingAddress.complete) {
239
+ throw validationError('Please complete your billing address.');
240
+ }
241
+ details.name = billingAddress.value.name;
242
+ details.address = billingAddress.value.address;
243
+ if (plan.collectPhoneFromAddress) {
244
+ details.phone = billingAddress.value.phone;
245
+ }
246
+ }
247
+ if (plan.emailElement != null) {
248
+ // Before any change event the element shows its prefilled value
249
+ const email = (_a = collected.email) !== null && _a !== void 0 ? _a : (_b = plan.emailElement.defaultValues) === null || _b === void 0 ? void 0 : _b.email;
250
+ if (isBlank(email)) {
251
+ throw validationError('Please enter your email address.');
252
+ }
253
+ if (collected.emailComplete === false || (collected.emailComplete == null && !looksLikeEmail(email))) {
254
+ throw validationError('Please enter a valid email address.');
255
+ }
256
+ details.email = email;
257
+ }
258
+ Object.assign(details, plan.fixedBillingDetails);
259
+ return Object.keys(details).length === 0 ? undefined : details;
76
260
  };
77
261
  /**
78
262
  * Stripe error types after which the customer can fix the input or simply try again.