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,121 +1,9 @@
1
1
  import { r as registerInstance, a as createEvent, h, g as getElement } from './index-C6bbmyga.js';
2
- import { s as serviceFactory, c as checkPlatform, i as i18n } from './factory-DeqoYLf_.js';
3
- import { S as StripeAPIError } from './error-XRfh5Wrs.js';
2
+ import { c as checkPlatform, i as i18n } from './i18n-B6JoQetF.js';
3
+ import { s as serviceFactory } from './factory-Cd6OGTWN.js';
4
+ import { b as buildSubmitEventProps, c as confirmPaymentOrSetup, a as confirmCheckoutSession, i as isSubmitButtonDisabled } from './stripe-payment-element.helpers-CipV87b8.js';
4
5
  import './index-CBXaOfXU.js';
5
-
6
- /**
7
- * Determine whether the submit button should be disabled.
8
- * For Checkout Session mode: the checkout is ready once Stripe finished loading.
9
- * For Payment Intent / Setup Intent mode: an intent client secret must be present.
10
- * @param params progress / loading state and the current mode information
11
- * @returns true when the submit button should be disabled
12
- */
13
- const isSubmitButtonDisabled = (params) => {
14
- const { progress, isCheckoutSession, loadStripeStatus, intentClientSecret } = params;
15
- const hasValidSecret = isCheckoutSession ? loadStripeStatus === 'success' : intentClientSecret != null && intentClientSecret !== '';
16
- return progress === 'loading' || !hasValidSecret;
17
- };
18
- /**
19
- * Run the default Stripe confirmation flow for Payment Intent / Setup Intent mode.
20
- * Calls `confirmPayment` or `confirmSetup` depending on the intent type.
21
- * @param stripe the loaded Stripe.js instance
22
- * @param elements the Stripe Elements instance bound to the payment element
23
- * @param intentType the configured intent type
24
- * @param returnUrl the URL Stripe should redirect back to when required
25
- * @returns the confirmation result
26
- * @throws StripeAPIError when Stripe returns an error
27
- */
28
- const confirmPaymentOrSetup = async (stripe, elements, intentType, returnUrl) => {
29
- const result = await (() => {
30
- if (intentType === 'payment') {
31
- return stripe.confirmPayment({
32
- elements,
33
- confirmParams: {
34
- return_url: returnUrl,
35
- },
36
- redirect: 'if_required',
37
- });
38
- }
39
- return stripe.confirmSetup({
40
- elements,
41
- confirmParams: {
42
- return_url: returnUrl,
43
- },
44
- redirect: 'if_required',
45
- });
46
- })();
47
- if (result.error) {
48
- throw new StripeAPIError(result.error);
49
- }
50
- return result;
51
- };
52
- /**
53
- * Confirm a Checkout Session payment using the checkout actions.
54
- * @param checkout the Stripe Checkout instance
55
- * @param returnUrl the URL Stripe should redirect back to when required
56
- * @returns the confirmation result
57
- * @throws StripeAPIError when loading actions or confirming fails
58
- */
59
- const confirmCheckoutSession = async (checkout, returnUrl) => {
60
- var _a;
61
- // Load actions from the checkout session
62
- const loadActionsResult = await checkout.loadActions();
63
- if (loadActionsResult.type === 'error') {
64
- // Create a StripeError-compatible object from the Checkout Session error
65
- const stripeError = {
66
- type: 'api_error',
67
- code: loadActionsResult.error.code || 'checkout_session_error',
68
- message: loadActionsResult.error.message,
69
- };
70
- throw new StripeAPIError(stripeError);
71
- }
72
- const { actions } = loadActionsResult;
73
- // Confirm the payment using checkout session actions
74
- const result = await actions.confirm({
75
- returnUrl,
76
- redirect: 'if_required',
77
- });
78
- if (result.type === 'error') {
79
- // Create a StripeError-compatible object from the confirm error
80
- const stripeError = {
81
- type: 'card_error',
82
- code: result.error.code || 'payment_failed',
83
- message: result.error.message,
84
- decline_code: result.error.code === 'paymentFailed' ? (_a = result.error.paymentFailed) === null || _a === void 0 ? void 0 : _a.declineCode : undefined,
85
- };
86
- throw new StripeAPIError(stripeError);
87
- }
88
- return result;
89
- };
90
- /**
91
- * Resolve the mode-specific properties for a submit event.
92
- * Picks the Checkout or Elements payload depending on the active mode and
93
- * reports a descriptive error string when the required instance is missing.
94
- * @param params the resolved Stripe instances and client secrets for the current mode
95
- * @returns the submit event props, or an error message when an instance is missing
96
- */
97
- const buildSubmitEventProps = (params) => {
98
- const { stripe, isCheckoutSession, checkout, checkoutSessionClientSecret, elements, intentClientSecret } = params;
99
- const props = {
100
- stripe,
101
- };
102
- if (isCheckoutSession) {
103
- // Checkout Session mode
104
- if (checkout == null) {
105
- return { error: 'Checkout not properly initialized' };
106
- }
107
- props.checkout = checkout;
108
- props.checkoutSessionClientSecret = checkoutSessionClientSecret;
109
- return { props };
110
- }
111
- // Payment Intent / Setup Intent mode
112
- if (elements == null) {
113
- return { error: 'Elements not properly initialized' };
114
- }
115
- props.elements = elements;
116
- props.intentClientSecret = intentClientSecret;
117
- return { props };
118
- };
6
+ import './error-XRfh5Wrs.js';
119
7
 
120
8
  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)}`;
121
9
 
@@ -135,26 +23,14 @@ const StripePaymentElement = class {
135
23
  * ```
136
24
  */
137
25
  async initStripe(publishableKey, options) {
26
+ const generation = ++this.initGeneration;
138
27
  await this.stripeService.initialize(publishableKey, {
139
28
  stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
140
29
  applicationName: this.applicationName,
30
+ // Payment Element needs the client secret when the Elements group is created
31
+ clientSecret: this.intentClientSecret,
141
32
  });
142
- // If already successfully loaded, initialize elements immediately
143
- if (this.stripeService.state.loadStripeStatus === 'success') {
144
- await this.initElement();
145
- this.stripeLoadedEventHandler();
146
- }
147
- else {
148
- // Otherwise, wait for successful load
149
- const unsubscribe = this.stripeService.onChange('loadStripeStatus', async (newState) => {
150
- if (newState !== 'success') {
151
- return;
152
- }
153
- await this.initElement();
154
- this.stripeLoadedEventHandler();
155
- unsubscribe(); // Clean up listener after first success
156
- });
157
- }
33
+ await this.mountWhenLoaded(generation);
158
34
  }
159
35
  /**
160
36
  * Get Stripe.js and initialize with Checkout Session mode
@@ -176,27 +52,13 @@ const StripePaymentElement = class {
176
52
  * ```
177
53
  */
178
54
  async initStripeWithCheckoutSession(publishableKey, checkoutSessionClientSecret, options) {
55
+ const generation = ++this.initGeneration;
179
56
  await this.stripeService.initializeWithCheckoutSession(publishableKey, checkoutSessionClientSecret, {
180
57
  stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
181
58
  applicationName: this.applicationName,
182
59
  elementsOptions: options === null || options === void 0 ? void 0 : options.elementsOptions,
183
60
  });
184
- // If already successfully loaded, initialize elements immediately
185
- if (this.stripeService.state.loadStripeStatus === 'success') {
186
- await this.initElement();
187
- this.stripeLoadedEventHandler();
188
- }
189
- else {
190
- // Otherwise, wait for successful load
191
- const unsubscribe = this.stripeService.onChange('loadStripeStatus', async (newState) => {
192
- if (newState !== 'success') {
193
- return;
194
- }
195
- await this.initElement();
196
- this.stripeLoadedEventHandler();
197
- unsubscribe(); // Clean up listener after first success
198
- });
199
- }
61
+ await this.mountWhenLoaded(generation);
200
62
  }
201
63
  /**
202
64
  * Update the form submit progress
@@ -238,18 +100,32 @@ const StripePaymentElement = class {
238
100
  const options = {};
239
101
  options.stripeAccount = this.stripeService.state.stripeAccount;
240
102
  const hasOptionValue = Object.values(options).filter(value => value != null && value !== '').length > 0;
103
+ if (this.hasCheckoutSessionClientSecret()) {
104
+ this.initStripeWithCheckoutSession(publishableKey, this.checkoutSessionClientSecret, { stripeAccount: options.stripeAccount });
105
+ return;
106
+ }
241
107
  this.initStripe(publishableKey, hasOptionValue ? options : undefined);
242
108
  }
243
109
  updateStripeAccountId(stripeAccount) {
110
+ if (this.hasCheckoutSessionClientSecret()) {
111
+ this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey, this.checkoutSessionClientSecret, { stripeAccount });
112
+ return;
113
+ }
244
114
  this.initStripe(this.stripeService.state.publishableKey, {
245
115
  stripeAccount: stripeAccount,
246
116
  });
247
117
  }
248
118
  async updateIntentClientSecret() {
249
- // Re-initialize the payment element when client secret changes
250
- if (this.stripeService.state.loadStripeStatus === 'success') {
251
- await this.initElement();
119
+ // Checkout Session mode takes precedence (same rule as startStripe); an intent secret must not switch the mode
120
+ if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
121
+ return;
252
122
  }
123
+ // The Elements group is bound to its client secret, so it has to be recreated when the secret changes
124
+ const { publishableKey, stripeAccount } = this.stripeService.state;
125
+ if (publishableKey == null || publishableKey === '') {
126
+ return;
127
+ }
128
+ await this.initStripe(publishableKey, { stripeAccount });
253
129
  }
254
130
  async updateCheckoutSessionClientSecret(newValue) {
255
131
  // Re-initialize with checkout session when client secret changes
@@ -303,6 +179,13 @@ const StripePaymentElement = class {
303
179
  if (['success', 'loading'].includes(this.stripeService.state.loadStripeStatus)) {
304
180
  return;
305
181
  }
182
+ // Retry in the same mode as the initial start
183
+ if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
184
+ this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey, this.checkoutSessionClientSecret, {
185
+ stripeAccount: this.stripeService.state.stripeAccount,
186
+ });
187
+ return;
188
+ }
306
189
  this.initStripe(this.stripeService.state.publishableKey, {
307
190
  stripeAccount: this.stripeService.state.stripeAccount,
308
191
  });
@@ -354,6 +237,8 @@ const StripePaymentElement = class {
354
237
  this.formSubmit = createEvent(this, "formSubmit", 7);
355
238
  this.defaultFormSubmitResult = createEvent(this, "defaultFormSubmitResult", 7);
356
239
  this.checkoutSessionConfirmResult = createEvent(this, "checkoutSessionConfirmResult", 7);
240
+ // Incremented on every initStripe call so that a superseded call stops after its awaits
241
+ this.initGeneration = 0;
357
242
  /**
358
243
  * Default submit handle type.
359
244
  * If you want to use `setupIntent`, should update this attribute.
@@ -395,11 +280,71 @@ const StripePaymentElement = class {
395
280
  // Dependency Injection via factory
396
281
  this.stripeService = serviceFactory.createStripeService();
397
282
  this.paymentElementManager = serviceFactory.createPaymentElementManager(this.stripeService);
398
- if (this.publishableKey != null && this.publishableKey !== '') {
399
- this.initStripe(this.publishableKey, {
283
+ }
284
+ /**
285
+ * Props are not yet populated inside the constructor when the component is registered via
286
+ * the custom-elements build (`dist/components/*`), so initialization that depends on them
287
+ * must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
288
+ */
289
+ componentWillLoad() {
290
+ this.startStripe();
291
+ }
292
+ /**
293
+ * Mount the element once Stripe.js has loaded, unless a newer init call (of either mode) has superseded this one.
294
+ * @param generation - The value of `initGeneration` taken when the init call started
295
+ */
296
+ async mountWhenLoaded(generation) {
297
+ // A newer init call supersedes this one
298
+ if (generation !== this.initGeneration) {
299
+ return;
300
+ }
301
+ // If already successfully loaded, initialize elements immediately
302
+ if (this.stripeService.state.loadStripeStatus === 'success') {
303
+ await this.initElement();
304
+ if (generation !== this.initGeneration) {
305
+ return;
306
+ }
307
+ this.stripeLoadedEventHandler();
308
+ return;
309
+ }
310
+ // Otherwise, wait for successful load
311
+ const unsubscribe = this.stripeService.onChange('loadStripeStatus', async (newState) => {
312
+ if (generation !== this.initGeneration) {
313
+ unsubscribe();
314
+ return;
315
+ }
316
+ if (newState !== 'success') {
317
+ return;
318
+ }
319
+ await this.initElement();
320
+ if (generation !== this.initGeneration) {
321
+ unsubscribe();
322
+ return;
323
+ }
324
+ this.stripeLoadedEventHandler();
325
+ unsubscribe(); // Clean up listener after first success
326
+ });
327
+ }
328
+ hasCheckoutSessionClientSecret() {
329
+ return this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '';
330
+ }
331
+ /**
332
+ * Start Stripe.js in the mode that matches the given props.
333
+ * Checkout Session mode when `checkoutSessionClientSecret` is set, PaymentIntent / SetupIntent mode otherwise.
334
+ */
335
+ startStripe() {
336
+ if (this.publishableKey == null || this.publishableKey === '') {
337
+ return;
338
+ }
339
+ if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
340
+ this.initStripeWithCheckoutSession(this.publishableKey, this.checkoutSessionClientSecret, {
400
341
  stripeAccount: this.stripeAccount,
401
342
  });
343
+ return;
402
344
  }
345
+ this.initStripe(this.publishableKey, {
346
+ stripeAccount: this.stripeAccount,
347
+ });
403
348
  }
404
349
  /**
405
350
  * Initialize Component using Stripe Element
@@ -0,0 +1,117 @@
1
+ import { S as StripeAPIError } from './error-XRfh5Wrs.js';
2
+
3
+ /**
4
+ * Determine whether the submit button should be disabled.
5
+ * For Checkout Session mode: the checkout is ready once Stripe finished loading.
6
+ * For Payment Intent / Setup Intent mode: an intent client secret must be present.
7
+ * @param params progress / loading state and the current mode information
8
+ * @returns true when the submit button should be disabled
9
+ */
10
+ const isSubmitButtonDisabled = (params) => {
11
+ const { progress, isCheckoutSession, loadStripeStatus, intentClientSecret } = params;
12
+ const hasValidSecret = isCheckoutSession ? loadStripeStatus === 'success' : intentClientSecret != null && intentClientSecret !== '';
13
+ return progress === 'loading' || !hasValidSecret;
14
+ };
15
+ /**
16
+ * Run the default Stripe confirmation flow for Payment Intent / Setup Intent mode.
17
+ * Calls `confirmPayment` or `confirmSetup` depending on the intent type.
18
+ * @param stripe the loaded Stripe.js instance
19
+ * @param elements the Stripe Elements instance bound to the payment element
20
+ * @param intentType the configured intent type
21
+ * @param returnUrl the URL Stripe should redirect back to when required
22
+ * @returns the confirmation result
23
+ * @throws StripeAPIError when Stripe returns an error
24
+ */
25
+ const confirmPaymentOrSetup = async (stripe, elements, intentType, returnUrl) => {
26
+ const result = await (() => {
27
+ if (intentType === 'payment') {
28
+ return stripe.confirmPayment({
29
+ elements,
30
+ confirmParams: {
31
+ return_url: returnUrl,
32
+ },
33
+ redirect: 'if_required',
34
+ });
35
+ }
36
+ return stripe.confirmSetup({
37
+ elements,
38
+ confirmParams: {
39
+ return_url: returnUrl,
40
+ },
41
+ redirect: 'if_required',
42
+ });
43
+ })();
44
+ if (result.error) {
45
+ throw new StripeAPIError(result.error);
46
+ }
47
+ return result;
48
+ };
49
+ /**
50
+ * Confirm a Checkout Session payment using the checkout actions.
51
+ * @param checkout the Stripe Checkout instance
52
+ * @param returnUrl the URL Stripe should redirect back to when required
53
+ * @returns the confirmation result
54
+ * @throws StripeAPIError when loading actions or confirming fails
55
+ */
56
+ const confirmCheckoutSession = async (checkout, returnUrl) => {
57
+ var _a;
58
+ // Load actions from the checkout session
59
+ const loadActionsResult = await checkout.loadActions();
60
+ if (loadActionsResult.type === 'error') {
61
+ // Create a StripeError-compatible object from the Checkout Session error
62
+ const stripeError = {
63
+ type: 'api_error',
64
+ code: loadActionsResult.error.code || 'checkout_session_error',
65
+ message: loadActionsResult.error.message,
66
+ };
67
+ throw new StripeAPIError(stripeError);
68
+ }
69
+ const { actions } = loadActionsResult;
70
+ // Confirm the payment using checkout session actions
71
+ const result = await actions.confirm({
72
+ returnUrl,
73
+ redirect: 'if_required',
74
+ });
75
+ if (result.type === 'error') {
76
+ // Create a StripeError-compatible object from the confirm error
77
+ const stripeError = {
78
+ type: 'card_error',
79
+ code: result.error.code || 'payment_failed',
80
+ message: result.error.message,
81
+ decline_code: result.error.code === 'paymentFailed' ? (_a = result.error.paymentFailed) === null || _a === void 0 ? void 0 : _a.declineCode : undefined,
82
+ };
83
+ throw new StripeAPIError(stripeError);
84
+ }
85
+ return result;
86
+ };
87
+ /**
88
+ * Resolve the mode-specific properties for a submit event.
89
+ * Picks the Checkout or Elements payload depending on the active mode and
90
+ * reports a descriptive error string when the required instance is missing.
91
+ * @param params the resolved Stripe instances and client secrets for the current mode
92
+ * @returns the submit event props, or an error message when an instance is missing
93
+ */
94
+ const buildSubmitEventProps = (params) => {
95
+ const { stripe, isCheckoutSession, checkout, checkoutSessionClientSecret, elements, intentClientSecret } = params;
96
+ const props = {
97
+ stripe,
98
+ };
99
+ if (isCheckoutSession) {
100
+ // Checkout Session mode
101
+ if (checkout == null) {
102
+ return { error: 'Checkout not properly initialized' };
103
+ }
104
+ props.checkout = checkout;
105
+ props.checkoutSessionClientSecret = checkoutSessionClientSecret;
106
+ return { props };
107
+ }
108
+ // Payment Intent / Setup Intent mode
109
+ if (elements == null) {
110
+ return { error: 'Elements not properly initialized' };
111
+ }
112
+ props.elements = elements;
113
+ props.intentClientSecret = intentClientSecret;
114
+ return { props };
115
+ };
116
+
117
+ export { confirmCheckoutSession as a, buildSubmitEventProps as b, confirmPaymentOrSetup as c, isSubmitButtonDisabled as i };
@@ -4,6 +4,16 @@ import { l as loadStripe } from './index-CBXaOfXU.js';
4
4
  const stripePaymentRequestButtonCss = () => `:host{display:block}`;
5
5
 
6
6
  const StripePaymentRequestButton = class {
7
+ constructor(hostRef) {
8
+ registerInstance(this, hostRef);
9
+ this.stripeLoaded = createEvent(this, "stripeLoaded", 7);
10
+ this.loadStripeStatus = '';
11
+ /**
12
+ * Overwrite the application name that registered
13
+ * For wrapper library (like Capacitor)
14
+ */
15
+ this.applicationName = 'stripe-pwa-elements';
16
+ }
7
17
  /**
8
18
  * Check isAvailable ApplePay or GooglePay.
9
19
  * If you run this method, you should run before initStripe.
@@ -56,15 +66,12 @@ const StripePaymentRequestButton = class {
56
66
  }
57
67
  this.stripeLoaded.emit(event);
58
68
  }
59
- constructor(hostRef) {
60
- registerInstance(this, hostRef);
61
- this.stripeLoaded = createEvent(this, "stripeLoaded", 7);
62
- this.loadStripeStatus = '';
63
- /**
64
- * Overwrite the application name that registered
65
- * For wrapper library (like Capacitor)
66
- */
67
- this.applicationName = 'stripe-pwa-elements';
69
+ /**
70
+ * Props are not yet populated inside the constructor when the component is registered via
71
+ * the custom-elements build (`dist/components/*`), so initialization that depends on them
72
+ * must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
73
+ */
74
+ componentWillLoad() {
68
75
  if (this.publishableKey !== undefined && this.paymentRequestOption !== undefined) {
69
76
  this.initStripe(this.publishableKey, {
70
77
  stripeAccount: this.stripeAccount,
@@ -78,7 +85,7 @@ const StripePaymentRequestButton = class {
78
85
  console.warn('[stripe-pwa-elements] <stripe-payment-request-button> is deprecated. ' +
79
86
  'stripe.paymentRequest() is being removed in Stripe.js 9.x (deprecated 2025-09-30 / removed 2026-03-25). ' +
80
87
  'Please migrate to <stripe-express-checkout-element>, which supports Apple Pay, Google Pay, Link, PayPal, and more. ' +
81
- 'Migration guide: https://hideokamoto.github.io/stripe-pwa-elements/guides/migrate-payment-request-button-to-express-checkout/');
88
+ 'Migration guide: https://stripe-pwa-elements-docs.wp-kyoto.workers.dev/guides/migrate-payment-request-button-to-express-checkout/');
82
89
  }
83
90
  /**
84
91
  * @param option
@@ -185,7 +192,7 @@ const StripePaymentRequestButton = class {
185
192
  this.stripe = undefined;
186
193
  }
187
194
  render() {
188
- return (h(Host, { key: '6340656e6d6f7ac25db9c42e8cd82be9e342640d' }, h("div", { key: '2c83b290ee0fc7663b15d6e5ee7a76380f54875b', id: "payment-request" }, h("div", { key: 'bff7ac4d9f5cba737fa7addbc594c275164ff04a', id: "payment-request-button" })), h("slot", { key: 'de55b77ffa140ba83a6de8592f95bc75f4ffabf5' })));
195
+ return (h(Host, { key: '644a4b729c72e87b42df5e1b43262d3195e7ebc6' }, h("div", { key: 'aff26789868bbec0f1f6abc463fb14d7f3e73c1b', id: "payment-request" }, h("div", { key: '074a25f3c5b2575696ddaeacf2715935212964a5', id: "payment-request-button" })), h("slot", { key: '5173400bd63ab201f02934cea4edcab4bb7eed9c' })));
189
196
  }
190
197
  get el() { return getElement(this); }
191
198
  };