stripe-pwa-elements 4.0.4 → 4.1.0

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 (66) hide show
  1. package/dist/cjs/{factory-Cm6zUD7R.js → factory-yd5HDEZn.js} +2 -1
  2. package/dist/cjs/{i18n-lBbOeQt4.js → i18n-CWEsGqxV.js} +2 -2
  3. package/dist/cjs/ion-icon_2.cjs.entry.js +1 -1
  4. package/dist/cjs/loader.cjs.js +1 -1
  5. package/dist/cjs/stripe-address-element.cjs.entry.js +2 -2
  6. package/dist/cjs/stripe-card-element.cjs.entry.js +3 -3
  7. package/dist/cjs/stripe-currency-selector.cjs.entry.js +2 -2
  8. package/dist/cjs/stripe-elements.cjs.js +1 -1
  9. package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +2 -2
  10. package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +2 -2
  11. package/dist/cjs/stripe-payment-element.cjs.entry.js +19 -8
  12. package/dist/cjs/stripe-payment-element.helpers-D1JnhTa-.js +182 -0
  13. package/dist/cjs/stripe-payment-sheet.cjs.entry.js +73 -58
  14. package/dist/collection/components/stripe-card-element/stripe-card-element.js +2 -2
  15. package/dist/collection/components/stripe-payment-element/stripe-payment-element.helpers.js +9 -32
  16. package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +88 -6
  17. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.checkout.js +60 -48
  18. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +5 -2
  19. package/dist/collection/services/stripe-service.js +1 -0
  20. package/dist/collection/utils/checkout-confirm.js +84 -0
  21. package/dist/collection/utils/i18n.js +2 -2
  22. package/dist/components/factory.js +1 -1
  23. package/dist/components/i18n.js +1 -1
  24. package/dist/components/stripe-card-element2.js +1 -1
  25. package/dist/components/stripe-payment-element.helpers.js +1 -1
  26. package/dist/components/stripe-payment-element.js +1 -1
  27. package/dist/components/stripe-payment-sheet.js +1 -1
  28. package/dist/esm/{factory-BaGv8K_i.js → factory-B_WxdnxM.js} +2 -1
  29. package/dist/esm/{i18n-CL5n3bOb.js → i18n-HWdALSvT.js} +2 -2
  30. package/dist/esm/ion-icon_2.entry.js +1 -1
  31. package/dist/esm/loader.js +1 -1
  32. package/dist/esm/stripe-address-element.entry.js +2 -2
  33. package/dist/esm/stripe-card-element.entry.js +3 -3
  34. package/dist/esm/stripe-currency-selector.entry.js +2 -2
  35. package/dist/esm/stripe-elements.js +1 -1
  36. package/dist/esm/stripe-express-checkout-element.entry.js +2 -2
  37. package/dist/esm/stripe-link-authentication-element.entry.js +2 -2
  38. package/dist/esm/stripe-payment-element.entry.js +19 -8
  39. package/dist/esm/stripe-payment-element.helpers-PuWxhMNR.js +176 -0
  40. package/dist/esm/stripe-payment-sheet.entry.js +73 -58
  41. package/dist/stripe-elements/{p-f5552c81.entry.js → p-2e2bf0fe.entry.js} +1 -1
  42. package/dist/stripe-elements/{p-3fc4583a.entry.js → p-32a2d5a4.entry.js} +1 -1
  43. package/dist/stripe-elements/{p-b62c9dae.entry.js → p-84d45b48.entry.js} +1 -1
  44. package/dist/stripe-elements/{p-CL5n3bOb.js → p-HWdALSvT.js} +1 -1
  45. package/dist/stripe-elements/{p-5d3d93ec.entry.js → p-a266da6f.entry.js} +1 -1
  46. package/dist/stripe-elements/{p-7e826964.entry.js → p-b4faa9db.entry.js} +1 -1
  47. package/dist/stripe-elements/p-c4a0e310.entry.js +1 -0
  48. package/dist/stripe-elements/{p-2e41699e.entry.js → p-e660d76a.entry.js} +1 -1
  49. package/dist/stripe-elements/p-eeebfbbf.entry.js +1 -0
  50. package/dist/stripe-elements/p-n0XJSLU3.js +1 -0
  51. package/dist/stripe-elements/p-wrjrFokg.js +1 -0
  52. package/dist/stripe-elements/stripe-elements.esm.js +1 -1
  53. package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +5 -0
  54. package/dist/types/components/stripe-payment-element/stripe-payment-element.d.ts +38 -0
  55. package/dist/types/components/stripe-payment-element/stripe-payment-element.helpers.d.ts +8 -2
  56. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.checkout.d.ts +19 -11
  57. package/dist/types/components.d.ts +36 -4
  58. package/dist/types/services/interfaces.d.ts +3 -1
  59. package/dist/types/utils/checkout-confirm.d.ts +35 -0
  60. package/package.json +1 -1
  61. package/dist/cjs/stripe-payment-element.helpers-lafmSRmb.js +0 -121
  62. package/dist/esm/stripe-payment-element.helpers-CklK5RlF.js +0 -116
  63. package/dist/stripe-elements/p-7a8f783c.entry.js +0 -1
  64. package/dist/stripe-elements/p-BoZLkOAy.js +0 -1
  65. package/dist/stripe-elements/p-DlMEZwSe.js +0 -1
  66. package/dist/stripe-elements/p-b69f6103.entry.js +0 -1
@@ -0,0 +1,176 @@
1
+ import { S as StripeAPIError } from './error-XRfh5Wrs.js';
2
+
3
+ /**
4
+ * Whether a confirm failure means the session was created with `return_url`, which rejects `returnUrl`.
5
+ * Stripe raises this before any payment processing, so retrying without `returnUrl` is safe.
6
+ * `actions.confirm()` reports it both as a thrown `IntegrationError` and as an error result depending on the SDK version.
7
+ * @param error - Error thrown by `actions.confirm()` or the error of its result
8
+ */
9
+ const isCheckoutReturnUrlConflict = (error) => {
10
+ const message = error instanceof Error ? error.message : error === null || error === void 0 ? void 0 : error.message;
11
+ return typeof message === 'string' && message.includes('cannot provide `returnUrl`');
12
+ };
13
+ /**
14
+ * Throw when the session can no longer be paid. Stripe documents an `expired` session as "No further processing will occur",
15
+ * and a `complete` one is already paid or being paid, so confirming again cannot succeed.
16
+ * @param status - `session.status` from `getSession()`; undefined when it cannot be read
17
+ * @param message - Message of the confirm error, if any
18
+ * @throws StripeAPIError of type `invalid_request_error` (unrecoverable), with the code `checkout_session_expired` or `checkout_session_complete`
19
+ */
20
+ const assertCheckoutSessionOpen = (status, message) => {
21
+ if (status == null || status.type === 'open') {
22
+ return;
23
+ }
24
+ throw new StripeAPIError({
25
+ type: 'invalid_request_error',
26
+ code: `checkout_session_${status.type}`,
27
+ message: message !== null && message !== void 0 ? message : `The Checkout Session is ${status.type} and can no longer be paid.`,
28
+ });
29
+ };
30
+ /**
31
+ * Confirm a Checkout Session through the checkout actions.
32
+ *
33
+ * Stripe requires exactly one of `returnUrl` (confirm argument) or the session's `return_url`, and the client
34
+ * cannot tell which one a session has (`getSession()` does not expose it). So the first attempt passes
35
+ * `returnUrl`, and when Stripe rejects it because the session already has `return_url`, the confirmation is
36
+ * retried without `returnUrl` (Stripe then redirects to the session's `return_url` automatically).
37
+ *
38
+ * Errors are thrown as `StripeAPIError`:
39
+ * - session `expired` or `complete` (before confirming or after a failed confirm): `invalid_request_error`
40
+ * - `paymentFailed` on an open session (a decline): `card_error`
41
+ * - any other confirm error on an open session, or a failure to load the actions: `api_error`
42
+ * @param checkout - The Checkout instance from `initCheckoutElementsSdk`
43
+ * @param returnUrl - Where Stripe redirects after a redirect-based payment method, when the session has no `return_url`
44
+ * @param email - Customer email; needed when the session was created without `customer_email` or `customer`
45
+ * @returns The confirmation result
46
+ * @throws StripeAPIError when the actions cannot be loaded, the session can no longer be paid, or the confirmation fails
47
+ */
48
+ const confirmCheckoutActions = async (checkout, returnUrl, email) => {
49
+ const loadActionsResult = await checkout.loadActions();
50
+ if (loadActionsResult.type === 'error') {
51
+ throw new StripeAPIError({
52
+ type: 'api_error',
53
+ code: 'checkout_session_error',
54
+ message: loadActionsResult.error.message,
55
+ });
56
+ }
57
+ const { actions } = loadActionsResult;
58
+ const sessionStatus = () => { var _a, _b; return (_b = (_a = actions.getSession) === null || _a === void 0 ? void 0 : _a.call(actions)) === null || _b === void 0 ? void 0 : _b.status; };
59
+ assertCheckoutSessionOpen(sessionStatus());
60
+ const confirmWith = (withReturnUrl) => actions.confirm(Object.assign(Object.assign({ redirect: 'if_required' }, (withReturnUrl && returnUrl !== '' ? { returnUrl } : {})), (email != null && email !== '' ? { email } : {})));
61
+ // First attempt with returnUrl; a session created with `return_url` rejects it before processing.
62
+ // The rejection can arrive either as a thrown error or as an error result, so both are retried without it.
63
+ let result;
64
+ try {
65
+ result = await confirmWith(true);
66
+ if (result.type === 'error' && isCheckoutReturnUrlConflict(result.error)) {
67
+ result = await confirmWith(false);
68
+ }
69
+ }
70
+ catch (e) {
71
+ if (!isCheckoutReturnUrlConflict(e)) {
72
+ throw e;
73
+ }
74
+ result = await confirmWith(false);
75
+ }
76
+ if (result.type === 'error') {
77
+ const { code, message } = result.error;
78
+ assertCheckoutSessionOpen(sessionStatus(), message);
79
+ if (code === 'paymentFailed') {
80
+ throw new StripeAPIError({ type: 'card_error', code, message });
81
+ }
82
+ throw new StripeAPIError({ type: 'api_error', code: 'checkout_session_error', message });
83
+ }
84
+ return result;
85
+ };
86
+
87
+ /**
88
+ * Determine whether the submit button should be disabled.
89
+ * For Checkout Session mode: the checkout is ready once Stripe finished loading.
90
+ * For Payment Intent / Setup Intent mode: an intent client secret must be present.
91
+ * The button stays disabled after a successful payment as well: the intent or
92
+ * checkout is already confirmed and cannot be submitted again.
93
+ * @param params progress / loading state and the current mode information
94
+ * @returns true when the submit button should be disabled
95
+ */
96
+ const isSubmitButtonDisabled = (params) => {
97
+ const { progress, isCheckoutSession, loadStripeStatus, intentClientSecret } = params;
98
+ const hasValidSecret = isCheckoutSession ? loadStripeStatus === 'success' : intentClientSecret != null && intentClientSecret !== '';
99
+ return progress === 'loading' || progress === 'success' || !hasValidSecret;
100
+ };
101
+ /**
102
+ * Run the default Stripe confirmation flow for Payment Intent / Setup Intent mode.
103
+ * Calls `confirmPayment` or `confirmSetup` depending on the intent type.
104
+ * @param stripe the loaded Stripe.js instance
105
+ * @param elements the Stripe Elements instance bound to the payment element
106
+ * @param intentType the configured intent type
107
+ * @param returnUrl the URL Stripe should redirect back to when required
108
+ * @param extraConfirmParams optional params merged into `confirmParams` (for example `payment_method_data.billing_details`)
109
+ * @returns the confirmation result
110
+ * @throws StripeAPIError when Stripe returns an error
111
+ */
112
+ const confirmPaymentOrSetup = async (stripe, elements, intentType, returnUrl, extraConfirmParams) => {
113
+ const result = await (() => {
114
+ if (intentType === 'payment') {
115
+ return stripe.confirmPayment({
116
+ elements,
117
+ confirmParams: Object.assign({ return_url: returnUrl }, extraConfirmParams),
118
+ redirect: 'if_required',
119
+ });
120
+ }
121
+ return stripe.confirmSetup({
122
+ elements,
123
+ confirmParams: Object.assign({ return_url: returnUrl }, extraConfirmParams),
124
+ redirect: 'if_required',
125
+ });
126
+ })();
127
+ if (result.error) {
128
+ throw new StripeAPIError(result.error);
129
+ }
130
+ return result;
131
+ };
132
+ /**
133
+ * Confirm a Checkout Session payment using the checkout actions.
134
+ *
135
+ * Stripe requires exactly one of `returnUrl` (confirm argument) or the session's `return_url`, and the client
136
+ * cannot tell which one a session has (`getSession()` does not expose it). The shared implementation passes
137
+ * `returnUrl` first and retries without it when Stripe rejects it because the session already has
138
+ * `return_url`. See `confirmCheckoutActions` for the full behavior and error classification.
139
+ * @param checkout the Stripe Checkout instance
140
+ * @param returnUrl URL Stripe should redirect back to when the session has no `return_url`
141
+ * @param email customer email, required when the session was created without `customer_email` or `customer`
142
+ * @returns the confirmation result
143
+ * @throws StripeAPIError when loading actions or confirming fails
144
+ */
145
+ const confirmCheckoutSession = async (checkout, returnUrl, email) => confirmCheckoutActions(checkout, returnUrl, email);
146
+ /**
147
+ * Resolve the mode-specific properties for a submit event.
148
+ * Picks the Checkout or Elements payload depending on the active mode and
149
+ * reports a descriptive error string when the required instance is missing.
150
+ * @param params the resolved Stripe instances and client secrets for the current mode
151
+ * @returns the submit event props, or an error message when an instance is missing
152
+ */
153
+ const buildSubmitEventProps = (params) => {
154
+ const { stripe, isCheckoutSession, checkout, checkoutSessionClientSecret, elements, intentClientSecret } = params;
155
+ const props = {
156
+ stripe,
157
+ };
158
+ if (isCheckoutSession) {
159
+ // Checkout Session mode
160
+ if (checkout == null) {
161
+ return { error: 'Checkout not properly initialized' };
162
+ }
163
+ props.checkout = checkout;
164
+ props.checkoutSessionClientSecret = checkoutSessionClientSecret;
165
+ return { props };
166
+ }
167
+ // Payment Intent / Setup Intent mode
168
+ if (elements == null) {
169
+ return { error: 'Elements not properly initialized' };
170
+ }
171
+ props.elements = elements;
172
+ props.intentClientSecret = intentClientSecret;
173
+ return { props };
174
+ };
175
+
176
+ export { confirmCheckoutSession as a, buildSubmitEventProps as b, confirmPaymentOrSetup as c, confirmCheckoutActions as d, isSubmitButtonDisabled as i };
@@ -1,9 +1,9 @@
1
1
  import { r as registerInstance, a as createEvent, h, d as Host, g as getElement } from './index-C6bbmyga.js';
2
- import { c as checkPlatform, i as i18n } from './i18n-CL5n3bOb.js';
3
- import { s as serviceFactory, f as findElement } from './factory-BaGv8K_i.js';
4
- import { c as confirmPaymentOrSetup } from './stripe-payment-element.helpers-CklK5RlF.js';
5
- import { S as StripeAPIError } from './error-XRfh5Wrs.js';
2
+ import { c as checkPlatform, i as i18n } from './i18n-HWdALSvT.js';
3
+ import { s as serviceFactory, f as findElement } from './factory-B_WxdnxM.js';
4
+ import { d as confirmCheckoutActions, c as confirmPaymentOrSetup } from './stripe-payment-element.helpers-PuWxhMNR.js';
6
5
  import './index-CBXaOfXU.js';
6
+ import './error-XRfh5Wrs.js';
7
7
 
8
8
  /**
9
9
  * State machine behind `<stripe-payment-sheet>`.
@@ -234,13 +234,13 @@ const THEMES = {
234
234
  /**
235
235
  * Drop keys whose value is undefined.
236
236
  */
237
- const compact = (value) => Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
237
+ const compact$1 = (value) => Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
238
238
  /**
239
239
  * Convert a Capacitor address to the Stripe shape (`postalCode` → `postal_code`), dropping keys that are not given.
240
240
  */
241
241
  const toStripeAddress = (address) => {
242
242
  const { postalCode } = address, rest = __rest(address, ["postalCode"]);
243
- return compact(Object.assign(Object.assign({}, rest), { postal_code: postalCode }));
243
+ return compact$1(Object.assign(Object.assign({}, rest), { postal_code: postalCode }));
244
244
  };
245
245
  /**
246
246
  * Payment Element billing fields to turn off: the `never` ones (passed from `defaultBillingDetails` at confirmation)
@@ -251,7 +251,7 @@ const toBillingDetailsFields = (config) => {
251
251
  return undefined;
252
252
  }
253
253
  const { email, name, phone, address } = config;
254
- const fields = compact({
254
+ const fields = compact$1({
255
255
  email: email === 'never' || email === 'always' ? 'never' : undefined,
256
256
  name: name === 'never' ? 'never' : undefined,
257
257
  phone: phone === 'never' || (phone === 'always' && address === 'full') ? 'never' : undefined,
@@ -274,7 +274,7 @@ const toPaymentElementOptions = (options) => {
274
274
  const { merchantDisplayName, paymentMethodLayout, defaultBillingDetails, billingDetailsCollectionConfiguration, enableApplePay, enableGooglePay } = options;
275
275
  const elementOptions = {};
276
276
  const billingDetailsFields = toBillingDetailsFields(billingDetailsCollectionConfiguration);
277
- const wallets = compact({ applePay: toWalletOption(enableApplePay), googlePay: toWalletOption(enableGooglePay) });
277
+ const wallets = compact$1({ applePay: toWalletOption(enableApplePay), googlePay: toWalletOption(enableGooglePay) });
278
278
  if (billingDetailsFields != null) {
279
279
  elementOptions.fields = { billingDetails: billingDetailsFields };
280
280
  }
@@ -289,7 +289,7 @@ const toPaymentElementOptions = (options) => {
289
289
  }
290
290
  if (defaultBillingDetails != null) {
291
291
  const { address } = defaultBillingDetails, contact = __rest(defaultBillingDetails, ["address"]);
292
- const billingDetails = compact(contact);
292
+ const billingDetails = compact$1(contact);
293
293
  if (address != null) {
294
294
  billingDetails.address = toStripeAddress(address);
295
295
  }
@@ -340,7 +340,7 @@ const unsupportedOptionKeys = (options, intentKind) => {
340
340
  const toAddressDefaultValues = (details) => {
341
341
  const { name, phone, address } = details;
342
342
  const country = address === null || address === void 0 ? void 0 : address.country;
343
- return compact({ name, phone, address: country == null || country === '' ? undefined : Object.assign(Object.assign({}, toStripeAddress(address)), { country }) });
343
+ return compact$1({ name, phone, address: country == null || country === '' ? undefined : Object.assign(Object.assign({}, toStripeAddress(address)), { country }) });
344
344
  };
345
345
  const isBlank = (value) => value == null || value === '';
346
346
  /**
@@ -484,17 +484,66 @@ const toCheckoutPaymentElementOptions = (options) => {
484
484
  const { layout } = toPaymentElementOptions(options);
485
485
  return layout == null ? {} : { layout };
486
486
  };
487
+ /**
488
+ * Drop keys whose value is undefined.
489
+ */
490
+ const compact = (value) => Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
491
+ /**
492
+ * Build the `defaultValues` passed to `initCheckoutElementsSdk` from the payment sheet options.
493
+ * The email and phone prefill the Checkout Elements; name and address are passed as `billingAddress`,
494
+ * which Stripe only accepts with a country, so a name or address without `country` cannot be prefilled.
495
+ * @param options - Payment sheet options
496
+ */
497
+ const toCheckoutDefaultValues = (options) => {
498
+ var _a, _b;
499
+ const details = options === null || options === void 0 ? void 0 : options.defaultBillingDetails;
500
+ if (details == null) {
501
+ return undefined;
502
+ }
503
+ const values = {};
504
+ if (details.email != null && details.email !== '') {
505
+ values.email = details.email;
506
+ }
507
+ if (details.phone != null && details.phone !== '') {
508
+ values.phoneNumber = details.phone;
509
+ }
510
+ const country = (_a = details.address) === null || _a === void 0 ? void 0 : _a.country;
511
+ if (country != null && country !== '') {
512
+ const address = details.address;
513
+ const checkoutAddress = compact({
514
+ country,
515
+ line1: address === null || address === void 0 ? void 0 : address.line1,
516
+ line2: address === null || address === void 0 ? void 0 : address.line2,
517
+ city: address === null || address === void 0 ? void 0 : address.city,
518
+ postal_code: address === null || address === void 0 ? void 0 : address.postalCode,
519
+ state: address === null || address === void 0 ? void 0 : address.state,
520
+ });
521
+ const contact = { name: (_b = details.name) !== null && _b !== void 0 ? _b : null, address: checkoutAddress };
522
+ values.billingAddress = contact;
523
+ }
524
+ return Object.keys(values).length === 0 ? undefined : values;
525
+ };
487
526
  /**
488
527
  * List the given options that a Checkout Session does not use, sorted by name.
489
- * Name, phone and address come from the session or from other Checkout elements; the email is passed to `confirm`.
528
+ * Name and address are prefilled through `defaultValues`, which Stripe only accepts with a country, so they are
529
+ * listed when they cannot be used. The email is passed to `confirm` and the phone prefilled through `defaultValues`.
490
530
  * @param options - Payment sheet options
491
531
  */
492
532
  const checkoutIgnoredOptionKeys = (options) => {
533
+ var _a;
493
534
  if (options == null) {
494
535
  return [];
495
536
  }
496
537
  const { merchantDisplayName, defaultBillingDetails } = options;
497
- const keys = ['name', 'phone', 'address'].filter(key => (defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails[key]) != null).map(key => `defaultBillingDetails.${key}`);
538
+ const keys = [];
539
+ const country = (_a = defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails.address) === null || _a === void 0 ? void 0 : _a.country;
540
+ if (((defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails.name) != null || (defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails.address) != null) && (country == null || country === '')) {
541
+ for (const key of ['name', 'address']) {
542
+ if ((defaultBillingDetails === null || defaultBillingDetails === void 0 ? void 0 : defaultBillingDetails[key]) != null) {
543
+ keys.push(`defaultBillingDetails.${key}`);
544
+ }
545
+ }
546
+ }
498
547
  if (merchantDisplayName != null) {
499
548
  keys.push('merchantDisplayName');
500
549
  }
@@ -512,60 +561,23 @@ const toCheckoutElementsOptions = (options) => {
512
561
  const appearance = toAppearance(options === null || options === void 0 ? void 0 : options.style);
513
562
  return appearance == null ? undefined : { appearance };
514
563
  };
515
- /**
516
- * Throw when the session can no longer be paid. Stripe documents an `expired` session as "No further processing will occur",
517
- * and a `complete` one is already paid or being paid, so confirming again cannot succeed.
518
- * @param status - `session.status` from `getSession()`; undefined when it cannot be read
519
- * @param message - Message of the confirm error, if any
520
- * @throws StripeAPIError of type `invalid_request_error` (unrecoverable), with the code `checkout_session_expired` or `checkout_session_complete`
521
- */
522
- const assertSessionOpen = (status, message) => {
523
- if (status == null || status.type === 'open') {
524
- return;
525
- }
526
- throw new StripeAPIError({
527
- type: 'invalid_request_error',
528
- code: `checkout_session_${status.type}`,
529
- message: message !== null && message !== void 0 ? message : `The Checkout Session is ${status.type} and can no longer be paid.`,
530
- });
531
- };
532
564
  /**
533
565
  * Confirm a Checkout Session from the payment sheet.
534
566
  *
535
- * Unlike the default of `confirm`, which always redirects to `returnUrl`, this passes `redirect: 'if_required'`
536
- * so that payment methods without a redirect finish in the page and can be reported as `paymentSheetCompleted`.
567
+ * The shared implementation (see `confirmCheckoutActions`) retries without `returnUrl` when the session was
568
+ * created with `return_url`, and passes `redirect: 'if_required'` so that payment methods without a redirect
569
+ * finish in the page and can be reported as `paymentSheetCompleted`.
537
570
  *
538
- * Errors are thrown as `StripeAPIError` with a `type` that `isRecoverableConfirmError` understands.
539
- * A confirm error only carries `code: 'paymentFailed'` or `code: null` (`StripeCheckoutConfirmResult` in @stripe/stripe-js),
540
- * so whether the session can still be paid is read from `session.status`:
541
- * - session `expired` or `complete` (before confirming or after a failed confirm): `invalid_request_error`, which ends the sheet
542
- * - `paymentFailed` on an open session (a decline): `card_error`, which keeps the sheet open
543
- * - any other confirm error on an open session, or a failure to load the actions: `api_error`, which keeps the sheet open
571
+ * Errors are thrown as `StripeAPIError` with a `type` that `isRecoverableConfirmError` understands:
572
+ * an expired or complete session is an `invalid_request_error` (unrecoverable), a decline is a `card_error`,
573
+ * and any other failure is an `api_error` (both recoverable).
544
574
  * @param checkout - The Checkout instance from `initCheckoutElementsSdk`
545
- * @param returnUrl - Where Stripe redirects after a redirect-based payment method
575
+ * @param returnUrl - Where Stripe redirects after a redirect-based payment method, when the session has no `return_url`
546
576
  * @param email - Customer email; needed when the session was created without `customer_email` or `customer`
547
577
  * @returns The confirmation result
548
578
  * @throws StripeAPIError when the actions cannot be loaded, the session can no longer be paid, or the confirmation fails
549
579
  */
550
- const confirmCheckoutSessionSheet = async (checkout, returnUrl, email) => {
551
- const loadActionsResult = await checkout.loadActions();
552
- if (loadActionsResult.type === 'error') {
553
- throw new StripeAPIError({ type: 'api_error', code: 'checkout_session_error', message: loadActionsResult.error.message });
554
- }
555
- const { actions } = loadActionsResult;
556
- const sessionStatus = () => { var _a, _b; return (_b = (_a = actions.getSession) === null || _a === void 0 ? void 0 : _a.call(actions)) === null || _b === void 0 ? void 0 : _b.status; };
557
- assertSessionOpen(sessionStatus());
558
- const result = await actions.confirm(Object.assign({ returnUrl, redirect: 'if_required' }, (email != null && email !== '' ? { email } : {})));
559
- if (result.type === 'error') {
560
- const { code, message } = result.error;
561
- assertSessionOpen(sessionStatus(), message);
562
- if (code === 'paymentFailed') {
563
- throw new StripeAPIError({ type: 'card_error', code, message });
564
- }
565
- throw new StripeAPIError({ type: 'api_error', code: 'checkout_session_error', message });
566
- }
567
- return result;
568
- };
580
+ const confirmCheckoutSessionSheet = async (checkout, returnUrl, email) => confirmCheckoutActions(checkout, returnUrl, email);
569
581
 
570
582
  const stripePaymentSheetCss = () => `: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{display:contents}.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 .stripe-heading{font-size:24px;font-weight:bold;color:var(--color-heading-text);margin-bottom:24px}.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 .stripe-submit{margin-top:32px}.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)}`;
571
583
 
@@ -889,6 +901,7 @@ const StripePaymentSheet = class {
889
901
  stripeAccount: this.stripeAccount,
890
902
  applicationName: this.applicationName,
891
903
  elementsOptions: toCheckoutElementsOptions(this.options),
904
+ defaultValues: toCheckoutDefaultValues(this.options),
892
905
  });
893
906
  if (generation !== this.sheet.generation) {
894
907
  return;
@@ -910,6 +923,8 @@ const StripePaymentSheet = class {
910
923
  }
911
924
  confirmCheckoutSession(generation) {
912
925
  var _a, _b;
926
+ // returnUrl defaults to the current page; confirmCheckoutSessionSheet retries without it when the
927
+ // session was created with `return_url` (which rejects the argument before processing)
913
928
  const returnUrl = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.returnURL) !== null && _b !== void 0 ? _b : window.location.href;
914
929
  return this.runConfirm(generation, async () => {
915
930
  var _a, _b;
@@ -959,7 +974,7 @@ const StripePaymentSheet = class {
959
974
  var _a, _b, _c;
960
975
  const { phase } = this.sheet;
961
976
  const confirming = phase === 'confirming';
962
- return (h(Host, { key: 'e6b2c3cb168039eb428eaaee1dce598f534c18e7' }, h("stripe-modal", { key: 'ef1515b07cca402c4db8818e2e94ca80e4d954c2', open: this.visible, showCloseButton: !confirming, onClose: this.handleModalClose }, h("div", { key: '9252fa1653b206d211756c94325c73a8ec482a37', class: "stripe-payment-sheet-wrap" }, h("form", { key: '904a54f2439e0356c2cbf9227326efe446aa08ce', id: "stripe-payment-sheet", onSubmit: this.handleSubmit }, h("div", { key: '103d81e3c56cfba1c421e1bf140a49e2b392c6b5', class: "stripe-heading" }, i18n.t(this.sheetTitle)), h("div", { key: 'cda58a48db7b04af1981407b7100def815404e35', class: "payment-info visible" }, h("div", { key: 'cbe248666aa4807c25d492df1ab1de017bc78e2c', class: "stripe-payment-sheet-email" }, ((_a = this.collection) === null || _a === void 0 ? void 0 : _a.emailElement) != null && h("div", { key: 'b0210c6cce85d1affaa83e3fa30785158c9bab98', id: "link-authentication-element" })), h("div", { key: '2420956298e5b36c63f3fbea6b4e32429b7ace27', class: "stripe-payment-sheet-shipping-address" }, ((_b = this.collection) === null || _b === void 0 ? void 0 : _b.shippingAddressElement) != null && h("div", { key: 'ae41335a42c59598e1addbfdea0a13342c026456', id: "address-element" })), h("div", { key: '3196844c9396c40548a3c632733565027df3cea7', class: "stripe-payment-sheet-billing-address" }, ((_c = this.collection) === null || _c === void 0 ? void 0 : _c.billingAddressElement) != null && h("div", { key: '269a99368975db70722fc181a1c099859f23d3d6', id: "address-element" })), h("div", { key: '2a63173a607501ff08ac072956cdbe462a4400c1', id: "payment-element" })), h("div", { key: '7a72a86097aca2af6491c56b52258286ef820283', class: "stripe-element-errors", role: "alert" }, this.errorMessage), h("div", { key: '10f05d5ecfa53cde350f00acffd86e232e370fe7', class: "stripe-submit" }, h("button", { key: 'a7ad3e538b94403bd8c71b31bd405c1b0c59543c', type: "submit", disabled: phase !== 'presented' }, confirming ? i18n.t('Loading') : i18n.t(this.buttonLabel))))))));
977
+ return (h(Host, { key: '52591afbd5af5ceb2530a37248e3bb1f410f880c' }, h("stripe-modal", { key: '607c26d28f381b5017f9714fca398c2f5eb9c066', open: this.visible, showCloseButton: !confirming, onClose: this.handleModalClose }, h("div", { key: '44cfb1929b178257878d5a42d8441b2f7f823436', class: "stripe-payment-sheet-wrap" }, h("form", { key: '20be8d4cb150883936241639c299a86d081c1903', id: "stripe-payment-sheet", onSubmit: this.handleSubmit }, h("div", { key: '14e5c98793de6d2ebb1a1cc755e501b427915d9f', class: "stripe-heading" }, i18n.t(this.sheetTitle)), h("div", { key: '235ac34c0c2260793756960caa75ef9f62e401fd', class: "payment-info visible" }, h("div", { key: '10ed4c9be02a08429b8bfd028f40be409613250b', class: "stripe-payment-sheet-email" }, ((_a = this.collection) === null || _a === void 0 ? void 0 : _a.emailElement) != null && h("div", { key: '5a21882fc11b839287bd499f9441b7a37b2f7e4d', id: "link-authentication-element" })), h("div", { key: 'd88e637fcecc62bba18fc25cdf674a03624ceb8a', class: "stripe-payment-sheet-shipping-address" }, ((_b = this.collection) === null || _b === void 0 ? void 0 : _b.shippingAddressElement) != null && h("div", { key: '934f6b59ce787c6452191f1df14b1848f847db4a', id: "address-element" })), h("div", { key: '1fe9f0371e0669c6b5485b19672ee02169312674', class: "stripe-payment-sheet-billing-address" }, ((_c = this.collection) === null || _c === void 0 ? void 0 : _c.billingAddressElement) != null && h("div", { key: 'fb548084588b34ffcd8534cc2b0a402e1af60d76', id: "address-element" })), h("div", { key: '8dec277132c63cc11c49962f136b67685e810ccb', id: "payment-element" })), h("div", { key: 'e0f20ba527fb9b941cc8d70d7631a03dcfc2c370', class: "stripe-element-errors", role: "alert" }, this.errorMessage), h("div", { key: 'db7357b49c141ff9272f1b4690f933ea54d9bfb3', class: "stripe-submit" }, h("button", { key: '9112ed21047df0b2fdfa5f8d6b7872f878062dc1', type: "submit", disabled: phase !== 'presented' }, confirming ? i18n.t('Loading') : i18n.t(this.buttonLabel))))))));
963
978
  }
964
979
  get el() { return getElement(this); }
965
980
  static get watchers() { return {
@@ -1 +1 @@
1
- import{r as t,a as s,h as e,g as r}from"./p-C6bbmyga.js";import{c as i,i as o}from"./p-CL5n3bOb.js";import{s as c}from"./p-DlMEZwSe.js";import"./p-CBXaOfXU.js";const n=class{updatePublishableKey(t){this.initStripe(t,{stripeAccount:this.stripeAccount})}updateStripeAccountId(t){const s=this.stripeService.state.publishableKey||this.publishableKey;s&&this.initStripe(s,{stripeAccount:t})}async initStripe(t,s){if(await this.stripeService.initialize(t,{stripeAccount:null==s?void 0:s.stripeAccount,applicationName:this.applicationName}),"success"===this.stripeService.state.loadStripeStatus)await this.initElement(),this.stripeLoadedEventHandler();else{const t=this.stripeService.onChange("loadStripeStatus",(async s=>{"success"===s&&(await this.initElement(),this.stripeLoadedEventHandler(),t())}))}}async setErrorMessage(t){return this.currencySelectorElementManager.setError(t),this}async getSelectedCurrency(){return this.currencySelectorElementManager.getState().selectedCurrency}stripeLoadedEventHandler(){const t={stripe:this.stripeService.getStripe()};this.stripeDidLoaded&&this.stripeDidLoaded(t),this.stripeLoaded.emit(t)}async currencyChangeEventHandler(t){const s={currency:t};this.currencyChange.emit(s),this.handleCurrencyChange&&await this.handleCurrencyChange(s)}componentWillRender(){this.stripeService.state.publishableKey&&(["success","loading"].includes(this.stripeService.state.loadStripeStatus)||this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:this.stripeService.state.stripeAccount}))}constructor(e){t(this,e),this.stripeLoaded=s(this,"stripeLoaded",7),this.currencyChange=s(this,"currencyChange",7),this.applicationName="stripe-pwa-elements",this.stripeService=c.createStripeService(),this.currencySelectorElementManager=c.createCurrencySelectorElementManager(this.stripeService)}componentWillLoad(){this.publishableKey&&this.initStripe(this.publishableKey,{stripeAccount:this.stripeAccount})}async initElement(){const t={};this.clientSecret&&(t.clientSecret=this.clientSecret),(await this.currencySelectorElementManager.initialize(this.el,t)).on("change",(t=>{var s;(null===(s=null==t?void 0:t.value)||void 0===s?void 0:s.currency)&&this.currencyChangeEventHandler(t.value.currency)}))}componentDidLoad(){const t=i();t&&this.el.classList.add(t)}disconnectedCallback(){this.currencySelectorElementManager.unmount()}render(){const{loadStripeStatus:t}=this.stripeService.state,{errorMessage:s}=this.currencySelectorElementManager.getState();return"failure"===t?e("p",null,o.t("Failed to load Stripe")):e("div",{class:"stripe-currency-selector-wrap"},e("div",{id:"currency-selector"}),s?e("div",{id:"currency-selector-errors",class:"stripe-element-errors"},s):null)}get el(){return r(this)}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}}};n.style=':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}:host{box-sizing:border-box}:host *: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}:host button{cursor:pointer}:host{display:block;width:100%}.stripe-currency-selector-wrap{width:100%;padding:0;margin:0}.stripe-currency-selector-wrap #currency-selector{width:100%;min-height:40px}.stripe-currency-selector-wrap #currency-selector-errors{margin-top:8px}';export{n as stripe_currency_selector}
1
+ import{r as t,a as s,h as e,g as r}from"./p-C6bbmyga.js";import{c as i,i as o}from"./p-HWdALSvT.js";import{s as c}from"./p-n0XJSLU3.js";import"./p-CBXaOfXU.js";const n=class{updatePublishableKey(t){this.initStripe(t,{stripeAccount:this.stripeAccount})}updateStripeAccountId(t){const s=this.stripeService.state.publishableKey||this.publishableKey;s&&this.initStripe(s,{stripeAccount:t})}async initStripe(t,s){if(await this.stripeService.initialize(t,{stripeAccount:null==s?void 0:s.stripeAccount,applicationName:this.applicationName}),"success"===this.stripeService.state.loadStripeStatus)await this.initElement(),this.stripeLoadedEventHandler();else{const t=this.stripeService.onChange("loadStripeStatus",(async s=>{"success"===s&&(await this.initElement(),this.stripeLoadedEventHandler(),t())}))}}async setErrorMessage(t){return this.currencySelectorElementManager.setError(t),this}async getSelectedCurrency(){return this.currencySelectorElementManager.getState().selectedCurrency}stripeLoadedEventHandler(){const t={stripe:this.stripeService.getStripe()};this.stripeDidLoaded&&this.stripeDidLoaded(t),this.stripeLoaded.emit(t)}async currencyChangeEventHandler(t){const s={currency:t};this.currencyChange.emit(s),this.handleCurrencyChange&&await this.handleCurrencyChange(s)}componentWillRender(){this.stripeService.state.publishableKey&&(["success","loading"].includes(this.stripeService.state.loadStripeStatus)||this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:this.stripeService.state.stripeAccount}))}constructor(e){t(this,e),this.stripeLoaded=s(this,"stripeLoaded",7),this.currencyChange=s(this,"currencyChange",7),this.applicationName="stripe-pwa-elements",this.stripeService=c.createStripeService(),this.currencySelectorElementManager=c.createCurrencySelectorElementManager(this.stripeService)}componentWillLoad(){this.publishableKey&&this.initStripe(this.publishableKey,{stripeAccount:this.stripeAccount})}async initElement(){const t={};this.clientSecret&&(t.clientSecret=this.clientSecret),(await this.currencySelectorElementManager.initialize(this.el,t)).on("change",(t=>{var s;(null===(s=null==t?void 0:t.value)||void 0===s?void 0:s.currency)&&this.currencyChangeEventHandler(t.value.currency)}))}componentDidLoad(){const t=i();t&&this.el.classList.add(t)}disconnectedCallback(){this.currencySelectorElementManager.unmount()}render(){const{loadStripeStatus:t}=this.stripeService.state,{errorMessage:s}=this.currencySelectorElementManager.getState();return"failure"===t?e("p",null,o.t("Failed to load Stripe")):e("div",{class:"stripe-currency-selector-wrap"},e("div",{id:"currency-selector"}),s?e("div",{id:"currency-selector-errors",class:"stripe-element-errors"},s):null)}get el(){return r(this)}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}}};n.style=':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}:host{box-sizing:border-box}:host *: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}:host button{cursor:pointer}:host{display:block;width:100%}.stripe-currency-selector-wrap{width:100%;padding:0;margin:0}.stripe-currency-selector-wrap #currency-selector{width:100%;min-height:40px}.stripe-currency-selector-wrap #currency-selector-errors{margin-top:8px}';export{n as stripe_currency_selector}
@@ -1 +1 @@
1
- import{r as t,a as e,h as s,g as i}from"./p-C6bbmyga.js";import{c as r,i as o}from"./p-CL5n3bOb.js";import{s as n}from"./p-DlMEZwSe.js";import{S as a}from"./p-XRfh5Wrs.js";import"./p-CBXaOfXU.js";const c=class{updatePublishableKey(t){const e={};e.stripeAccount=this.stripeService.state.stripeAccount;const s=Object.values(e).filter(Boolean).length>0;this.initStripe(t,s?e:void 0)}updateStripeAccountId(t){this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:t})}async updateProgress(t){return this.progress=t,this}async setErrorMessage(t){return this.expressCheckoutManager.setError(t),this}async initStripe(t,e){if(await this.stripeService.initialize(t,{stripeAccount:null==e?void 0:e.stripeAccount,applicationName:this.applicationName,clientSecret:this.clientSecret,elementsOptions:this.buildElementsOptions()}),"success"===this.stripeService.state.loadStripeStatus)await this.initElement(),this.stripeLoadedEventHandler();else{const t=this.stripeService.onChange("loadStripeStatus",(async e=>{"success"===e&&(await this.initElement(),this.stripeLoadedEventHandler(),t())}))}}buildElementsOptions(){if(null!=this.currency&&""!==this.currency){if("setup"===this.intentType)return{mode:"setup",currency:this.currency};if(void 0!==this.amount)return{mode:"payment",amount:this.amount,currency:this.currency}}}async updateElementOptions(t){return this.expressCheckoutManager.update(t),this}stripeLoadedEventHandler(){const t={stripe:this.stripeService.getStripe()};null!=this.stripeDidLoaded&&this.stripeDidLoaded(t),this.stripeLoaded.emit(t)}async defaultConfirmResultHandler(t){this.defaultConfirmResult.emit(t)}constructor(s){t(this,s),this.stripeLoaded=e(this,"stripeLoaded",7),this.confirm=e(this,"confirm",7),this.expressCheckoutClick=e(this,"expressCheckoutClick",7),this.cancel=e(this,"cancel",7),this.defaultConfirmResult=e(this,"defaultConfirmResult",7),this.intentType="payment",this.applicationName="stripe-pwa-elements",this.shouldUseDefaultConfirmAction=!0,this.progress="",this.stripeService=n.createStripeService(),this.expressCheckoutManager=n.createExpressCheckoutElementManager(this.stripeService)}componentWillLoad(){null!=this.publishableKey&&""!==this.publishableKey&&this.initStripe(this.publishableKey,{stripeAccount:this.stripeAccount})}componentWillUpdate(){null!=this.stripeService.state.publishableKey&&""!==this.stripeService.state.publishableKey&&(["success","loading"].includes(this.stripeService.state.loadStripeStatus)||this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:this.stripeService.state.stripeAccount}))}async defaultConfirmAction(t){try{this.progress="loading";const e=this.stripeService.getStripe(),{intentType:s,clientSecret:i}=this;if(null==e)throw new Error("Stripe not initialized");if(null==i||""===i)throw new Error("Client secret is required");const r=await(()=>"payment"===s?e.confirmPayment({elements:this.stripeService.getElements(),clientSecret:i,confirmParams:{return_url:`${window.location.origin}${window.location.pathname}`},redirect:"if_required"}):e.confirmSetup({elements:this.stripeService.getElements(),clientSecret:i,confirmParams:{return_url:`${window.location.origin}${window.location.pathname}`},redirect:"if_required"}))();if(null!=r.error)throw new a(r.error);t.complete("success"),this.progress="success",this.defaultConfirmResultHandler(r)}catch(e){console.error(e),t.complete("fail"),this.expressCheckoutManager.setError(e.message),this.progress="failure",this.defaultConfirmResultHandler(e)}}async initElement(){const t={mode:"payment"===this.intentType?"payment":"setup"};if(void 0!==this.amount&&(t.amount=this.amount),null!=this.currency&&""!==this.currency&&(t.currency=this.currency),null!=this.buttonHeight&&""!==this.buttonHeight)if("string"==typeof this.buttonHeight){const e=parseInt(this.buttonHeight.replace("px",""),10);isNaN(e)||(t.buttonHeight=e)}else t.buttonHeight=this.buttonHeight;await this.expressCheckoutManager.initialize(this.el,t,{onConfirm:async t=>{this.confirm.emit(t),this.shouldUseDefaultConfirmAction&&null!=this.clientSecret&&""!==this.clientSecret&&await this.defaultConfirmAction(t)},onClick:t=>{this.expressCheckoutClick.emit(t)},onCancel:()=>{this.cancel.emit(),this.progress=""}})}componentDidLoad(){this.el.classList.add(r())}disconnectedCallback(){this.expressCheckoutManager.unmount()}render(){const{loadStripeStatus:t}=this.stripeService.state,{errorMessage:e,isReady:i}=this.expressCheckoutManager.getState();return"failure"===t?s("p",null,o.t("Failed to load Stripe")):"loading"===t?s("p",null,o.t("Loading")):s("div",{class:"stripe-express-checkout-wrap"},s("div",{id:"express-checkout-element"}),e&&s("div",{id:"express-checkout-errors",class:"stripe-element-errors"},e),!i&&"success"===t&&s("div",{class:"stripe-express-checkout-loading"},o.t("Loading")))}get el(){return i(this)}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}}};c.style=":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-express-checkout-wrap{width:100%;max-width:500px;margin:0 auto;padding:1rem 0}.stripe-express-checkout-wrap #express-checkout-element{margin-bottom:1rem}.stripe-express-checkout-wrap .stripe-element-errors{color:var(--stripe-error-color, #fa755a);font-size:14px;margin-top:0.5rem;padding:0.5rem;background-color:var(--stripe-error-bg, #fff5f5);border:1px solid var(--stripe-error-border, #fdd);border-radius:6px}.stripe-express-checkout-wrap .stripe-express-checkout-loading{text-align:center;padding:1rem;color:var(--stripe-loading-color, #6772e5);font-size:14px}";export{c as stripe_express_checkout_element}
1
+ import{r as t,a as e,h as s,g as i}from"./p-C6bbmyga.js";import{c as r,i as o}from"./p-HWdALSvT.js";import{s as n}from"./p-n0XJSLU3.js";import{S as a}from"./p-XRfh5Wrs.js";import"./p-CBXaOfXU.js";const c=class{updatePublishableKey(t){const e={};e.stripeAccount=this.stripeService.state.stripeAccount;const s=Object.values(e).filter(Boolean).length>0;this.initStripe(t,s?e:void 0)}updateStripeAccountId(t){this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:t})}async updateProgress(t){return this.progress=t,this}async setErrorMessage(t){return this.expressCheckoutManager.setError(t),this}async initStripe(t,e){if(await this.stripeService.initialize(t,{stripeAccount:null==e?void 0:e.stripeAccount,applicationName:this.applicationName,clientSecret:this.clientSecret,elementsOptions:this.buildElementsOptions()}),"success"===this.stripeService.state.loadStripeStatus)await this.initElement(),this.stripeLoadedEventHandler();else{const t=this.stripeService.onChange("loadStripeStatus",(async e=>{"success"===e&&(await this.initElement(),this.stripeLoadedEventHandler(),t())}))}}buildElementsOptions(){if(null!=this.currency&&""!==this.currency){if("setup"===this.intentType)return{mode:"setup",currency:this.currency};if(void 0!==this.amount)return{mode:"payment",amount:this.amount,currency:this.currency}}}async updateElementOptions(t){return this.expressCheckoutManager.update(t),this}stripeLoadedEventHandler(){const t={stripe:this.stripeService.getStripe()};null!=this.stripeDidLoaded&&this.stripeDidLoaded(t),this.stripeLoaded.emit(t)}async defaultConfirmResultHandler(t){this.defaultConfirmResult.emit(t)}constructor(s){t(this,s),this.stripeLoaded=e(this,"stripeLoaded",7),this.confirm=e(this,"confirm",7),this.expressCheckoutClick=e(this,"expressCheckoutClick",7),this.cancel=e(this,"cancel",7),this.defaultConfirmResult=e(this,"defaultConfirmResult",7),this.intentType="payment",this.applicationName="stripe-pwa-elements",this.shouldUseDefaultConfirmAction=!0,this.progress="",this.stripeService=n.createStripeService(),this.expressCheckoutManager=n.createExpressCheckoutElementManager(this.stripeService)}componentWillLoad(){null!=this.publishableKey&&""!==this.publishableKey&&this.initStripe(this.publishableKey,{stripeAccount:this.stripeAccount})}componentWillUpdate(){null!=this.stripeService.state.publishableKey&&""!==this.stripeService.state.publishableKey&&(["success","loading"].includes(this.stripeService.state.loadStripeStatus)||this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:this.stripeService.state.stripeAccount}))}async defaultConfirmAction(t){try{this.progress="loading";const e=this.stripeService.getStripe(),{intentType:s,clientSecret:i}=this;if(null==e)throw new Error("Stripe not initialized");if(null==i||""===i)throw new Error("Client secret is required");const r=await(()=>"payment"===s?e.confirmPayment({elements:this.stripeService.getElements(),clientSecret:i,confirmParams:{return_url:`${window.location.origin}${window.location.pathname}`},redirect:"if_required"}):e.confirmSetup({elements:this.stripeService.getElements(),clientSecret:i,confirmParams:{return_url:`${window.location.origin}${window.location.pathname}`},redirect:"if_required"}))();if(null!=r.error)throw new a(r.error);t.complete("success"),this.progress="success",this.defaultConfirmResultHandler(r)}catch(e){console.error(e),t.complete("fail"),this.expressCheckoutManager.setError(e.message),this.progress="failure",this.defaultConfirmResultHandler(e)}}async initElement(){const t={mode:"payment"===this.intentType?"payment":"setup"};if(void 0!==this.amount&&(t.amount=this.amount),null!=this.currency&&""!==this.currency&&(t.currency=this.currency),null!=this.buttonHeight&&""!==this.buttonHeight)if("string"==typeof this.buttonHeight){const e=parseInt(this.buttonHeight.replace("px",""),10);isNaN(e)||(t.buttonHeight=e)}else t.buttonHeight=this.buttonHeight;await this.expressCheckoutManager.initialize(this.el,t,{onConfirm:async t=>{this.confirm.emit(t),this.shouldUseDefaultConfirmAction&&null!=this.clientSecret&&""!==this.clientSecret&&await this.defaultConfirmAction(t)},onClick:t=>{this.expressCheckoutClick.emit(t)},onCancel:()=>{this.cancel.emit(),this.progress=""}})}componentDidLoad(){this.el.classList.add(r())}disconnectedCallback(){this.expressCheckoutManager.unmount()}render(){const{loadStripeStatus:t}=this.stripeService.state,{errorMessage:e,isReady:i}=this.expressCheckoutManager.getState();return"failure"===t?s("p",null,o.t("Failed to load Stripe")):"loading"===t?s("p",null,o.t("Loading")):s("div",{class:"stripe-express-checkout-wrap"},s("div",{id:"express-checkout-element"}),e&&s("div",{id:"express-checkout-errors",class:"stripe-element-errors"},e),!i&&"success"===t&&s("div",{class:"stripe-express-checkout-loading"},o.t("Loading")))}get el(){return i(this)}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}}};c.style=":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-express-checkout-wrap{width:100%;max-width:500px;margin:0 auto;padding:1rem 0}.stripe-express-checkout-wrap #express-checkout-element{margin-bottom:1rem}.stripe-express-checkout-wrap .stripe-element-errors{color:var(--stripe-error-color, #fa755a);font-size:14px;margin-top:0.5rem;padding:0.5rem;background-color:var(--stripe-error-bg, #fff5f5);border:1px solid var(--stripe-error-border, #fdd);border-radius:6px}.stripe-express-checkout-wrap .stripe-express-checkout-loading{text-align:center;padding:1rem;color:var(--stripe-loading-color, #6772e5);font-size:14px}";export{c as stripe_express_checkout_element}
@@ -1 +1 @@
1
- import{r as t,a as i,h as e,g as n}from"./p-C6bbmyga.js";import{c as s,i as a}from"./p-CL5n3bOb.js";import{s as r}from"./p-DlMEZwSe.js";import"./p-CBXaOfXU.js";const o=class{updatePublishableKey(t){const i={};this.stripeAccount&&(i.stripeAccount=this.stripeAccount),this.initStripe(t,Object.keys(i).length?i:void 0)}updateStripeAccountId(t){const i=this.stripeService.state.publishableKey||this.publishableKey;i&&this.initStripe(i,{stripeAccount:t})}async initStripe(t,i){if(await this.stripeService.initialize(t,{stripeAccount:null==i?void 0:i.stripeAccount,applicationName:this.applicationName}),"success"===this.stripeService.state.loadStripeStatus)await this.initElement(),this.stripeLoadedEventHandler();else{const t=this.stripeService.onChange("loadStripeStatus",(async i=>{"success"===i&&(await this.initElement(),this.stripeLoadedEventHandler(),t())}))}}async updateProgress(t){return this.progress=t,this}async setErrorMessage(t){return this.linkAuthenticationElementManager.setError(t),this}async getEmail(){return this.linkAuthenticationElementManager.getState().email}stripeLoadedEventHandler(){const t=this.stripeService.getStripe();if(!t)return void console.error("Stripe instance is not available");const i={stripe:t};this.stripeDidLoaded&&this.stripeDidLoaded(i),this.stripeLoaded.emit(i)}linkAuthenticationChangeEventHandler(t){const i=this.linkAuthenticationElementManager.getElement(),e=this.stripeService.getStripe();if(!i||!e)return void console.error("Link Authentication Element not initialized");const n={stripe:e,linkAuthenticationElement:i,email:t};this.handleChange&&this.handleChange(n),this.linkAuthenticationChange.emit(n)}componentWillRender(){this.stripeService.state.publishableKey&&(["success","loading"].includes(this.stripeService.state.loadStripeStatus)||this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:this.stripeService.state.stripeAccount}))}constructor(e){t(this,e),this.stripeLoaded=i(this,"stripeLoaded",7),this.linkAuthenticationChange=i(this,"linkAuthenticationChange",7),this.applicationName="stripe-pwa-elements",this.progress="",this.stripeService=r.createStripeService(),this.linkAuthenticationElementManager=r.createLinkAuthenticationElementManager(this.stripeService)}componentWillLoad(){this.publishableKey&&this.initStripe(this.publishableKey,{stripeAccount:this.stripeAccount})}async initElement(){const t={};this.defaultEmail&&(t.defaultValues={email:this.defaultEmail}),await this.linkAuthenticationElementManager.initialize(this.el,Object.keys(t).length?t:void 0),this.linkAuthenticationElementManager.onChange("email",(t=>{this.linkAuthenticationChangeEventHandler(t)}))}componentDidLoad(){const t=s();t&&this.el.classList.add(t)}disconnectedCallback(){this.linkAuthenticationElementManager.unmount()}render(){const{loadStripeStatus:t}=this.stripeService.state,{errorMessage:i}=this.linkAuthenticationElementManager.getState();return"failure"===t?e("p",null,a.t("Failed to load Stripe")):e("div",{class:"stripe-link-authentication-wrap"},e("div",{class:"stripe-link-authentication-container"},e("div",{id:"link-authentication-element"}),e("div",{id:"link-authentication-errors",class:"stripe-element-errors"},i)))}get el(){return n(this)}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}}};o.style=':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-link-authentication-wrap{box-sizing:border-box}.stripe-link-authentication-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-link-authentication-wrap button{cursor:pointer}.stripe-link-authentication-wrap{display:block;width:100%;background:#fff;padding:16px}.stripe-link-authentication-wrap .stripe-link-authentication-container #link-authentication-element .StripeElement{padding:8px 16px;min-height:64px;border-radius:6px;display:flex;justify-content:center;align-items:center}.stripe-link-authentication-wrap .stripe-link-authentication-container #link-authentication-element .StripeElement>.__PrivateStripeElement{width:100%}.stripe-link-authentication-wrap .stripe-link-authentication-container .stripe-element-errors{margin-top:8px;font-size:14px;color:var(--color-text-error)}';export{o as stripe_link_authentication_element}
1
+ import{r as t,a as i,h as e,g as n}from"./p-C6bbmyga.js";import{c as s,i as a}from"./p-HWdALSvT.js";import{s as r}from"./p-n0XJSLU3.js";import"./p-CBXaOfXU.js";const o=class{updatePublishableKey(t){const i={};this.stripeAccount&&(i.stripeAccount=this.stripeAccount),this.initStripe(t,Object.keys(i).length?i:void 0)}updateStripeAccountId(t){const i=this.stripeService.state.publishableKey||this.publishableKey;i&&this.initStripe(i,{stripeAccount:t})}async initStripe(t,i){if(await this.stripeService.initialize(t,{stripeAccount:null==i?void 0:i.stripeAccount,applicationName:this.applicationName}),"success"===this.stripeService.state.loadStripeStatus)await this.initElement(),this.stripeLoadedEventHandler();else{const t=this.stripeService.onChange("loadStripeStatus",(async i=>{"success"===i&&(await this.initElement(),this.stripeLoadedEventHandler(),t())}))}}async updateProgress(t){return this.progress=t,this}async setErrorMessage(t){return this.linkAuthenticationElementManager.setError(t),this}async getEmail(){return this.linkAuthenticationElementManager.getState().email}stripeLoadedEventHandler(){const t=this.stripeService.getStripe();if(!t)return void console.error("Stripe instance is not available");const i={stripe:t};this.stripeDidLoaded&&this.stripeDidLoaded(i),this.stripeLoaded.emit(i)}linkAuthenticationChangeEventHandler(t){const i=this.linkAuthenticationElementManager.getElement(),e=this.stripeService.getStripe();if(!i||!e)return void console.error("Link Authentication Element not initialized");const n={stripe:e,linkAuthenticationElement:i,email:t};this.handleChange&&this.handleChange(n),this.linkAuthenticationChange.emit(n)}componentWillRender(){this.stripeService.state.publishableKey&&(["success","loading"].includes(this.stripeService.state.loadStripeStatus)||this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:this.stripeService.state.stripeAccount}))}constructor(e){t(this,e),this.stripeLoaded=i(this,"stripeLoaded",7),this.linkAuthenticationChange=i(this,"linkAuthenticationChange",7),this.applicationName="stripe-pwa-elements",this.progress="",this.stripeService=r.createStripeService(),this.linkAuthenticationElementManager=r.createLinkAuthenticationElementManager(this.stripeService)}componentWillLoad(){this.publishableKey&&this.initStripe(this.publishableKey,{stripeAccount:this.stripeAccount})}async initElement(){const t={};this.defaultEmail&&(t.defaultValues={email:this.defaultEmail}),await this.linkAuthenticationElementManager.initialize(this.el,Object.keys(t).length?t:void 0),this.linkAuthenticationElementManager.onChange("email",(t=>{this.linkAuthenticationChangeEventHandler(t)}))}componentDidLoad(){const t=s();t&&this.el.classList.add(t)}disconnectedCallback(){this.linkAuthenticationElementManager.unmount()}render(){const{loadStripeStatus:t}=this.stripeService.state,{errorMessage:i}=this.linkAuthenticationElementManager.getState();return"failure"===t?e("p",null,a.t("Failed to load Stripe")):e("div",{class:"stripe-link-authentication-wrap"},e("div",{class:"stripe-link-authentication-container"},e("div",{id:"link-authentication-element"}),e("div",{id:"link-authentication-errors",class:"stripe-element-errors"},i)))}get el(){return n(this)}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}}};o.style=':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-link-authentication-wrap{box-sizing:border-box}.stripe-link-authentication-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-link-authentication-wrap button{cursor:pointer}.stripe-link-authentication-wrap{display:block;width:100%;background:#fff;padding:16px}.stripe-link-authentication-wrap .stripe-link-authentication-container #link-authentication-element .StripeElement{padding:8px 16px;min-height:64px;border-radius:6px;display:flex;justify-content:center;align-items:center}.stripe-link-authentication-wrap .stripe-link-authentication-container #link-authentication-element .StripeElement>.__PrivateStripeElement{width:100%}.stripe-link-authentication-wrap .stripe-link-authentication-container .stripe-element-errors{margin-top:8px;font-size:14px;color:var(--color-text-error)}';export{o as stripe_link_authentication_element}