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