stripe-pwa-elements 4.0.1 → 4.0.3

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 (107) hide show
  1. package/dist/cjs/factory-Cm6zUD7R.js +1206 -0
  2. package/dist/cjs/{factory-Cd2VI_N2.js → i18n-lBbOeQt4.js} +12 -1149
  3. package/dist/cjs/ion-icon_2.cjs.entry.js +725 -0
  4. package/dist/cjs/loader.cjs.js +1 -1
  5. package/dist/cjs/stripe-address-element.cjs.entry.js +5 -4
  6. package/dist/cjs/stripe-card-element-modal.cjs.entry.js +3 -2
  7. package/dist/cjs/{stripe-card-element_2.cjs.entry.js → stripe-card-element.cjs.entry.js} +8 -93
  8. package/dist/cjs/stripe-currency-selector.cjs.entry.js +4 -3
  9. package/dist/cjs/stripe-elements.cjs.js +1 -1
  10. package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +24 -5
  11. package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +4 -3
  12. package/dist/cjs/stripe-payment-element.cjs.entry.js +12 -124
  13. package/dist/cjs/stripe-payment-element.helpers-CvAhIqLt.js +119 -0
  14. package/dist/cjs/stripe-payment-request-button.cjs.entry.js +2 -2
  15. package/dist/cjs/stripe-payment-sheet.cjs.entry.js +987 -0
  16. package/dist/collection/collection-manifest.json +2 -1
  17. package/dist/collection/components/stripe-address-element/stripe-address-element.js +2 -2
  18. package/dist/collection/components/stripe-card-element/stripe-card-element.js +3 -2
  19. package/dist/collection/components/stripe-card-element-modal/stripe-card-element-modal.js +4 -3
  20. package/dist/collection/components/stripe-express-checkout-element/stripe-express-checkout-element.js +18 -0
  21. package/dist/collection/components/stripe-modal/stripe-modal.css +27 -1
  22. package/dist/collection/components/stripe-modal/stripe-modal.js +132 -1
  23. package/dist/collection/components/stripe-payment-element/stripe-payment-element.helpers.js +4 -7
  24. package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +4 -4
  25. package/dist/collection/components/stripe-payment-request-button/stripe-payment-request-button.js +3 -3
  26. package/dist/collection/components/stripe-payment-sheet/payment-sheet-state.js +193 -0
  27. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.checkout.js +94 -0
  28. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.css +68 -0
  29. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.helpers.js +274 -0
  30. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +763 -0
  31. package/dist/collection/services/express-checkout-element-manager.js +36 -2
  32. package/dist/collection/services/link-authentication-element-manager.js +5 -0
  33. package/dist/collection/services/stripe-service.js +20 -6
  34. package/dist/collection/utils/focus.js +76 -0
  35. package/dist/collection/utils/i18n.js +12 -0
  36. package/dist/components/factory.js +1 -1
  37. package/dist/components/i18n.js +1 -0
  38. package/dist/components/stripe-address-element.js +1 -1
  39. package/dist/components/stripe-card-element-modal.js +1 -1
  40. package/dist/components/stripe-card-element2.js +1 -1
  41. package/dist/components/stripe-currency-selector.js +1 -1
  42. package/dist/components/stripe-express-checkout-element.js +1 -1
  43. package/dist/components/stripe-link-authentication-element.js +1 -1
  44. package/dist/components/stripe-modal2.js +1 -1
  45. package/dist/components/stripe-payment-element.helpers.js +1 -0
  46. package/dist/components/stripe-payment-element.js +1 -1
  47. package/dist/components/stripe-payment-request-button2.js +1 -1
  48. package/dist/components/stripe-payment-sheet.d.ts +11 -0
  49. package/dist/components/stripe-payment-sheet.js +1 -0
  50. package/dist/esm/factory-BaGv8K_i.js +1203 -0
  51. package/dist/esm/{factory-VTa1Gc94.js → i18n-CL5n3bOb.js} +13 -1149
  52. package/dist/esm/ion-icon_2.entry.js +722 -0
  53. package/dist/esm/loader.js +1 -1
  54. package/dist/esm/stripe-address-element.entry.js +2 -1
  55. package/dist/esm/stripe-card-element-modal.entry.js +3 -2
  56. package/dist/esm/{stripe-card-element_2.entry.js → stripe-card-element.entry.js} +6 -90
  57. package/dist/esm/stripe-currency-selector.entry.js +2 -1
  58. package/dist/esm/stripe-elements.js +1 -1
  59. package/dist/esm/stripe-express-checkout-element.entry.js +20 -1
  60. package/dist/esm/stripe-link-authentication-element.entry.js +2 -1
  61. package/dist/esm/stripe-payment-element.entry.js +4 -116
  62. package/dist/esm/stripe-payment-element.helpers-Bu9RfxS4.js +114 -0
  63. package/dist/esm/stripe-payment-request-button.entry.js +2 -2
  64. package/dist/esm/stripe-payment-sheet.entry.js +985 -0
  65. package/dist/stripe-elements/p-2e41699e.entry.js +1 -0
  66. package/dist/stripe-elements/p-3fc4583a.entry.js +1 -0
  67. package/dist/stripe-elements/{p-ae0c336e.entry.js → p-4891edf0.entry.js} +1 -1
  68. package/dist/stripe-elements/p-7e826964.entry.js +1 -0
  69. package/dist/stripe-elements/p-BhKXGROE.js +1 -0
  70. package/dist/stripe-elements/p-CL5n3bOb.js +1 -0
  71. package/dist/stripe-elements/p-DlMEZwSe.js +1 -0
  72. package/dist/stripe-elements/p-a395a5d1.entry.js +1 -0
  73. package/dist/stripe-elements/p-b62c9dae.entry.js +1 -0
  74. package/dist/stripe-elements/p-b7c20e8e.entry.js +1 -0
  75. package/dist/stripe-elements/p-ba791c8f.entry.js +1 -0
  76. package/dist/stripe-elements/p-bec62526.entry.js +1 -0
  77. package/dist/stripe-elements/p-f5552c81.entry.js +1 -0
  78. package/dist/stripe-elements/stripe-elements.esm.js +1 -1
  79. package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +2 -1
  80. package/dist/types/components/stripe-card-element-modal/stripe-card-element-modal.d.ts +2 -1
  81. package/dist/types/components/stripe-express-checkout-element/stripe-express-checkout-element.d.ts +5 -0
  82. package/dist/types/components/stripe-modal/stripe-modal.d.ts +43 -0
  83. package/dist/types/components/stripe-payment-element/stripe-payment-element.helpers.d.ts +7 -2
  84. package/dist/types/components/stripe-payment-request-button/stripe-payment-request-button.d.ts +1 -1
  85. package/dist/types/components/stripe-payment-sheet/payment-sheet-state.d.ts +121 -0
  86. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.checkout.d.ts +39 -0
  87. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.d.ts +157 -0
  88. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.helpers.d.ts +153 -0
  89. package/dist/types/components.d.ts +182 -10
  90. package/dist/types/index.d.ts +2 -0
  91. package/dist/types/services/interfaces.d.ts +3 -0
  92. package/dist/types/services/stripe-service.d.ts +7 -2
  93. package/dist/types/utils/focus.d.ts +15 -0
  94. package/package.json +7 -3
  95. package/readme.md +59 -6
  96. package/dist/cjs/ion-icon.cjs.entry.js +0 -431
  97. package/dist/components/utils.js +0 -1
  98. package/dist/esm/ion-icon.entry.js +0 -429
  99. package/dist/stripe-elements/p-1bd46766.entry.js +0 -1
  100. package/dist/stripe-elements/p-1c6e0a45.entry.js +0 -1
  101. package/dist/stripe-elements/p-3f42ca0c.entry.js +0 -1
  102. package/dist/stripe-elements/p-5cf62945.entry.js +0 -1
  103. package/dist/stripe-elements/p-74de1556.entry.js +0 -1
  104. package/dist/stripe-elements/p-76e57d78.entry.js +0 -1
  105. package/dist/stripe-elements/p-840d499f.entry.js +0 -1
  106. package/dist/stripe-elements/p-CrjrbGJ3.js +0 -1
  107. package/dist/stripe-elements/p-cfd8e081.entry.js +0 -1
@@ -8,7 +8,8 @@
8
8
  "components/stripe-link-authentication-element/stripe-link-authentication-element.js",
9
9
  "components/stripe-payment-request-button/stripe-payment-request-button.js",
10
10
  "components/stripe-card-element-modal/stripe-card-element-modal.js",
11
- "components/stripe-modal/stripe-modal.js"
11
+ "components/stripe-modal/stripe-modal.js",
12
+ "components/stripe-payment-sheet/stripe-payment-sheet.js"
12
13
  ],
13
14
  "mixins": [],
14
15
  "compiler": {
@@ -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
  }
@@ -228,7 +228,8 @@ export class StripeCardElement {
228
228
  */
229
229
  this.showLabel = false;
230
230
  /**
231
- * The component will provide a function to call the `stripe.confirmCardPayment`API.
231
+ * The component will confirm the intent for you: `stripe.confirmCardPayment` when `intentType` is `'payment'`,
232
+ * `stripe.confirmCardSetup` when it is `'setup'`.
232
233
  * If you want to customize the behavior, should set false.
233
234
  * And listen the 'formSubmit' event on the element
234
235
  */
@@ -578,7 +579,7 @@ export class StripeCardElement {
578
579
  "optional": false,
579
580
  "docs": {
580
581
  "tags": [],
581
- "text": "The component will provide a function to call the `stripe.confirmCardPayment`API.\nIf you want to customize the behavior, should set false.\nAnd listen the 'formSubmit' event on the element"
582
+ "text": "The component will confirm the intent for you: `stripe.confirmCardPayment` when `intentType` is `'payment'`,\n`stripe.confirmCardSetup` when it is `'setup'`.\nIf you want to customize the behavior, should set false.\nAnd listen the 'formSubmit' event on the element"
582
583
  },
583
584
  "getter": false,
584
585
  "setter": false,
@@ -6,7 +6,8 @@ export class StripeCardElementModal {
6
6
  */
7
7
  this.showLabel = false;
8
8
  /**
9
- * The component will provide a function to call the `stripe.confirmCardPayment`API.
9
+ * The component will confirm the intent for you: `stripe.confirmCardPayment` when `intentType` is `'payment'`,
10
+ * `stripe.confirmCardSetup` when it is `'setup'`.
10
11
  * If you want to customize the behavior, should set false.
11
12
  * And listen the 'formSubmit' event on the element
12
13
  */
@@ -94,7 +95,7 @@ export class StripeCardElementModal {
94
95
  cardElement.setPaymentRequestOption(options);
95
96
  }
96
97
  render() {
97
- return (h("stripe-modal", { key: 'a0229c55472e3c6f417086fa08d79e1ec8a8c485', open: this.open, showCloseButton: this.showCloseButton }, h("stripe-card-element", { key: '799f08c781bad089cec8b1338e9a714d080abd51', showLabel: this.showLabel, publishableKey: this.publishableKey, intentClientSecret: this.intentClientSecret, shouldUseDefaultFormSubmitAction: this.shouldUseDefaultFormSubmitAction, handleSubmit: this.handleSubmit, stripeDidLoaded: this.stripeDidLoaded, intentType: this.intentType, zip: this.zip, buttonLabel: this.buttonLabel, sheetTitle: this.sheetTitle, applicationName: this.applicationName })));
98
+ return (h("stripe-modal", { key: '4904f57b562da9ce4fc348fb376f931cac707540', open: this.open, showCloseButton: this.showCloseButton }, h("stripe-card-element", { key: '8707fa6e32ca82b700f53fc2a257b8af1cc7b45c', showLabel: this.showLabel, publishableKey: this.publishableKey, intentClientSecret: this.intentClientSecret, shouldUseDefaultFormSubmitAction: this.shouldUseDefaultFormSubmitAction, handleSubmit: this.handleSubmit, stripeDidLoaded: this.stripeDidLoaded, intentType: this.intentType, zip: this.zip, buttonLabel: this.buttonLabel, sheetTitle: this.sheetTitle, applicationName: this.applicationName })));
98
99
  }
99
100
  static get is() { return "stripe-card-element-modal"; }
100
101
  static get originalStyleUrls() {
@@ -264,7 +265,7 @@ export class StripeCardElementModal {
264
265
  "optional": false,
265
266
  "docs": {
266
267
  "tags": [],
267
- "text": "The component will provide a function to call the `stripe.confirmCardPayment`API.\nIf you want to customize the behavior, should set false.\nAnd listen the 'formSubmit' event on the element"
268
+ "text": "The component will confirm the intent for you: `stripe.confirmCardPayment` when `intentType` is `'payment'`,\n`stripe.confirmCardSetup` when it is `'setup'`.\nIf you want to customize the behavior, should set false.\nAnd listen the 'formSubmit' event on the element"
268
269
  },
269
270
  "getter": false,
270
271
  "setter": false,
@@ -83,6 +83,8 @@ export class StripeExpressCheckoutElement {
83
83
  await this.stripeService.initialize(publishableKey, {
84
84
  stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
85
85
  applicationName: this.applicationName,
86
+ clientSecret: this.clientSecret,
87
+ elementsOptions: this.buildElementsOptions(),
86
88
  });
87
89
  // If already successfully loaded, initialize elements immediately
88
90
  if (this.stripeService.state.loadStripeStatus === 'success') {
@@ -101,6 +103,22 @@ export class StripeExpressCheckoutElement {
101
103
  });
102
104
  }
103
105
  }
106
+ /**
107
+ * Options for `stripe.elements()` when there is no client secret.
108
+ * Stripe.js reads mode / amount / currency from the Elements group, not from the element itself.
109
+ */
110
+ buildElementsOptions() {
111
+ if (this.currency == null || this.currency === '') {
112
+ return undefined;
113
+ }
114
+ if (this.intentType === 'setup') {
115
+ return { mode: 'setup', currency: this.currency };
116
+ }
117
+ if (this.amount === undefined) {
118
+ return undefined;
119
+ }
120
+ return { mode: 'payment', amount: this.amount, currency: this.currency };
121
+ }
104
122
  /**
105
123
  * Update element options dynamically
106
124
  * @param options - Partial options to update
@@ -33,11 +33,13 @@
33
33
  opacity: 0;
34
34
  pointer-events: none;
35
35
  will-change: transform;
36
+ visibility: hidden;
36
37
  }
37
38
 
38
39
  .modal-row.open {
39
40
  opacity: 1;
40
41
  pointer-events: auto;
42
+ visibility: visible;
41
43
  position: fixed;
42
44
  top: 0;
43
45
  left: 0;
@@ -85,14 +87,38 @@
85
87
  padding: 16px 8px 24px;
86
88
  background-color: #fff;
87
89
  width: 100%;
90
+ max-height: 100vh;
91
+ max-height: 100dvh;
92
+ overflow-y: auto;
93
+ overscroll-behavior: contain;
88
94
  }
89
95
 
90
96
  .modal-close-button-wrap {
91
97
  padding-left: 8px;
92
98
  }
93
99
  .modal-close-button-wrap .modal-close-button {
100
+ display: block;
101
+ width: 32px;
102
+ cursor: pointer;
103
+ border-radius: 4px;
104
+ }
105
+ .modal-close-button-wrap .modal-close-button:focus-visible {
106
+ outline: 2px solid var(--color-label, #000);
107
+ outline-offset: 2px;
108
+ }
109
+ .modal-close-button-wrap .modal-close-button ion-icon {
94
110
  width: 32px;
95
111
  display: block;
96
112
  fill: var(--color-label);
97
- cursor: pointer;
113
+ }
114
+
115
+ .modal-child:focus {
116
+ outline: none;
117
+ }
118
+
119
+ .focus-guard {
120
+ position: absolute;
121
+ width: 1px;
122
+ height: 1px;
123
+ overflow: hidden;
98
124
  }
@@ -1,5 +1,7 @@
1
1
  import { Host, h } from "@stencil/core";
2
2
  import { checkPlatform } from "../../utils/utils";
3
+ import { getDeepActiveElement, getTabbableElements } from "../../utils/focus";
4
+ import { i18n } from "../../utils/i18n";
3
5
  export class StripeModal {
4
6
  constructor() {
5
7
  /**
@@ -16,14 +18,64 @@ export class StripeModal {
16
18
  * Ionic Ref: https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/accordion/accordion.tsx#L83
17
19
  */
18
20
  this.renderedOpen = false;
21
+ /**
22
+ * The element that had focus before the modal opened. Focus returns to it when the modal closes.
23
+ */
24
+ this.returnFocusElement = null;
25
+ /**
26
+ * Set when the modal opens; the initial focus is moved after the open state has been rendered.
27
+ */
28
+ this.shouldFocusOnRender = false;
29
+ /**
30
+ * The last element inside the modal that received focus.
31
+ * `FocusEvent.relatedTarget` is `null` when focus crosses an iframe boundary (e.g. leaving a Stripe Elements field),
32
+ * so the guards fall back to this value to tell which way focus is moving.
33
+ */
34
+ this.lastFocusedInside = null;
35
+ this.handleKeyDown = (event) => {
36
+ if (!this.open || event.key !== 'Escape') {
37
+ return;
38
+ }
39
+ // Escape that cancels an IME composition (keyCode 229) or that a slotted widget (e.g. an autocomplete popup) already handled must not close the modal
40
+ if (event.isComposing || event.keyCode === 229 || event.defaultPrevented) {
41
+ return;
42
+ }
43
+ // Prevent an outer modal (or the page) from also reacting to the same key press
44
+ event.preventDefault();
45
+ event.stopPropagation();
46
+ this.closeModal();
47
+ };
48
+ /**
49
+ * Whether focus came from a focusable element inside the modal (not from the container itself or from outside).
50
+ * The guards use it to tell Tab from Shift+Tab: a guard cannot see the key, but it can see where focus came from.
51
+ */
52
+ this.handleFocusIn = (event) => {
53
+ var _a, _b;
54
+ const target = ((_b = (_a = event.composedPath) === null || _a === void 0 ? void 0 : _a.call(event)[0]) !== null && _b !== void 0 ? _b : event.target);
55
+ if ((target === null || target === void 0 ? void 0 : target.classList) !== undefined && !target.classList.contains('focus-guard')) {
56
+ this.lastFocusedInside = target;
57
+ }
58
+ };
59
+ this.handleStartGuardFocus = (event) => {
60
+ // Shift+Tab from the first element wraps to the last; Tab from the container (or from outside) enters at the first
61
+ this.cameFromFocusableInside(event) ? this.focusLastElement() : this.focusFirstElement();
62
+ };
63
+ this.handleEndGuardFocus = (event) => {
64
+ // Tab from the last element wraps to the first; Shift+Tab from outside enters at the last
65
+ this.isInsideModal(this.getFocusOrigin(event)) ? this.focusFirstElement() : this.focusLastElement();
66
+ };
19
67
  }
20
68
  onOpenChange(open) {
21
69
  if (open) {
70
+ this.rememberFocus();
22
71
  this.openModalAnimation();
23
72
  }
24
73
  else {
25
74
  this.renderedOpen = false;
75
+ this.shouldFocusOnRender = false;
76
+ this.lastFocusedInside = null;
26
77
  this.close.emit();
78
+ this.restoreFocus();
27
79
  }
28
80
  }
29
81
  /**
@@ -50,20 +102,98 @@ export class StripeModal {
50
102
  this.el.classList.add(platformName);
51
103
  }
52
104
  if (this.open) {
105
+ this.rememberFocus();
53
106
  this.openModalAnimation();
54
107
  }
55
108
  }
109
+ componentDidRender() {
110
+ if (this.shouldFocusOnRender && this.renderedOpen) {
111
+ this.shouldFocusOnRender = false;
112
+ this.focusFirstElement();
113
+ }
114
+ }
115
+ rememberFocus() {
116
+ var _a;
117
+ if (typeof document === 'undefined') {
118
+ return;
119
+ }
120
+ const active = getDeepActiveElement(document);
121
+ // Ignore focus that is already inside the modal and the default document focus
122
+ if (active === null || active === document.body || this.el.contains(active) || ((_a = this.el.shadowRoot) === null || _a === void 0 ? void 0 : _a.contains(active)) === true) {
123
+ return;
124
+ }
125
+ this.returnFocusElement = active;
126
+ }
127
+ restoreFocus() {
128
+ const target = this.returnFocusElement;
129
+ this.returnFocusElement = null;
130
+ if (target != null && target.isConnected && typeof target.focus === 'function') {
131
+ target.focus();
132
+ }
133
+ }
134
+ getTabbableElements() {
135
+ if (this.dialogElement === undefined) {
136
+ return [];
137
+ }
138
+ return getTabbableElements(this.dialogElement).filter(element => !element.classList.contains('focus-guard'));
139
+ }
140
+ isInsideModal(node) {
141
+ var _a;
142
+ return node !== null && (this.el.contains(node) || ((_a = this.dialogElement) === null || _a === void 0 ? void 0 : _a.contains(node)) === true);
143
+ }
144
+ getFocusOrigin(event) {
145
+ var _a;
146
+ return (_a = event.relatedTarget) !== null && _a !== void 0 ? _a : this.lastFocusedInside;
147
+ }
148
+ /**
149
+ * Whether focus came from a focusable element inside the modal (not from the container itself or from outside).
150
+ * The guards use it to tell Tab from Shift+Tab: a guard cannot see the key, but it can see where focus came from.
151
+ */
152
+ cameFromFocusableInside(event) {
153
+ const from = this.getFocusOrigin(event);
154
+ return from !== this.dialogElement && this.isInsideModal(from);
155
+ }
156
+ /**
157
+ * Slotted content is hidden (and therefore not focusable) while the open transition runs.
158
+ * When it ends, move focus from the placeholder (container / close button) into the content, unless the user already moved it.
159
+ */
160
+ focusContentAfterLoading() {
161
+ var _a;
162
+ if (!this.open || this.contentElement === undefined) {
163
+ return;
164
+ }
165
+ const active = getDeepActiveElement(document);
166
+ const focusIsIdle = active === null || active === document.body || active === this.dialogElement || active === this.closeButtonElement;
167
+ if (!focusIsIdle) {
168
+ return;
169
+ }
170
+ (_a = getTabbableElements(this.contentElement)[0]) === null || _a === void 0 ? void 0 : _a.focus();
171
+ }
172
+ focusFirstElement() {
173
+ var _a;
174
+ const [first] = this.getTabbableElements();
175
+ (_a = (first !== null && first !== void 0 ? first : this.dialogElement)) === null || _a === void 0 ? void 0 : _a.focus();
176
+ }
177
+ focusLastElement() {
178
+ var _a, _b;
179
+ const elements = this.getTabbableElements();
180
+ (_b = ((_a = elements[elements.length - 1]) !== null && _a !== void 0 ? _a : this.dialogElement)) === null || _b === void 0 ? void 0 : _b.focus();
181
+ }
56
182
  openModalAnimation() {
183
+ this.shouldFocusOnRender = true;
57
184
  if (!this.el.shadowRoot) {
58
185
  this.renderedOpen = true;
59
186
  return;
60
187
  }
61
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;
62
191
  modalChild.classList.add('loading');
63
192
  modalChild.style.willChange = 'transform';
64
193
  modalChild.addEventListener('transitionend', () => {
65
194
  modalChild.style.willChange = 'auto';
66
195
  modalChild.classList.remove('loading');
196
+ this.focusContentAfterLoading();
67
197
  }, { once: true });
68
198
  requestAnimationFrame(() => {
69
199
  this.renderedOpen = this.open;
@@ -71,7 +201,8 @@ export class StripeModal {
71
201
  }
72
202
  render() {
73
203
  const { renderedOpen, showCloseButton } = this;
74
- return (h(Host, { key: '38fb86acf7cf5887a426c67b1a1271f7fae7048c' }, h("div", { key: 'f751d92c327ee2e564edfcd4d18f4dca43c20c37', class: `modal-row${renderedOpen ? ' open' : ''}`, onClick: () => this.closeModal() }, h("div", { key: '11519ccd44a5069df3247c530a2c1e114eab7aef', class: "modal-child", onClick: e => e.stopPropagation() }, showCloseButton ? (h("div", { class: "modal-close-button-wrap" }, h("ion-icon", { name: "close", size: "large", class: "modal-close-button", onClick: () => this.closeModal() }))) : null, h("div", { key: 'a41f7f263b488b5bbc2a999cbabf6b9e407bca85', class: "modal-loading" }, h("svg", { key: '0b3b25cb2812bc4d837fb4b7e6af4a5f42f0247e', version: "1.1", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 2400 2400" }, h("g", { key: '10a9f9ec59699e6d2988b9c65cd02da1754fd760', "stroke-width": "200", "stroke-linecap": "round", stroke: "currentColor", fill: "none", id: "spinner" }, h("line", { key: 'ed271fa584b930ceed5397c271b31e0d48c72f72', x1: "1200", y1: "600", x2: "1200", y2: "100" }), h("line", { key: '3cf855a84f3ab58b914b7aeb784fbc5b95d8ae94', opacity: "0.5", x1: "1200", y1: "2300", x2: "1200", y2: "1800" }), h("line", { key: '2cce4b62a276399235509e94f47a63acf9c69a0f', opacity: "0.917", x1: "900", y1: "680.4", x2: "650", y2: "247.4" }), h("line", { key: '64c175ef068591417b043f7630a44d34eae7cb59', opacity: "0.417", x1: "1750", y1: "2152.6", x2: "1500", y2: "1719.6" }), h("line", { key: '0856a654e3aa756dfb1e9fc316b8b379fa9d5a4e', opacity: "0.833", x1: "680.4", y1: "900", x2: "247.4", y2: "650" }), h("line", { key: 'c60f1f8495df9b8cdcc8941255d08c01a0e1c02f', opacity: "0.333", x1: "2152.6", y1: "1750", x2: "1719.6", y2: "1500" }), h("line", { key: '204bc2a7765e43b86f91c3fb9b1e72a3a39bb323', opacity: "0.75", x1: "600", y1: "1200", x2: "100", y2: "1200" }), h("line", { key: '7584b272f9efd7f746c1bcc5c8a5576098b02381', opacity: "0.25", x1: "2300", y1: "1200", x2: "1800", y2: "1200" }), h("line", { key: '7a053e9eb5f0da3fbf6fb7c9680bf73073bb126d', opacity: "0.667", x1: "680.4", y1: "1500", x2: "247.4", y2: "1750" }), h("line", { key: 'f8b817095143d739589e45c99b03c7afbdfc8293', opacity: "0.167", x1: "2152.6", y1: "650", x2: "1719.6", y2: "900" }), h("line", { key: 'aae0e36dbdfff44196f9758c8a5ed2337139ebe0', opacity: "0.583", x1: "900", y1: "1719.6", x2: "650", y2: "2152.6" }), h("line", { key: '3a257b30cb289f29ba386ccca7519bcdc22c3786', opacity: "0.083", x1: "1750", y1: "247.4", x2: "1500", y2: "680.4" }), h("animateTransform", { key: 'c6b8e73025589403dd3d08f84b02eb824763d056', 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: 'da5ef8031e5b826d854a065d8172389cdd84fbf0', class: "modal-content" }, h("slot", { key: 'fbe97a3a4d5489de5ae6f49342c58d537b317842' }))))));
204
+ const guardTabIndex = renderedOpen ? 0 : -1;
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 })))));
75
206
  }
76
207
  static get is() { return "stripe-modal"; }
77
208
  static get encapsulation() { return "shadow"; }
@@ -18,25 +18,22 @@ export const isSubmitButtonDisabled = (params) => {
18
18
  * @param elements the Stripe Elements instance bound to the payment element
19
19
  * @param intentType the configured intent type
20
20
  * @param returnUrl the URL Stripe should redirect back to when required
21
+ * @param extraConfirmParams optional params merged into `confirmParams` (for example `payment_method_data.billing_details`)
21
22
  * @returns the confirmation result
22
23
  * @throws StripeAPIError when Stripe returns an error
23
24
  */
24
- export const confirmPaymentOrSetup = async (stripe, elements, intentType, returnUrl) => {
25
+ export const confirmPaymentOrSetup = async (stripe, elements, intentType, returnUrl, extraConfirmParams) => {
25
26
  const result = await (() => {
26
27
  if (intentType === 'payment') {
27
28
  return stripe.confirmPayment({
28
29
  elements,
29
- confirmParams: {
30
- return_url: returnUrl,
31
- },
30
+ confirmParams: Object.assign({ return_url: returnUrl }, extraConfirmParams),
32
31
  redirect: 'if_required',
33
32
  });
34
33
  }
35
34
  return stripe.confirmSetup({
36
35
  elements,
37
- confirmParams: {
38
- return_url: returnUrl,
39
- },
36
+ confirmParams: Object.assign({ return_url: returnUrl }, extraConfirmParams),
40
37
  redirect: 'if_required',
41
38
  });
42
39
  })();
@@ -658,7 +658,7 @@ export class StripePaymentElement {
658
658
  "references": {
659
659
  "PaymentElementSubmitHandler": {
660
660
  "location": "local",
661
- "path": "/Users/okamotohidetaka/development/oss/stripe-pwa-elements/src/components/stripe-payment-element/stripe-payment-element.tsx",
661
+ "path": "/home/circleci/project/src/components/stripe-payment-element/stripe-payment-element.tsx",
662
662
  "id": "src/components/stripe-payment-element/stripe-payment-element.tsx::PaymentElementSubmitHandler"
663
663
  }
664
664
  }
@@ -748,7 +748,7 @@ export class StripePaymentElement {
748
748
  "references": {
749
749
  "PaymentElementSubmitEvent": {
750
750
  "location": "local",
751
- "path": "/Users/okamotohidetaka/development/oss/stripe-pwa-elements/src/components/stripe-payment-element/stripe-payment-element.tsx",
751
+ "path": "/home/circleci/project/src/components/stripe-payment-element/stripe-payment-element.tsx",
752
752
  "id": "src/components/stripe-payment-element/stripe-payment-element.tsx::PaymentElementSubmitEvent"
753
753
  }
754
754
  }
@@ -797,7 +797,7 @@ export class StripePaymentElement {
797
797
  "references": {
798
798
  "CheckoutSessionFormSubmitResult": {
799
799
  "location": "local",
800
- "path": "/Users/okamotohidetaka/development/oss/stripe-pwa-elements/src/components/stripe-payment-element/stripe-payment-element.tsx",
800
+ "path": "/home/circleci/project/src/components/stripe-payment-element/stripe-payment-element.tsx",
801
801
  "id": "src/components/stripe-payment-element/stripe-payment-element.tsx::CheckoutSessionFormSubmitResult"
802
802
  }
803
803
  }
@@ -869,7 +869,7 @@ export class StripePaymentElement {
869
869
  },
870
870
  "InitCheckoutSessionOptions": {
871
871
  "location": "local",
872
- "path": "/Users/okamotohidetaka/development/oss/stripe-pwa-elements/src/components/stripe-payment-element/stripe-payment-element.tsx",
872
+ "path": "/home/circleci/project/src/components/stripe-payment-element/stripe-payment-element.tsx",
873
873
  "id": "src/components/stripe-payment-element/stripe-payment-element.tsx::InitCheckoutSessionOptions"
874
874
  }
875
875
  },
@@ -5,7 +5,7 @@ import { loadStripe } from "@stripe/stripe-js";
5
5
  * `stripe.paymentRequest()` is being removed in Stripe.js 9.x (deprecated as of 2025-09-30 / 2026-03-25).
6
6
  * Please migrate to `<stripe-express-checkout-element>` which supports Apple Pay, Google Pay, Link, PayPal,
7
7
  * and more via the modern Express Checkout Element API.
8
- * Migration guide: https://hideokamoto.github.io/stripe-pwa-elements/guides/migrate-payment-request-button-to-express-checkout/
8
+ * Migration guide: https://stripe-pwa-elements-docs.wp-kyoto.workers.dev/guides/migrate-payment-request-button-to-express-checkout/
9
9
  */
10
10
  export class StripePaymentRequestButton {
11
11
  constructor() {
@@ -87,7 +87,7 @@ export class StripePaymentRequestButton {
87
87
  console.warn('[stripe-pwa-elements] <stripe-payment-request-button> is deprecated. ' +
88
88
  'stripe.paymentRequest() is being removed in Stripe.js 9.x (deprecated 2025-09-30 / removed 2026-03-25). ' +
89
89
  'Please migrate to <stripe-express-checkout-element>, which supports Apple Pay, Google Pay, Link, PayPal, and more. ' +
90
- 'Migration guide: https://hideokamoto.github.io/stripe-pwa-elements/guides/migrate-payment-request-button-to-express-checkout/');
90
+ 'Migration guide: https://stripe-pwa-elements-docs.wp-kyoto.workers.dev/guides/migrate-payment-request-button-to-express-checkout/');
91
91
  }
92
92
  /**
93
93
  * @param option
@@ -194,7 +194,7 @@ export class StripePaymentRequestButton {
194
194
  this.stripe = undefined;
195
195
  }
196
196
  render() {
197
- return (h(Host, { key: 'dd3ae348f9e9c798acdeca095ad9c157afd4734f' }, h("div", { key: 'f2e13b6980318ede1812d4f54223b7aeb9cfc51b', id: "payment-request" }, h("div", { key: 'ff6c1218924044d1ffc11354909f25c1745ef254', id: "payment-request-button" })), h("slot", { key: 'ec2131a0503baa15cdcf3571040e9ce6040da708' })));
197
+ return (h(Host, { key: '644a4b729c72e87b42df5e1b43262d3195e7ebc6' }, h("div", { key: 'aff26789868bbec0f1f6abc463fb14d7f3e73c1b', id: "payment-request" }, h("div", { key: '074a25f3c5b2575696ddaeacf2715935212964a5', id: "payment-request-button" })), h("slot", { key: '5173400bd63ab201f02934cea4edcab4bb7eed9c' })));
198
198
  }
199
199
  static get is() { return "stripe-payment-request-button"; }
200
200
  static get originalStyleUrls() {
@@ -0,0 +1,193 @@
1
+ /**
2
+ * State machine behind `<stripe-payment-sheet>`.
3
+ *
4
+ * Pure functions only: the component feeds events in and performs the returned effects
5
+ * (loading Stripe.js, showing the modal, confirming, emitting events, resolving `present()`).
6
+ * The same rules are model-checked in Quint; see the exhaustive test next to this file.
7
+ */
8
+ export const initialSheetState = {
9
+ phase: 'idle',
10
+ generation: 0,
11
+ pendingPresent: false,
12
+ openRequested: false,
13
+ };
14
+ const CLIENT_SECRET_PATTERNS = [
15
+ [/^pi_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/, 'payment'],
16
+ [/^seti_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/, 'setup'],
17
+ ];
18
+ /**
19
+ * Tell whether a client secret belongs to a PaymentIntent or a SetupIntent from its prefix.
20
+ * @param clientSecret - The `client_secret` of a PaymentIntent (`pi_..._secret_...`) or SetupIntent (`seti_..._secret_...`)
21
+ * @returns The intent kind, or undefined when the format is not recognized
22
+ */
23
+ export const intentKindFromClientSecret = (clientSecret) => {
24
+ const match = CLIENT_SECRET_PATTERNS.find(([pattern]) => pattern.test(clientSecret));
25
+ return match === null || match === void 0 ? void 0 : match[1];
26
+ };
27
+ /**
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
+ };
41
+ const unchanged = (state) => ({ state, effects: [] });
42
+ /**
43
+ * Resolve the pending `present()` promise, if any.
44
+ */
45
+ const resolvePending = (state, result) => {
46
+ if (!state.pendingPresent) {
47
+ return unchanged(state);
48
+ }
49
+ return { state: Object.assign(Object.assign({}, state), { pendingPresent: false }), effects: [{ type: 'resolvePresent', result }] };
50
+ };
51
+ /**
52
+ * Close the sheet as canceled: hide it, emit the event and resolve `present()`.
53
+ */
54
+ const cancel = (state) => {
55
+ const resolved = resolvePending(Object.assign(Object.assign({}, state), { openRequested: false }), 'paymentSheetCanceled');
56
+ const visible = state.phase === 'presented' || state.phase === 'confirming';
57
+ return {
58
+ state: resolved.state,
59
+ effects: [...(visible ? [{ type: 'hide' }] : []), { type: 'emit', event: 'paymentSheetCanceled' }, ...resolved.effects],
60
+ };
61
+ };
62
+ const changeSecret = (state, clientSecret, source) => {
63
+ if (clientSecret === '') {
64
+ return unchanged(state);
65
+ }
66
+ // Never drop the result of a running confirmation; apply the new secret once it finishes
67
+ if (state.phase === 'confirming') {
68
+ return unchanged(Object.assign(Object.assign({}, state), { deferredSecret: { clientSecret, source } }));
69
+ }
70
+ const canceled = state.phase === 'presented' ? cancel(state) : unchanged(state);
71
+ const generation = state.generation + 1;
72
+ const intentKind = intentKindOf(clientSecret, source);
73
+ if (intentKind == null) {
74
+ const resolved = resolvePending(Object.assign(Object.assign({}, canceled.state), { phase: 'loadFailed', generation, intentKind: undefined, openRequested: false }), 'paymentSheetFailed');
75
+ return {
76
+ state: resolved.state,
77
+ effects: [...canceled.effects, { type: 'emit', event: 'paymentSheetFailedToLoad' }, ...resolved.effects],
78
+ };
79
+ }
80
+ return {
81
+ state: Object.assign(Object.assign({}, canceled.state), { phase: 'loading', generation, intentKind }),
82
+ effects: [...canceled.effects, { type: 'load', generation, clientSecret, intentKind }],
83
+ };
84
+ };
85
+ /**
86
+ * Apply a secret that arrived while confirming.
87
+ */
88
+ const applyDeferredSecret = (result) => {
89
+ const { deferredSecret } = result.state;
90
+ if (deferredSecret == null) {
91
+ return result;
92
+ }
93
+ const next = changeSecret(Object.assign(Object.assign({}, result.state), { deferredSecret: undefined }), deferredSecret.clientSecret, deferredSecret.source);
94
+ return { state: next.state, effects: [...result.effects, ...next.effects] };
95
+ };
96
+ const isCurrentConfirmation = (state, generation) => state.phase === 'confirming' && state.generation === generation;
97
+ /**
98
+ * Compute the next state and the effects to perform for an event.
99
+ * @param state - Current state
100
+ * @param event - Event to handle
101
+ */
102
+ export const transition = (state, event) => {
103
+ switch (event.type) {
104
+ case 'secretChanged':
105
+ return changeSecret(state, event.clientSecret, event.source);
106
+ case 'loadSucceeded': {
107
+ if (event.generation !== state.generation || state.phase !== 'loading') {
108
+ return unchanged(state);
109
+ }
110
+ const open = state.openRequested;
111
+ return {
112
+ state: Object.assign(Object.assign({}, state), { phase: open ? 'presented' : 'ready', openRequested: false }),
113
+ effects: [{ type: 'emit', event: 'paymentSheetLoaded' }, ...(open ? [{ type: 'show' }] : [])],
114
+ };
115
+ }
116
+ case 'loadFailed': {
117
+ if (event.generation !== state.generation || state.phase !== 'loading') {
118
+ return unchanged(state);
119
+ }
120
+ const resolved = resolvePending(Object.assign(Object.assign({}, state), { phase: 'loadFailed', openRequested: false }), 'paymentSheetFailed');
121
+ return { state: resolved.state, effects: [{ type: 'emit', event: 'paymentSheetFailedToLoad' }, ...resolved.effects] };
122
+ }
123
+ case 'presentRequested':
124
+ if (state.pendingPresent) {
125
+ return unchanged(state);
126
+ }
127
+ switch (state.phase) {
128
+ case 'ready':
129
+ return { state: Object.assign(Object.assign({}, state), { phase: 'presented', pendingPresent: true }), effects: [{ type: 'show' }] };
130
+ case 'idle':
131
+ case 'loading':
132
+ return unchanged(Object.assign(Object.assign({}, state), { pendingPresent: true, openRequested: true }));
133
+ case 'presented':
134
+ case 'confirming':
135
+ // Already shown through the `open` attribute: wait for its result
136
+ return unchanged(Object.assign(Object.assign({}, state), { pendingPresent: true }));
137
+ default:
138
+ // loadFailed / completed / errored: nothing can be shown
139
+ return { state, effects: [{ type: 'resolvePresent', result: 'paymentSheetFailed' }] };
140
+ }
141
+ case 'openRequested':
142
+ if (state.phase === 'ready') {
143
+ return { state: Object.assign(Object.assign({}, state), { phase: 'presented' }), effects: [{ type: 'show' }] };
144
+ }
145
+ if (state.phase === 'idle' || state.phase === 'loading') {
146
+ return unchanged(Object.assign(Object.assign({}, state), { openRequested: true }));
147
+ }
148
+ return unchanged(state);
149
+ case 'closeRequested':
150
+ if (state.phase === 'presented') {
151
+ const canceled = cancel(state);
152
+ return { state: Object.assign(Object.assign({}, canceled.state), { phase: 'ready' }), effects: canceled.effects };
153
+ }
154
+ // Closing before the sheet was shown withdraws the request to open it
155
+ if ((state.phase === 'idle' || state.phase === 'loading') && state.openRequested) {
156
+ return cancel(state);
157
+ }
158
+ return unchanged(state);
159
+ case 'submitted':
160
+ if (state.phase !== 'presented' || state.intentKind == null) {
161
+ return unchanged(state);
162
+ }
163
+ return {
164
+ state: Object.assign(Object.assign({}, state), { phase: 'confirming' }),
165
+ effects: [{ type: 'confirm', generation: state.generation, intentKind: state.intentKind }],
166
+ };
167
+ case 'confirmSucceeded': {
168
+ if (!isCurrentConfirmation(state, event.generation)) {
169
+ return unchanged(state);
170
+ }
171
+ const resolved = resolvePending(Object.assign(Object.assign({}, state), { phase: 'completed' }), 'paymentSheetCompleted');
172
+ return applyDeferredSecret({
173
+ state: resolved.state,
174
+ effects: [{ type: 'hide' }, { type: 'emit', event: 'paymentSheetCompleted' }, ...resolved.effects],
175
+ });
176
+ }
177
+ case 'confirmDeclined':
178
+ if (!isCurrentConfirmation(state, event.generation)) {
179
+ return unchanged(state);
180
+ }
181
+ return applyDeferredSecret({ state: Object.assign(Object.assign({}, state), { phase: 'presented' }), effects: [{ type: 'showError', message: event.message }] });
182
+ case 'confirmFailed': {
183
+ if (!isCurrentConfirmation(state, event.generation)) {
184
+ return unchanged(state);
185
+ }
186
+ const resolved = resolvePending(Object.assign(Object.assign({}, state), { phase: 'errored' }), 'paymentSheetFailed');
187
+ return applyDeferredSecret({
188
+ state: resolved.state,
189
+ effects: [{ type: 'hide' }, { type: 'emit', event: 'paymentSheetFailed' }, ...resolved.effects],
190
+ });
191
+ }
192
+ }
193
+ };