stripe-pwa-elements 4.0.2 → 4.0.4

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 (72) hide show
  1. package/dist/cjs/{factory-tenFFIul.js → factory-Cm6zUD7R.js} +7 -1
  2. package/dist/cjs/{i18n-FhEOc8vz.js → i18n-lBbOeQt4.js} +6 -0
  3. package/dist/cjs/ion-icon_2.cjs.entry.js +5 -3
  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 +13 -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 +11 -3
  12. package/dist/cjs/{stripe-payment-element.helpers-DukP33RI.js → stripe-payment-element.helpers-lafmSRmb.js} +7 -8
  13. package/dist/cjs/stripe-payment-sheet.cjs.entry.js +516 -35
  14. package/dist/collection/components/stripe-address-element/stripe-address-element.js +2 -2
  15. package/dist/collection/components/stripe-card-element/stripe-card-element.js +11 -1
  16. package/dist/collection/components/stripe-modal/stripe-modal.css +4 -0
  17. package/dist/collection/components/stripe-modal/stripe-modal.js +3 -1
  18. package/dist/collection/components/stripe-payment-element/stripe-payment-element.helpers.js +7 -8
  19. package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +12 -4
  20. package/dist/collection/components/stripe-payment-sheet/payment-sheet-state.js +21 -7
  21. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.checkout.js +94 -0
  22. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.helpers.js +193 -9
  23. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +240 -21
  24. package/dist/collection/services/link-authentication-element-manager.js +5 -0
  25. package/dist/collection/utils/i18n.js +6 -0
  26. package/dist/components/factory.js +1 -1
  27. package/dist/components/i18n.js +1 -1
  28. package/dist/components/stripe-card-element2.js +1 -1
  29. package/dist/components/stripe-modal2.js +1 -1
  30. package/dist/components/stripe-payment-element.helpers.js +1 -1
  31. package/dist/components/stripe-payment-element.js +1 -1
  32. package/dist/components/stripe-payment-sheet.js +1 -1
  33. package/dist/esm/{factory-Cd6OGTWN.js → factory-BaGv8K_i.js} +7 -2
  34. package/dist/esm/{i18n-B6JoQetF.js → i18n-CL5n3bOb.js} +6 -0
  35. package/dist/esm/ion-icon_2.entry.js +5 -3
  36. package/dist/esm/loader.js +1 -1
  37. package/dist/esm/stripe-address-element.entry.js +2 -2
  38. package/dist/esm/stripe-card-element.entry.js +13 -3
  39. package/dist/esm/stripe-currency-selector.entry.js +2 -2
  40. package/dist/esm/stripe-elements.js +1 -1
  41. package/dist/esm/stripe-express-checkout-element.entry.js +2 -2
  42. package/dist/esm/stripe-link-authentication-element.entry.js +2 -2
  43. package/dist/esm/stripe-payment-element.entry.js +11 -3
  44. package/dist/esm/{stripe-payment-element.helpers-CipV87b8.js → stripe-payment-element.helpers-CklK5RlF.js} +7 -8
  45. package/dist/esm/stripe-payment-sheet.entry.js +516 -35
  46. package/dist/stripe-elements/{p-f892e375.entry.js → p-2e41699e.entry.js} +1 -1
  47. package/dist/stripe-elements/{p-6a9c8b7a.entry.js → p-3fc4583a.entry.js} +1 -1
  48. package/dist/stripe-elements/p-5d3d93ec.entry.js +1 -0
  49. package/dist/stripe-elements/p-7a8f783c.entry.js +1 -0
  50. package/dist/stripe-elements/{p-915b86ed.entry.js → p-7e826964.entry.js} +1 -1
  51. package/dist/stripe-elements/p-BoZLkOAy.js +1 -0
  52. package/dist/stripe-elements/p-CL5n3bOb.js +1 -0
  53. package/dist/stripe-elements/{p-C7MQk9FK.js → p-DlMEZwSe.js} +1 -1
  54. package/dist/stripe-elements/{p-5338bc5e.entry.js → p-b62c9dae.entry.js} +1 -1
  55. package/dist/stripe-elements/p-b69f6103.entry.js +1 -0
  56. package/dist/stripe-elements/{p-7fe4a287.entry.js → p-f5552c81.entry.js} +1 -1
  57. package/dist/stripe-elements/stripe-elements.esm.js +1 -1
  58. package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +1 -0
  59. package/dist/types/components/stripe-payment-element/stripe-payment-element.helpers.d.ts +9 -2
  60. package/dist/types/components/stripe-payment-sheet/payment-sheet-state.d.ts +21 -4
  61. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.checkout.d.ts +39 -0
  62. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.d.ts +50 -5
  63. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.helpers.d.ts +66 -8
  64. package/dist/types/components.d.ts +22 -9
  65. package/dist/types/services/interfaces.d.ts +2 -0
  66. package/package.json +4 -2
  67. package/readme.md +78 -27
  68. package/dist/stripe-elements/p-B6JoQetF.js +0 -1
  69. package/dist/stripe-elements/p-DFAhQS0n.js +0 -1
  70. package/dist/stripe-elements/p-b06a254f.entry.js +0 -1
  71. package/dist/stripe-elements/p-b91c4fa7.entry.js +0 -1
  72. package/dist/stripe-elements/p-e7372ca7.entry.js +0 -1
@@ -1,13 +1,17 @@
1
1
  import { h, Host } from "@stencil/core";
2
2
  import { i18n } from "../../utils/i18n";
3
3
  import { checkPlatform } from "../../utils/utils";
4
+ import { findElement } from "../../utils/element-finder";
4
5
  import { serviceFactory } from "../../services/factory";
5
6
  import { confirmPaymentOrSetup } from "../stripe-payment-element/stripe-payment-element.helpers";
6
7
  import { initialSheetState, transition } from "./payment-sheet-state";
7
- import { isRecoverableConfirmError, toAppearance, toPaymentElementOptions, unsupportedOptionKeys } from "./stripe-payment-sheet.helpers";
8
+ import { collectedBillingDetails, isRecoverableConfirmError, isSheetValidationError, planBillingDetailsCollection, toAppearance, toPaymentElementOptions, unsupportedOptionKeys, } from "./stripe-payment-sheet.helpers";
9
+ import { checkoutIgnoredOptionKeys, confirmCheckoutSessionSheet, toCheckoutElementsOptions, toCheckoutPaymentElementOptions } from "./stripe-payment-sheet.checkout";
10
+ const nonEmpty = (value) => (value == null || value === '' ? undefined : value);
8
11
  /**
9
12
  * A payment sheet: the Payment Element in a modal, with the same events and results as the native PaymentSheet
10
- * of `@capacitor-community/stripe`. PaymentIntent and SetupIntent are told apart by the client secret prefix.
13
+ * of `@capacitor-community/stripe`. PaymentIntent and SetupIntent are told apart by the client secret prefix;
14
+ * a Checkout Session is used when `checkout-session-client-secret` is set.
11
15
  */
12
16
  export class StripePaymentSheet {
13
17
  /**
@@ -38,6 +42,7 @@ export class StripePaymentSheet {
38
42
  }
39
43
  constructor() {
40
44
  this.warnedUnsupportedOptions = false;
45
+ this.warnedCheckoutIgnoredOptions = false;
41
46
  /**
42
47
  * Whether the sheet is shown. Setting it to false closes the sheet as canceled.
43
48
  */
@@ -74,6 +79,9 @@ export class StripePaymentSheet {
74
79
  };
75
80
  this.stripeService = serviceFactory.createStripeService();
76
81
  this.paymentElementManager = serviceFactory.createPaymentElementManager(this.stripeService);
82
+ this.billingAddressElementManager = serviceFactory.createAddressElementManager(this.stripeService);
83
+ this.shippingAddressElementManager = serviceFactory.createAddressElementManager(this.stripeService);
84
+ this.emailElementManager = serviceFactory.createLinkAuthenticationElementManager(this.stripeService);
77
85
  }
78
86
  /**
79
87
  * Props are not yet populated inside the constructor with the custom-elements build,
@@ -90,12 +98,43 @@ export class StripePaymentSheet {
90
98
  }
91
99
  disconnectedCallback() {
92
100
  this.paymentElementManager.unmount();
101
+ this.unmountExtraElements();
93
102
  }
103
+ unmountExtraElements() {
104
+ this.billingAddressElementManager.unmount();
105
+ this.shippingAddressElementManager.unmount();
106
+ this.emailElementManager.unmount();
107
+ }
108
+ /**
109
+ * Decide what to load from the attributes and load it only when it differs from the last load.
110
+ * A change that does not alter the result (the attribute that is not used, or an empty value that means unset)
111
+ * must neither reload Stripe.js nor cancel an open sheet.
112
+ */
94
113
  startLoading() {
95
- if (this.publishableKey == null || this.publishableKey === '' || this.intentClientSecret == null) {
114
+ const target = this.loadTarget();
115
+ if (target == null || target.key === this.lastLoadKey) {
96
116
  return;
97
117
  }
98
- this.dispatch({ type: 'secretChanged', clientSecret: this.intentClientSecret });
118
+ this.lastLoadKey = target.key;
119
+ this.dispatch({ type: 'secretChanged', clientSecret: target.clientSecret, source: target.source });
120
+ }
121
+ /**
122
+ * The secret to load and a key of everything the load depends on, or undefined when nothing can be loaded.
123
+ * The Checkout Session wins when both secrets are set (the same rule as `stripe-payment-element`).
124
+ */
125
+ loadTarget() {
126
+ var _a;
127
+ const publishableKey = nonEmpty(this.publishableKey);
128
+ if (publishableKey == null) {
129
+ return undefined;
130
+ }
131
+ const checkoutSessionClientSecret = nonEmpty(this.checkoutSessionClientSecret);
132
+ const intentClientSecret = nonEmpty(this.intentClientSecret);
133
+ const [clientSecret, source] = checkoutSessionClientSecret != null ? [checkoutSessionClientSecret, 'checkoutSession'] : [intentClientSecret, 'intent'];
134
+ if (clientSecret == null) {
135
+ return undefined;
136
+ }
137
+ return { key: JSON.stringify([publishableKey, (_a = nonEmpty(this.stripeAccount)) !== null && _a !== void 0 ? _a : null, source, clientSecret]), clientSecret, source };
99
138
  }
100
139
  dispatch(event) {
101
140
  const { state, effects } = transition(this.sheet, event);
@@ -106,7 +145,12 @@ export class StripePaymentSheet {
106
145
  var _a;
107
146
  switch (effect.type) {
108
147
  case 'load':
109
- this.load(effect.generation, effect.clientSecret);
148
+ if (effect.intentKind === 'checkoutSession') {
149
+ this.loadCheckoutSession(effect.generation, effect.clientSecret);
150
+ }
151
+ else {
152
+ this.load(effect.generation, effect.clientSecret, effect.intentKind);
153
+ }
110
154
  break;
111
155
  case 'show':
112
156
  this.visible = true;
@@ -117,7 +161,12 @@ export class StripePaymentSheet {
117
161
  this.open = false;
118
162
  break;
119
163
  case 'confirm':
120
- this.confirm(effect.generation, effect.intentKind);
164
+ if (effect.intentKind === 'checkoutSession') {
165
+ this.confirmCheckoutSession(effect.generation);
166
+ }
167
+ else {
168
+ this.confirm(effect.generation, effect.intentKind);
169
+ }
121
170
  break;
122
171
  case 'showError':
123
172
  this.errorMessage = effect.message;
@@ -132,16 +181,20 @@ export class StripePaymentSheet {
132
181
  break;
133
182
  }
134
183
  }
135
- async load(generation, clientSecret) {
184
+ async load(generation, clientSecret, intentKind) {
136
185
  var _a;
137
- this.warnUnsupportedOptions();
186
+ this.warnUnsupportedOptions(intentKind);
187
+ // A newer load started while this one was waiting: stop before touching the elements, so that only the latest load mounts and emits
188
+ const superseded = () => generation !== this.sheet.generation;
138
189
  try {
190
+ // Fails before loading Stripe.js when a `never` field has no default value, so that Stripe never rejects the confirmation
191
+ const collection = planBillingDetailsCollection(this.options, intentKind);
139
192
  await this.stripeService.initialize(this.publishableKey, {
140
193
  stripeAccount: this.stripeAccount,
141
194
  applicationName: this.applicationName,
142
195
  clientSecret,
143
196
  });
144
- if (generation !== this.sheet.generation) {
197
+ if (superseded()) {
145
198
  return;
146
199
  }
147
200
  if (this.stripeService.state.loadStripeStatus !== 'success') {
@@ -150,24 +203,110 @@ export class StripePaymentSheet {
150
203
  const appearance = toAppearance((_a = this.options) === null || _a === void 0 ? void 0 : _a.style);
151
204
  if (appearance != null) {
152
205
  await this.stripeService.getElements().update({ appearance });
206
+ if (superseded()) {
207
+ return;
208
+ }
209
+ }
210
+ if (!(await this.mountExtraElements(collection, superseded))) {
211
+ return;
153
212
  }
154
213
  await this.paymentElementManager.initialize(this.el, toPaymentElementOptions(this.options));
155
214
  this.dispatch({ type: 'loadSucceeded', generation });
156
215
  }
157
216
  catch (e) {
217
+ if (superseded()) {
218
+ return;
219
+ }
158
220
  this.lastError = e;
159
221
  this.dispatch({ type: 'loadFailed', generation });
160
222
  }
161
223
  }
162
- async confirm(generation, intentKind) {
163
- var _a, _b, _c;
164
- try {
224
+ /**
225
+ * Render the mount points of the plan's extra elements and mount them. Elements a previous load needed but this one does not are unmounted
226
+ * (the managers unmount their previous element themselves when initialized again).
227
+ */
228
+ async mountExtraElements(collection, superseded) {
229
+ this.collection = collection;
230
+ const { emailElement, shippingAddressElement, billingAddressElement } = collection;
231
+ const extraElements = [
232
+ {
233
+ manager: this.emailElementManager,
234
+ selector: '.stripe-payment-sheet-email',
235
+ mount: emailElement && (container => this.emailElementManager.initialize(container, emailElement)),
236
+ },
237
+ {
238
+ manager: this.shippingAddressElementManager,
239
+ selector: '.stripe-payment-sheet-shipping-address',
240
+ mount: shippingAddressElement && (container => this.shippingAddressElementManager.initialize(container, shippingAddressElement)),
241
+ },
242
+ {
243
+ manager: this.billingAddressElementManager,
244
+ selector: '.stripe-payment-sheet-billing-address',
245
+ mount: billingAddressElement && (container => this.billingAddressElementManager.initialize(container, billingAddressElement)),
246
+ },
247
+ ];
248
+ for (const { manager, selector, mount } of extraElements) {
249
+ if (mount == null) {
250
+ manager.unmount();
251
+ continue;
252
+ }
253
+ // The container is looked up with findElement, which waits for it in case the sheet has not rendered yet
254
+ const container = await findElement(this.el, selector);
255
+ if (superseded()) {
256
+ return false;
257
+ }
258
+ await mount(container);
259
+ if (superseded()) {
260
+ return false;
261
+ }
262
+ }
263
+ return true;
264
+ }
265
+ /**
266
+ * Billing details read from the extra elements and the `never` fields, as extra confirm params
267
+ */
268
+ async confirmParams() {
269
+ var _a;
270
+ const collection = this.collection;
271
+ if (collection == null) {
272
+ return undefined;
273
+ }
274
+ const billingAddress = collection.billingAddressElement != null ? await ((_a = this.billingAddressElementManager.getElement()) === null || _a === void 0 ? void 0 : _a.getValue()) : undefined;
275
+ const emailState = collection.emailElement != null ? this.emailElementManager.getState() : undefined;
276
+ const billingDetails = collectedBillingDetails(collection, { billingAddress, email: emailState === null || emailState === void 0 ? void 0 : emailState.email, emailComplete: emailState === null || emailState === void 0 ? void 0 : emailState.complete });
277
+ return billingDetails == null ? undefined : { payment_method_data: { billing_details: billingDetails } };
278
+ }
279
+ confirm(generation, intentKind) {
280
+ return this.runConfirm(generation, async () => {
281
+ var _a, _b;
282
+ const elements = this.stripeService.getElements();
283
+ // elements.submit() comes first, with nothing awaited before it, as in Stripe's submit handler examples:
284
+ // it validates the elements and collects what wallets (Apple Pay, Google Pay) need while the customer's click still counts,
285
+ // and other asynchronous work may follow once it has resolved
286
+ const { error: submitError } = await elements.submit();
287
+ if (submitError != null) {
288
+ throw submitError;
289
+ }
165
290
  const returnUrl = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.returnURL) !== null && _b !== void 0 ? _b : window.location.href;
166
- this.lastResult = await confirmPaymentOrSetup(this.stripeService.getStripe(), this.stripeService.getElements(), intentKind, returnUrl);
291
+ const extraConfirmParams = await this.confirmParams();
292
+ return confirmPaymentOrSetup(this.stripeService.getStripe(), elements, intentKind, returnUrl, extraConfirmParams);
293
+ });
294
+ }
295
+ /**
296
+ * Run a confirmation and report its result to the state machine.
297
+ * `confirm` is called synchronously, so that its first step still runs inside the customer's submit event.
298
+ * Errors the customer can fix or retry keep the sheet open; others end it with `paymentSheetFailed`.
299
+ */
300
+ async runConfirm(generation, confirm) {
301
+ var _a;
302
+ try {
303
+ this.lastResult = await confirm();
167
304
  this.dispatch({ type: 'confirmSucceeded', generation });
168
305
  }
169
306
  catch (e) {
170
- const message = (_c = e.message) !== null && _c !== void 0 ? _c : String(e);
307
+ const rawMessage = (_a = e.message) !== null && _a !== void 0 ? _a : String(e);
308
+ // Stripe's messages are already localized; the sheet's own validation messages are i18n keys
309
+ const message = isSheetValidationError(e) ? i18n.t(rawMessage) : rawMessage;
171
310
  if (isRecoverableConfirmError(e)) {
172
311
  this.dispatch({ type: 'confirmDeclined', generation, message });
173
312
  return;
@@ -176,6 +315,48 @@ export class StripePaymentSheet {
176
315
  this.dispatch({ type: 'confirmFailed', generation, message });
177
316
  }
178
317
  }
318
+ async loadCheckoutSession(generation, clientSecret) {
319
+ this.warnUnsupportedOptions('checkoutSession');
320
+ this.warnCheckoutIgnoredOptions();
321
+ // The extra billing elements belong to intent mode; remove those of an earlier intent load
322
+ this.collection = undefined;
323
+ this.unmountExtraElements();
324
+ try {
325
+ await this.stripeService.initializeWithCheckoutSession(this.publishableKey, clientSecret, {
326
+ stripeAccount: this.stripeAccount,
327
+ applicationName: this.applicationName,
328
+ elementsOptions: toCheckoutElementsOptions(this.options),
329
+ });
330
+ if (generation !== this.sheet.generation) {
331
+ return;
332
+ }
333
+ if (this.stripeService.state.loadStripeStatus !== 'success') {
334
+ throw new Error('Failed to load Stripe.js');
335
+ }
336
+ await this.paymentElementManager.initialize(this.el, toCheckoutPaymentElementOptions(this.options));
337
+ this.dispatch({ type: 'loadSucceeded', generation });
338
+ }
339
+ catch (e) {
340
+ // An error of a load that a newer load replaced is not reported
341
+ if (generation !== this.sheet.generation) {
342
+ return;
343
+ }
344
+ this.lastError = e;
345
+ this.dispatch({ type: 'loadFailed', generation });
346
+ }
347
+ }
348
+ confirmCheckoutSession(generation) {
349
+ var _a, _b;
350
+ const returnUrl = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.returnURL) !== null && _b !== void 0 ? _b : window.location.href;
351
+ return this.runConfirm(generation, async () => {
352
+ var _a, _b;
353
+ const checkout = this.stripeService.getCheckout();
354
+ if (checkout == null) {
355
+ throw new Error('Checkout Session is not initialized');
356
+ }
357
+ return confirmCheckoutSessionSheet(checkout, returnUrl, (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.defaultBillingDetails) === null || _b === void 0 ? void 0 : _b.email);
358
+ });
359
+ }
179
360
  emit(event) {
180
361
  switch (event) {
181
362
  case 'paymentSheetLoaded':
@@ -195,18 +376,27 @@ export class StripePaymentSheet {
195
376
  break;
196
377
  }
197
378
  }
198
- warnUnsupportedOptions() {
199
- const keys = unsupportedOptionKeys(this.options);
379
+ warnUnsupportedOptions(intentKind) {
380
+ const keys = unsupportedOptionKeys(this.options, intentKind);
200
381
  if (this.warnedUnsupportedOptions || keys.length === 0) {
201
382
  return;
202
383
  }
203
384
  this.warnedUnsupportedOptions = true;
204
385
  console.warn(`<stripe-payment-sheet>: these options have no effect on the web yet: ${keys.join(', ')}`);
205
386
  }
387
+ warnCheckoutIgnoredOptions() {
388
+ const keys = checkoutIgnoredOptionKeys(this.options);
389
+ if (this.warnedCheckoutIgnoredOptions || keys.length === 0) {
390
+ return;
391
+ }
392
+ this.warnedCheckoutIgnoredOptions = true;
393
+ console.warn(`<stripe-payment-sheet>: these options have no effect with a Checkout Session: ${keys.join(', ')}`);
394
+ }
206
395
  render() {
396
+ var _a, _b, _c;
207
397
  const { phase } = this.sheet;
208
398
  const confirming = phase === 'confirming';
209
- return (h(Host, { key: 'ecb6de4b0674af9f5ecf86acce93e092c3bee881' }, h("stripe-modal", { key: '137473608d8cc3c0833c34529f1dafb9fc0cba34', open: this.visible, showCloseButton: !confirming, onClose: this.handleModalClose }, h("div", { key: '0da153ef48ddc5464f050ea1921a69f975a7d8e1', class: "stripe-payment-sheet-wrap" }, h("form", { key: '6f6653aee9d0ad54c8bf935ace2f6d4fdc648e1f', id: "stripe-payment-sheet", onSubmit: this.handleSubmit }, h("div", { key: '85d3e28a20679051decdb02d590c2144e652f0bd', class: "stripe-heading" }, i18n.t(this.sheetTitle)), h("div", { key: 'f6b8d90a3731732c0b36af0512a5ace87a12f98d', class: "payment-info visible" }, h("div", { key: '813a1ad3a0db2efa650aceff828412999f34ff2b', id: "payment-element" })), h("div", { key: '63bd6a8c20dd7b8b92aa2171553c13570ab17808', class: "stripe-element-errors", role: "alert" }, this.errorMessage), h("div", { key: 'f70e9b353ae9eecd1300bbbd40ebb731ef44c344', class: "stripe-submit" }, h("button", { key: '6f32a7b94132091348680476b0e7292072800dbf', type: "submit", disabled: phase !== 'presented' }, confirming ? i18n.t('Loading') : i18n.t(this.buttonLabel))))))));
399
+ 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))))))));
210
400
  }
211
401
  static get is() { return "stripe-payment-sheet"; }
212
402
  static get originalStyleUrls() {
@@ -259,6 +449,25 @@ export class StripePaymentSheet {
259
449
  "reflect": false,
260
450
  "attribute": "intent-client-secret"
261
451
  },
452
+ "checkoutSessionClientSecret": {
453
+ "type": "string",
454
+ "mutable": false,
455
+ "complexType": {
456
+ "original": "string",
457
+ "resolved": "string",
458
+ "references": {}
459
+ },
460
+ "required": false,
461
+ "optional": true,
462
+ "docs": {
463
+ "tags": [],
464
+ "text": "The client secret of a Checkout Session created with `ui_mode: 'elements'` (named `custom` in older Stripe API versions). Its format is not inspected.\nWhen it is set, it is used instead of `intent-client-secret` (the same rule as `stripe-payment-element`).\nCreate the session with `customer_email` or `customer`, or pass `options.defaultBillingDetails.email`, because the sheet has no email field."
465
+ },
466
+ "getter": false,
467
+ "setter": false,
468
+ "reflect": false,
469
+ "attribute": "checkout-session-client-secret"
470
+ },
262
471
  "stripeAccount": {
263
472
  "type": "string",
264
473
  "mutable": false,
@@ -391,7 +600,8 @@ export class StripePaymentSheet {
391
600
  return {
392
601
  "sheet": {},
393
602
  "visible": {},
394
- "errorMessage": {}
603
+ "errorMessage": {},
604
+ "collection": {}
395
605
  };
396
606
  }
397
607
  static get events() {
@@ -440,11 +650,11 @@ export class StripePaymentSheet {
440
650
  "composed": true,
441
651
  "docs": {
442
652
  "tags": [],
443
- "text": "The payment or setup succeeded"
653
+ "text": "The payment or setup succeeded. In Checkout Session mode the detail is the result of `confirm` (`{ type: 'success', session }`)"
444
654
  },
445
655
  "complexType": {
446
- "original": "PaymentIntentResult | SetupIntentResult",
447
- "resolved": "{ paymentIntent: PaymentIntent; error?: undefined; } | { paymentIntent?: undefined; error: StripeError; } | { setupIntent: SetupIntent; error?: undefined; } | { setupIntent?: undefined; error: StripeError; }",
656
+ "original": "PaymentIntentResult | SetupIntentResult | StripeCheckoutConfirmResult",
657
+ "resolved": "{ paymentIntent: PaymentIntent; error?: undefined; } | { paymentIntent?: undefined; error: StripeError; } | { setupIntent: SetupIntent; error?: undefined; } | { setupIntent?: undefined; error: StripeError; } | { type: \"error\"; error: ConfirmError; } | { type: \"success\"; session: StripeCheckoutSession; }",
448
658
  "references": {
449
659
  "PaymentIntentResult": {
450
660
  "location": "import",
@@ -457,6 +667,12 @@ export class StripePaymentSheet {
457
667
  "path": "@stripe/stripe-js",
458
668
  "id": "node_modules::SetupIntentResult",
459
669
  "referenceLocation": "SetupIntentResult"
670
+ },
671
+ "StripeCheckoutConfirmResult": {
672
+ "location": "import",
673
+ "path": "@stripe/stripe-js",
674
+ "id": "node_modules::StripeCheckoutConfirmResult",
675
+ "referenceLocation": "StripeCheckoutConfirmResult"
460
676
  }
461
677
  }
462
678
  }
@@ -533,6 +749,9 @@ export class StripePaymentSheet {
533
749
  }, {
534
750
  "propName": "intentClientSecret",
535
751
  "methodName": "handleSecretChange"
752
+ }, {
753
+ "propName": "checkoutSessionClientSecret",
754
+ "methodName": "handleSecretChange"
536
755
  }, {
537
756
  "propName": "stripeAccount",
538
757
  "methodName": "handleSecretChange"
@@ -15,6 +15,7 @@ export class LinkAuthenticationElementManager {
15
15
  this.store = createStore({
16
16
  errorMessage: '',
17
17
  email: undefined,
18
+ complete: undefined,
18
19
  });
19
20
  }
20
21
  /**
@@ -47,6 +48,9 @@ export class LinkAuthenticationElementManager {
47
48
  if (this.linkAuthenticationElement != null) {
48
49
  this.unmount();
49
50
  }
51
+ // The values of a previous element do not apply to the new one
52
+ this.store.set('email', undefined);
53
+ this.store.set('complete', undefined);
50
54
  // Create link authentication element
51
55
  const linkAuthentication = elements.create('linkAuthentication', options);
52
56
  const linkAuthenticationElementDiv = await findElement(containerElement, '#link-authentication-element');
@@ -57,6 +61,7 @@ export class LinkAuthenticationElementManager {
57
61
  // Unconditionally set email from event.value.email
58
62
  // This handles all cases: valid email, empty string, or undefined
59
63
  this.store.set('email', (_a = event.value) === null || _a === void 0 ? void 0 : _a.email);
64
+ this.store.set('complete', event.complete);
60
65
  });
61
66
  this.linkAuthenticationElement = linkAuthentication;
62
67
  return this.linkAuthenticationElement;
@@ -26,6 +26,9 @@ i18next.use(I18nextBrowserLanguageDetector).init({
26
26
  'Payment information': '支払情報',
27
27
  'Billing address': '請求先住所',
28
28
  'Save': '保存',
29
+ 'Please complete your billing address.': '請求先住所を入力してください。',
30
+ 'Please enter your email address.': 'メールアドレスを入力してください。',
31
+ 'Please enter a valid email address.': '有効なメールアドレスを入力してください。',
29
32
  },
30
33
  },
31
34
  'pt-BR': {
@@ -43,6 +46,9 @@ i18next.use(I18nextBrowserLanguageDetector).init({
43
46
  'Country or region': 'País ou região',
44
47
  'Postal Code': 'Cep',
45
48
  'Close': 'Fechar',
49
+ 'Please complete your billing address.': 'Preencha seu endereço de cobrança.',
50
+ 'Please enter your email address.': 'Informe seu endereço de e-mail.',
51
+ 'Please enter a valid email address.': 'Informe um endereço de e-mail válido.',
46
52
  },
47
53
  },
48
54
  },
@@ -1 +1 @@
1
- import*as t from"@stencil/core/internal/client";import{l as e}from"./index2.js";import{i}from"./i18n.js";const r=(()=>{let t;return(...e)=>{t&&clearTimeout(t),t=setTimeout((()=>{t=0,(t=>{for(let e of t.keys()){const i=t.get(e).filter((t=>{const e=t.deref();return e&&(!("isConnected"in(i=e))||i.isConnected);var i}));t.set(e,i)}})(...e)}),2e3)}})(),s=t.forceUpdate,n=t.getRenderingRef,o=(t,e)=>{const i=t.indexOf(e);i>=0&&(t[i]=t[t.length-1],t.length--)},l=(t,e)=>{const i=((t,e=(t,e)=>t!==e)=>{const i=()=>{return("function"==typeof(e=t)?e():e)??{};var e},r=i();let s=new Map(Object.entries(r));const n="undefined"!=typeof Proxy,l=n?null:{},c={dispose:[],get:[],set:[],reset:[]},a=new Map,h=()=>{s=new Map(Object.entries(i())),n||m(),c.reset.forEach((t=>t()))},u=t=>(c.get.forEach((e=>e(t))),s.get(t)),d=(t,i)=>{const r=s.get(t);e(i,r,t)&&(s.set(t,i),n||g(t),c.set.forEach((e=>e(t,i,r))))},v=n?new Proxy(r,{get:(t,e)=>u(e),ownKeys:()=>Array.from(s.keys()),getOwnPropertyDescriptor:()=>({enumerable:!0,configurable:!0}),has:(t,e)=>s.has(e),set:(t,e,i)=>(d(e,i),!0)}):(m(),l),p=(t,e)=>(c[t].push(e),()=>{o(c[t],e)});function g(t){!n&&l&&(Object.prototype.hasOwnProperty.call(l,t)||Object.defineProperty(l,t,{configurable:!0,enumerable:!0,get:()=>u(t),set(e){d(t,e)}}))}function m(){if(n||!l)return;const t=new Set(s.keys());for(const e of Object.keys(l))t.has(e)||delete l[e];for(const e of t)g(e)}return{state:v,get:u,set:d,on:p,onChange:(t,e)=>{const r=(i,r)=>{i===t&&e(r)},s=()=>{const r=i();e(r[t])},n=p("set",r),o=p("reset",s);return a.set(e,{setHandler:r,resetHandler:s,propName:t}),()=>{n(),o(),a.delete(e)}},use:(...t)=>{const e=t.reduce(((t,e)=>(e.set&&t.push(p("set",e.set)),e.get&&t.push(p("get",e.get)),e.reset&&t.push(p("reset",e.reset)),e.dispose&&t.push(p("dispose",e.dispose)),t)),[]);return()=>e.forEach((t=>t()))},dispose:()=>{c.dispose.forEach((t=>t())),h()},reset:h,forceUpdate:t=>{const e=s.get(t);c.set.forEach((i=>i(t,e,e)))},removeListener:(t,e)=>{const i=a.get(e);i&&i.propName===t&&(o(c.set,i.setHandler),o(c.reset,i.resetHandler),a.delete(e))}}})(t,e);return i.use((()=>{if("function"!=typeof n||"function"!=typeof s)return{};const t=s,e=n,i=new Map;return{dispose:()=>i.clear(),get:t=>{const r=e();r&&((t,e,i)=>{let r=t.get(e);r||(r=[],t.set(e,r)),r.some((t=>t.deref()===i))||r.push(new WeakRef(i))})(i,t,r)},set:e=>{const s=i.get(e);if(s){const r=s.filter((e=>{const i=e.deref();return!!i&&t(i)}));i.set(e,r)}r(i)},reset:()=>{i.forEach((e=>{e.forEach((e=>{const i=e.deref();i&&t(i)}))})),r(i)}}})()),i};class c{constructor(){this.store=l({loadStripeStatus:"",applicationName:"stripe-pwa-elements",isCheckoutSession:!1}),this.initGeneration=0,this.changeListeners=new Map}get state(){return this.store.state}onChange(t,e){const i=this.store.onChange(t,e);return this.changeListeners.has(t)||this.changeListeners.set(t,[]),this.changeListeners.get(t).push(i),i}async initialize(t,i){const r=null!=(null==i?void 0:i.elementsOptions)?JSON.stringify(i.elementsOptions):void 0,s=null!=this.store.state.stripe&&!this.store.state.isCheckoutSession&&this.store.state.publishableKey===t&&this.store.state.stripeAccount===(null==i?void 0:i.stripeAccount)&&this.intentClientSecret===(null==i?void 0:i.clientSecret)&&this.elementsOptionsKey===r;if(this.store.state.publishableKey=t,this.store.state.isCheckoutSession=!1,this.intentClientSecret=null==i?void 0:i.clientSecret,this.elementsOptionsKey=r,null!=(null==i?void 0:i.stripeAccount)&&""!==(null==i?void 0:i.stripeAccount)&&(this.store.state.stripeAccount=i.stripeAccount),null!=(null==i?void 0:i.applicationName)&&""!==(null==i?void 0:i.applicationName)&&(this.store.state.applicationName=i.applicationName),s)return;const n=++this.initGeneration;this.store.state.loadStripeStatus="loading";try{const r=await e(t,{stripeAccount:null==i?void 0:i.stripeAccount});if(n!==this.initGeneration)return;r.registerAppInfo({name:this.store.state.applicationName}),this.store.state.stripe=r,this.store.state.elements=null!=(null==i?void 0:i.clientSecret)&&""!==i.clientSecret?r.elements({clientSecret:i.clientSecret}):null!=(null==i?void 0:i.elementsOptions)?r.elements(i.elementsOptions):r.elements(),this.store.state.checkout=void 0,this.store.state.loadStripeStatus="success"}catch(t){console.error("Failed to load Stripe.js:",t),this.store.state.loadStripeStatus="failure"}}async initializeWithCheckoutSession(t,i,r){const s=++this.initGeneration;this.store.state.publishableKey=t,this.store.state.isCheckoutSession=!0,null!=(null==r?void 0:r.stripeAccount)&&""!==(null==r?void 0:r.stripeAccount)&&(this.store.state.stripeAccount=r.stripeAccount),null!=(null==r?void 0:r.applicationName)&&""!==(null==r?void 0:r.applicationName)&&(this.store.state.applicationName=r.applicationName),this.store.state.loadStripeStatus="loading";try{const n=await e(t,{stripeAccount:null==r?void 0:r.stripeAccount});if(s!==this.initGeneration)return;n.registerAppInfo({name:this.store.state.applicationName}),this.store.state.stripe=n;const o=n.initCheckoutElementsSdk({clientSecret:i,elementsOptions:null==r?void 0:r.elementsOptions});this.store.state.checkout=o,this.store.state.elements=void 0,this.store.state.loadStripeStatus="success"}catch(t){console.error("Failed to initialize Stripe Checkout:",t),this.store.state.loadStripeStatus="failure"}}getStripe(){return this.store.state.stripe}getElements(){return this.store.state.elements}getCheckout(){return this.store.state.checkout}reset(){this.store.reset()}dispose(){this.changeListeners.forEach((t=>{t.forEach((t=>t()))})),this.changeListeners.clear(),this.store.dispose()}}function a(t,e,i=5e3){return new Promise(((r,s)=>{const n=t.querySelector(e);if(null!=n)return r(n);const o=setTimeout((()=>{l.disconnect(),s(new Error(`Element "${e}" not found within ${i}ms`))}),i),l=new MutationObserver((()=>{const i=t.querySelector(e);null!=i&&(clearTimeout(o),l.disconnect(),r(i))}));l.observe(t,{childList:!0,subtree:!0})}))}new c;class h{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",errorSource:void 0})}getState(){return this.store.state}async initialize(t){const e=this.stripeService.getElements();if(null==e)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.cardElements&&this.unmount();const r=e.create("cardNumber",{placeholder:i.t("Card Number")}),s=await a(t,"#card-number");r.mount(s),r.on("change",this.handleCardError("cardNumber"));const n=e.create("cardExpiry"),o=await a(t,"#card-expiry");n.mount(o),n.on("change",this.handleCardError("cardExpiry"));const l=e.create("cardCvc"),c=await a(t,"#card-cvc");return l.mount(c),l.on("change",this.handleCardError("cardCvc")),this.cardElements={cardNumber:r,cardExpiry:n,cardCVC:l},this.cardElements}getElements(){return this.cardElements}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage",""),this.store.set("errorSource",void 0)}unmount(){var t,e,i;null!=this.cardElements&&(null===(t=this.cardElements.cardNumber)||void 0===t||t.unmount(),null===(e=this.cardElements.cardExpiry)||void 0===e||e.unmount(),null===(i=this.cardElements.cardCVC)||void 0===i||i.unmount(),this.cardElements=void 0)}handleCardError(t){return({error:e})=>{if(e)return this.store.set("errorMessage",e.message),void this.store.set("errorSource",t);this.store.state.errorSource===t&&(this.store.set("errorMessage",""),this.store.set("errorSource",void 0))}}}class u{constructor(t){this.stripeService=t,this.store=l({errorMessage:""})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.state.isCheckoutSession;if(null!=this.paymentElement&&this.unmount(),i){const t=this.stripeService.getCheckout();if(null==t)throw new Error("StripeService not initialized with Checkout Session. Call StripeService.initializeWithCheckoutSession() first.");this.paymentElement=t.createPaymentElement(e)}else{const t=this.stripeService.getElements();if(null==t)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");this.paymentElement=t.create("payment",e||{})}const r=await a(t,"#payment-element");return this.paymentElement.mount(r),this.paymentElement}getElement(){return this.paymentElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.paymentElement&&(this.paymentElement.unmount(),this.paymentElement=void 0)}}class d{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",isComplete:!1})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.addressElement&&this.unmount(),this.addressElement=i.create("address",e||{mode:"billing"});const r=await a(t,"#address-element");return this.addressElement.mount(r),this.addressElement.on("change",(t=>{this.store.set("errorMessage",""),this.store.set("isComplete",t.complete)})),this.addressElement}getElement(){return this.addressElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.addressElement&&(this.addressElement.unmount(),this.addressElement=void 0)}}class v{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",email:void 0})}getState(){return this.store.state}onChange(t,e){return this.store.onChange(t,e)}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.linkAuthenticationElement&&this.unmount();const r=i.create("linkAuthentication",e),s=await a(t,"#link-authentication-element");return r.mount(s),r.on("change",(t=>{var e;this.store.set("email",null===(e=t.value)||void 0===e?void 0:e.email)})),this.linkAuthenticationElement=r,this.linkAuthenticationElement}getElement(){return this.linkAuthenticationElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.linkAuthenticationElement&&(this.linkAuthenticationElement.unmount(),this.linkAuthenticationElement=void 0)}}class p{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",selectedCurrency:void 0})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.currencySelectorElement&&this.unmount();const r=await a(t,"#currency-selector");return this.currencySelectorElement=i.create("currencySelector",e||{}),this.currencySelectorElement.mount(r),this.currencySelectorElement.on("change",(t=>{var e;this.store.set("errorMessage",""),(null===(e=null==t?void 0:t.value)||void 0===e?void 0:e.currency)&&this.store.set("selectedCurrency",t.value.currency)})),this.currencySelectorElement}getElement(){return this.currencySelectorElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.currencySelectorElement&&(this.currencySelectorElement.unmount(),this.currencySelectorElement=void 0)}}var g=function(t,e){var i={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(i[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(r=Object.getOwnPropertySymbols(t);s<r.length;s++)e.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(t,r[s])&&(i[r[s]]=t[r[s]])}return i};class m{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",isReady:!1})}getState(){return this.store.state}async initialize(t,e,i){const r=this.stripeService.getElements();if(null==r)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.expressCheckoutElement&&this.unmount();const s=g(e,["mode","amount","currency"]),n=Object.assign({},s);if(n.buttonHeight&&"string"==typeof n.buttonHeight){const t=parseInt(n.buttonHeight.replace("px",""),10);isNaN(t)||(n.buttonHeight=t)}const o=r.create("expressCheckout",n),l=await a(t,"#express-checkout-element");return null!=(null==i?void 0:i.onConfirm)&&o.on("confirm",i.onConfirm),null!=(null==i?void 0:i.onClick)&&o.on("click",i.onClick),null!=(null==i?void 0:i.onCancel)&&o.on("cancel",i.onCancel),null!=(null==i?void 0:i.onShippingAddressChange)&&o.on("shippingaddresschange",i.onShippingAddressChange),null!=(null==i?void 0:i.onShippingRateChange)&&o.on("shippingratechange",i.onShippingRateChange),o.on("ready",(()=>{this.store.set("isReady",!0)})),o.mount(l),this.expressCheckoutElement=o,this.expressCheckoutElement}getElement(){return this.expressCheckoutElement}update(t){var e;if(null==this.expressCheckoutElement)return void console.warn("Express Checkout Element not initialized. Cannot update options.");const{mode:i,amount:r,currency:s}=t,n=g(t,["mode","amount","currency"]),o={};void 0!==i&&(o.mode=i),void 0!==r&&(o.amount=r),void 0!==s&&(o.currency=s),Object.keys(o).length>0&&(null===(e=this.stripeService.getElements())||void 0===e||e.update(o));const l=Object.assign({},n);if(l.buttonHeight&&"string"==typeof l.buttonHeight){const t=parseInt(l.buttonHeight.replace("px",""),10);isNaN(t)||(l.buttonHeight=t)}0!==Object.keys(l).length&&this.expressCheckoutElement.update(l)}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.expressCheckoutElement&&(this.expressCheckoutElement.unmount(),this.expressCheckoutElement=void 0,this.store.set("isReady",!1))}}const f=new class{createStripeService(){return new c}createCardElementManager(t){return new h(t)}createPaymentElementManager(t){return new u(t)}createAddressElementManager(t){return new d(t)}createLinkAuthenticationElementManager(t){return new v(t)}createCurrencySelectorElementManager(t){return new p(t)}createExpressCheckoutElementManager(t){return new m(t)}};export{f as s}
1
+ import*as t from"@stencil/core/internal/client";import{l as e}from"./index2.js";import{i}from"./i18n.js";const r=(()=>{let t;return(...e)=>{t&&clearTimeout(t),t=setTimeout((()=>{t=0,(t=>{for(let e of t.keys()){const i=t.get(e).filter((t=>{const e=t.deref();return e&&(!("isConnected"in(i=e))||i.isConnected);var i}));t.set(e,i)}})(...e)}),2e3)}})(),s=t.forceUpdate,n=t.getRenderingRef,o=(t,e)=>{const i=t.indexOf(e);i>=0&&(t[i]=t[t.length-1],t.length--)},l=(t,e)=>{const i=((t,e=(t,e)=>t!==e)=>{const i=()=>{return("function"==typeof(e=t)?e():e)??{};var e},r=i();let s=new Map(Object.entries(r));const n="undefined"!=typeof Proxy,l=n?null:{},c={dispose:[],get:[],set:[],reset:[]},a=new Map,h=()=>{s=new Map(Object.entries(i())),n||m(),c.reset.forEach((t=>t()))},u=t=>(c.get.forEach((e=>e(t))),s.get(t)),d=(t,i)=>{const r=s.get(t);e(i,r,t)&&(s.set(t,i),n||g(t),c.set.forEach((e=>e(t,i,r))))},v=n?new Proxy(r,{get:(t,e)=>u(e),ownKeys:()=>Array.from(s.keys()),getOwnPropertyDescriptor:()=>({enumerable:!0,configurable:!0}),has:(t,e)=>s.has(e),set:(t,e,i)=>(d(e,i),!0)}):(m(),l),p=(t,e)=>(c[t].push(e),()=>{o(c[t],e)});function g(t){!n&&l&&(Object.prototype.hasOwnProperty.call(l,t)||Object.defineProperty(l,t,{configurable:!0,enumerable:!0,get:()=>u(t),set(e){d(t,e)}}))}function m(){if(n||!l)return;const t=new Set(s.keys());for(const e of Object.keys(l))t.has(e)||delete l[e];for(const e of t)g(e)}return{state:v,get:u,set:d,on:p,onChange:(t,e)=>{const r=(i,r)=>{i===t&&e(r)},s=()=>{const r=i();e(r[t])},n=p("set",r),o=p("reset",s);return a.set(e,{setHandler:r,resetHandler:s,propName:t}),()=>{n(),o(),a.delete(e)}},use:(...t)=>{const e=t.reduce(((t,e)=>(e.set&&t.push(p("set",e.set)),e.get&&t.push(p("get",e.get)),e.reset&&t.push(p("reset",e.reset)),e.dispose&&t.push(p("dispose",e.dispose)),t)),[]);return()=>e.forEach((t=>t()))},dispose:()=>{c.dispose.forEach((t=>t())),h()},reset:h,forceUpdate:t=>{const e=s.get(t);c.set.forEach((i=>i(t,e,e)))},removeListener:(t,e)=>{const i=a.get(e);i&&i.propName===t&&(o(c.set,i.setHandler),o(c.reset,i.resetHandler),a.delete(e))}}})(t,e);return i.use((()=>{if("function"!=typeof n||"function"!=typeof s)return{};const t=s,e=n,i=new Map;return{dispose:()=>i.clear(),get:t=>{const r=e();r&&((t,e,i)=>{let r=t.get(e);r||(r=[],t.set(e,r)),r.some((t=>t.deref()===i))||r.push(new WeakRef(i))})(i,t,r)},set:e=>{const s=i.get(e);if(s){const r=s.filter((e=>{const i=e.deref();return!!i&&t(i)}));i.set(e,r)}r(i)},reset:()=>{i.forEach((e=>{e.forEach((e=>{const i=e.deref();i&&t(i)}))})),r(i)}}})()),i};class c{constructor(){this.store=l({loadStripeStatus:"",applicationName:"stripe-pwa-elements",isCheckoutSession:!1}),this.initGeneration=0,this.changeListeners=new Map}get state(){return this.store.state}onChange(t,e){const i=this.store.onChange(t,e);return this.changeListeners.has(t)||this.changeListeners.set(t,[]),this.changeListeners.get(t).push(i),i}async initialize(t,i){const r=null!=(null==i?void 0:i.elementsOptions)?JSON.stringify(i.elementsOptions):void 0,s=null!=this.store.state.stripe&&!this.store.state.isCheckoutSession&&this.store.state.publishableKey===t&&this.store.state.stripeAccount===(null==i?void 0:i.stripeAccount)&&this.intentClientSecret===(null==i?void 0:i.clientSecret)&&this.elementsOptionsKey===r;if(this.store.state.publishableKey=t,this.store.state.isCheckoutSession=!1,this.intentClientSecret=null==i?void 0:i.clientSecret,this.elementsOptionsKey=r,null!=(null==i?void 0:i.stripeAccount)&&""!==(null==i?void 0:i.stripeAccount)&&(this.store.state.stripeAccount=i.stripeAccount),null!=(null==i?void 0:i.applicationName)&&""!==(null==i?void 0:i.applicationName)&&(this.store.state.applicationName=i.applicationName),s)return;const n=++this.initGeneration;this.store.state.loadStripeStatus="loading";try{const r=await e(t,{stripeAccount:null==i?void 0:i.stripeAccount});if(n!==this.initGeneration)return;r.registerAppInfo({name:this.store.state.applicationName}),this.store.state.stripe=r,this.store.state.elements=null!=(null==i?void 0:i.clientSecret)&&""!==i.clientSecret?r.elements({clientSecret:i.clientSecret}):null!=(null==i?void 0:i.elementsOptions)?r.elements(i.elementsOptions):r.elements(),this.store.state.checkout=void 0,this.store.state.loadStripeStatus="success"}catch(t){console.error("Failed to load Stripe.js:",t),this.store.state.loadStripeStatus="failure"}}async initializeWithCheckoutSession(t,i,r){const s=++this.initGeneration;this.store.state.publishableKey=t,this.store.state.isCheckoutSession=!0,null!=(null==r?void 0:r.stripeAccount)&&""!==(null==r?void 0:r.stripeAccount)&&(this.store.state.stripeAccount=r.stripeAccount),null!=(null==r?void 0:r.applicationName)&&""!==(null==r?void 0:r.applicationName)&&(this.store.state.applicationName=r.applicationName),this.store.state.loadStripeStatus="loading";try{const n=await e(t,{stripeAccount:null==r?void 0:r.stripeAccount});if(s!==this.initGeneration)return;n.registerAppInfo({name:this.store.state.applicationName}),this.store.state.stripe=n;const o=n.initCheckoutElementsSdk({clientSecret:i,elementsOptions:null==r?void 0:r.elementsOptions});this.store.state.checkout=o,this.store.state.elements=void 0,this.store.state.loadStripeStatus="success"}catch(t){console.error("Failed to initialize Stripe Checkout:",t),this.store.state.loadStripeStatus="failure"}}getStripe(){return this.store.state.stripe}getElements(){return this.store.state.elements}getCheckout(){return this.store.state.checkout}reset(){this.store.reset()}dispose(){this.changeListeners.forEach((t=>{t.forEach((t=>t()))})),this.changeListeners.clear(),this.store.dispose()}}function a(t,e,i=5e3){return new Promise(((r,s)=>{const n=t.querySelector(e);if(null!=n)return r(n);const o=setTimeout((()=>{l.disconnect(),s(new Error(`Element "${e}" not found within ${i}ms`))}),i),l=new MutationObserver((()=>{const i=t.querySelector(e);null!=i&&(clearTimeout(o),l.disconnect(),r(i))}));l.observe(t,{childList:!0,subtree:!0})}))}new c;class h{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",errorSource:void 0})}getState(){return this.store.state}async initialize(t){const e=this.stripeService.getElements();if(null==e)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.cardElements&&this.unmount();const r=e.create("cardNumber",{placeholder:i.t("Card Number")}),s=await a(t,"#card-number");r.mount(s),r.on("change",this.handleCardError("cardNumber"));const n=e.create("cardExpiry"),o=await a(t,"#card-expiry");n.mount(o),n.on("change",this.handleCardError("cardExpiry"));const l=e.create("cardCvc"),c=await a(t,"#card-cvc");return l.mount(c),l.on("change",this.handleCardError("cardCvc")),this.cardElements={cardNumber:r,cardExpiry:n,cardCVC:l},this.cardElements}getElements(){return this.cardElements}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage",""),this.store.set("errorSource",void 0)}unmount(){var t,e,i;null!=this.cardElements&&(null===(t=this.cardElements.cardNumber)||void 0===t||t.unmount(),null===(e=this.cardElements.cardExpiry)||void 0===e||e.unmount(),null===(i=this.cardElements.cardCVC)||void 0===i||i.unmount(),this.cardElements=void 0)}handleCardError(t){return({error:e})=>{if(e)return this.store.set("errorMessage",e.message),void this.store.set("errorSource",t);this.store.state.errorSource===t&&(this.store.set("errorMessage",""),this.store.set("errorSource",void 0))}}}class u{constructor(t){this.stripeService=t,this.store=l({errorMessage:""})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.state.isCheckoutSession;if(null!=this.paymentElement&&this.unmount(),i){const t=this.stripeService.getCheckout();if(null==t)throw new Error("StripeService not initialized with Checkout Session. Call StripeService.initializeWithCheckoutSession() first.");this.paymentElement=t.createPaymentElement(e)}else{const t=this.stripeService.getElements();if(null==t)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");this.paymentElement=t.create("payment",e||{})}const r=await a(t,"#payment-element");return this.paymentElement.mount(r),this.paymentElement}getElement(){return this.paymentElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.paymentElement&&(this.paymentElement.unmount(),this.paymentElement=void 0)}}class d{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",isComplete:!1})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.addressElement&&this.unmount(),this.addressElement=i.create("address",e||{mode:"billing"});const r=await a(t,"#address-element");return this.addressElement.mount(r),this.addressElement.on("change",(t=>{this.store.set("errorMessage",""),this.store.set("isComplete",t.complete)})),this.addressElement}getElement(){return this.addressElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.addressElement&&(this.addressElement.unmount(),this.addressElement=void 0)}}class v{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",email:void 0,complete:void 0})}getState(){return this.store.state}onChange(t,e){return this.store.onChange(t,e)}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.linkAuthenticationElement&&this.unmount(),this.store.set("email",void 0),this.store.set("complete",void 0);const r=i.create("linkAuthentication",e),s=await a(t,"#link-authentication-element");return r.mount(s),r.on("change",(t=>{var e;this.store.set("email",null===(e=t.value)||void 0===e?void 0:e.email),this.store.set("complete",t.complete)})),this.linkAuthenticationElement=r,this.linkAuthenticationElement}getElement(){return this.linkAuthenticationElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.linkAuthenticationElement&&(this.linkAuthenticationElement.unmount(),this.linkAuthenticationElement=void 0)}}class p{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",selectedCurrency:void 0})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.currencySelectorElement&&this.unmount();const r=await a(t,"#currency-selector");return this.currencySelectorElement=i.create("currencySelector",e||{}),this.currencySelectorElement.mount(r),this.currencySelectorElement.on("change",(t=>{var e;this.store.set("errorMessage",""),(null===(e=null==t?void 0:t.value)||void 0===e?void 0:e.currency)&&this.store.set("selectedCurrency",t.value.currency)})),this.currencySelectorElement}getElement(){return this.currencySelectorElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.currencySelectorElement&&(this.currencySelectorElement.unmount(),this.currencySelectorElement=void 0)}}var g=function(t,e){var i={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(i[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(r=Object.getOwnPropertySymbols(t);s<r.length;s++)e.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(t,r[s])&&(i[r[s]]=t[r[s]])}return i};class m{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",isReady:!1})}getState(){return this.store.state}async initialize(t,e,i){const r=this.stripeService.getElements();if(null==r)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.expressCheckoutElement&&this.unmount();const s=g(e,["mode","amount","currency"]),n=Object.assign({},s);if(n.buttonHeight&&"string"==typeof n.buttonHeight){const t=parseInt(n.buttonHeight.replace("px",""),10);isNaN(t)||(n.buttonHeight=t)}const o=r.create("expressCheckout",n),l=await a(t,"#express-checkout-element");return null!=(null==i?void 0:i.onConfirm)&&o.on("confirm",i.onConfirm),null!=(null==i?void 0:i.onClick)&&o.on("click",i.onClick),null!=(null==i?void 0:i.onCancel)&&o.on("cancel",i.onCancel),null!=(null==i?void 0:i.onShippingAddressChange)&&o.on("shippingaddresschange",i.onShippingAddressChange),null!=(null==i?void 0:i.onShippingRateChange)&&o.on("shippingratechange",i.onShippingRateChange),o.on("ready",(()=>{this.store.set("isReady",!0)})),o.mount(l),this.expressCheckoutElement=o,this.expressCheckoutElement}getElement(){return this.expressCheckoutElement}update(t){var e;if(null==this.expressCheckoutElement)return void console.warn("Express Checkout Element not initialized. Cannot update options.");const{mode:i,amount:r,currency:s}=t,n=g(t,["mode","amount","currency"]),o={};void 0!==i&&(o.mode=i),void 0!==r&&(o.amount=r),void 0!==s&&(o.currency=s),Object.keys(o).length>0&&(null===(e=this.stripeService.getElements())||void 0===e||e.update(o));const l=Object.assign({},n);if(l.buttonHeight&&"string"==typeof l.buttonHeight){const t=parseInt(l.buttonHeight.replace("px",""),10);isNaN(t)||(l.buttonHeight=t)}0!==Object.keys(l).length&&this.expressCheckoutElement.update(l)}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.expressCheckoutElement&&(this.expressCheckoutElement.unmount(),this.expressCheckoutElement=void 0,this.store.set("isReady",!1))}}const f=new class{createStripeService(){return new c}createCardElementManager(t){return new h(t)}createPaymentElementManager(t){return new u(t)}createAddressElementManager(t){return new d(t)}createLinkAuthenticationElementManager(t){return new v(t)}createCurrencySelectorElementManager(t){return new p(t)}createExpressCheckoutElementManager(t){return new m(t)}};export{a as f,f as s}