stripe-pwa-elements 4.0.0 → 4.0.2

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 (108) hide show
  1. package/dist/cjs/factory-tenFFIul.js +1200 -0
  2. package/dist/cjs/{factory-da3xAKkz.js → i18n-FhEOc8vz.js} +6 -1131
  3. package/dist/cjs/ion-icon_2.cjs.entry.js +723 -0
  4. package/dist/cjs/loader.cjs.js +1 -1
  5. package/dist/cjs/stripe-address-element.cjs.entry.js +12 -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} +15 -82
  8. package/dist/cjs/stripe-currency-selector.cjs.entry.js +11 -3
  9. package/dist/cjs/stripe-elements.cjs.js +1 -1
  10. package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +31 -5
  11. package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +11 -3
  12. package/dist/cjs/stripe-payment-element.cjs.entry.js +106 -161
  13. package/dist/cjs/stripe-payment-element.helpers-DukP33RI.js +122 -0
  14. package/dist/cjs/stripe-payment-request-button.cjs.entry.js +23 -16
  15. package/dist/cjs/stripe-payment-sheet.cjs.entry.js +506 -0
  16. package/dist/collection/collection-manifest.json +3 -2
  17. package/dist/collection/components/stripe-address-element/stripe-address-element.js +7 -0
  18. package/dist/collection/components/stripe-card-element/stripe-card-element.js +10 -2
  19. package/dist/collection/components/stripe-card-element-modal/stripe-card-element-modal.js +4 -3
  20. package/dist/collection/components/stripe-currency-selector/stripe-currency-selector.js +7 -0
  21. package/dist/collection/components/stripe-express-checkout-element/stripe-express-checkout-element.js +25 -0
  22. package/dist/collection/components/stripe-link-authentication-element/stripe-link-authentication-element.js +7 -0
  23. package/dist/collection/components/stripe-modal/stripe-modal.css +23 -1
  24. package/dist/collection/components/stripe-modal/stripe-modal.js +147 -6
  25. package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +94 -37
  26. package/dist/collection/components/stripe-payment-request-button/stripe-payment-request-button.js +17 -10
  27. package/dist/collection/components/stripe-payment-sheet/payment-sheet-state.js +179 -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 +90 -0
  30. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +544 -0
  31. package/dist/collection/services/express-checkout-element-manager.js +36 -2
  32. package/dist/collection/services/stripe-service.js +37 -5
  33. package/dist/collection/utils/focus.js +76 -0
  34. package/dist/collection/utils/i18n.js +6 -0
  35. package/dist/components/factory.js +1 -1
  36. package/dist/components/i18n.js +1 -0
  37. package/dist/components/stripe-address-element.js +1 -1
  38. package/dist/components/stripe-card-element-modal.js +1 -1
  39. package/dist/components/stripe-card-element2.js +1 -1
  40. package/dist/components/stripe-currency-selector.js +1 -1
  41. package/dist/components/stripe-express-checkout-element.js +1 -1
  42. package/dist/components/stripe-link-authentication-element.js +1 -1
  43. package/dist/components/stripe-modal2.js +1 -1
  44. package/dist/components/stripe-payment-element.helpers.js +1 -0
  45. package/dist/components/stripe-payment-element.js +1 -1
  46. package/dist/components/stripe-payment-request-button2.js +1 -1
  47. package/dist/components/stripe-payment-sheet.d.ts +11 -0
  48. package/dist/components/stripe-payment-sheet.js +1 -0
  49. package/dist/esm/factory-Cd6OGTWN.js +1198 -0
  50. package/dist/esm/{factory-DeqoYLf_.js → i18n-B6JoQetF.js} +7 -1131
  51. package/dist/esm/ion-icon_2.entry.js +720 -0
  52. package/dist/esm/loader.js +1 -1
  53. package/dist/esm/stripe-address-element.entry.js +9 -1
  54. package/dist/esm/stripe-card-element-modal.entry.js +3 -2
  55. package/dist/esm/{stripe-card-element_2.entry.js → stripe-card-element.entry.js} +13 -79
  56. package/dist/esm/stripe-currency-selector.entry.js +9 -1
  57. package/dist/esm/stripe-elements.js +1 -1
  58. package/dist/esm/stripe-express-checkout-element.entry.js +27 -1
  59. package/dist/esm/stripe-link-authentication-element.entry.js +9 -1
  60. package/dist/esm/stripe-payment-element.entry.js +98 -153
  61. package/dist/esm/stripe-payment-element.helpers-CipV87b8.js +117 -0
  62. package/dist/esm/stripe-payment-request-button.entry.js +18 -11
  63. package/dist/esm/stripe-payment-sheet.entry.js +504 -0
  64. package/dist/stripe-elements/{p-38e7b187.entry.js → p-4891edf0.entry.js} +1 -1
  65. package/dist/stripe-elements/p-5338bc5e.entry.js +1 -0
  66. package/dist/stripe-elements/p-6a9c8b7a.entry.js +1 -0
  67. package/dist/stripe-elements/p-7fe4a287.entry.js +1 -0
  68. package/dist/stripe-elements/p-915b86ed.entry.js +1 -0
  69. package/dist/stripe-elements/p-B6JoQetF.js +1 -0
  70. package/dist/stripe-elements/p-C7MQk9FK.js +1 -0
  71. package/dist/stripe-elements/p-DFAhQS0n.js +1 -0
  72. package/dist/stripe-elements/p-b06a254f.entry.js +1 -0
  73. package/dist/stripe-elements/p-b91c4fa7.entry.js +1 -0
  74. package/dist/stripe-elements/p-ba791c8f.entry.js +1 -0
  75. package/dist/stripe-elements/p-e7372ca7.entry.js +1 -0
  76. package/dist/stripe-elements/p-f892e375.entry.js +1 -0
  77. package/dist/stripe-elements/stripe-elements.esm.js +1 -1
  78. package/dist/types/components/stripe-address-element/stripe-address-element.d.ts +6 -0
  79. package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +8 -1
  80. package/dist/types/components/stripe-card-element-modal/stripe-card-element-modal.d.ts +2 -1
  81. package/dist/types/components/stripe-currency-selector/stripe-currency-selector.d.ts +6 -0
  82. package/dist/types/components/stripe-express-checkout-element/stripe-express-checkout-element.d.ts +11 -0
  83. package/dist/types/components/stripe-link-authentication-element/stripe-link-authentication-element.d.ts +6 -0
  84. package/dist/types/components/stripe-modal/stripe-modal.d.ts +44 -0
  85. package/dist/types/components/stripe-payment-element/stripe-payment-element.d.ts +18 -0
  86. package/dist/types/components/stripe-payment-request-button/stripe-payment-request-button.d.ts +7 -2
  87. package/dist/types/components/stripe-payment-sheet/payment-sheet-state.d.ts +104 -0
  88. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.d.ts +112 -0
  89. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.helpers.d.ts +95 -0
  90. package/dist/types/components.d.ts +169 -10
  91. package/dist/types/index.d.ts +2 -0
  92. package/dist/types/services/interfaces.d.ts +2 -0
  93. package/dist/types/services/stripe-service.d.ts +12 -3
  94. package/dist/types/utils/focus.d.ts +15 -0
  95. package/package.json +5 -3
  96. package/readme.md +46 -10
  97. package/dist/cjs/ion-icon.cjs.entry.js +0 -431
  98. package/dist/components/utils.js +0 -1
  99. package/dist/esm/ion-icon.entry.js +0 -429
  100. package/dist/stripe-elements/p--sA2m1ad.js +0 -1
  101. package/dist/stripe-elements/p-44495284.entry.js +0 -1
  102. package/dist/stripe-elements/p-4ba675fa.entry.js +0 -1
  103. package/dist/stripe-elements/p-5cf62945.entry.js +0 -1
  104. package/dist/stripe-elements/p-c24ae181.entry.js +0 -1
  105. package/dist/stripe-elements/p-d9e86451.entry.js +0 -1
  106. package/dist/stripe-elements/p-f09c86a0.entry.js +0 -1
  107. package/dist/stripe-elements/p-f64f394d.entry.js +0 -1
  108. package/dist/stripe-elements/p-f6d2425e.entry.js +0 -1
@@ -1,123 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./index-Dkb0SxZc.js');
4
- var factory = require('./factory-da3xAKkz.js');
5
- var error = require('./error-FFC4kSs5.js');
4
+ var i18n = require('./i18n-FhEOc8vz.js');
5
+ var factory = require('./factory-tenFFIul.js');
6
+ var stripePaymentElement_helpers = require('./stripe-payment-element.helpers-DukP33RI.js');
6
7
  require('./index-CYbA1N_k.js');
7
-
8
- /**
9
- * Determine whether the submit button should be disabled.
10
- * For Checkout Session mode: the checkout is ready once Stripe finished loading.
11
- * For Payment Intent / Setup Intent mode: an intent client secret must be present.
12
- * @param params progress / loading state and the current mode information
13
- * @returns true when the submit button should be disabled
14
- */
15
- const isSubmitButtonDisabled = (params) => {
16
- const { progress, isCheckoutSession, loadStripeStatus, intentClientSecret } = params;
17
- const hasValidSecret = isCheckoutSession ? loadStripeStatus === 'success' : intentClientSecret != null && intentClientSecret !== '';
18
- return progress === 'loading' || !hasValidSecret;
19
- };
20
- /**
21
- * Run the default Stripe confirmation flow for Payment Intent / Setup Intent mode.
22
- * Calls `confirmPayment` or `confirmSetup` depending on the intent type.
23
- * @param stripe the loaded Stripe.js instance
24
- * @param elements the Stripe Elements instance bound to the payment element
25
- * @param intentType the configured intent type
26
- * @param returnUrl the URL Stripe should redirect back to when required
27
- * @returns the confirmation result
28
- * @throws StripeAPIError when Stripe returns an error
29
- */
30
- const confirmPaymentOrSetup = async (stripe, elements, intentType, returnUrl) => {
31
- const result = await (() => {
32
- if (intentType === 'payment') {
33
- return stripe.confirmPayment({
34
- elements,
35
- confirmParams: {
36
- return_url: returnUrl,
37
- },
38
- redirect: 'if_required',
39
- });
40
- }
41
- return stripe.confirmSetup({
42
- elements,
43
- confirmParams: {
44
- return_url: returnUrl,
45
- },
46
- redirect: 'if_required',
47
- });
48
- })();
49
- if (result.error) {
50
- throw new error.StripeAPIError(result.error);
51
- }
52
- return result;
53
- };
54
- /**
55
- * Confirm a Checkout Session payment using the checkout actions.
56
- * @param checkout the Stripe Checkout instance
57
- * @param returnUrl the URL Stripe should redirect back to when required
58
- * @returns the confirmation result
59
- * @throws StripeAPIError when loading actions or confirming fails
60
- */
61
- const confirmCheckoutSession = async (checkout, returnUrl) => {
62
- var _a;
63
- // Load actions from the checkout session
64
- const loadActionsResult = await checkout.loadActions();
65
- if (loadActionsResult.type === 'error') {
66
- // Create a StripeError-compatible object from the Checkout Session error
67
- const stripeError = {
68
- type: 'api_error',
69
- code: loadActionsResult.error.code || 'checkout_session_error',
70
- message: loadActionsResult.error.message,
71
- };
72
- throw new error.StripeAPIError(stripeError);
73
- }
74
- const { actions } = loadActionsResult;
75
- // Confirm the payment using checkout session actions
76
- const result = await actions.confirm({
77
- returnUrl,
78
- redirect: 'if_required',
79
- });
80
- if (result.type === 'error') {
81
- // Create a StripeError-compatible object from the confirm error
82
- const stripeError = {
83
- type: 'card_error',
84
- code: result.error.code || 'payment_failed',
85
- message: result.error.message,
86
- decline_code: result.error.code === 'paymentFailed' ? (_a = result.error.paymentFailed) === null || _a === void 0 ? void 0 : _a.declineCode : undefined,
87
- };
88
- throw new error.StripeAPIError(stripeError);
89
- }
90
- return result;
91
- };
92
- /**
93
- * Resolve the mode-specific properties for a submit event.
94
- * Picks the Checkout or Elements payload depending on the active mode and
95
- * reports a descriptive error string when the required instance is missing.
96
- * @param params the resolved Stripe instances and client secrets for the current mode
97
- * @returns the submit event props, or an error message when an instance is missing
98
- */
99
- const buildSubmitEventProps = (params) => {
100
- const { stripe, isCheckoutSession, checkout, checkoutSessionClientSecret, elements, intentClientSecret } = params;
101
- const props = {
102
- stripe,
103
- };
104
- if (isCheckoutSession) {
105
- // Checkout Session mode
106
- if (checkout == null) {
107
- return { error: 'Checkout not properly initialized' };
108
- }
109
- props.checkout = checkout;
110
- props.checkoutSessionClientSecret = checkoutSessionClientSecret;
111
- return { props };
112
- }
113
- // Payment Intent / Setup Intent mode
114
- if (elements == null) {
115
- return { error: 'Elements not properly initialized' };
116
- }
117
- props.elements = elements;
118
- props.intentClientSecret = intentClientSecret;
119
- return { props };
120
- };
8
+ require('./error-FFC4kSs5.js');
121
9
 
122
10
  const stripePaymentElementCss = () => `:root{--color-label:#565656;--color-placeholder:#acacac;--color-heading-text:#333;--color-text-error:#ef4444;--color-input-border:#e4e4e6;--color-input-border-shadow:rgba(228, 228, 230, 0.6);--color-button-text:rgba(255, 255, 255, 0.95);--color-button-text-disabled:rgba(255, 255, 255, 0.4);--color-primary:#0074d4}.stripe-payment-sheet-wrap{box-sizing:border-box}.stripe-payment-sheet-wrap *:where(:not(iframe,canvas,img,svg,video):not(svg *)){all:unset;display:revert;background:none;border:none;font-family:"Roboto", sans-serif;box-sizing:border-box}.stripe-payment-sheet-wrap button{cursor:pointer}.stripe-payment-sheet-wrap{display:block;width:100%;background:#fff;padding:32px 16px}.stripe-payment-sheet-wrap .StripeElement{padding:8px 16px;min-height:64px;border-radius:6px;display:flex;justify-content:center;align-items:center}.stripe-payment-sheet-wrap .StripeElement>.__PrivateStripeElement{width:100%}.stripe-payment-sheet-wrap .stripe-heading{font-size:24px;font-weight:bold;color:var(--color-heading-text);margin-bottom:24px}.stripe-payment-sheet-wrap .stripe-section-title{font-size:14px;font-weight:bold;color:var(--color-label);margin-bottom:8px}.stripe-payment-sheet-wrap .payment-info{margin-top:8px}.stripe-payment-sheet-wrap .stripe-element-errors{margin-top:8px;font-size:14px;color:var(--color-text-error)}.stripe-payment-sheet-wrap button{display:block;color:var(--color-button-text);background-color:var(--color-primary);width:100%;text-align:center;padding:16px 16px;font-size:18px;border-radius:6px;min-height:42px}.stripe-payment-sheet-wrap button:disabled{color:var(--color-button-text-disabled)}`;
123
11
 
@@ -137,26 +25,14 @@ const StripePaymentElement = class {
137
25
  * ```
138
26
  */
139
27
  async initStripe(publishableKey, options) {
28
+ const generation = ++this.initGeneration;
140
29
  await this.stripeService.initialize(publishableKey, {
141
30
  stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
142
31
  applicationName: this.applicationName,
32
+ // Payment Element needs the client secret when the Elements group is created
33
+ clientSecret: this.intentClientSecret,
143
34
  });
144
- // If already successfully loaded, initialize elements immediately
145
- if (this.stripeService.state.loadStripeStatus === 'success') {
146
- await this.initElement();
147
- this.stripeLoadedEventHandler();
148
- }
149
- else {
150
- // Otherwise, wait for successful load
151
- const unsubscribe = this.stripeService.onChange('loadStripeStatus', async (newState) => {
152
- if (newState !== 'success') {
153
- return;
154
- }
155
- await this.initElement();
156
- this.stripeLoadedEventHandler();
157
- unsubscribe(); // Clean up listener after first success
158
- });
159
- }
35
+ await this.mountWhenLoaded(generation);
160
36
  }
161
37
  /**
162
38
  * Get Stripe.js and initialize with Checkout Session mode
@@ -178,27 +54,13 @@ const StripePaymentElement = class {
178
54
  * ```
179
55
  */
180
56
  async initStripeWithCheckoutSession(publishableKey, checkoutSessionClientSecret, options) {
57
+ const generation = ++this.initGeneration;
181
58
  await this.stripeService.initializeWithCheckoutSession(publishableKey, checkoutSessionClientSecret, {
182
59
  stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
183
60
  applicationName: this.applicationName,
184
61
  elementsOptions: options === null || options === void 0 ? void 0 : options.elementsOptions,
185
62
  });
186
- // If already successfully loaded, initialize elements immediately
187
- if (this.stripeService.state.loadStripeStatus === 'success') {
188
- await this.initElement();
189
- this.stripeLoadedEventHandler();
190
- }
191
- else {
192
- // Otherwise, wait for successful load
193
- const unsubscribe = this.stripeService.onChange('loadStripeStatus', async (newState) => {
194
- if (newState !== 'success') {
195
- return;
196
- }
197
- await this.initElement();
198
- this.stripeLoadedEventHandler();
199
- unsubscribe(); // Clean up listener after first success
200
- });
201
- }
63
+ await this.mountWhenLoaded(generation);
202
64
  }
203
65
  /**
204
66
  * Update the form submit progress
@@ -240,18 +102,32 @@ const StripePaymentElement = class {
240
102
  const options = {};
241
103
  options.stripeAccount = this.stripeService.state.stripeAccount;
242
104
  const hasOptionValue = Object.values(options).filter(value => value != null && value !== '').length > 0;
105
+ if (this.hasCheckoutSessionClientSecret()) {
106
+ this.initStripeWithCheckoutSession(publishableKey, this.checkoutSessionClientSecret, { stripeAccount: options.stripeAccount });
107
+ return;
108
+ }
243
109
  this.initStripe(publishableKey, hasOptionValue ? options : undefined);
244
110
  }
245
111
  updateStripeAccountId(stripeAccount) {
112
+ if (this.hasCheckoutSessionClientSecret()) {
113
+ this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey, this.checkoutSessionClientSecret, { stripeAccount });
114
+ return;
115
+ }
246
116
  this.initStripe(this.stripeService.state.publishableKey, {
247
117
  stripeAccount: stripeAccount,
248
118
  });
249
119
  }
250
120
  async updateIntentClientSecret() {
251
- // Re-initialize the payment element when client secret changes
252
- if (this.stripeService.state.loadStripeStatus === 'success') {
253
- await this.initElement();
121
+ // Checkout Session mode takes precedence (same rule as startStripe); an intent secret must not switch the mode
122
+ if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
123
+ return;
254
124
  }
125
+ // The Elements group is bound to its client secret, so it has to be recreated when the secret changes
126
+ const { publishableKey, stripeAccount } = this.stripeService.state;
127
+ if (publishableKey == null || publishableKey === '') {
128
+ return;
129
+ }
130
+ await this.initStripe(publishableKey, { stripeAccount });
255
131
  }
256
132
  async updateCheckoutSessionClientSecret(newValue) {
257
133
  // Re-initialize with checkout session when client secret changes
@@ -277,7 +153,7 @@ const StripePaymentElement = class {
277
153
  console.error('Stripe not properly initialized');
278
154
  return;
279
155
  }
280
- const result = buildSubmitEventProps({
156
+ const result = stripePaymentElement_helpers.buildSubmitEventProps({
281
157
  stripe,
282
158
  isCheckoutSession,
283
159
  checkout: this.stripeService.getCheckout(),
@@ -305,6 +181,13 @@ const StripePaymentElement = class {
305
181
  if (['success', 'loading'].includes(this.stripeService.state.loadStripeStatus)) {
306
182
  return;
307
183
  }
184
+ // Retry in the same mode as the initial start
185
+ if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
186
+ this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey, this.checkoutSessionClientSecret, {
187
+ stripeAccount: this.stripeService.state.stripeAccount,
188
+ });
189
+ return;
190
+ }
308
191
  this.initStripe(this.stripeService.state.publishableKey, {
309
192
  stripeAccount: this.stripeService.state.stripeAccount,
310
193
  });
@@ -321,7 +204,7 @@ const StripePaymentElement = class {
321
204
  try {
322
205
  // Get current page URL for return_url
323
206
  const returnUrl = window.location.href;
324
- const result = await confirmPaymentOrSetup(stripe, elements, this.intentType, returnUrl);
207
+ const result = await stripePaymentElement_helpers.confirmPaymentOrSetup(stripe, elements, this.intentType, returnUrl);
325
208
  this.defaultFormSubmitResultHandler(result);
326
209
  }
327
210
  catch (e) {
@@ -341,7 +224,7 @@ const StripePaymentElement = class {
341
224
  try {
342
225
  // Get current page URL for return_url
343
226
  const returnUrl = window.location.href;
344
- const result = await confirmCheckoutSession(checkout, returnUrl);
227
+ const result = await stripePaymentElement_helpers.confirmCheckoutSession(checkout, returnUrl);
345
228
  this.checkoutSessionConfirmResultHandler(result);
346
229
  }
347
230
  catch (e) {
@@ -356,6 +239,8 @@ const StripePaymentElement = class {
356
239
  this.formSubmit = index.createEvent(this, "formSubmit", 7);
357
240
  this.defaultFormSubmitResult = index.createEvent(this, "defaultFormSubmitResult", 7);
358
241
  this.checkoutSessionConfirmResult = index.createEvent(this, "checkoutSessionConfirmResult", 7);
242
+ // Incremented on every initStripe call so that a superseded call stops after its awaits
243
+ this.initGeneration = 0;
359
244
  /**
360
245
  * Default submit handle type.
361
246
  * If you want to use `setupIntent`, should update this attribute.
@@ -397,11 +282,71 @@ const StripePaymentElement = class {
397
282
  // Dependency Injection via factory
398
283
  this.stripeService = factory.serviceFactory.createStripeService();
399
284
  this.paymentElementManager = factory.serviceFactory.createPaymentElementManager(this.stripeService);
400
- if (this.publishableKey != null && this.publishableKey !== '') {
401
- this.initStripe(this.publishableKey, {
285
+ }
286
+ /**
287
+ * Props are not yet populated inside the constructor when the component is registered via
288
+ * the custom-elements build (`dist/components/*`), so initialization that depends on them
289
+ * must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
290
+ */
291
+ componentWillLoad() {
292
+ this.startStripe();
293
+ }
294
+ /**
295
+ * Mount the element once Stripe.js has loaded, unless a newer init call (of either mode) has superseded this one.
296
+ * @param generation - The value of `initGeneration` taken when the init call started
297
+ */
298
+ async mountWhenLoaded(generation) {
299
+ // A newer init call supersedes this one
300
+ if (generation !== this.initGeneration) {
301
+ return;
302
+ }
303
+ // If already successfully loaded, initialize elements immediately
304
+ if (this.stripeService.state.loadStripeStatus === 'success') {
305
+ await this.initElement();
306
+ if (generation !== this.initGeneration) {
307
+ return;
308
+ }
309
+ this.stripeLoadedEventHandler();
310
+ return;
311
+ }
312
+ // Otherwise, wait for successful load
313
+ const unsubscribe = this.stripeService.onChange('loadStripeStatus', async (newState) => {
314
+ if (generation !== this.initGeneration) {
315
+ unsubscribe();
316
+ return;
317
+ }
318
+ if (newState !== 'success') {
319
+ return;
320
+ }
321
+ await this.initElement();
322
+ if (generation !== this.initGeneration) {
323
+ unsubscribe();
324
+ return;
325
+ }
326
+ this.stripeLoadedEventHandler();
327
+ unsubscribe(); // Clean up listener after first success
328
+ });
329
+ }
330
+ hasCheckoutSessionClientSecret() {
331
+ return this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '';
332
+ }
333
+ /**
334
+ * Start Stripe.js in the mode that matches the given props.
335
+ * Checkout Session mode when `checkoutSessionClientSecret` is set, PaymentIntent / SetupIntent mode otherwise.
336
+ */
337
+ startStripe() {
338
+ if (this.publishableKey == null || this.publishableKey === '') {
339
+ return;
340
+ }
341
+ if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
342
+ this.initStripeWithCheckoutSession(this.publishableKey, this.checkoutSessionClientSecret, {
402
343
  stripeAccount: this.stripeAccount,
403
344
  });
345
+ return;
404
346
  }
347
+ this.initStripe(this.publishableKey, {
348
+ stripeAccount: this.stripeAccount,
349
+ });
405
350
  }
406
351
  /**
407
352
  * Initialize Component using Stripe Element
@@ -428,7 +373,7 @@ const StripePaymentElement = class {
428
373
  return;
429
374
  }
430
375
  // Build submit event props based on mode (shared with formSubmitEventHandler)
431
- const result = buildSubmitEventProps({
376
+ const result = stripePaymentElement_helpers.buildSubmitEventProps({
432
377
  stripe,
433
378
  isCheckoutSession,
434
379
  checkout: this.stripeService.getCheckout(),
@@ -476,7 +421,7 @@ const StripePaymentElement = class {
476
421
  formElement.addEventListener('submit', this._submitHandler);
477
422
  }
478
423
  componentDidLoad() {
479
- this.el.classList.add(factory.checkPlatform());
424
+ this.el.classList.add(i18n.checkPlatform());
480
425
  }
481
426
  disconnectedCallback() {
482
427
  this.paymentElementManager.unmount();
@@ -492,10 +437,10 @@ const StripePaymentElement = class {
492
437
  const { loadStripeStatus, isCheckoutSession } = this.stripeService.state;
493
438
  const { errorMessage } = this.paymentElementManager.getState();
494
439
  if (loadStripeStatus === 'failure') {
495
- return index.h("p", null, factory.i18n.t('Failed to load Stripe'));
440
+ return index.h("p", null, i18n.i18n.t('Failed to load Stripe'));
496
441
  }
497
442
  // Determine if button should be disabled (see isSubmitButtonDisabled helper for mode-specific rules)
498
- const disabled = isSubmitButtonDisabled({
443
+ const disabled = stripePaymentElement_helpers.isSubmitButtonDisabled({
499
444
  progress: this.progress,
500
445
  isCheckoutSession: isCheckoutSession === true,
501
446
  loadStripeStatus,
@@ -505,7 +450,7 @@ const StripePaymentElement = class {
505
450
  // NOTE: `stripe-payment-sheet-wrap` is a legacy CSS class kept for backward compatibility.
506
451
  // It is a leftover from a former component name but is part of the public DOM contract,
507
452
  // so external stylesheets may target it. Keep it in the rendered output and the .scss.
508
- index.h("div", { class: "stripe-payment-sheet-wrap" }, index.h("form", { id: "stripe-payment-element" }, index.h("div", { class: "stripe-heading" }, factory.i18n.t(this.sheetTitle)), index.h("div", null, index.h("div", { class: "stripe-section-title" }, factory.i18n.t('Payment information'))), index.h("div", { class: "payment-info visible" }, index.h("div", { id: "payment-element" })), index.h("div", { id: "payment-errors", class: "stripe-element-errors" }, errorMessage), index.h("div", { style: { marginTop: '32px' } }, index.h("button", { type: "submit", disabled: disabled }, this.progress === 'loading' ? factory.i18n.t('Loading') : factory.i18n.t(this.buttonLabel))))));
453
+ index.h("div", { class: "stripe-payment-sheet-wrap" }, index.h("form", { id: "stripe-payment-element" }, index.h("div", { class: "stripe-heading" }, i18n.i18n.t(this.sheetTitle)), index.h("div", null, index.h("div", { class: "stripe-section-title" }, i18n.i18n.t('Payment information'))), index.h("div", { class: "payment-info visible" }, index.h("div", { id: "payment-element" })), index.h("div", { id: "payment-errors", class: "stripe-element-errors" }, errorMessage), index.h("div", { style: { marginTop: '32px' } }, index.h("button", { type: "submit", disabled: disabled }, this.progress === 'loading' ? i18n.i18n.t('Loading') : i18n.i18n.t(this.buttonLabel))))));
509
454
  }
510
455
  get el() { return index.getElement(this); }
511
456
  static get watchers() { return {
@@ -0,0 +1,122 @@
1
+ 'use strict';
2
+
3
+ var error = require('./error-FFC4kSs5.js');
4
+
5
+ /**
6
+ * Determine whether the submit button should be disabled.
7
+ * For Checkout Session mode: the checkout is ready once Stripe finished loading.
8
+ * For Payment Intent / Setup Intent mode: an intent client secret must be present.
9
+ * @param params progress / loading state and the current mode information
10
+ * @returns true when the submit button should be disabled
11
+ */
12
+ const isSubmitButtonDisabled = (params) => {
13
+ const { progress, isCheckoutSession, loadStripeStatus, intentClientSecret } = params;
14
+ const hasValidSecret = isCheckoutSession ? loadStripeStatus === 'success' : intentClientSecret != null && intentClientSecret !== '';
15
+ return progress === 'loading' || !hasValidSecret;
16
+ };
17
+ /**
18
+ * Run the default Stripe confirmation flow for Payment Intent / Setup Intent mode.
19
+ * Calls `confirmPayment` or `confirmSetup` depending on the intent type.
20
+ * @param stripe the loaded Stripe.js instance
21
+ * @param elements the Stripe Elements instance bound to the payment element
22
+ * @param intentType the configured intent type
23
+ * @param returnUrl the URL Stripe should redirect back to when required
24
+ * @returns the confirmation result
25
+ * @throws StripeAPIError when Stripe returns an error
26
+ */
27
+ const confirmPaymentOrSetup = async (stripe, elements, intentType, returnUrl) => {
28
+ const result = await (() => {
29
+ if (intentType === 'payment') {
30
+ return stripe.confirmPayment({
31
+ elements,
32
+ confirmParams: {
33
+ return_url: returnUrl,
34
+ },
35
+ redirect: 'if_required',
36
+ });
37
+ }
38
+ return stripe.confirmSetup({
39
+ elements,
40
+ confirmParams: {
41
+ return_url: returnUrl,
42
+ },
43
+ redirect: 'if_required',
44
+ });
45
+ })();
46
+ if (result.error) {
47
+ throw new error.StripeAPIError(result.error);
48
+ }
49
+ return result;
50
+ };
51
+ /**
52
+ * Confirm a Checkout Session payment using the checkout actions.
53
+ * @param checkout the Stripe Checkout instance
54
+ * @param returnUrl the URL Stripe should redirect back to when required
55
+ * @returns the confirmation result
56
+ * @throws StripeAPIError when loading actions or confirming fails
57
+ */
58
+ const confirmCheckoutSession = async (checkout, returnUrl) => {
59
+ var _a;
60
+ // Load actions from the checkout session
61
+ const loadActionsResult = await checkout.loadActions();
62
+ if (loadActionsResult.type === 'error') {
63
+ // Create a StripeError-compatible object from the Checkout Session error
64
+ const stripeError = {
65
+ type: 'api_error',
66
+ code: loadActionsResult.error.code || 'checkout_session_error',
67
+ message: loadActionsResult.error.message,
68
+ };
69
+ throw new error.StripeAPIError(stripeError);
70
+ }
71
+ const { actions } = loadActionsResult;
72
+ // Confirm the payment using checkout session actions
73
+ const result = await actions.confirm({
74
+ returnUrl,
75
+ redirect: 'if_required',
76
+ });
77
+ if (result.type === 'error') {
78
+ // Create a StripeError-compatible object from the confirm error
79
+ const stripeError = {
80
+ type: 'card_error',
81
+ code: result.error.code || 'payment_failed',
82
+ message: result.error.message,
83
+ decline_code: result.error.code === 'paymentFailed' ? (_a = result.error.paymentFailed) === null || _a === void 0 ? void 0 : _a.declineCode : undefined,
84
+ };
85
+ throw new error.StripeAPIError(stripeError);
86
+ }
87
+ return result;
88
+ };
89
+ /**
90
+ * Resolve the mode-specific properties for a submit event.
91
+ * Picks the Checkout or Elements payload depending on the active mode and
92
+ * reports a descriptive error string when the required instance is missing.
93
+ * @param params the resolved Stripe instances and client secrets for the current mode
94
+ * @returns the submit event props, or an error message when an instance is missing
95
+ */
96
+ const buildSubmitEventProps = (params) => {
97
+ const { stripe, isCheckoutSession, checkout, checkoutSessionClientSecret, elements, intentClientSecret } = params;
98
+ const props = {
99
+ stripe,
100
+ };
101
+ if (isCheckoutSession) {
102
+ // Checkout Session mode
103
+ if (checkout == null) {
104
+ return { error: 'Checkout not properly initialized' };
105
+ }
106
+ props.checkout = checkout;
107
+ props.checkoutSessionClientSecret = checkoutSessionClientSecret;
108
+ return { props };
109
+ }
110
+ // Payment Intent / Setup Intent mode
111
+ if (elements == null) {
112
+ return { error: 'Elements not properly initialized' };
113
+ }
114
+ props.elements = elements;
115
+ props.intentClientSecret = intentClientSecret;
116
+ return { props };
117
+ };
118
+
119
+ exports.buildSubmitEventProps = buildSubmitEventProps;
120
+ exports.confirmCheckoutSession = confirmCheckoutSession;
121
+ exports.confirmPaymentOrSetup = confirmPaymentOrSetup;
122
+ exports.isSubmitButtonDisabled = isSubmitButtonDisabled;
@@ -1,11 +1,21 @@
1
1
  'use strict';
2
2
 
3
- var index$1 = require('./index-Dkb0SxZc.js');
4
- var index = require('./index-CYbA1N_k.js');
3
+ var index = require('./index-Dkb0SxZc.js');
4
+ var index$1 = require('./index-CYbA1N_k.js');
5
5
 
6
6
  const stripePaymentRequestButtonCss = () => `:host{display:block}`;
7
7
 
8
8
  const StripePaymentRequestButton = class {
9
+ constructor(hostRef) {
10
+ index.registerInstance(this, hostRef);
11
+ this.stripeLoaded = index.createEvent(this, "stripeLoaded", 7);
12
+ this.loadStripeStatus = '';
13
+ /**
14
+ * Overwrite the application name that registered
15
+ * For wrapper library (like Capacitor)
16
+ */
17
+ this.applicationName = 'stripe-pwa-elements';
18
+ }
9
19
  /**
10
20
  * Check isAvailable ApplePay or GooglePay.
11
21
  * If you run this method, you should run before initStripe.
@@ -14,7 +24,7 @@ const StripePaymentRequestButton = class {
14
24
  if (this.publishableKey === undefined) {
15
25
  throw new Error('You should set publishableKey before calling this method.');
16
26
  }
17
- const stripe = await index.loadStripe(this.publishableKey, {
27
+ const stripe = await index$1.loadStripe(this.publishableKey, {
18
28
  stripeAccount: this.stripeAccount,
19
29
  });
20
30
  const paymentRequest = stripe.paymentRequest({
@@ -58,15 +68,12 @@ const StripePaymentRequestButton = class {
58
68
  }
59
69
  this.stripeLoaded.emit(event);
60
70
  }
61
- constructor(hostRef) {
62
- index$1.registerInstance(this, hostRef);
63
- this.stripeLoaded = index$1.createEvent(this, "stripeLoaded", 7);
64
- this.loadStripeStatus = '';
65
- /**
66
- * Overwrite the application name that registered
67
- * For wrapper library (like Capacitor)
68
- */
69
- this.applicationName = 'stripe-pwa-elements';
71
+ /**
72
+ * Props are not yet populated inside the constructor when the component is registered via
73
+ * the custom-elements build (`dist/components/*`), so initialization that depends on them
74
+ * must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
75
+ */
76
+ componentWillLoad() {
70
77
  if (this.publishableKey !== undefined && this.paymentRequestOption !== undefined) {
71
78
  this.initStripe(this.publishableKey, {
72
79
  stripeAccount: this.stripeAccount,
@@ -80,7 +87,7 @@ const StripePaymentRequestButton = class {
80
87
  console.warn('[stripe-pwa-elements] <stripe-payment-request-button> is deprecated. ' +
81
88
  'stripe.paymentRequest() is being removed in Stripe.js 9.x (deprecated 2025-09-30 / removed 2026-03-25). ' +
82
89
  'Please migrate to <stripe-express-checkout-element>, which supports Apple Pay, Google Pay, Link, PayPal, and more. ' +
83
- '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/');
84
91
  }
85
92
  /**
86
93
  * @param option
@@ -97,7 +104,7 @@ const StripePaymentRequestButton = class {
97
104
  */
98
105
  async initStripe(publishableKey, options = undefined) {
99
106
  this.loadStripeStatus = 'loading';
100
- index.loadStripe(publishableKey, {
107
+ index$1.loadStripe(publishableKey, {
101
108
  stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
102
109
  })
103
110
  .then(stripe => {
@@ -187,9 +194,9 @@ const StripePaymentRequestButton = class {
187
194
  this.stripe = undefined;
188
195
  }
189
196
  render() {
190
- return (index$1.h(index$1.Host, { key: '6340656e6d6f7ac25db9c42e8cd82be9e342640d' }, index$1.h("div", { key: '2c83b290ee0fc7663b15d6e5ee7a76380f54875b', id: "payment-request" }, index$1.h("div", { key: 'bff7ac4d9f5cba737fa7addbc594c275164ff04a', id: "payment-request-button" })), index$1.h("slot", { key: 'de55b77ffa140ba83a6de8592f95bc75f4ffabf5' })));
197
+ return (index.h(index.Host, { key: '644a4b729c72e87b42df5e1b43262d3195e7ebc6' }, index.h("div", { key: 'aff26789868bbec0f1f6abc463fb14d7f3e73c1b', id: "payment-request" }, index.h("div", { key: '074a25f3c5b2575696ddaeacf2715935212964a5', id: "payment-request-button" })), index.h("slot", { key: '5173400bd63ab201f02934cea4edcab4bb7eed9c' })));
191
198
  }
192
- get el() { return index$1.getElement(this); }
199
+ get el() { return index.getElement(this); }
193
200
  };
194
201
  StripePaymentRequestButton.style = stripePaymentRequestButtonCss();
195
202