stripe-pwa-elements 3.2.0 → 4.0.1

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 (237) hide show
  1. package/dist/cjs/app-globals-V2Kpy_OQ.js +0 -3
  2. package/dist/cjs/error-FFC4kSs5.js +0 -3
  3. package/dist/cjs/{factory-CbbbSvkg.js → factory-Cd2VI_N2.js} +216 -77
  4. package/dist/cjs/{index-Ba1pBePA.js → index-CYbA1N_k.js} +24 -6
  5. package/dist/cjs/index-Dkb0SxZc.js +4694 -0
  6. package/dist/cjs/index.cjs.js +0 -1
  7. package/dist/cjs/ion-icon.cjs.entry.js +22 -13
  8. package/dist/cjs/loader.cjs.js +2 -3
  9. package/dist/cjs/stripe-address-element.cjs.entry.js +41 -26
  10. package/dist/cjs/stripe-card-element-modal.cjs.entry.js +6 -7
  11. package/dist/cjs/stripe-card-element_2.cjs.entry.js +129 -72
  12. package/dist/cjs/stripe-currency-selector.cjs.entry.js +20 -10
  13. package/dist/cjs/stripe-elements.cjs.js +31 -5
  14. package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +32 -22
  15. package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +20 -10
  16. package/dist/cjs/stripe-payment-element.cjs.entry.js +283 -167
  17. package/dist/cjs/stripe-payment-request-button.cjs.entry.js +30 -18
  18. package/dist/collection/collection-manifest.json +6 -5
  19. package/dist/collection/components/stripe-address-element/stripe-address-element.js +36 -21
  20. package/dist/collection/components/stripe-card-element/stripe-card-element.helpers.js +57 -0
  21. package/dist/collection/components/stripe-card-element/stripe-card-element.js +62 -68
  22. package/dist/collection/components/stripe-card-element-modal/stripe-card-element-modal.js +15 -11
  23. package/dist/collection/components/stripe-currency-selector/stripe-currency-selector.js +17 -6
  24. package/dist/collection/components/stripe-express-checkout-element/stripe-express-checkout-element.js +35 -20
  25. package/dist/collection/components/stripe-link-authentication-element/stripe-link-authentication-element.js +19 -7
  26. package/dist/collection/components/stripe-modal/stripe-modal.js +18 -7
  27. package/dist/collection/components/stripe-payment-element/stripe-payment-element.helpers.js +114 -0
  28. package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +162 -162
  29. package/dist/collection/components/stripe-payment-request-button/stripe-payment-request-button.js +48 -19
  30. package/dist/collection/index.js +0 -1
  31. package/dist/collection/interfaces.js +0 -1
  32. package/dist/collection/services/address-element-manager.js +3 -4
  33. package/dist/collection/services/card-element-manager.js +3 -4
  34. package/dist/collection/services/currency-selector-element-manager.js +3 -4
  35. package/dist/collection/services/express-checkout-element-manager.js +9 -10
  36. package/dist/collection/services/factory.js +0 -1
  37. package/dist/collection/services/interfaces.js +0 -1
  38. package/dist/collection/services/link-authentication-element-manager.js +3 -4
  39. package/dist/collection/services/payment-element-manager.js +4 -5
  40. package/dist/collection/services/stripe-service.js +27 -10
  41. package/dist/collection/utils/element-finder.js +2 -3
  42. package/dist/collection/utils/error.js +0 -1
  43. package/dist/collection/utils/i18n.js +0 -1
  44. package/dist/collection/utils/platform.js +0 -1
  45. package/dist/collection/utils/test-setup.js +0 -1
  46. package/dist/collection/utils/utils.js +2 -3
  47. package/dist/components/error.js +1 -16
  48. package/dist/components/factory.js +1 -3736
  49. package/dist/components/icon.js +1 -459
  50. package/dist/components/index.d.ts +2 -0
  51. package/dist/components/index.js +1 -4
  52. package/dist/components/index2.js +1 -192
  53. package/dist/components/ion-icon.js +1 -9
  54. package/dist/components/stripe-address-element.js +1 -327
  55. package/dist/components/stripe-card-element-modal.js +1 -174
  56. package/dist/components/stripe-card-element.js +1 -9
  57. package/dist/components/stripe-card-element2.js +1 -440
  58. package/dist/components/stripe-currency-selector.js +1 -218
  59. package/dist/components/stripe-express-checkout-element.js +1 -332
  60. package/dist/components/stripe-link-authentication-element.js +1 -256
  61. package/dist/components/stripe-modal.js +1 -9
  62. package/dist/components/stripe-modal2.js +1 -112
  63. package/dist/components/stripe-payment-element.js +1 -510
  64. package/dist/components/stripe-payment-request-button.js +1 -9
  65. package/dist/components/stripe-payment-request-button2.js +1 -224
  66. package/dist/components/utils.js +1 -89
  67. package/dist/esm/app-globals-DQuL1Twl.js +0 -3
  68. package/dist/esm/error-XRfh5Wrs.js +0 -3
  69. package/dist/esm/{factory-Drde6-y7.js → factory-VTa1Gc94.js} +216 -77
  70. package/dist/esm/index-C6bbmyga.js +4677 -0
  71. package/dist/esm/{index-BHDCxQOb.js → index-CBXaOfXU.js} +24 -6
  72. package/dist/esm/index.js +0 -1
  73. package/dist/esm/ion-icon.entry.js +22 -13
  74. package/dist/esm/loader.js +3 -4
  75. package/dist/esm/stripe-address-element.entry.js +41 -26
  76. package/dist/esm/stripe-card-element-modal.entry.js +6 -7
  77. package/dist/esm/stripe-card-element_2.entry.js +129 -72
  78. package/dist/esm/stripe-currency-selector.entry.js +20 -10
  79. package/dist/esm/stripe-elements.js +32 -6
  80. package/dist/esm/stripe-express-checkout-element.entry.js +32 -22
  81. package/dist/esm/stripe-link-authentication-element.entry.js +20 -10
  82. package/dist/esm/stripe-payment-element.entry.js +283 -167
  83. package/dist/esm/stripe-payment-request-button.entry.js +27 -15
  84. package/dist/stripe-elements/index.esm.js +0 -2
  85. package/dist/stripe-elements/p-1bd46766.entry.js +1 -0
  86. package/dist/stripe-elements/p-1c6e0a45.entry.js +1 -0
  87. package/dist/stripe-elements/p-3f42ca0c.entry.js +1 -0
  88. package/dist/stripe-elements/p-5cf62945.entry.js +1 -0
  89. package/dist/stripe-elements/p-74de1556.entry.js +1 -0
  90. package/dist/stripe-elements/p-76e57d78.entry.js +1 -0
  91. package/dist/stripe-elements/p-840d499f.entry.js +1 -0
  92. package/dist/stripe-elements/p-C6bbmyga.js +2 -0
  93. package/dist/stripe-elements/p-CBXaOfXU.js +1 -0
  94. package/dist/stripe-elements/p-CrjrbGJ3.js +1 -0
  95. package/dist/stripe-elements/p-DQuL1Twl.js +1 -2
  96. package/dist/stripe-elements/p-XRfh5Wrs.js +1 -2
  97. package/dist/stripe-elements/p-ae0c336e.entry.js +1 -0
  98. package/dist/stripe-elements/p-cfd8e081.entry.js +1 -0
  99. package/dist/stripe-elements/stripe-elements.esm.js +1 -2
  100. package/dist/stripe-elements/svg/.gitignore +4 -0
  101. package/dist/types/components/stripe-address-element/stripe-address-element.d.ts +6 -0
  102. package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +11 -1
  103. package/dist/types/components/stripe-card-element/stripe-card-element.helpers.d.ts +29 -0
  104. package/dist/types/components/stripe-card-element-modal/stripe-card-element-modal.d.ts +4 -4
  105. package/dist/types/components/stripe-currency-selector/stripe-currency-selector.d.ts +6 -0
  106. package/dist/types/components/stripe-express-checkout-element/stripe-express-checkout-element.d.ts +6 -0
  107. package/dist/types/components/stripe-link-authentication-element/stripe-link-authentication-element.d.ts +6 -0
  108. package/dist/types/components/stripe-modal/stripe-modal.d.ts +1 -0
  109. package/dist/types/components/stripe-payment-element/stripe-payment-element.d.ts +20 -2
  110. package/dist/types/components/stripe-payment-element/stripe-payment-element.helpers.d.ts +54 -0
  111. package/dist/types/components/stripe-payment-request-button/stripe-payment-request-button.d.ts +14 -1
  112. package/dist/types/components.d.ts +139 -29
  113. package/dist/types/index.d.ts +1 -0
  114. package/dist/types/services/interfaces.d.ts +4 -3
  115. package/dist/types/services/stripe-service.d.ts +8 -4
  116. package/dist/types/stencil-public-runtime.d.ts +110 -5
  117. package/package.json +50 -30
  118. package/readme.md +386 -133
  119. package/dist/cjs/app-globals-V2Kpy_OQ.js.map +0 -1
  120. package/dist/cjs/error-FFC4kSs5.js.map +0 -1
  121. package/dist/cjs/factory-CbbbSvkg.js.map +0 -1
  122. package/dist/cjs/index-BXVW_rzh.js +0 -1932
  123. package/dist/cjs/index-BXVW_rzh.js.map +0 -1
  124. package/dist/cjs/index-Ba1pBePA.js.map +0 -1
  125. package/dist/cjs/index.cjs.js.map +0 -1
  126. package/dist/cjs/ion-icon.entry.cjs.js.map +0 -1
  127. package/dist/cjs/loader.cjs.js.map +0 -1
  128. package/dist/cjs/stripe-address-element.entry.cjs.js.map +0 -1
  129. package/dist/cjs/stripe-card-element-modal.entry.cjs.js.map +0 -1
  130. package/dist/cjs/stripe-card-element.stripe-modal.entry.cjs.js.map +0 -1
  131. package/dist/cjs/stripe-currency-selector.entry.cjs.js.map +0 -1
  132. package/dist/cjs/stripe-elements.cjs.js.map +0 -1
  133. package/dist/cjs/stripe-express-checkout-element.entry.cjs.js.map +0 -1
  134. package/dist/cjs/stripe-link-authentication-element.entry.cjs.js.map +0 -1
  135. package/dist/cjs/stripe-payment-element.entry.cjs.js.map +0 -1
  136. package/dist/cjs/stripe-payment-request-button.entry.cjs.js.map +0 -1
  137. package/dist/collection/components/stripe-address-element/stripe-address-element.js.map +0 -1
  138. package/dist/collection/components/stripe-card-element/stripe-card-element.js.map +0 -1
  139. package/dist/collection/components/stripe-card-element-modal/stripe-card-element-modal.js.map +0 -1
  140. package/dist/collection/components/stripe-currency-selector/stripe-currency-selector.js.map +0 -1
  141. package/dist/collection/components/stripe-express-checkout-element/stripe-express-checkout-element.js.map +0 -1
  142. package/dist/collection/components/stripe-link-authentication-element/stripe-link-authentication-element.js.map +0 -1
  143. package/dist/collection/components/stripe-modal/stripe-modal.js.map +0 -1
  144. package/dist/collection/components/stripe-payment-element/stripe-payment-element.js.map +0 -1
  145. package/dist/collection/components/stripe-payment-request-button/stripe-payment-request-button.js.map +0 -1
  146. package/dist/collection/index.js.map +0 -1
  147. package/dist/collection/interfaces.js.map +0 -1
  148. package/dist/collection/services/address-element-manager.js.map +0 -1
  149. package/dist/collection/services/card-element-manager.js.map +0 -1
  150. package/dist/collection/services/currency-selector-element-manager.js.map +0 -1
  151. package/dist/collection/services/express-checkout-element-manager.js.map +0 -1
  152. package/dist/collection/services/factory.js.map +0 -1
  153. package/dist/collection/services/interfaces.js.map +0 -1
  154. package/dist/collection/services/link-authentication-element-manager.js.map +0 -1
  155. package/dist/collection/services/payment-element-manager.js.map +0 -1
  156. package/dist/collection/services/stripe-service.js.map +0 -1
  157. package/dist/collection/utils/element-finder.js.map +0 -1
  158. package/dist/collection/utils/error.js.map +0 -1
  159. package/dist/collection/utils/i18n.js.map +0 -1
  160. package/dist/collection/utils/platform.js.map +0 -1
  161. package/dist/collection/utils/test-setup.js.map +0 -1
  162. package/dist/collection/utils/utils.js.map +0 -1
  163. package/dist/components/error.js.map +0 -1
  164. package/dist/components/factory.js.map +0 -1
  165. package/dist/components/icon.js.map +0 -1
  166. package/dist/components/index.js.map +0 -1
  167. package/dist/components/index2.js.map +0 -1
  168. package/dist/components/ion-icon.js.map +0 -1
  169. package/dist/components/stripe-address-element.js.map +0 -1
  170. package/dist/components/stripe-card-element-modal.js.map +0 -1
  171. package/dist/components/stripe-card-element.js.map +0 -1
  172. package/dist/components/stripe-card-element2.js.map +0 -1
  173. package/dist/components/stripe-currency-selector.js.map +0 -1
  174. package/dist/components/stripe-express-checkout-element.js.map +0 -1
  175. package/dist/components/stripe-link-authentication-element.js.map +0 -1
  176. package/dist/components/stripe-modal.js.map +0 -1
  177. package/dist/components/stripe-modal2.js.map +0 -1
  178. package/dist/components/stripe-payment-element.js.map +0 -1
  179. package/dist/components/stripe-payment-request-button.js.map +0 -1
  180. package/dist/components/stripe-payment-request-button2.js.map +0 -1
  181. package/dist/components/utils.js.map +0 -1
  182. package/dist/esm/app-globals-DQuL1Twl.js.map +0 -1
  183. package/dist/esm/error-XRfh5Wrs.js.map +0 -1
  184. package/dist/esm/factory-Drde6-y7.js.map +0 -1
  185. package/dist/esm/index-BHDCxQOb.js.map +0 -1
  186. package/dist/esm/index-DJwTOfxZ.js +0 -1920
  187. package/dist/esm/index-DJwTOfxZ.js.map +0 -1
  188. package/dist/esm/index.js.map +0 -1
  189. package/dist/esm/ion-icon.entry.js.map +0 -1
  190. package/dist/esm/loader.js.map +0 -1
  191. package/dist/esm/stripe-address-element.entry.js.map +0 -1
  192. package/dist/esm/stripe-card-element-modal.entry.js.map +0 -1
  193. package/dist/esm/stripe-card-element.stripe-modal.entry.js.map +0 -1
  194. package/dist/esm/stripe-currency-selector.entry.js.map +0 -1
  195. package/dist/esm/stripe-elements.js.map +0 -1
  196. package/dist/esm/stripe-express-checkout-element.entry.js.map +0 -1
  197. package/dist/esm/stripe-link-authentication-element.entry.js.map +0 -1
  198. package/dist/esm/stripe-payment-element.entry.js.map +0 -1
  199. package/dist/esm/stripe-payment-request-button.entry.js.map +0 -1
  200. package/dist/stripe-elements/index.esm.js.map +0 -1
  201. package/dist/stripe-elements/ion-icon.entry.esm.js.map +0 -1
  202. package/dist/stripe-elements/loader.esm.js.map +0 -1
  203. package/dist/stripe-elements/p-02f6e421.entry.js +0 -2
  204. package/dist/stripe-elements/p-02f6e421.entry.js.map +0 -1
  205. package/dist/stripe-elements/p-19888fa6.entry.js +0 -2
  206. package/dist/stripe-elements/p-19888fa6.entry.js.map +0 -1
  207. package/dist/stripe-elements/p-4d505729.entry.js +0 -2
  208. package/dist/stripe-elements/p-4d505729.entry.js.map +0 -1
  209. package/dist/stripe-elements/p-7e7ad92a.entry.js +0 -2
  210. package/dist/stripe-elements/p-7e7ad92a.entry.js.map +0 -1
  211. package/dist/stripe-elements/p-8bb4212c.entry.js +0 -2
  212. package/dist/stripe-elements/p-8bb4212c.entry.js.map +0 -1
  213. package/dist/stripe-elements/p-9aee2b6b.entry.js +0 -2
  214. package/dist/stripe-elements/p-9aee2b6b.entry.js.map +0 -1
  215. package/dist/stripe-elements/p-BHDCxQOb.js +0 -2
  216. package/dist/stripe-elements/p-BHDCxQOb.js.map +0 -1
  217. package/dist/stripe-elements/p-DI2vmGaI.js +0 -2
  218. package/dist/stripe-elements/p-DI2vmGaI.js.map +0 -1
  219. package/dist/stripe-elements/p-DJwTOfxZ.js +0 -3
  220. package/dist/stripe-elements/p-DJwTOfxZ.js.map +0 -1
  221. package/dist/stripe-elements/p-DQuL1Twl.js.map +0 -1
  222. package/dist/stripe-elements/p-XRfh5Wrs.js.map +0 -1
  223. package/dist/stripe-elements/p-ba251393.entry.js +0 -2
  224. package/dist/stripe-elements/p-ba251393.entry.js.map +0 -1
  225. package/dist/stripe-elements/p-c649edfc.entry.js +0 -2
  226. package/dist/stripe-elements/p-c649edfc.entry.js.map +0 -1
  227. package/dist/stripe-elements/p-e8bb43ae.entry.js +0 -2
  228. package/dist/stripe-elements/p-e8bb43ae.entry.js.map +0 -1
  229. package/dist/stripe-elements/stripe-address-element.entry.esm.js.map +0 -1
  230. package/dist/stripe-elements/stripe-card-element-modal.entry.esm.js.map +0 -1
  231. package/dist/stripe-elements/stripe-card-element.stripe-modal.entry.esm.js.map +0 -1
  232. package/dist/stripe-elements/stripe-currency-selector.entry.esm.js.map +0 -1
  233. package/dist/stripe-elements/stripe-elements.esm.js.map +0 -1
  234. package/dist/stripe-elements/stripe-express-checkout-element.entry.esm.js.map +0 -1
  235. package/dist/stripe-elements/stripe-link-authentication-element.entry.esm.js.map +0 -1
  236. package/dist/stripe-elements/stripe-payment-element.entry.esm.js.map +0 -1
  237. package/dist/stripe-elements/stripe-payment-request-button.entry.esm.js.map +0 -1
@@ -2,7 +2,7 @@ import { h } from "@stencil/core";
2
2
  import { checkPlatform } from "../../utils/utils";
3
3
  import { i18n } from "../../utils/i18n";
4
4
  import { serviceFactory } from "../../services/factory";
5
- import { StripeAPIError } from "../../utils/error";
5
+ import { confirmCheckoutSession, confirmPaymentOrSetup, isSubmitButtonDisabled, buildSubmitEventProps } from "./stripe-payment-element.helpers";
6
6
  export class StripePaymentElement {
7
7
  /**
8
8
  * Get Stripe.js, and initialize elements
@@ -19,26 +19,14 @@ export class StripePaymentElement {
19
19
  * ```
20
20
  */
21
21
  async initStripe(publishableKey, options) {
22
+ const generation = ++this.initGeneration;
22
23
  await this.stripeService.initialize(publishableKey, {
23
24
  stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
24
25
  applicationName: this.applicationName,
26
+ // Payment Element needs the client secret when the Elements group is created
27
+ clientSecret: this.intentClientSecret,
25
28
  });
26
- // If already successfully loaded, initialize elements immediately
27
- if (this.stripeService.state.loadStripeStatus === 'success') {
28
- await this.initElement();
29
- this.stripeLoadedEventHandler();
30
- }
31
- else {
32
- // Otherwise, wait for successful load
33
- const unsubscribe = this.stripeService.onChange('loadStripeStatus', async (newState) => {
34
- if (newState !== 'success') {
35
- return;
36
- }
37
- await this.initElement();
38
- this.stripeLoadedEventHandler();
39
- unsubscribe(); // Clean up listener after first success
40
- });
41
- }
29
+ await this.mountWhenLoaded(generation);
42
30
  }
43
31
  /**
44
32
  * Get Stripe.js and initialize with Checkout Session mode
@@ -60,27 +48,13 @@ export class StripePaymentElement {
60
48
  * ```
61
49
  */
62
50
  async initStripeWithCheckoutSession(publishableKey, checkoutSessionClientSecret, options) {
51
+ const generation = ++this.initGeneration;
63
52
  await this.stripeService.initializeWithCheckoutSession(publishableKey, checkoutSessionClientSecret, {
64
53
  stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
65
54
  applicationName: this.applicationName,
66
55
  elementsOptions: options === null || options === void 0 ? void 0 : options.elementsOptions,
67
56
  });
68
- // If already successfully loaded, initialize elements immediately
69
- if (this.stripeService.state.loadStripeStatus === 'success') {
70
- await this.initElement();
71
- this.stripeLoadedEventHandler();
72
- }
73
- else {
74
- // Otherwise, wait for successful load
75
- const unsubscribe = this.stripeService.onChange('loadStripeStatus', async (newState) => {
76
- if (newState !== 'success') {
77
- return;
78
- }
79
- await this.initElement();
80
- this.stripeLoadedEventHandler();
81
- unsubscribe(); // Clean up listener after first success
82
- });
83
- }
57
+ await this.mountWhenLoaded(generation);
84
58
  }
85
59
  /**
86
60
  * Update the form submit progress
@@ -121,23 +95,37 @@ export class StripePaymentElement {
121
95
  updatePublishableKey(publishableKey) {
122
96
  const options = {};
123
97
  options.stripeAccount = this.stripeService.state.stripeAccount;
124
- const hasOptionValue = Object.values(options).filter(Boolean).length > 0;
98
+ const hasOptionValue = Object.values(options).filter(value => value != null && value !== '').length > 0;
99
+ if (this.hasCheckoutSessionClientSecret()) {
100
+ this.initStripeWithCheckoutSession(publishableKey, this.checkoutSessionClientSecret, { stripeAccount: options.stripeAccount });
101
+ return;
102
+ }
125
103
  this.initStripe(publishableKey, hasOptionValue ? options : undefined);
126
104
  }
127
105
  updateStripeAccountId(stripeAccount) {
106
+ if (this.hasCheckoutSessionClientSecret()) {
107
+ this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey, this.checkoutSessionClientSecret, { stripeAccount });
108
+ return;
109
+ }
128
110
  this.initStripe(this.stripeService.state.publishableKey, {
129
111
  stripeAccount: stripeAccount,
130
112
  });
131
113
  }
132
114
  async updateIntentClientSecret() {
133
- // Re-initialize the payment element when client secret changes
134
- if (this.stripeService.state.loadStripeStatus === 'success') {
135
- await this.initElement();
115
+ // Checkout Session mode takes precedence (same rule as startStripe); an intent secret must not switch the mode
116
+ if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
117
+ return;
136
118
  }
119
+ // The Elements group is bound to its client secret, so it has to be recreated when the secret changes
120
+ const { publishableKey, stripeAccount } = this.stripeService.state;
121
+ if (publishableKey == null || publishableKey === '') {
122
+ return;
123
+ }
124
+ await this.initStripe(publishableKey, { stripeAccount });
137
125
  }
138
126
  async updateCheckoutSessionClientSecret(newValue) {
139
127
  // Re-initialize with checkout session when client secret changes
140
- if (this.publishableKey && newValue) {
128
+ if (this.publishableKey != null && this.publishableKey !== '' && newValue != null && newValue !== '') {
141
129
  await this.initStripeWithCheckoutSession(this.publishableKey, newValue, {
142
130
  stripeAccount: this.stripeAccount,
143
131
  });
@@ -147,42 +135,31 @@ export class StripePaymentElement {
147
135
  const event = {
148
136
  stripe: this.stripeService.getStripe(),
149
137
  };
150
- if (this.stripeDidLoaded) {
138
+ if (this.stripeDidLoaded != null) {
151
139
  this.stripeDidLoaded(event);
152
140
  }
153
141
  this.stripeLoaded.emit(event);
154
142
  }
155
143
  async formSubmitEventHandler() {
156
144
  const stripe = this.stripeService.getStripe();
157
- const isCheckoutSession = this.stripeService.state.isCheckoutSession;
158
- if (!stripe) {
145
+ const isCheckoutSession = this.stripeService.state.isCheckoutSession === true;
146
+ if (stripe == null) {
159
147
  console.error('Stripe not properly initialized');
160
148
  return;
161
149
  }
162
- const eventData = {
150
+ const result = buildSubmitEventProps({
163
151
  stripe,
164
- };
165
- if (isCheckoutSession) {
166
- // Checkout Session mode
167
- const checkout = this.stripeService.getCheckout();
168
- if (!checkout) {
169
- console.error('Checkout not properly initialized');
170
- return;
171
- }
172
- eventData.checkout = checkout;
173
- eventData.checkoutSessionClientSecret = this.checkoutSessionClientSecret;
174
- }
175
- else {
176
- // Payment Intent / Setup Intent mode
177
- const elements = this.stripeService.getElements();
178
- if (!elements) {
179
- console.error('Elements not properly initialized');
180
- return;
181
- }
182
- eventData.elements = elements;
183
- eventData.intentClientSecret = this.intentClientSecret;
152
+ isCheckoutSession,
153
+ checkout: this.stripeService.getCheckout(),
154
+ checkoutSessionClientSecret: this.checkoutSessionClientSecret,
155
+ elements: this.stripeService.getElements(),
156
+ intentClientSecret: this.intentClientSecret,
157
+ });
158
+ if ('error' in result) {
159
+ console.error(result.error);
160
+ return;
184
161
  }
185
- this.formSubmit.emit(eventData);
162
+ this.formSubmit.emit(result.props);
186
163
  }
187
164
  async defaultFormSubmitResultHandler(result) {
188
165
  this.defaultFormSubmitResult.emit(result);
@@ -191,12 +168,20 @@ export class StripePaymentElement {
191
168
  this.checkoutSessionConfirmResult.emit(result);
192
169
  }
193
170
  componentWillRender() {
194
- if (!this.stripeService.state.publishableKey) {
171
+ const { publishableKey } = this.stripeService.state;
172
+ if (publishableKey == null || publishableKey === '') {
195
173
  return;
196
174
  }
197
175
  if (['success', 'loading'].includes(this.stripeService.state.loadStripeStatus)) {
198
176
  return;
199
177
  }
178
+ // Retry in the same mode as the initial start
179
+ if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
180
+ this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey, this.checkoutSessionClientSecret, {
181
+ stripeAccount: this.stripeService.state.stripeAccount,
182
+ });
183
+ return;
184
+ }
200
185
  this.initStripe(this.stripeService.state.publishableKey, {
201
186
  stripeAccount: this.stripeService.state.stripeAccount,
202
187
  });
@@ -211,30 +196,9 @@ export class StripePaymentElement {
211
196
  async defaultFormSubmitAction(event, { stripe, elements }) {
212
197
  event.preventDefault();
213
198
  try {
214
- const { intentType } = this;
215
199
  // Get current page URL for return_url
216
200
  const returnUrl = window.location.href;
217
- const result = await (() => {
218
- if (intentType === 'payment') {
219
- return stripe.confirmPayment({
220
- elements,
221
- confirmParams: {
222
- return_url: returnUrl,
223
- },
224
- redirect: 'if_required',
225
- });
226
- }
227
- return stripe.confirmSetup({
228
- elements,
229
- confirmParams: {
230
- return_url: returnUrl,
231
- },
232
- redirect: 'if_required',
233
- });
234
- })();
235
- if (result.error) {
236
- throw new StripeAPIError(result.error);
237
- }
201
+ const result = await confirmPaymentOrSetup(stripe, elements, this.intentType, returnUrl);
238
202
  this.defaultFormSubmitResultHandler(result);
239
203
  }
240
204
  catch (e) {
@@ -250,38 +214,11 @@ export class StripePaymentElement {
250
214
  * @param checkout - The Stripe Checkout instance
251
215
  */
252
216
  async checkoutSessionFormSubmitAction(event, checkout) {
253
- var _a;
254
217
  event.preventDefault();
255
218
  try {
256
- // Load actions from the checkout session
257
- const loadActionsResult = await checkout.loadActions();
258
- if (loadActionsResult.type === 'error') {
259
- // Create a StripeError-compatible object from the Checkout Session error
260
- const stripeError = {
261
- type: 'api_error',
262
- code: loadActionsResult.error.code || 'checkout_session_error',
263
- message: loadActionsResult.error.message,
264
- };
265
- throw new StripeAPIError(stripeError);
266
- }
267
- const { actions } = loadActionsResult;
268
219
  // Get current page URL for return_url
269
220
  const returnUrl = window.location.href;
270
- // Confirm the payment using checkout session actions
271
- const result = await actions.confirm({
272
- returnUrl,
273
- redirect: 'if_required',
274
- });
275
- if (result.type === 'error') {
276
- // Create a StripeError-compatible object from the confirm error
277
- const stripeError = {
278
- type: 'card_error',
279
- code: result.error.code || 'payment_failed',
280
- message: result.error.message,
281
- decline_code: result.error.code === 'paymentFailed' ? (_a = result.error.paymentFailed) === null || _a === void 0 ? void 0 : _a.declineCode : undefined,
282
- };
283
- throw new StripeAPIError(stripeError);
284
- }
221
+ const result = await confirmCheckoutSession(checkout, returnUrl);
285
222
  this.checkoutSessionConfirmResultHandler(result);
286
223
  }
287
224
  catch (e) {
@@ -291,6 +228,8 @@ export class StripePaymentElement {
291
228
  }
292
229
  }
293
230
  constructor() {
231
+ // Incremented on every initStripe call so that a superseded call stops after its awaits
232
+ this.initGeneration = 0;
294
233
  /**
295
234
  * Default submit handle type.
296
235
  * If you want to use `setupIntent`, should update this attribute.
@@ -332,11 +271,71 @@ export class StripePaymentElement {
332
271
  // Dependency Injection via factory
333
272
  this.stripeService = serviceFactory.createStripeService();
334
273
  this.paymentElementManager = serviceFactory.createPaymentElementManager(this.stripeService);
335
- if (this.publishableKey) {
336
- this.initStripe(this.publishableKey, {
274
+ }
275
+ /**
276
+ * Props are not yet populated inside the constructor when the component is registered via
277
+ * the custom-elements build (`dist/components/*`), so initialization that depends on them
278
+ * must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
279
+ */
280
+ componentWillLoad() {
281
+ this.startStripe();
282
+ }
283
+ /**
284
+ * Mount the element once Stripe.js has loaded, unless a newer init call (of either mode) has superseded this one.
285
+ * @param generation - The value of `initGeneration` taken when the init call started
286
+ */
287
+ async mountWhenLoaded(generation) {
288
+ // A newer init call supersedes this one
289
+ if (generation !== this.initGeneration) {
290
+ return;
291
+ }
292
+ // If already successfully loaded, initialize elements immediately
293
+ if (this.stripeService.state.loadStripeStatus === 'success') {
294
+ await this.initElement();
295
+ if (generation !== this.initGeneration) {
296
+ return;
297
+ }
298
+ this.stripeLoadedEventHandler();
299
+ return;
300
+ }
301
+ // Otherwise, wait for successful load
302
+ const unsubscribe = this.stripeService.onChange('loadStripeStatus', async (newState) => {
303
+ if (generation !== this.initGeneration) {
304
+ unsubscribe();
305
+ return;
306
+ }
307
+ if (newState !== 'success') {
308
+ return;
309
+ }
310
+ await this.initElement();
311
+ if (generation !== this.initGeneration) {
312
+ unsubscribe();
313
+ return;
314
+ }
315
+ this.stripeLoadedEventHandler();
316
+ unsubscribe(); // Clean up listener after first success
317
+ });
318
+ }
319
+ hasCheckoutSessionClientSecret() {
320
+ return this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '';
321
+ }
322
+ /**
323
+ * Start Stripe.js in the mode that matches the given props.
324
+ * Checkout Session mode when `checkoutSessionClientSecret` is set, PaymentIntent / SetupIntent mode otherwise.
325
+ */
326
+ startStripe() {
327
+ if (this.publishableKey == null || this.publishableKey === '') {
328
+ return;
329
+ }
330
+ if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
331
+ this.initStripeWithCheckoutSession(this.publishableKey, this.checkoutSessionClientSecret, {
337
332
  stripeAccount: this.stripeAccount,
338
333
  });
334
+ return;
339
335
  }
336
+ this.initStripe(this.publishableKey, {
337
+ stripeAccount: this.stripeAccount,
338
+ });
340
339
  }
341
340
  /**
342
341
  * Initialize Component using Stripe Element
@@ -346,57 +345,47 @@ export class StripePaymentElement {
346
345
  await this.paymentElementManager.initialize(this.el);
347
346
  // Add form submit listener scoped to this component instance
348
347
  const formElement = this.el.querySelector('#stripe-payment-element');
349
- if (!formElement) {
348
+ if (formElement == null) {
350
349
  console.error('Form element #stripe-payment-element not found');
351
350
  return;
352
351
  }
353
352
  // Remove existing listener if present to prevent duplicates
354
- if (this._submitHandler) {
353
+ if (this._submitHandler != null) {
355
354
  formElement.removeEventListener('submit', this._submitHandler);
356
355
  }
357
356
  // Create and store the submit handler
358
357
  this._submitHandler = async (e) => {
359
358
  const stripe = this.stripeService.getStripe();
360
- const isCheckoutSession = this.stripeService.state.isCheckoutSession;
361
- if (!stripe) {
359
+ const isCheckoutSession = this.stripeService.state.isCheckoutSession === true;
360
+ if (stripe == null) {
362
361
  console.error('Stripe not properly initialized');
363
362
  return;
364
363
  }
365
- // Build submit event props based on mode
366
- const submitEventProps = {
364
+ // Build submit event props based on mode (shared with formSubmitEventHandler)
365
+ const result = buildSubmitEventProps({
367
366
  stripe,
368
- };
369
- if (isCheckoutSession) {
370
- // Checkout Session mode
371
- const checkout = this.stripeService.getCheckout();
372
- if (!checkout) {
373
- console.error('Checkout not properly initialized');
374
- return;
375
- }
376
- submitEventProps.checkout = checkout;
377
- submitEventProps.checkoutSessionClientSecret = this.checkoutSessionClientSecret;
378
- }
379
- else {
380
- // Payment Intent / Setup Intent mode
381
- const elements = this.stripeService.getElements();
382
- if (!elements) {
383
- console.error('Elements not properly initialized');
384
- return;
385
- }
386
- submitEventProps.elements = elements;
387
- submitEventProps.intentClientSecret = this.intentClientSecret;
367
+ isCheckoutSession,
368
+ checkout: this.stripeService.getCheckout(),
369
+ checkoutSessionClientSecret: this.checkoutSessionClientSecret,
370
+ elements: this.stripeService.getElements(),
371
+ intentClientSecret: this.intentClientSecret,
372
+ });
373
+ if ('error' in result) {
374
+ console.error(result.error);
375
+ return;
388
376
  }
377
+ const submitEventProps = result.props;
389
378
  this.progress = 'loading';
390
379
  try {
391
- if (this.handleSubmit) {
380
+ if (this.handleSubmit != null) {
392
381
  await this.handleSubmit(e, submitEventProps);
393
382
  }
394
383
  else if (this.shouldUseDefaultFormSubmitAction === true) {
395
- if (isCheckoutSession && submitEventProps.checkout) {
384
+ if (isCheckoutSession && submitEventProps.checkout != null) {
396
385
  // Use Checkout Session confirmation
397
386
  await this.checkoutSessionFormSubmitAction(e, submitEventProps.checkout);
398
387
  }
399
- else if (this.intentClientSecret) {
388
+ else if (this.intentClientSecret != null && this.intentClientSecret !== '') {
400
389
  // Use Payment Intent / Setup Intent confirmation
401
390
  await this.defaultFormSubmitAction(e, submitEventProps);
402
391
  }
@@ -408,7 +397,7 @@ export class StripePaymentElement {
408
397
  e.preventDefault();
409
398
  }
410
399
  await this.formSubmitEventHandler();
411
- if (this.handleSubmit || this.shouldUseDefaultFormSubmitAction === true) {
400
+ if (this.handleSubmit != null || this.shouldUseDefaultFormSubmitAction === true) {
412
401
  this.progress = 'success';
413
402
  }
414
403
  }
@@ -426,9 +415,9 @@ export class StripePaymentElement {
426
415
  disconnectedCallback() {
427
416
  this.paymentElementManager.unmount();
428
417
  // Remove event listener to prevent memory leaks
429
- if (this._submitHandler) {
418
+ if (this._submitHandler != null) {
430
419
  const formElement = this.el.querySelector('#stripe-payment-element');
431
- if (formElement) {
420
+ if (formElement != null) {
432
421
  formElement.removeEventListener('submit', this._submitHandler);
433
422
  }
434
423
  }
@@ -439,12 +428,18 @@ export class StripePaymentElement {
439
428
  if (loadStripeStatus === 'failure') {
440
429
  return h("p", null, i18n.t('Failed to load Stripe'));
441
430
  }
442
- // Determine if button should be disabled
443
- // For Checkout Session mode: check if checkout is initialized (loadStripeStatus === 'success')
444
- // For Payment Intent mode: check if intentClientSecret is set
445
- const hasValidSecret = isCheckoutSession ? loadStripeStatus === 'success' : !!this.intentClientSecret;
446
- const disabled = this.progress === 'loading' || !hasValidSecret;
447
- return (h("div", { class: "stripe-payment-sheet-wrap" }, h("form", { id: "stripe-payment-element" }, h("div", { class: "stripe-heading" }, i18n.t(this.sheetTitle)), h("div", null, h("div", { class: "stripe-section-title" }, i18n.t('Payment information'))), h("div", { class: "payment-info visible" }, h("div", { id: "payment-element" })), h("div", { id: "payment-errors", class: "stripe-element-errors" }, errorMessage), h("div", { style: { marginTop: '32px' } }, h("button", { type: "submit", disabled: disabled }, this.progress === 'loading' ? i18n.t('Loading') : i18n.t(this.buttonLabel))))));
431
+ // Determine if button should be disabled (see isSubmitButtonDisabled helper for mode-specific rules)
432
+ const disabled = isSubmitButtonDisabled({
433
+ progress: this.progress,
434
+ isCheckoutSession: isCheckoutSession === true,
435
+ loadStripeStatus,
436
+ intentClientSecret: this.intentClientSecret,
437
+ });
438
+ return (
439
+ // NOTE: `stripe-payment-sheet-wrap` is a legacy CSS class kept for backward compatibility.
440
+ // It is a leftover from a former component name but is part of the public DOM contract,
441
+ // so external stylesheets may target it. Keep it in the rendered output and the .scss.
442
+ h("div", { class: "stripe-payment-sheet-wrap" }, h("form", { id: "stripe-payment-element" }, h("div", { class: "stripe-heading" }, i18n.t(this.sheetTitle)), h("div", null, h("div", { class: "stripe-section-title" }, i18n.t('Payment information'))), h("div", { class: "payment-info visible" }, h("div", { id: "payment-element" })), h("div", { id: "payment-errors", class: "stripe-element-errors" }, errorMessage), h("div", { style: { marginTop: '32px' } }, h("button", { type: "submit", disabled: disabled }, this.progress === 'loading' ? i18n.t('Loading') : i18n.t(this.buttonLabel))))));
448
443
  }
449
444
  static get is() { return "stripe-payment-element"; }
450
445
  static get originalStyleUrls() {
@@ -469,7 +464,8 @@ export class StripePaymentElement {
469
464
  "IntentType": {
470
465
  "location": "import",
471
466
  "path": "../../interfaces",
472
- "id": "src/interfaces.ts::IntentType"
467
+ "id": "src/interfaces.ts::IntentType",
468
+ "referenceLocation": "IntentType"
473
469
  }
474
470
  }
475
471
  },
@@ -686,7 +682,8 @@ export class StripePaymentElement {
686
682
  "StripeDidLoadedHandler": {
687
683
  "location": "import",
688
684
  "path": "../../interfaces",
689
- "id": "src/interfaces.ts::StripeDidLoadedHandler"
685
+ "id": "src/interfaces.ts::StripeDidLoadedHandler",
686
+ "referenceLocation": "StripeDidLoadedHandler"
690
687
  }
691
688
  }
692
689
  },
@@ -727,7 +724,8 @@ export class StripePaymentElement {
727
724
  "StripeLoadedEvent": {
728
725
  "location": "import",
729
726
  "path": "../../interfaces",
730
- "id": "src/interfaces.ts::StripeLoadedEvent"
727
+ "id": "src/interfaces.ts::StripeLoadedEvent",
728
+ "referenceLocation": "StripeLoadedEvent"
731
729
  }
732
730
  }
733
731
  }
@@ -746,7 +744,7 @@ export class StripePaymentElement {
746
744
  },
747
745
  "complexType": {
748
746
  "original": "PaymentElementSubmitEvent",
749
- "resolved": "{ stripe: Stripe; elements?: StripeElements; intentClientSecret?: string; checkout?: StripeCheckout; checkoutSessionClientSecret?: string; }",
747
+ "resolved": "{ stripe: Stripe; elements?: StripeElements; intentClientSecret?: string; checkout?: StripeCheckoutElementsSdk; checkoutSessionClientSecret?: string; }",
750
748
  "references": {
751
749
  "PaymentElementSubmitEvent": {
752
750
  "location": "local",
@@ -775,7 +773,8 @@ export class StripePaymentElement {
775
773
  "DefaultFormSubmitResult": {
776
774
  "location": "import",
777
775
  "path": "../../interfaces",
778
- "id": "src/interfaces.ts::DefaultFormSubmitResult"
776
+ "id": "src/interfaces.ts::DefaultFormSubmitResult",
777
+ "referenceLocation": "DefaultFormSubmitResult"
779
778
  }
780
779
  }
781
780
  }
@@ -827,7 +826,8 @@ export class StripePaymentElement {
827
826
  "InitStripeOptions": {
828
827
  "location": "import",
829
828
  "path": "../../interfaces",
830
- "id": "src/interfaces.ts::InitStripeOptions"
829
+ "id": "src/interfaces.ts::InitStripeOptions",
830
+ "referenceLocation": "InitStripeOptions"
831
831
  }
832
832
  },
833
833
  "return": "Promise<void>"
@@ -908,7 +908,8 @@ export class StripePaymentElement {
908
908
  "ProgressStatus": {
909
909
  "location": "import",
910
910
  "path": "../../interfaces",
911
- "id": "src/interfaces.ts::ProgressStatus"
911
+ "id": "src/interfaces.ts::ProgressStatus",
912
+ "referenceLocation": "ProgressStatus"
912
913
  }
913
914
  },
914
915
  "return": "Promise<this>"
@@ -976,4 +977,3 @@ export class StripePaymentElement {
976
977
  }];
977
978
  }
978
979
  }
979
- //# sourceMappingURL=stripe-payment-element.js.map