stripe-pwa-elements 4.0.1 → 4.0.3

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 (107) hide show
  1. package/dist/cjs/factory-Cm6zUD7R.js +1206 -0
  2. package/dist/cjs/{factory-Cd2VI_N2.js → i18n-lBbOeQt4.js} +12 -1149
  3. package/dist/cjs/ion-icon_2.cjs.entry.js +725 -0
  4. package/dist/cjs/loader.cjs.js +1 -1
  5. package/dist/cjs/stripe-address-element.cjs.entry.js +5 -4
  6. package/dist/cjs/stripe-card-element-modal.cjs.entry.js +3 -2
  7. package/dist/cjs/{stripe-card-element_2.cjs.entry.js → stripe-card-element.cjs.entry.js} +8 -93
  8. package/dist/cjs/stripe-currency-selector.cjs.entry.js +4 -3
  9. package/dist/cjs/stripe-elements.cjs.js +1 -1
  10. package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +24 -5
  11. package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +4 -3
  12. package/dist/cjs/stripe-payment-element.cjs.entry.js +12 -124
  13. package/dist/cjs/stripe-payment-element.helpers-CvAhIqLt.js +119 -0
  14. package/dist/cjs/stripe-payment-request-button.cjs.entry.js +2 -2
  15. package/dist/cjs/stripe-payment-sheet.cjs.entry.js +987 -0
  16. package/dist/collection/collection-manifest.json +2 -1
  17. package/dist/collection/components/stripe-address-element/stripe-address-element.js +2 -2
  18. package/dist/collection/components/stripe-card-element/stripe-card-element.js +3 -2
  19. package/dist/collection/components/stripe-card-element-modal/stripe-card-element-modal.js +4 -3
  20. package/dist/collection/components/stripe-express-checkout-element/stripe-express-checkout-element.js +18 -0
  21. package/dist/collection/components/stripe-modal/stripe-modal.css +27 -1
  22. package/dist/collection/components/stripe-modal/stripe-modal.js +132 -1
  23. package/dist/collection/components/stripe-payment-element/stripe-payment-element.helpers.js +4 -7
  24. package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +4 -4
  25. package/dist/collection/components/stripe-payment-request-button/stripe-payment-request-button.js +3 -3
  26. package/dist/collection/components/stripe-payment-sheet/payment-sheet-state.js +193 -0
  27. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.checkout.js +94 -0
  28. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.css +68 -0
  29. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.helpers.js +274 -0
  30. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +763 -0
  31. package/dist/collection/services/express-checkout-element-manager.js +36 -2
  32. package/dist/collection/services/link-authentication-element-manager.js +5 -0
  33. package/dist/collection/services/stripe-service.js +20 -6
  34. package/dist/collection/utils/focus.js +76 -0
  35. package/dist/collection/utils/i18n.js +12 -0
  36. package/dist/components/factory.js +1 -1
  37. package/dist/components/i18n.js +1 -0
  38. package/dist/components/stripe-address-element.js +1 -1
  39. package/dist/components/stripe-card-element-modal.js +1 -1
  40. package/dist/components/stripe-card-element2.js +1 -1
  41. package/dist/components/stripe-currency-selector.js +1 -1
  42. package/dist/components/stripe-express-checkout-element.js +1 -1
  43. package/dist/components/stripe-link-authentication-element.js +1 -1
  44. package/dist/components/stripe-modal2.js +1 -1
  45. package/dist/components/stripe-payment-element.helpers.js +1 -0
  46. package/dist/components/stripe-payment-element.js +1 -1
  47. package/dist/components/stripe-payment-request-button2.js +1 -1
  48. package/dist/components/stripe-payment-sheet.d.ts +11 -0
  49. package/dist/components/stripe-payment-sheet.js +1 -0
  50. package/dist/esm/factory-BaGv8K_i.js +1203 -0
  51. package/dist/esm/{factory-VTa1Gc94.js → i18n-CL5n3bOb.js} +13 -1149
  52. package/dist/esm/ion-icon_2.entry.js +722 -0
  53. package/dist/esm/loader.js +1 -1
  54. package/dist/esm/stripe-address-element.entry.js +2 -1
  55. package/dist/esm/stripe-card-element-modal.entry.js +3 -2
  56. package/dist/esm/{stripe-card-element_2.entry.js → stripe-card-element.entry.js} +6 -90
  57. package/dist/esm/stripe-currency-selector.entry.js +2 -1
  58. package/dist/esm/stripe-elements.js +1 -1
  59. package/dist/esm/stripe-express-checkout-element.entry.js +20 -1
  60. package/dist/esm/stripe-link-authentication-element.entry.js +2 -1
  61. package/dist/esm/stripe-payment-element.entry.js +4 -116
  62. package/dist/esm/stripe-payment-element.helpers-Bu9RfxS4.js +114 -0
  63. package/dist/esm/stripe-payment-request-button.entry.js +2 -2
  64. package/dist/esm/stripe-payment-sheet.entry.js +985 -0
  65. package/dist/stripe-elements/p-2e41699e.entry.js +1 -0
  66. package/dist/stripe-elements/p-3fc4583a.entry.js +1 -0
  67. package/dist/stripe-elements/{p-ae0c336e.entry.js → p-4891edf0.entry.js} +1 -1
  68. package/dist/stripe-elements/p-7e826964.entry.js +1 -0
  69. package/dist/stripe-elements/p-BhKXGROE.js +1 -0
  70. package/dist/stripe-elements/p-CL5n3bOb.js +1 -0
  71. package/dist/stripe-elements/p-DlMEZwSe.js +1 -0
  72. package/dist/stripe-elements/p-a395a5d1.entry.js +1 -0
  73. package/dist/stripe-elements/p-b62c9dae.entry.js +1 -0
  74. package/dist/stripe-elements/p-b7c20e8e.entry.js +1 -0
  75. package/dist/stripe-elements/p-ba791c8f.entry.js +1 -0
  76. package/dist/stripe-elements/p-bec62526.entry.js +1 -0
  77. package/dist/stripe-elements/p-f5552c81.entry.js +1 -0
  78. package/dist/stripe-elements/stripe-elements.esm.js +1 -1
  79. package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +2 -1
  80. package/dist/types/components/stripe-card-element-modal/stripe-card-element-modal.d.ts +2 -1
  81. package/dist/types/components/stripe-express-checkout-element/stripe-express-checkout-element.d.ts +5 -0
  82. package/dist/types/components/stripe-modal/stripe-modal.d.ts +43 -0
  83. package/dist/types/components/stripe-payment-element/stripe-payment-element.helpers.d.ts +7 -2
  84. package/dist/types/components/stripe-payment-request-button/stripe-payment-request-button.d.ts +1 -1
  85. package/dist/types/components/stripe-payment-sheet/payment-sheet-state.d.ts +121 -0
  86. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.checkout.d.ts +39 -0
  87. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.d.ts +157 -0
  88. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.helpers.d.ts +153 -0
  89. package/dist/types/components.d.ts +182 -10
  90. package/dist/types/index.d.ts +2 -0
  91. package/dist/types/services/interfaces.d.ts +3 -0
  92. package/dist/types/services/stripe-service.d.ts +7 -2
  93. package/dist/types/utils/focus.d.ts +15 -0
  94. package/package.json +7 -3
  95. package/readme.md +59 -6
  96. package/dist/cjs/ion-icon.cjs.entry.js +0 -431
  97. package/dist/components/utils.js +0 -1
  98. package/dist/esm/ion-icon.entry.js +0 -429
  99. package/dist/stripe-elements/p-1bd46766.entry.js +0 -1
  100. package/dist/stripe-elements/p-1c6e0a45.entry.js +0 -1
  101. package/dist/stripe-elements/p-3f42ca0c.entry.js +0 -1
  102. package/dist/stripe-elements/p-5cf62945.entry.js +0 -1
  103. package/dist/stripe-elements/p-74de1556.entry.js +0 -1
  104. package/dist/stripe-elements/p-76e57d78.entry.js +0 -1
  105. package/dist/stripe-elements/p-840d499f.entry.js +0 -1
  106. package/dist/stripe-elements/p-CrjrbGJ3.js +0 -1
  107. package/dist/stripe-elements/p-cfd8e081.entry.js +0 -1
@@ -0,0 +1,1203 @@
1
+ import { S as StencilCore } from './index-C6bbmyga.js';
2
+ import { l as loadStripe } from './index-CBXaOfXU.js';
3
+ import { i as i18n } from './i18n-CL5n3bOb.js';
4
+
5
+ const appendToMap = (map, propName, value) => {
6
+ let refs = map.get(propName);
7
+ if (!refs) {
8
+ refs = [];
9
+ map.set(propName, refs);
10
+ }
11
+ if (!refs.some((ref) => ref.deref() === value)) {
12
+ refs.push(new WeakRef(value));
13
+ }
14
+ };
15
+ const debounce = (fn, ms) => {
16
+ let timeoutId;
17
+ return (...args) => {
18
+ if (timeoutId) {
19
+ clearTimeout(timeoutId);
20
+ }
21
+ timeoutId = setTimeout(() => {
22
+ timeoutId = 0;
23
+ fn(...args);
24
+ }, ms);
25
+ };
26
+ };
27
+
28
+ /**
29
+ * Check if a possible element isConnected.
30
+ * The property might not be there, so we check for it.
31
+ *
32
+ * We want it to return true if isConnected is not a property,
33
+ * otherwise we would remove these elements and would not update.
34
+ *
35
+ * Better leak in Edge than to be useless.
36
+ */
37
+ const isConnected = (maybeElement) => !('isConnected' in maybeElement) || maybeElement.isConnected;
38
+ const cleanupElements = debounce((map) => {
39
+ for (let key of map.keys()) {
40
+ const refs = map.get(key).filter((ref) => {
41
+ const elm = ref.deref();
42
+ return elm && isConnected(elm);
43
+ });
44
+ map.set(key, refs);
45
+ }
46
+ }, 2_000);
47
+ const core = StencilCore;
48
+ const forceUpdate = core.forceUpdate;
49
+ const getRenderingRef = core.getRenderingRef;
50
+ const stencilSubscription = () => {
51
+ if (typeof getRenderingRef !== 'function' || typeof forceUpdate !== 'function') {
52
+ // If we are not in a stencil project, we do nothing.
53
+ // This function is not really exported by @stencil/core.
54
+ return {};
55
+ }
56
+ const ensureForceUpdate = forceUpdate;
57
+ const ensureGetRenderingRef = getRenderingRef;
58
+ const elmsToUpdate = new Map();
59
+ return {
60
+ dispose: () => elmsToUpdate.clear(),
61
+ get: (propName) => {
62
+ const elm = ensureGetRenderingRef();
63
+ if (elm) {
64
+ appendToMap(elmsToUpdate, propName, elm);
65
+ }
66
+ },
67
+ set: (propName) => {
68
+ const refs = elmsToUpdate.get(propName);
69
+ if (refs) {
70
+ const nextRefs = refs.filter((ref) => {
71
+ const elm = ref.deref();
72
+ if (!elm)
73
+ return false;
74
+ return ensureForceUpdate(elm);
75
+ });
76
+ elmsToUpdate.set(propName, nextRefs);
77
+ }
78
+ cleanupElements(elmsToUpdate);
79
+ },
80
+ reset: () => {
81
+ elmsToUpdate.forEach((refs) => {
82
+ refs.forEach((ref) => {
83
+ const elm = ref.deref();
84
+ if (elm)
85
+ ensureForceUpdate(elm);
86
+ });
87
+ });
88
+ cleanupElements(elmsToUpdate);
89
+ },
90
+ };
91
+ };
92
+
93
+ const unwrap = (val) => (typeof val === 'function' ? val() : val);
94
+ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) => {
95
+ const resolveDefaultState = () => (unwrap(defaultState) ?? {});
96
+ const initialState = resolveDefaultState();
97
+ let states = new Map(Object.entries(initialState));
98
+ const proxyAvailable = typeof Proxy !== 'undefined';
99
+ const plainState = proxyAvailable ? null : {};
100
+ const handlers = {
101
+ dispose: [],
102
+ get: [],
103
+ set: [],
104
+ reset: [],
105
+ };
106
+ // Track onChange listeners to enable removeListener functionality
107
+ const changeListeners = new Map();
108
+ const reset = () => {
109
+ // When resetting the state, the default state may be a function - unwrap it to invoke it.
110
+ // otherwise, the state won't be properly reset
111
+ states = new Map(Object.entries(resolveDefaultState()));
112
+ if (!proxyAvailable) {
113
+ syncPlainStateKeys();
114
+ }
115
+ handlers.reset.forEach((cb) => cb());
116
+ };
117
+ const dispose = () => {
118
+ // Call first dispose as resetting the state would
119
+ // cause less updates ;)
120
+ handlers.dispose.forEach((cb) => cb());
121
+ reset();
122
+ };
123
+ const get = (propName) => {
124
+ handlers.get.forEach((cb) => cb(propName));
125
+ return states.get(propName);
126
+ };
127
+ const set = (propName, value) => {
128
+ const oldValue = states.get(propName);
129
+ if (shouldUpdate(value, oldValue, propName)) {
130
+ states.set(propName, value);
131
+ if (!proxyAvailable) {
132
+ ensurePlainProperty(propName);
133
+ }
134
+ handlers.set.forEach((cb) => cb(propName, value, oldValue));
135
+ }
136
+ };
137
+ const state = (proxyAvailable
138
+ ? new Proxy(initialState, {
139
+ get(_, propName) {
140
+ return get(propName);
141
+ },
142
+ ownKeys(_) {
143
+ return Array.from(states.keys());
144
+ },
145
+ getOwnPropertyDescriptor() {
146
+ return {
147
+ enumerable: true,
148
+ configurable: true,
149
+ };
150
+ },
151
+ has(_, propName) {
152
+ return states.has(propName);
153
+ },
154
+ set(_, propName, value) {
155
+ set(propName, value);
156
+ return true;
157
+ },
158
+ })
159
+ : (() => {
160
+ syncPlainStateKeys();
161
+ return plainState;
162
+ })());
163
+ const on = (eventName, callback) => {
164
+ handlers[eventName].push(callback);
165
+ return () => {
166
+ removeFromArray(handlers[eventName], callback);
167
+ };
168
+ };
169
+ const onChange = (propName, cb) => {
170
+ const setHandler = (key, newValue) => {
171
+ if (key === propName) {
172
+ cb(newValue);
173
+ }
174
+ };
175
+ const resetHandler = () => {
176
+ const snapshot = resolveDefaultState();
177
+ cb(snapshot[propName]);
178
+ };
179
+ // Register the handlers
180
+ const unSet = on('set', setHandler);
181
+ const unReset = on('reset', resetHandler);
182
+ // Track the relationship between the user callback and internal handlers
183
+ changeListeners.set(cb, { setHandler, resetHandler, propName });
184
+ return () => {
185
+ unSet();
186
+ unReset();
187
+ changeListeners.delete(cb);
188
+ };
189
+ };
190
+ const use = (...subscriptions) => {
191
+ const unsubs = subscriptions.reduce((unsubs, subscription) => {
192
+ if (subscription.set) {
193
+ unsubs.push(on('set', subscription.set));
194
+ }
195
+ if (subscription.get) {
196
+ unsubs.push(on('get', subscription.get));
197
+ }
198
+ if (subscription.reset) {
199
+ unsubs.push(on('reset', subscription.reset));
200
+ }
201
+ if (subscription.dispose) {
202
+ unsubs.push(on('dispose', subscription.dispose));
203
+ }
204
+ return unsubs;
205
+ }, []);
206
+ return () => unsubs.forEach((unsub) => unsub());
207
+ };
208
+ const forceUpdate = (key) => {
209
+ const oldValue = states.get(key);
210
+ handlers.set.forEach((cb) => cb(key, oldValue, oldValue));
211
+ };
212
+ const removeListener = (propName, listener) => {
213
+ const listenerInfo = changeListeners.get(listener);
214
+ if (listenerInfo && listenerInfo.propName === propName) {
215
+ // Remove the specific handlers that were created for this listener
216
+ removeFromArray(handlers.set, listenerInfo.setHandler);
217
+ removeFromArray(handlers.reset, listenerInfo.resetHandler);
218
+ changeListeners.delete(listener);
219
+ }
220
+ };
221
+ function ensurePlainProperty(key) {
222
+ if (proxyAvailable || !plainState) {
223
+ return;
224
+ }
225
+ if (Object.prototype.hasOwnProperty.call(plainState, key)) {
226
+ return;
227
+ }
228
+ Object.defineProperty(plainState, key, {
229
+ configurable: true,
230
+ enumerable: true,
231
+ get() {
232
+ return get(key);
233
+ },
234
+ set(value) {
235
+ set(key, value);
236
+ },
237
+ });
238
+ }
239
+ function syncPlainStateKeys() {
240
+ if (proxyAvailable || !plainState) {
241
+ return;
242
+ }
243
+ const knownKeys = new Set(states.keys());
244
+ for (const key of Object.keys(plainState)) {
245
+ if (!knownKeys.has(key)) {
246
+ delete plainState[key];
247
+ }
248
+ }
249
+ for (const key of knownKeys) {
250
+ ensurePlainProperty(key);
251
+ }
252
+ }
253
+ return {
254
+ state,
255
+ get,
256
+ set,
257
+ on,
258
+ onChange,
259
+ use,
260
+ dispose,
261
+ reset,
262
+ forceUpdate,
263
+ removeListener,
264
+ };
265
+ };
266
+ const removeFromArray = (array, item) => {
267
+ const index = array.indexOf(item);
268
+ if (index >= 0) {
269
+ array[index] = array[array.length - 1];
270
+ array.length--;
271
+ }
272
+ };
273
+
274
+ const createStore = (defaultState, shouldUpdate) => {
275
+ const map = createObservableMap(defaultState, shouldUpdate);
276
+ map.use(stencilSubscription());
277
+ return map;
278
+ };
279
+
280
+ /**
281
+ * Core Stripe Service
282
+ * Manages Stripe.js initialization and Elements instance only
283
+ * Does NOT manage specific element types (Card, Payment, etc.)
284
+ */
285
+ class StripeServiceClass {
286
+ constructor() {
287
+ this.store = createStore({
288
+ loadStripeStatus: '',
289
+ applicationName: 'stripe-pwa-elements',
290
+ isCheckoutSession: false,
291
+ });
292
+ /** Incremented on every init so that a slower, older call cannot overwrite newer state */
293
+ this.initGeneration = 0;
294
+ this.changeListeners = new Map();
295
+ }
296
+ /**
297
+ * Get the reactive state object
298
+ * Components can use this directly in render() for automatic reactivity
299
+ */
300
+ get state() {
301
+ return this.store.state;
302
+ }
303
+ /**
304
+ * Register a callback for when a specific state property changes
305
+ * @param key - The state property to watch
306
+ * @param callback - Function to call when the property changes
307
+ * @returns Unsubscribe function
308
+ */
309
+ onChange(key, callback) {
310
+ const dispose = this.store.onChange(key, callback);
311
+ // Track listeners for cleanup
312
+ if (!this.changeListeners.has(key)) {
313
+ this.changeListeners.set(key, []);
314
+ }
315
+ this.changeListeners.get(key).push(dispose);
316
+ return dispose;
317
+ }
318
+ /**
319
+ * Initialize Stripe.js client with Payment Intent mode
320
+ * @param publishableKey - Your Stripe publishable API key
321
+ * @param options - Optional configuration. `clientSecret` is the PaymentIntent / SetupIntent client secret;
322
+ * `elementsOptions` (mode / amount / currency) is used to create Elements when there is no client secret.
323
+ * `clientSecret` takes priority when both are given.
324
+ */
325
+ async initialize(publishableKey, options) {
326
+ const elementsOptionsKey = (options === null || options === void 0 ? void 0 : options.elementsOptions) != null ? JSON.stringify(options.elementsOptions) : undefined;
327
+ // Capture the previous config before overwriting it, so we can detect real changes
328
+ const isUpToDate = this.store.state.stripe != null &&
329
+ !this.store.state.isCheckoutSession &&
330
+ this.store.state.publishableKey === publishableKey &&
331
+ this.store.state.stripeAccount === (options === null || options === void 0 ? void 0 : options.stripeAccount) &&
332
+ this.intentClientSecret === (options === null || options === void 0 ? void 0 : options.clientSecret) &&
333
+ this.elementsOptionsKey === elementsOptionsKey;
334
+ // Update configuration
335
+ this.store.state.publishableKey = publishableKey;
336
+ this.store.state.isCheckoutSession = false;
337
+ this.intentClientSecret = options === null || options === void 0 ? void 0 : options.clientSecret;
338
+ this.elementsOptionsKey = elementsOptionsKey;
339
+ if ((options === null || options === void 0 ? void 0 : options.stripeAccount) != null && (options === null || options === void 0 ? void 0 : options.stripeAccount) !== '') {
340
+ this.store.state.stripeAccount = options.stripeAccount;
341
+ }
342
+ if ((options === null || options === void 0 ? void 0 : options.applicationName) != null && (options === null || options === void 0 ? void 0 : options.applicationName) !== '') {
343
+ this.store.state.applicationName = options.applicationName;
344
+ }
345
+ // If Stripe.js already loaded with same config, do nothing.
346
+ // Return before bumping the generation, so an in-flight init for this same config is not discarded.
347
+ if (isUpToDate) {
348
+ return;
349
+ }
350
+ const generation = ++this.initGeneration;
351
+ this.store.state.loadStripeStatus = 'loading';
352
+ try {
353
+ const stripe = await loadStripe(publishableKey, {
354
+ stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
355
+ });
356
+ if (generation !== this.initGeneration) {
357
+ return;
358
+ }
359
+ // Register app info
360
+ stripe.registerAppInfo({
361
+ name: this.store.state.applicationName,
362
+ });
363
+ this.store.state.stripe = stripe;
364
+ // Elements must be created with a client secret, or with mode / amount / currency, depending on the element type
365
+ if ((options === null || options === void 0 ? void 0 : options.clientSecret) != null && options.clientSecret !== '') {
366
+ this.store.state.elements = stripe.elements({ clientSecret: options.clientSecret });
367
+ }
368
+ else if ((options === null || options === void 0 ? void 0 : options.elementsOptions) != null) {
369
+ this.store.state.elements = stripe.elements(options.elementsOptions);
370
+ }
371
+ else {
372
+ this.store.state.elements = stripe.elements();
373
+ }
374
+ this.store.state.checkout = undefined;
375
+ this.store.state.loadStripeStatus = 'success';
376
+ }
377
+ catch (e) {
378
+ console.error('Failed to load Stripe.js:', e);
379
+ this.store.state.loadStripeStatus = 'failure';
380
+ }
381
+ }
382
+ /**
383
+ * Initialize Stripe.js client with Checkout Session mode
384
+ * @param publishableKey - Your Stripe publishable API key
385
+ * @param checkoutSessionClientSecret - The client secret from Checkout Session
386
+ * @param options - Optional configuration (`clientSecret` is the PaymentIntent / SetupIntent client secret)
387
+ */
388
+ async initializeWithCheckoutSession(publishableKey, checkoutSessionClientSecret, options) {
389
+ const generation = ++this.initGeneration;
390
+ // Update configuration
391
+ this.store.state.publishableKey = publishableKey;
392
+ this.store.state.isCheckoutSession = true;
393
+ if ((options === null || options === void 0 ? void 0 : options.stripeAccount) != null && (options === null || options === void 0 ? void 0 : options.stripeAccount) !== '') {
394
+ this.store.state.stripeAccount = options.stripeAccount;
395
+ }
396
+ if ((options === null || options === void 0 ? void 0 : options.applicationName) != null && (options === null || options === void 0 ? void 0 : options.applicationName) !== '') {
397
+ this.store.state.applicationName = options.applicationName;
398
+ }
399
+ this.store.state.loadStripeStatus = 'loading';
400
+ try {
401
+ const stripe = await loadStripe(publishableKey, {
402
+ stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
403
+ });
404
+ if (generation !== this.initGeneration) {
405
+ return;
406
+ }
407
+ // Register app info
408
+ stripe.registerAppInfo({
409
+ name: this.store.state.applicationName,
410
+ });
411
+ this.store.state.stripe = stripe;
412
+ // Initialize Checkout instance instead of Elements
413
+ const checkout = stripe.initCheckoutElementsSdk({
414
+ clientSecret: checkoutSessionClientSecret,
415
+ elementsOptions: options === null || options === void 0 ? void 0 : options.elementsOptions,
416
+ });
417
+ this.store.state.checkout = checkout;
418
+ this.store.state.elements = undefined;
419
+ this.store.state.loadStripeStatus = 'success';
420
+ }
421
+ catch (e) {
422
+ console.error('Failed to initialize Stripe Checkout:', e);
423
+ this.store.state.loadStripeStatus = 'failure';
424
+ }
425
+ }
426
+ /**
427
+ * Get the current Stripe instance
428
+ */
429
+ getStripe() {
430
+ return this.store.state.stripe;
431
+ }
432
+ /**
433
+ * Get the current Elements instance
434
+ */
435
+ getElements() {
436
+ return this.store.state.elements;
437
+ }
438
+ /**
439
+ * Get the current Checkout instance (for Checkout Session mode)
440
+ */
441
+ getCheckout() {
442
+ return this.store.state.checkout;
443
+ }
444
+ /**
445
+ * Reset the service to initial state
446
+ * Useful for testing and cleanup
447
+ */
448
+ reset() {
449
+ this.store.reset();
450
+ }
451
+ /**
452
+ * Dispose of all listeners and reset state
453
+ * Should be called in test cleanup
454
+ */
455
+ dispose() {
456
+ // Dispose all onChange listeners
457
+ this.changeListeners.forEach(listeners => {
458
+ listeners.forEach(dispose => dispose());
459
+ });
460
+ this.changeListeners.clear();
461
+ // Dispose the store
462
+ this.store.dispose();
463
+ }
464
+ }
465
+ /**
466
+ * Singleton instance of StripeService (for backward compatibility)
467
+ * New code should use ServiceFactory for better testability
468
+ *
469
+ * @deprecated Use ServiceFactory.createStripeService() for better DI support
470
+ */
471
+ new StripeServiceClass();
472
+
473
+ /**
474
+ * Wait for an element to appear in the DOM
475
+ * @param containerElement - Parent element to search in
476
+ * @param selector - CSS selector
477
+ * @param timeout - Timeout in milliseconds (default: 5000ms)
478
+ * @returns Promise that resolves to the found element or rejects on timeout
479
+ */
480
+ function findElement(containerElement, selector, timeout = 5000) {
481
+ return new Promise((resolve, reject) => {
482
+ const elem = containerElement.querySelector(selector);
483
+ if (elem != null) {
484
+ return resolve(elem);
485
+ }
486
+ const timeoutId = setTimeout(() => {
487
+ observer.disconnect();
488
+ reject(new Error(`Element "${selector}" not found within ${timeout}ms`));
489
+ }, timeout);
490
+ const observer = new MutationObserver(() => {
491
+ const elem = containerElement.querySelector(selector);
492
+ if (elem != null) {
493
+ clearTimeout(timeoutId);
494
+ observer.disconnect();
495
+ resolve(elem);
496
+ }
497
+ });
498
+ observer.observe(containerElement, {
499
+ childList: true,
500
+ subtree: true,
501
+ });
502
+ });
503
+ }
504
+
505
+ /**
506
+ * Card Element Manager
507
+ * Manages Stripe Card Elements (cardNumber, cardExpiry, cardCvc)
508
+ * with dependency injection of StripeService
509
+ */
510
+ class CardElementManager {
511
+ /**
512
+ * Constructor with dependency injection
513
+ * @param stripeService - Injected Stripe service instance
514
+ */
515
+ constructor(stripeService) {
516
+ this.stripeService = stripeService;
517
+ this.store = createStore({
518
+ errorMessage: '',
519
+ errorSource: undefined,
520
+ });
521
+ }
522
+ /**
523
+ * Get current card element state (reactive)
524
+ */
525
+ getState() {
526
+ return this.store.state;
527
+ }
528
+ /**
529
+ * Initialize and mount card elements to DOM
530
+ * @param containerElement - Parent element containing mount points
531
+ * @returns Promise resolving to card element instances
532
+ */
533
+ async initialize(containerElement) {
534
+ const elements = this.stripeService.getElements();
535
+ if (elements == null) {
536
+ throw new Error('StripeService not initialized. Call StripeService.initialize() first.');
537
+ }
538
+ // Unmount if already initialized
539
+ if (this.cardElements != null) {
540
+ this.unmount();
541
+ }
542
+ // Create and mount card number element
543
+ const cardNumber = elements.create('cardNumber', {
544
+ placeholder: i18n.t('Card Number'),
545
+ });
546
+ const cardNumberElement = await findElement(containerElement, '#card-number');
547
+ cardNumber.mount(cardNumberElement);
548
+ cardNumber.on('change', this.handleCardError('cardNumber'));
549
+ // Create and mount card expiry element
550
+ const cardExpiry = elements.create('cardExpiry');
551
+ const cardExpiryElement = await findElement(containerElement, '#card-expiry');
552
+ cardExpiry.mount(cardExpiryElement);
553
+ cardExpiry.on('change', this.handleCardError('cardExpiry'));
554
+ // Create and mount card CVC element
555
+ const cardCVC = elements.create('cardCvc');
556
+ const cardCVCElement = await findElement(containerElement, '#card-cvc');
557
+ cardCVC.mount(cardCVCElement);
558
+ cardCVC.on('change', this.handleCardError('cardCvc'));
559
+ this.cardElements = {
560
+ cardNumber,
561
+ cardExpiry,
562
+ cardCVC,
563
+ };
564
+ return this.cardElements;
565
+ }
566
+ /**
567
+ * Get mounted card element instances
568
+ */
569
+ getElements() {
570
+ return this.cardElements;
571
+ }
572
+ /**
573
+ * Set error message (triggers reactivity)
574
+ */
575
+ setError(message) {
576
+ this.store.set('errorMessage', message);
577
+ }
578
+ /**
579
+ * Clear error message (triggers reactivity)
580
+ */
581
+ clearError() {
582
+ this.store.set('errorMessage', '');
583
+ this.store.set('errorSource', undefined);
584
+ }
585
+ /**
586
+ * Unmount all card elements
587
+ */
588
+ unmount() {
589
+ var _a, _b, _c;
590
+ if (this.cardElements == null) {
591
+ return;
592
+ }
593
+ (_a = this.cardElements.cardNumber) === null || _a === void 0 ? void 0 : _a.unmount();
594
+ (_b = this.cardElements.cardExpiry) === null || _b === void 0 ? void 0 : _b.unmount();
595
+ (_c = this.cardElements.cardCVC) === null || _c === void 0 ? void 0 : _c.unmount();
596
+ this.cardElements = undefined;
597
+ }
598
+ /**
599
+ * Handle card element errors
600
+ * Only clears error if it's from the same element type
601
+ * Uses store.set() to trigger reactivity
602
+ */
603
+ handleCardError(elementType) {
604
+ return ({ error }) => {
605
+ if (error) {
606
+ this.store.set('errorMessage', error.message);
607
+ this.store.set('errorSource', elementType);
608
+ return;
609
+ }
610
+ // Only clear error if it originated from the same element
611
+ if (this.store.state.errorSource === elementType) {
612
+ this.store.set('errorMessage', '');
613
+ this.store.set('errorSource', undefined);
614
+ }
615
+ };
616
+ }
617
+ }
618
+
619
+ /**
620
+ * Payment Element Manager
621
+ * Manages Stripe Payment Element (unified payment form)
622
+ * with dependency injection of StripeService
623
+ * Supports both Payment Intent mode and Checkout Session mode
624
+ */
625
+ class PaymentElementManager {
626
+ /**
627
+ * Constructor with dependency injection
628
+ * @param stripeService - Injected Stripe service instance
629
+ */
630
+ constructor(stripeService) {
631
+ this.stripeService = stripeService;
632
+ this.store = createStore({
633
+ errorMessage: '',
634
+ });
635
+ }
636
+ /**
637
+ * Get current payment element state (reactive)
638
+ */
639
+ getState() {
640
+ return this.store.state;
641
+ }
642
+ /**
643
+ * Initialize and mount payment element to DOM
644
+ * Supports both Payment Intent mode and Checkout Session mode
645
+ * @param containerElement - Parent element containing mount point
646
+ * @param options - Optional payment element options
647
+ * @returns Promise resolving to payment element instance
648
+ */
649
+ async initialize(containerElement, options) {
650
+ const isCheckoutSession = this.stripeService.state.isCheckoutSession;
651
+ // Unmount if already initialized
652
+ if (this.paymentElement != null) {
653
+ this.unmount();
654
+ }
655
+ if (isCheckoutSession) {
656
+ // Checkout Session mode: use checkout.createPaymentElement()
657
+ const checkout = this.stripeService.getCheckout();
658
+ if (checkout == null) {
659
+ throw new Error('StripeService not initialized with Checkout Session. Call StripeService.initializeWithCheckoutSession() first.');
660
+ }
661
+ // Create payment element using Checkout instance
662
+ this.paymentElement = checkout.createPaymentElement(options);
663
+ }
664
+ else {
665
+ // Payment Intent mode: use elements.create('payment')
666
+ const elements = this.stripeService.getElements();
667
+ if (elements == null) {
668
+ throw new Error('StripeService not initialized. Call StripeService.initialize() first.');
669
+ }
670
+ // Create payment element with options
671
+ const elementOptions = options || {};
672
+ // Create the payment element
673
+ this.paymentElement = elements.create('payment', elementOptions);
674
+ }
675
+ // Find mount point and mount
676
+ const paymentElementContainer = await findElement(containerElement, '#payment-element');
677
+ this.paymentElement.mount(paymentElementContainer);
678
+ // Note: Payment Element errors are handled during submission
679
+ // Use setError() method to manually set errors if needed
680
+ return this.paymentElement;
681
+ }
682
+ /**
683
+ * Get mounted payment element instance
684
+ */
685
+ getElement() {
686
+ return this.paymentElement;
687
+ }
688
+ /**
689
+ * Set error message (triggers reactivity)
690
+ */
691
+ setError(message) {
692
+ this.store.set('errorMessage', message);
693
+ }
694
+ /**
695
+ * Clear error message (triggers reactivity)
696
+ */
697
+ clearError() {
698
+ this.store.set('errorMessage', '');
699
+ }
700
+ /**
701
+ * Unmount payment element
702
+ */
703
+ unmount() {
704
+ if (this.paymentElement == null) {
705
+ return;
706
+ }
707
+ this.paymentElement.unmount();
708
+ this.paymentElement = undefined;
709
+ }
710
+ }
711
+
712
+ /**
713
+ * Address Element Manager
714
+ * Manages Stripe Address Element
715
+ * with dependency injection of StripeService
716
+ */
717
+ class AddressElementManager {
718
+ /**
719
+ * Constructor with dependency injection
720
+ * @param stripeService - Injected Stripe service instance
721
+ */
722
+ constructor(stripeService) {
723
+ this.stripeService = stripeService;
724
+ this.store = createStore({
725
+ errorMessage: '',
726
+ isComplete: false,
727
+ });
728
+ }
729
+ /**
730
+ * Get current address element state (reactive)
731
+ */
732
+ getState() {
733
+ return this.store.state;
734
+ }
735
+ /**
736
+ * Initialize and mount address element to DOM
737
+ * @param containerElement - Parent element containing mount point
738
+ * @param options - Address element options
739
+ * @returns Promise resolving to address element instance
740
+ */
741
+ async initialize(containerElement, options) {
742
+ const elements = this.stripeService.getElements();
743
+ if (elements == null) {
744
+ throw new Error('StripeService not initialized. Call StripeService.initialize() first.');
745
+ }
746
+ // Unmount if already initialized
747
+ if (this.addressElement != null) {
748
+ this.unmount();
749
+ }
750
+ // Create and mount address element
751
+ this.addressElement = elements.create('address', options || { mode: 'billing' });
752
+ const addressElementContainer = await findElement(containerElement, '#address-element');
753
+ this.addressElement.mount(addressElementContainer);
754
+ // Listen for changes
755
+ this.addressElement.on('change', event => {
756
+ // StripeAddressElementChangeEvent doesn't have an error property
757
+ // Errors are handled through the complete property and validation
758
+ this.store.set('errorMessage', '');
759
+ this.store.set('isComplete', event.complete);
760
+ });
761
+ return this.addressElement;
762
+ }
763
+ /**
764
+ * Get mounted address element instance
765
+ */
766
+ getElement() {
767
+ return this.addressElement;
768
+ }
769
+ /**
770
+ * Set error message (triggers reactivity)
771
+ */
772
+ setError(message) {
773
+ this.store.set('errorMessage', message);
774
+ }
775
+ /**
776
+ * Clear error message (triggers reactivity)
777
+ */
778
+ clearError() {
779
+ this.store.set('errorMessage', '');
780
+ }
781
+ /**
782
+ * Unmount address element
783
+ */
784
+ unmount() {
785
+ if (this.addressElement == null) {
786
+ return;
787
+ }
788
+ this.addressElement.unmount();
789
+ this.addressElement = undefined;
790
+ }
791
+ }
792
+
793
+ /**
794
+ * Link Authentication Element Manager
795
+ * Manages Stripe Link Authentication Element for email collection and Link authentication
796
+ * with dependency injection of StripeService
797
+ */
798
+ class LinkAuthenticationElementManager {
799
+ /**
800
+ * Constructor with dependency injection
801
+ * @param stripeService - Injected Stripe service instance
802
+ */
803
+ constructor(stripeService) {
804
+ this.stripeService = stripeService;
805
+ this.store = createStore({
806
+ errorMessage: '',
807
+ email: undefined,
808
+ complete: undefined,
809
+ });
810
+ }
811
+ /**
812
+ * Get current link authentication element state (reactive)
813
+ */
814
+ getState() {
815
+ return this.store.state;
816
+ }
817
+ /**
818
+ * Register state change listener
819
+ * @param key - State property to watch
820
+ * @param callback - Callback function invoked when property changes
821
+ * @returns Unsubscribe function
822
+ */
823
+ onChange(key, callback) {
824
+ return this.store.onChange(key, callback);
825
+ }
826
+ /**
827
+ * Initialize and mount link authentication element to DOM
828
+ * @param containerElement - Parent element containing mount point
829
+ * @param options - Optional configuration for Link Authentication Element
830
+ * @returns Promise resolving to link authentication element instance
831
+ */
832
+ async initialize(containerElement, options) {
833
+ const elements = this.stripeService.getElements();
834
+ if (elements == null) {
835
+ throw new Error('StripeService not initialized. Call StripeService.initialize() first.');
836
+ }
837
+ // Unmount if already initialized
838
+ if (this.linkAuthenticationElement != null) {
839
+ this.unmount();
840
+ }
841
+ // The values of a previous element do not apply to the new one
842
+ this.store.set('email', undefined);
843
+ this.store.set('complete', undefined);
844
+ // Create link authentication element
845
+ const linkAuthentication = elements.create('linkAuthentication', options);
846
+ const linkAuthenticationElementDiv = await findElement(containerElement, '#link-authentication-element');
847
+ linkAuthentication.mount(linkAuthenticationElementDiv);
848
+ // Listen for change events
849
+ linkAuthentication.on('change', event => {
850
+ var _a;
851
+ // Unconditionally set email from event.value.email
852
+ // This handles all cases: valid email, empty string, or undefined
853
+ this.store.set('email', (_a = event.value) === null || _a === void 0 ? void 0 : _a.email);
854
+ this.store.set('complete', event.complete);
855
+ });
856
+ this.linkAuthenticationElement = linkAuthentication;
857
+ return this.linkAuthenticationElement;
858
+ }
859
+ /**
860
+ * Get mounted link authentication element instance
861
+ */
862
+ getElement() {
863
+ return this.linkAuthenticationElement;
864
+ }
865
+ /**
866
+ * Set error message (triggers reactivity)
867
+ */
868
+ setError(message) {
869
+ this.store.set('errorMessage', message);
870
+ }
871
+ /**
872
+ * Clear error message (triggers reactivity)
873
+ */
874
+ clearError() {
875
+ this.store.set('errorMessage', '');
876
+ }
877
+ /**
878
+ * Unmount link authentication element
879
+ */
880
+ unmount() {
881
+ if (this.linkAuthenticationElement == null) {
882
+ return;
883
+ }
884
+ this.linkAuthenticationElement.unmount();
885
+ this.linkAuthenticationElement = undefined;
886
+ }
887
+ }
888
+
889
+ /**
890
+ * Currency Selector Element Manager
891
+ * Manages Stripe Currency Selector Element
892
+ * with dependency injection of StripeService
893
+ */
894
+ class CurrencySelectorElementManager {
895
+ /**
896
+ * Constructor with dependency injection
897
+ * @param stripeService - Injected Stripe service instance
898
+ */
899
+ constructor(stripeService) {
900
+ this.stripeService = stripeService;
901
+ this.store = createStore({
902
+ errorMessage: '',
903
+ selectedCurrency: undefined,
904
+ });
905
+ }
906
+ /**
907
+ * Get current currency selector element state (reactive)
908
+ */
909
+ getState() {
910
+ return this.store.state;
911
+ }
912
+ /**
913
+ * Initialize and mount currency selector element to DOM
914
+ * @param containerElement - Parent element containing mount point
915
+ * @param options - Currency selector element options
916
+ * @returns Promise resolving to currency selector element instance
917
+ * Note: StripeCurrencySelectorElementOptions is not yet exported in @stripe/stripe-js v8.6.0
918
+ */
919
+ async initialize(containerElement, options) {
920
+ const elements = this.stripeService.getElements();
921
+ if (elements == null) {
922
+ throw new Error('StripeService not initialized. Call StripeService.initialize() first.');
923
+ }
924
+ // Unmount if already initialized
925
+ if (this.currencySelectorElement != null) {
926
+ this.unmount();
927
+ }
928
+ // Find mount point first to avoid element leak if findElement throws
929
+ const currencySelectorElementContainer = await findElement(containerElement, '#currency-selector');
930
+ // Create and mount currency selector element
931
+ // Note: 'currencySelector' type is not yet in @stripe/stripe-js v8.6.0 type definitions
932
+ // but is documented in Stripe's Currency Selector Element documentation
933
+ this.currencySelectorElement = elements.create('currencySelector', options || {});
934
+ this.currencySelectorElement.mount(currencySelectorElementContainer);
935
+ // Listen for changes
936
+ // Note: The 'change' event type is not yet in @stripe/stripe-js type definitions
937
+ // but is documented in Stripe's Currency Selector Element documentation
938
+ this.currencySelectorElement.on('change', (event) => {
939
+ var _a;
940
+ // Clear error on change
941
+ this.store.set('errorMessage', '');
942
+ // Update selected currency if available
943
+ if ((_a = event === null || event === void 0 ? void 0 : event.value) === null || _a === void 0 ? void 0 : _a.currency) {
944
+ this.store.set('selectedCurrency', event.value.currency);
945
+ }
946
+ });
947
+ return this.currencySelectorElement;
948
+ }
949
+ /**
950
+ * Get mounted currency selector element instance
951
+ */
952
+ getElement() {
953
+ return this.currencySelectorElement;
954
+ }
955
+ /**
956
+ * Set error message (triggers reactivity)
957
+ */
958
+ setError(message) {
959
+ this.store.set('errorMessage', message);
960
+ }
961
+ /**
962
+ * Clear error message (triggers reactivity)
963
+ */
964
+ clearError() {
965
+ this.store.set('errorMessage', '');
966
+ }
967
+ /**
968
+ * Unmount currency selector element
969
+ */
970
+ unmount() {
971
+ if (this.currencySelectorElement == null) {
972
+ return;
973
+ }
974
+ this.currencySelectorElement.unmount();
975
+ this.currencySelectorElement = undefined;
976
+ }
977
+ }
978
+
979
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
980
+ var t = {};
981
+ for (var p in s)
982
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
983
+ t[p] = s[p];
984
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
985
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
986
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
987
+ t[p[i]] = s[p[i]];
988
+ }
989
+ return t;
990
+ };
991
+ /**
992
+ * Express Checkout Element Manager
993
+ * Manages Stripe Express Checkout Element
994
+ * with dependency injection of StripeService
995
+ */
996
+ class ExpressCheckoutElementManager {
997
+ /**
998
+ * Constructor with dependency injection
999
+ * @param stripeService - Injected Stripe service instance
1000
+ */
1001
+ constructor(stripeService) {
1002
+ this.stripeService = stripeService;
1003
+ this.store = createStore({
1004
+ errorMessage: '',
1005
+ isReady: false,
1006
+ });
1007
+ }
1008
+ /**
1009
+ * Get current express checkout element state (reactive)
1010
+ */
1011
+ getState() {
1012
+ return this.store.state;
1013
+ }
1014
+ /**
1015
+ * Initialize and mount express checkout element to DOM
1016
+ * @param containerElement - Parent element containing mount point
1017
+ * @param options - Express Checkout Element configuration options
1018
+ * @param eventHandlers - Event handlers for element events
1019
+ * @returns Promise resolving to express checkout element instance
1020
+ */
1021
+ async initialize(containerElement, options, eventHandlers) {
1022
+ const elements = this.stripeService.getElements();
1023
+ if (elements == null) {
1024
+ throw new Error('StripeService not initialized. Call StripeService.initialize() first.');
1025
+ }
1026
+ // Unmount if already initialized
1027
+ if (this.expressCheckoutElement != null) {
1028
+ this.unmount();
1029
+ }
1030
+ // mode / amount / currency belong to stripe.elements(), not to elements.create('expressCheckout')
1031
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1032
+ const restOptions = __rest(options, ["mode", "amount", "currency"]);
1033
+ const createOptions = Object.assign({}, restOptions);
1034
+ // Convert buttonHeight from string to number if present
1035
+ if (createOptions.buttonHeight && typeof createOptions.buttonHeight === 'string') {
1036
+ const height = parseInt(createOptions.buttonHeight.replace('px', ''), 10);
1037
+ if (!isNaN(height)) {
1038
+ createOptions.buttonHeight = height;
1039
+ }
1040
+ }
1041
+ // Create express checkout element
1042
+ // Note: 'expressCheckout' is not yet in the official Stripe type definitions
1043
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1044
+ const expressCheckout = elements.create('expressCheckout', createOptions);
1045
+ // Find the mount point
1046
+ const mountPoint = await findElement(containerElement, '#express-checkout-element');
1047
+ // Set up event handlers before mounting
1048
+ if ((eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onConfirm) != null) {
1049
+ expressCheckout.on('confirm', eventHandlers.onConfirm);
1050
+ }
1051
+ if ((eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onClick) != null) {
1052
+ expressCheckout.on('click', eventHandlers.onClick);
1053
+ }
1054
+ if ((eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onCancel) != null) {
1055
+ expressCheckout.on('cancel', eventHandlers.onCancel);
1056
+ }
1057
+ if ((eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onShippingAddressChange) != null) {
1058
+ expressCheckout.on('shippingaddresschange', eventHandlers.onShippingAddressChange);
1059
+ }
1060
+ if ((eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onShippingRateChange) != null) {
1061
+ expressCheckout.on('shippingratechange', eventHandlers.onShippingRateChange);
1062
+ }
1063
+ // Add ready event handler
1064
+ expressCheckout.on('ready', () => {
1065
+ this.store.set('isReady', true);
1066
+ });
1067
+ // Mount the element
1068
+ expressCheckout.mount(mountPoint);
1069
+ this.expressCheckoutElement = expressCheckout;
1070
+ return this.expressCheckoutElement;
1071
+ }
1072
+ /**
1073
+ * Get mounted express checkout element instance
1074
+ */
1075
+ getElement() {
1076
+ return this.expressCheckoutElement;
1077
+ }
1078
+ /**
1079
+ * Update element options dynamically
1080
+ * @param options - Partial options to update
1081
+ */
1082
+ update(options) {
1083
+ var _a;
1084
+ if (this.expressCheckoutElement == null) {
1085
+ console.warn('Express Checkout Element not initialized. Cannot update options.');
1086
+ return;
1087
+ }
1088
+ // mode / amount / currency are Elements group options, so they are updated with elements.update()
1089
+ const { mode, amount, currency } = options, elementOptions = __rest(options, ["mode", "amount", "currency"]);
1090
+ const groupOptions = {};
1091
+ if (mode !== undefined) {
1092
+ groupOptions.mode = mode;
1093
+ }
1094
+ if (amount !== undefined) {
1095
+ groupOptions.amount = amount;
1096
+ }
1097
+ if (currency !== undefined) {
1098
+ groupOptions.currency = currency;
1099
+ }
1100
+ if (Object.keys(groupOptions).length > 0) {
1101
+ (_a = this.stripeService.getElements()) === null || _a === void 0 ? void 0 : _a.update(groupOptions);
1102
+ }
1103
+ // Convert buttonHeight from string to number if present
1104
+ const updateOptions = Object.assign({}, elementOptions);
1105
+ if (updateOptions.buttonHeight && typeof updateOptions.buttonHeight === 'string') {
1106
+ const height = parseInt(updateOptions.buttonHeight.replace('px', ''), 10);
1107
+ if (!isNaN(height)) {
1108
+ updateOptions.buttonHeight = height;
1109
+ }
1110
+ }
1111
+ if (Object.keys(updateOptions).length === 0) {
1112
+ return;
1113
+ }
1114
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1115
+ this.expressCheckoutElement.update(updateOptions);
1116
+ }
1117
+ /**
1118
+ * Set error message (triggers reactivity)
1119
+ */
1120
+ setError(message) {
1121
+ this.store.set('errorMessage', message);
1122
+ }
1123
+ /**
1124
+ * Clear error message (triggers reactivity)
1125
+ */
1126
+ clearError() {
1127
+ this.store.set('errorMessage', '');
1128
+ }
1129
+ /**
1130
+ * Unmount express checkout element
1131
+ */
1132
+ unmount() {
1133
+ if (this.expressCheckoutElement == null) {
1134
+ return;
1135
+ }
1136
+ this.expressCheckoutElement.unmount();
1137
+ this.expressCheckoutElement = undefined;
1138
+ this.store.set('isReady', false);
1139
+ }
1140
+ }
1141
+
1142
+ /**
1143
+ * Service Factory
1144
+ * Creates service instances with proper dependency injection
1145
+ * Can be mocked in tests for better testability
1146
+ */
1147
+ class ServiceFactory {
1148
+ /**
1149
+ * Create a new StripeService instance
1150
+ */
1151
+ createStripeService() {
1152
+ return new StripeServiceClass();
1153
+ }
1154
+ /**
1155
+ * Create a new CardElementManager instance
1156
+ * @param stripeService - Injected StripeService dependency
1157
+ */
1158
+ createCardElementManager(stripeService) {
1159
+ return new CardElementManager(stripeService);
1160
+ }
1161
+ /**
1162
+ * Create a new PaymentElementManager instance
1163
+ * @param stripeService - Injected StripeService dependency
1164
+ */
1165
+ createPaymentElementManager(stripeService) {
1166
+ return new PaymentElementManager(stripeService);
1167
+ }
1168
+ /**
1169
+ * Create a new AddressElementManager instance
1170
+ * @param stripeService - Injected StripeService dependency
1171
+ */
1172
+ createAddressElementManager(stripeService) {
1173
+ return new AddressElementManager(stripeService);
1174
+ }
1175
+ /**
1176
+ * Create a new LinkAuthenticationElementManager instance
1177
+ * @param stripeService - Injected StripeService dependency
1178
+ */
1179
+ createLinkAuthenticationElementManager(stripeService) {
1180
+ return new LinkAuthenticationElementManager(stripeService);
1181
+ }
1182
+ /**
1183
+ * Create a new CurrencySelectorElementManager instance
1184
+ * @param stripeService - Injected StripeService dependency
1185
+ */
1186
+ createCurrencySelectorElementManager(stripeService) {
1187
+ return new CurrencySelectorElementManager(stripeService);
1188
+ }
1189
+ /**
1190
+ * Create a new ExpressCheckoutElementManager instance
1191
+ * @param stripeService - Injected StripeService dependency
1192
+ */
1193
+ createExpressCheckoutElementManager(stripeService) {
1194
+ return new ExpressCheckoutElementManager(stripeService);
1195
+ }
1196
+ }
1197
+ /**
1198
+ * Default factory instance
1199
+ * Can be replaced with a mock in tests
1200
+ */
1201
+ const serviceFactory = new ServiceFactory();
1202
+
1203
+ export { findElement as f, serviceFactory as s };