stripe-pwa-elements 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/dist/cjs/factory-tenFFIul.js +1200 -0
  2. package/dist/cjs/{factory-da3xAKkz.js → i18n-FhEOc8vz.js} +6 -1131
  3. package/dist/cjs/ion-icon_2.cjs.entry.js +723 -0
  4. package/dist/cjs/loader.cjs.js +1 -1
  5. package/dist/cjs/stripe-address-element.cjs.entry.js +12 -4
  6. package/dist/cjs/stripe-card-element-modal.cjs.entry.js +3 -2
  7. package/dist/cjs/{stripe-card-element_2.cjs.entry.js → stripe-card-element.cjs.entry.js} +15 -82
  8. package/dist/cjs/stripe-currency-selector.cjs.entry.js +11 -3
  9. package/dist/cjs/stripe-elements.cjs.js +1 -1
  10. package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +31 -5
  11. package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +11 -3
  12. package/dist/cjs/stripe-payment-element.cjs.entry.js +106 -161
  13. package/dist/cjs/stripe-payment-element.helpers-DukP33RI.js +122 -0
  14. package/dist/cjs/stripe-payment-request-button.cjs.entry.js +23 -16
  15. package/dist/cjs/stripe-payment-sheet.cjs.entry.js +506 -0
  16. package/dist/collection/collection-manifest.json +3 -2
  17. package/dist/collection/components/stripe-address-element/stripe-address-element.js +7 -0
  18. package/dist/collection/components/stripe-card-element/stripe-card-element.js +10 -2
  19. package/dist/collection/components/stripe-card-element-modal/stripe-card-element-modal.js +4 -3
  20. package/dist/collection/components/stripe-currency-selector/stripe-currency-selector.js +7 -0
  21. package/dist/collection/components/stripe-express-checkout-element/stripe-express-checkout-element.js +25 -0
  22. package/dist/collection/components/stripe-link-authentication-element/stripe-link-authentication-element.js +7 -0
  23. package/dist/collection/components/stripe-modal/stripe-modal.css +23 -1
  24. package/dist/collection/components/stripe-modal/stripe-modal.js +147 -6
  25. package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +94 -37
  26. package/dist/collection/components/stripe-payment-request-button/stripe-payment-request-button.js +17 -10
  27. package/dist/collection/components/stripe-payment-sheet/payment-sheet-state.js +179 -0
  28. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.css +68 -0
  29. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.helpers.js +90 -0
  30. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +544 -0
  31. package/dist/collection/services/express-checkout-element-manager.js +36 -2
  32. package/dist/collection/services/stripe-service.js +37 -5
  33. package/dist/collection/utils/focus.js +76 -0
  34. package/dist/collection/utils/i18n.js +6 -0
  35. package/dist/components/factory.js +1 -1
  36. package/dist/components/i18n.js +1 -0
  37. package/dist/components/stripe-address-element.js +1 -1
  38. package/dist/components/stripe-card-element-modal.js +1 -1
  39. package/dist/components/stripe-card-element2.js +1 -1
  40. package/dist/components/stripe-currency-selector.js +1 -1
  41. package/dist/components/stripe-express-checkout-element.js +1 -1
  42. package/dist/components/stripe-link-authentication-element.js +1 -1
  43. package/dist/components/stripe-modal2.js +1 -1
  44. package/dist/components/stripe-payment-element.helpers.js +1 -0
  45. package/dist/components/stripe-payment-element.js +1 -1
  46. package/dist/components/stripe-payment-request-button2.js +1 -1
  47. package/dist/components/stripe-payment-sheet.d.ts +11 -0
  48. package/dist/components/stripe-payment-sheet.js +1 -0
  49. package/dist/esm/factory-Cd6OGTWN.js +1198 -0
  50. package/dist/esm/{factory-DeqoYLf_.js → i18n-B6JoQetF.js} +7 -1131
  51. package/dist/esm/ion-icon_2.entry.js +720 -0
  52. package/dist/esm/loader.js +1 -1
  53. package/dist/esm/stripe-address-element.entry.js +9 -1
  54. package/dist/esm/stripe-card-element-modal.entry.js +3 -2
  55. package/dist/esm/{stripe-card-element_2.entry.js → stripe-card-element.entry.js} +13 -79
  56. package/dist/esm/stripe-currency-selector.entry.js +9 -1
  57. package/dist/esm/stripe-elements.js +1 -1
  58. package/dist/esm/stripe-express-checkout-element.entry.js +27 -1
  59. package/dist/esm/stripe-link-authentication-element.entry.js +9 -1
  60. package/dist/esm/stripe-payment-element.entry.js +98 -153
  61. package/dist/esm/stripe-payment-element.helpers-CipV87b8.js +117 -0
  62. package/dist/esm/stripe-payment-request-button.entry.js +18 -11
  63. package/dist/esm/stripe-payment-sheet.entry.js +504 -0
  64. package/dist/stripe-elements/{p-38e7b187.entry.js → p-4891edf0.entry.js} +1 -1
  65. package/dist/stripe-elements/p-5338bc5e.entry.js +1 -0
  66. package/dist/stripe-elements/p-6a9c8b7a.entry.js +1 -0
  67. package/dist/stripe-elements/p-7fe4a287.entry.js +1 -0
  68. package/dist/stripe-elements/p-915b86ed.entry.js +1 -0
  69. package/dist/stripe-elements/p-B6JoQetF.js +1 -0
  70. package/dist/stripe-elements/p-C7MQk9FK.js +1 -0
  71. package/dist/stripe-elements/p-DFAhQS0n.js +1 -0
  72. package/dist/stripe-elements/p-b06a254f.entry.js +1 -0
  73. package/dist/stripe-elements/p-b91c4fa7.entry.js +1 -0
  74. package/dist/stripe-elements/p-ba791c8f.entry.js +1 -0
  75. package/dist/stripe-elements/p-e7372ca7.entry.js +1 -0
  76. package/dist/stripe-elements/p-f892e375.entry.js +1 -0
  77. package/dist/stripe-elements/stripe-elements.esm.js +1 -1
  78. package/dist/types/components/stripe-address-element/stripe-address-element.d.ts +6 -0
  79. package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +8 -1
  80. package/dist/types/components/stripe-card-element-modal/stripe-card-element-modal.d.ts +2 -1
  81. package/dist/types/components/stripe-currency-selector/stripe-currency-selector.d.ts +6 -0
  82. package/dist/types/components/stripe-express-checkout-element/stripe-express-checkout-element.d.ts +11 -0
  83. package/dist/types/components/stripe-link-authentication-element/stripe-link-authentication-element.d.ts +6 -0
  84. package/dist/types/components/stripe-modal/stripe-modal.d.ts +44 -0
  85. package/dist/types/components/stripe-payment-element/stripe-payment-element.d.ts +18 -0
  86. package/dist/types/components/stripe-payment-request-button/stripe-payment-request-button.d.ts +7 -2
  87. package/dist/types/components/stripe-payment-sheet/payment-sheet-state.d.ts +104 -0
  88. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.d.ts +112 -0
  89. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.helpers.d.ts +95 -0
  90. package/dist/types/components.d.ts +169 -10
  91. package/dist/types/index.d.ts +2 -0
  92. package/dist/types/services/interfaces.d.ts +2 -0
  93. package/dist/types/services/stripe-service.d.ts +12 -3
  94. package/dist/types/utils/focus.d.ts +15 -0
  95. package/package.json +5 -3
  96. package/readme.md +46 -10
  97. package/dist/cjs/ion-icon.cjs.entry.js +0 -431
  98. package/dist/components/utils.js +0 -1
  99. package/dist/esm/ion-icon.entry.js +0 -429
  100. package/dist/stripe-elements/p--sA2m1ad.js +0 -1
  101. package/dist/stripe-elements/p-44495284.entry.js +0 -1
  102. package/dist/stripe-elements/p-4ba675fa.entry.js +0 -1
  103. package/dist/stripe-elements/p-5cf62945.entry.js +0 -1
  104. package/dist/stripe-elements/p-c24ae181.entry.js +0 -1
  105. package/dist/stripe-elements/p-d9e86451.entry.js +0 -1
  106. package/dist/stripe-elements/p-f09c86a0.entry.js +0 -1
  107. package/dist/stripe-elements/p-f64f394d.entry.js +0 -1
  108. package/dist/stripe-elements/p-f6d2425e.entry.js +0 -1
@@ -0,0 +1,1198 @@
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-B6JoQetF.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
+ });
809
+ }
810
+ /**
811
+ * Get current link authentication element state (reactive)
812
+ */
813
+ getState() {
814
+ return this.store.state;
815
+ }
816
+ /**
817
+ * Register state change listener
818
+ * @param key - State property to watch
819
+ * @param callback - Callback function invoked when property changes
820
+ * @returns Unsubscribe function
821
+ */
822
+ onChange(key, callback) {
823
+ return this.store.onChange(key, callback);
824
+ }
825
+ /**
826
+ * Initialize and mount link authentication element to DOM
827
+ * @param containerElement - Parent element containing mount point
828
+ * @param options - Optional configuration for Link Authentication Element
829
+ * @returns Promise resolving to link authentication element instance
830
+ */
831
+ async initialize(containerElement, options) {
832
+ const elements = this.stripeService.getElements();
833
+ if (elements == null) {
834
+ throw new Error('StripeService not initialized. Call StripeService.initialize() first.');
835
+ }
836
+ // Unmount if already initialized
837
+ if (this.linkAuthenticationElement != null) {
838
+ this.unmount();
839
+ }
840
+ // Create link authentication element
841
+ const linkAuthentication = elements.create('linkAuthentication', options);
842
+ const linkAuthenticationElementDiv = await findElement(containerElement, '#link-authentication-element');
843
+ linkAuthentication.mount(linkAuthenticationElementDiv);
844
+ // Listen for change events
845
+ linkAuthentication.on('change', event => {
846
+ var _a;
847
+ // Unconditionally set email from event.value.email
848
+ // This handles all cases: valid email, empty string, or undefined
849
+ this.store.set('email', (_a = event.value) === null || _a === void 0 ? void 0 : _a.email);
850
+ });
851
+ this.linkAuthenticationElement = linkAuthentication;
852
+ return this.linkAuthenticationElement;
853
+ }
854
+ /**
855
+ * Get mounted link authentication element instance
856
+ */
857
+ getElement() {
858
+ return this.linkAuthenticationElement;
859
+ }
860
+ /**
861
+ * Set error message (triggers reactivity)
862
+ */
863
+ setError(message) {
864
+ this.store.set('errorMessage', message);
865
+ }
866
+ /**
867
+ * Clear error message (triggers reactivity)
868
+ */
869
+ clearError() {
870
+ this.store.set('errorMessage', '');
871
+ }
872
+ /**
873
+ * Unmount link authentication element
874
+ */
875
+ unmount() {
876
+ if (this.linkAuthenticationElement == null) {
877
+ return;
878
+ }
879
+ this.linkAuthenticationElement.unmount();
880
+ this.linkAuthenticationElement = undefined;
881
+ }
882
+ }
883
+
884
+ /**
885
+ * Currency Selector Element Manager
886
+ * Manages Stripe Currency Selector Element
887
+ * with dependency injection of StripeService
888
+ */
889
+ class CurrencySelectorElementManager {
890
+ /**
891
+ * Constructor with dependency injection
892
+ * @param stripeService - Injected Stripe service instance
893
+ */
894
+ constructor(stripeService) {
895
+ this.stripeService = stripeService;
896
+ this.store = createStore({
897
+ errorMessage: '',
898
+ selectedCurrency: undefined,
899
+ });
900
+ }
901
+ /**
902
+ * Get current currency selector element state (reactive)
903
+ */
904
+ getState() {
905
+ return this.store.state;
906
+ }
907
+ /**
908
+ * Initialize and mount currency selector element to DOM
909
+ * @param containerElement - Parent element containing mount point
910
+ * @param options - Currency selector element options
911
+ * @returns Promise resolving to currency selector element instance
912
+ * Note: StripeCurrencySelectorElementOptions is not yet exported in @stripe/stripe-js v8.6.0
913
+ */
914
+ async initialize(containerElement, options) {
915
+ const elements = this.stripeService.getElements();
916
+ if (elements == null) {
917
+ throw new Error('StripeService not initialized. Call StripeService.initialize() first.');
918
+ }
919
+ // Unmount if already initialized
920
+ if (this.currencySelectorElement != null) {
921
+ this.unmount();
922
+ }
923
+ // Find mount point first to avoid element leak if findElement throws
924
+ const currencySelectorElementContainer = await findElement(containerElement, '#currency-selector');
925
+ // Create and mount currency selector element
926
+ // Note: 'currencySelector' type is not yet in @stripe/stripe-js v8.6.0 type definitions
927
+ // but is documented in Stripe's Currency Selector Element documentation
928
+ this.currencySelectorElement = elements.create('currencySelector', options || {});
929
+ this.currencySelectorElement.mount(currencySelectorElementContainer);
930
+ // Listen for changes
931
+ // Note: The 'change' event type is not yet in @stripe/stripe-js type definitions
932
+ // but is documented in Stripe's Currency Selector Element documentation
933
+ this.currencySelectorElement.on('change', (event) => {
934
+ var _a;
935
+ // Clear error on change
936
+ this.store.set('errorMessage', '');
937
+ // Update selected currency if available
938
+ if ((_a = event === null || event === void 0 ? void 0 : event.value) === null || _a === void 0 ? void 0 : _a.currency) {
939
+ this.store.set('selectedCurrency', event.value.currency);
940
+ }
941
+ });
942
+ return this.currencySelectorElement;
943
+ }
944
+ /**
945
+ * Get mounted currency selector element instance
946
+ */
947
+ getElement() {
948
+ return this.currencySelectorElement;
949
+ }
950
+ /**
951
+ * Set error message (triggers reactivity)
952
+ */
953
+ setError(message) {
954
+ this.store.set('errorMessage', message);
955
+ }
956
+ /**
957
+ * Clear error message (triggers reactivity)
958
+ */
959
+ clearError() {
960
+ this.store.set('errorMessage', '');
961
+ }
962
+ /**
963
+ * Unmount currency selector element
964
+ */
965
+ unmount() {
966
+ if (this.currencySelectorElement == null) {
967
+ return;
968
+ }
969
+ this.currencySelectorElement.unmount();
970
+ this.currencySelectorElement = undefined;
971
+ }
972
+ }
973
+
974
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
975
+ var t = {};
976
+ for (var p in s)
977
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
978
+ t[p] = s[p];
979
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
980
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
981
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
982
+ t[p[i]] = s[p[i]];
983
+ }
984
+ return t;
985
+ };
986
+ /**
987
+ * Express Checkout Element Manager
988
+ * Manages Stripe Express Checkout Element
989
+ * with dependency injection of StripeService
990
+ */
991
+ class ExpressCheckoutElementManager {
992
+ /**
993
+ * Constructor with dependency injection
994
+ * @param stripeService - Injected Stripe service instance
995
+ */
996
+ constructor(stripeService) {
997
+ this.stripeService = stripeService;
998
+ this.store = createStore({
999
+ errorMessage: '',
1000
+ isReady: false,
1001
+ });
1002
+ }
1003
+ /**
1004
+ * Get current express checkout element state (reactive)
1005
+ */
1006
+ getState() {
1007
+ return this.store.state;
1008
+ }
1009
+ /**
1010
+ * Initialize and mount express checkout element to DOM
1011
+ * @param containerElement - Parent element containing mount point
1012
+ * @param options - Express Checkout Element configuration options
1013
+ * @param eventHandlers - Event handlers for element events
1014
+ * @returns Promise resolving to express checkout element instance
1015
+ */
1016
+ async initialize(containerElement, options, eventHandlers) {
1017
+ const elements = this.stripeService.getElements();
1018
+ if (elements == null) {
1019
+ throw new Error('StripeService not initialized. Call StripeService.initialize() first.');
1020
+ }
1021
+ // Unmount if already initialized
1022
+ if (this.expressCheckoutElement != null) {
1023
+ this.unmount();
1024
+ }
1025
+ // mode / amount / currency belong to stripe.elements(), not to elements.create('expressCheckout')
1026
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1027
+ const restOptions = __rest(options, ["mode", "amount", "currency"]);
1028
+ const createOptions = Object.assign({}, restOptions);
1029
+ // Convert buttonHeight from string to number if present
1030
+ if (createOptions.buttonHeight && typeof createOptions.buttonHeight === 'string') {
1031
+ const height = parseInt(createOptions.buttonHeight.replace('px', ''), 10);
1032
+ if (!isNaN(height)) {
1033
+ createOptions.buttonHeight = height;
1034
+ }
1035
+ }
1036
+ // Create express checkout element
1037
+ // Note: 'expressCheckout' is not yet in the official Stripe type definitions
1038
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1039
+ const expressCheckout = elements.create('expressCheckout', createOptions);
1040
+ // Find the mount point
1041
+ const mountPoint = await findElement(containerElement, '#express-checkout-element');
1042
+ // Set up event handlers before mounting
1043
+ if ((eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onConfirm) != null) {
1044
+ expressCheckout.on('confirm', eventHandlers.onConfirm);
1045
+ }
1046
+ if ((eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onClick) != null) {
1047
+ expressCheckout.on('click', eventHandlers.onClick);
1048
+ }
1049
+ if ((eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onCancel) != null) {
1050
+ expressCheckout.on('cancel', eventHandlers.onCancel);
1051
+ }
1052
+ if ((eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onShippingAddressChange) != null) {
1053
+ expressCheckout.on('shippingaddresschange', eventHandlers.onShippingAddressChange);
1054
+ }
1055
+ if ((eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onShippingRateChange) != null) {
1056
+ expressCheckout.on('shippingratechange', eventHandlers.onShippingRateChange);
1057
+ }
1058
+ // Add ready event handler
1059
+ expressCheckout.on('ready', () => {
1060
+ this.store.set('isReady', true);
1061
+ });
1062
+ // Mount the element
1063
+ expressCheckout.mount(mountPoint);
1064
+ this.expressCheckoutElement = expressCheckout;
1065
+ return this.expressCheckoutElement;
1066
+ }
1067
+ /**
1068
+ * Get mounted express checkout element instance
1069
+ */
1070
+ getElement() {
1071
+ return this.expressCheckoutElement;
1072
+ }
1073
+ /**
1074
+ * Update element options dynamically
1075
+ * @param options - Partial options to update
1076
+ */
1077
+ update(options) {
1078
+ var _a;
1079
+ if (this.expressCheckoutElement == null) {
1080
+ console.warn('Express Checkout Element not initialized. Cannot update options.');
1081
+ return;
1082
+ }
1083
+ // mode / amount / currency are Elements group options, so they are updated with elements.update()
1084
+ const { mode, amount, currency } = options, elementOptions = __rest(options, ["mode", "amount", "currency"]);
1085
+ const groupOptions = {};
1086
+ if (mode !== undefined) {
1087
+ groupOptions.mode = mode;
1088
+ }
1089
+ if (amount !== undefined) {
1090
+ groupOptions.amount = amount;
1091
+ }
1092
+ if (currency !== undefined) {
1093
+ groupOptions.currency = currency;
1094
+ }
1095
+ if (Object.keys(groupOptions).length > 0) {
1096
+ (_a = this.stripeService.getElements()) === null || _a === void 0 ? void 0 : _a.update(groupOptions);
1097
+ }
1098
+ // Convert buttonHeight from string to number if present
1099
+ const updateOptions = Object.assign({}, elementOptions);
1100
+ if (updateOptions.buttonHeight && typeof updateOptions.buttonHeight === 'string') {
1101
+ const height = parseInt(updateOptions.buttonHeight.replace('px', ''), 10);
1102
+ if (!isNaN(height)) {
1103
+ updateOptions.buttonHeight = height;
1104
+ }
1105
+ }
1106
+ if (Object.keys(updateOptions).length === 0) {
1107
+ return;
1108
+ }
1109
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1110
+ this.expressCheckoutElement.update(updateOptions);
1111
+ }
1112
+ /**
1113
+ * Set error message (triggers reactivity)
1114
+ */
1115
+ setError(message) {
1116
+ this.store.set('errorMessage', message);
1117
+ }
1118
+ /**
1119
+ * Clear error message (triggers reactivity)
1120
+ */
1121
+ clearError() {
1122
+ this.store.set('errorMessage', '');
1123
+ }
1124
+ /**
1125
+ * Unmount express checkout element
1126
+ */
1127
+ unmount() {
1128
+ if (this.expressCheckoutElement == null) {
1129
+ return;
1130
+ }
1131
+ this.expressCheckoutElement.unmount();
1132
+ this.expressCheckoutElement = undefined;
1133
+ this.store.set('isReady', false);
1134
+ }
1135
+ }
1136
+
1137
+ /**
1138
+ * Service Factory
1139
+ * Creates service instances with proper dependency injection
1140
+ * Can be mocked in tests for better testability
1141
+ */
1142
+ class ServiceFactory {
1143
+ /**
1144
+ * Create a new StripeService instance
1145
+ */
1146
+ createStripeService() {
1147
+ return new StripeServiceClass();
1148
+ }
1149
+ /**
1150
+ * Create a new CardElementManager instance
1151
+ * @param stripeService - Injected StripeService dependency
1152
+ */
1153
+ createCardElementManager(stripeService) {
1154
+ return new CardElementManager(stripeService);
1155
+ }
1156
+ /**
1157
+ * Create a new PaymentElementManager instance
1158
+ * @param stripeService - Injected StripeService dependency
1159
+ */
1160
+ createPaymentElementManager(stripeService) {
1161
+ return new PaymentElementManager(stripeService);
1162
+ }
1163
+ /**
1164
+ * Create a new AddressElementManager instance
1165
+ * @param stripeService - Injected StripeService dependency
1166
+ */
1167
+ createAddressElementManager(stripeService) {
1168
+ return new AddressElementManager(stripeService);
1169
+ }
1170
+ /**
1171
+ * Create a new LinkAuthenticationElementManager instance
1172
+ * @param stripeService - Injected StripeService dependency
1173
+ */
1174
+ createLinkAuthenticationElementManager(stripeService) {
1175
+ return new LinkAuthenticationElementManager(stripeService);
1176
+ }
1177
+ /**
1178
+ * Create a new CurrencySelectorElementManager instance
1179
+ * @param stripeService - Injected StripeService dependency
1180
+ */
1181
+ createCurrencySelectorElementManager(stripeService) {
1182
+ return new CurrencySelectorElementManager(stripeService);
1183
+ }
1184
+ /**
1185
+ * Create a new ExpressCheckoutElementManager instance
1186
+ * @param stripeService - Injected StripeService dependency
1187
+ */
1188
+ createExpressCheckoutElementManager(stripeService) {
1189
+ return new ExpressCheckoutElementManager(stripeService);
1190
+ }
1191
+ }
1192
+ /**
1193
+ * Default factory instance
1194
+ * Can be replaced with a mock in tests
1195
+ */
1196
+ const serviceFactory = new ServiceFactory();
1197
+
1198
+ export { serviceFactory as s };