@funnelfox/billing 0.8.0-ffb-837.55 → 0.8.0-ffb-805.56

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.
package/README.md CHANGED
@@ -140,6 +140,8 @@ const checkout = await createCheckout({
140
140
  - `customer.externalId` (string, required) - Your user identifier
141
141
  - `customer.email` (string, optional) - Customer email
142
142
  - `customer.countryCode` (string, optional) - ISO country code
143
+ - `options.displayCurrency` (string, optional) - ISO 4217 currency the page showed the price in (from Billing's `price_points/resolve`). Billing charges it when the price point offers it, otherwise the price point's own currency. Also accepted by `initMethod`, `createClientSession`, the Stripe forms, and (currency only) `silentPurchase` and `mountWalletUpsell`.
144
+ - `options.displayCountry` (string, optional) - ISO 3166-1 alpha-2 country the page resolved that currency for.
143
145
  - `options.container` (string, required) - CSS selector for checkout container
144
146
  - `options.card.emailAddress.visible` (boolean, optional) - Shows an email field in the card form. Disabled by default.
145
147
  - `options.card.emailAddress.template` (string, optional) - Wraps the entered email before it is sent with payment, for example `{{email}}`.
@@ -561,7 +561,7 @@ exports.PaymentMethod = void 0;
561
561
  /**
562
562
  * @fileoverview Constants for Funnefox SDK
563
563
  */
564
- const SDK_VERSION = '0.8.0-ffb-837.55';
564
+ const SDK_VERSION = '0.8.0-ffb-805.56';
565
565
  const DEFAULTS = {
566
566
  BASE_URL: 'https://billing.funnelfox.com',
567
567
  REGION: 'default',
@@ -1452,6 +1452,12 @@ class APIClient {
1452
1452
  if (params.countryCode !== undefined) {
1453
1453
  payload.country_code = params.countryCode;
1454
1454
  }
1455
+ if (params.displayCurrency) {
1456
+ payload.display_currency_code = params.displayCurrency;
1457
+ }
1458
+ if (params.displayCountry) {
1459
+ payload.display_country_code = params.displayCountry;
1460
+ }
1455
1461
  return (await this.request(API_ENDPOINTS.CREATE_CLIENT_SESSION, {
1456
1462
  method: 'POST',
1457
1463
  body: JSON.stringify(payload),
@@ -1464,6 +1470,12 @@ class APIClient {
1464
1470
  pp_ident: params.priceId,
1465
1471
  client_metadata: params.clientMetadata || {},
1466
1472
  };
1473
+ if (params.displayCurrency) {
1474
+ payload.display_currency_code = params.displayCurrency;
1475
+ }
1476
+ if (params.displayCountry) {
1477
+ payload.display_country_code = params.displayCountry;
1478
+ }
1467
1479
  return await this.request(API_ENDPOINTS.UPDATE_CLIENT_SESSION, {
1468
1480
  method: 'POST',
1469
1481
  body: JSON.stringify(payload),
@@ -1663,6 +1675,8 @@ class SessionService {
1663
1675
  p.baseUrl || DEFAULTS.BASE_URL,
1664
1676
  p.region || DEFAULTS.REGION,
1665
1677
  p.countryCode ?? '',
1678
+ p.displayCurrency ?? '',
1679
+ p.displayCountry ?? '',
1666
1680
  p.priceId,
1667
1681
  p.externalId,
1668
1682
  p.email,
@@ -1690,6 +1704,8 @@ class SessionService {
1690
1704
  region: p.region || DEFAULTS.REGION,
1691
1705
  clientMetadata: p.clientMetadata,
1692
1706
  countryCode: p.countryCode,
1707
+ displayCurrency: p.displayCurrency,
1708
+ displayCountry: p.displayCountry,
1693
1709
  integration: p.integration,
1694
1710
  });
1695
1711
  this.cache.set(key, req);
@@ -2460,6 +2476,8 @@ class CheckoutInstance extends EventEmitter {
2460
2476
  region: this.region,
2461
2477
  clientMetadata: this.checkoutConfig.clientMetadata,
2462
2478
  countryCode: this.checkoutConfig.customer.countryCode,
2479
+ displayCurrency: this.checkoutConfig.displayCurrency,
2480
+ displayCountry: this.checkoutConfig.displayCountry,
2463
2481
  integration: 'primer',
2464
2482
  });
2465
2483
  const sessionResponse = response;
@@ -2756,6 +2774,8 @@ class CheckoutInstance extends EventEmitter {
2756
2774
  clientToken: this.clientToken,
2757
2775
  priceId: newPriceId,
2758
2776
  clientMetadata,
2777
+ displayCurrency: this.checkoutConfig.displayCurrency,
2778
+ displayCountry: this.checkoutConfig.displayCountry,
2759
2779
  });
2760
2780
  this.checkoutConfig.priceId = newPriceId;
2761
2781
  await this.primerWrapper.refreshClientSession();
@@ -3389,7 +3409,7 @@ async function createCheckout(options) {
3389
3409
  }
3390
3410
  }
3391
3411
  async function createClientSession(params) {
3392
- const { priceId, externalId, email, clientMetadata, countryCode } = params;
3412
+ const { priceId, externalId, email, clientMetadata, countryCode, displayCurrency, displayCountry, } = params;
3393
3413
  const config = resolveConfig(params, 'createClientSession');
3394
3414
  const apiClient = new APIClient({
3395
3415
  baseUrl: config.baseUrl,
@@ -3404,6 +3424,8 @@ async function createClientSession(params) {
3404
3424
  region: config.region,
3405
3425
  clientMetadata,
3406
3426
  countryCode,
3427
+ displayCurrency,
3428
+ displayCountry,
3407
3429
  });
3408
3430
  return apiClient.processSessionResponse(sessionResponse);
3409
3431
  }
@@ -3422,6 +3444,9 @@ function buildOneClickRequest(options) {
3422
3444
  if (options.citCardNetworks !== undefined) {
3423
3445
  payload.cit_card_networks = options.citCardNetworks;
3424
3446
  }
3447
+ if (options.displayCurrency) {
3448
+ payload.display_currency_code = options.displayCurrency;
3449
+ }
3425
3450
  return payload;
3426
3451
  }
3427
3452
  function silentPurchase(options) {
@@ -3877,6 +3902,8 @@ async function initMethod(method, element, options) {
3877
3902
  },
3878
3903
  container: '',
3879
3904
  clientMetadata: options.meta,
3905
+ displayCurrency: options.displayCurrency,
3906
+ displayCountry: options.displayCountry,
3880
3907
  card: options.card,
3881
3908
  style: options.style,
3882
3909
  applePay: {
@@ -3968,6 +3995,8 @@ async function createStripeCardForm(element, params) {
3968
3995
  email: params.email,
3969
3996
  clientMetadata: params.clientMetadata,
3970
3997
  countryCode: params.countryCode,
3998
+ displayCurrency: params.displayCurrency,
3999
+ displayCountry: params.displayCountry,
3971
4000
  integration: 'stripe',
3972
4001
  };
3973
4002
  const [session, { mountStripeCardForm }] = await Promise.all([
@@ -3996,6 +4025,8 @@ async function purchaseStripeWallet(params) {
3996
4025
  email: params.email,
3997
4026
  clientMetadata: params.clientMetadata,
3998
4027
  countryCode: params.countryCode,
4028
+ displayCurrency: params.displayCurrency,
4029
+ displayCountry: params.displayCountry,
3999
4030
  integration: 'stripe',
4000
4031
  };
4001
4032
  const [session, { purchaseWallet }] = await Promise.all([
@@ -4025,6 +4056,8 @@ async function getAvailableStripeWallet(params) {
4025
4056
  email: params.email,
4026
4057
  clientMetadata: params.clientMetadata,
4027
4058
  countryCode: params.countryCode,
4059
+ displayCurrency: params.displayCurrency,
4060
+ displayCountry: params.displayCountry,
4028
4061
  integration: 'stripe',
4029
4062
  }),
4030
4063
  Promise.resolve().then(function () { return require('./chunk-stripe-wallet.cjs.js'); }),
@@ -4489,6 +4522,9 @@ class WalletUpsell {
4489
4522
  payment_method_token: paymentMethodToken,
4490
4523
  session_id: session.sessionId,
4491
4524
  };
4525
+ if (this.options.displayCurrency) {
4526
+ payload.display_currency_code = this.options.displayCurrency;
4527
+ }
4492
4528
  const idempotencyKey = createIdempotencyKey();
4493
4529
  if (idempotencyKey) {
4494
4530
  payload.idempotency_key = idempotencyKey;
@@ -559,7 +559,7 @@ var PaymentMethod;
559
559
  /**
560
560
  * @fileoverview Constants for Funnefox SDK
561
561
  */
562
- const SDK_VERSION = '0.8.0-ffb-837.55';
562
+ const SDK_VERSION = '0.8.0-ffb-805.56';
563
563
  const DEFAULTS = {
564
564
  BASE_URL: 'https://billing.funnelfox.com',
565
565
  REGION: 'default',
@@ -1450,6 +1450,12 @@ class APIClient {
1450
1450
  if (params.countryCode !== undefined) {
1451
1451
  payload.country_code = params.countryCode;
1452
1452
  }
1453
+ if (params.displayCurrency) {
1454
+ payload.display_currency_code = params.displayCurrency;
1455
+ }
1456
+ if (params.displayCountry) {
1457
+ payload.display_country_code = params.displayCountry;
1458
+ }
1453
1459
  return (await this.request(API_ENDPOINTS.CREATE_CLIENT_SESSION, {
1454
1460
  method: 'POST',
1455
1461
  body: JSON.stringify(payload),
@@ -1462,6 +1468,12 @@ class APIClient {
1462
1468
  pp_ident: params.priceId,
1463
1469
  client_metadata: params.clientMetadata || {},
1464
1470
  };
1471
+ if (params.displayCurrency) {
1472
+ payload.display_currency_code = params.displayCurrency;
1473
+ }
1474
+ if (params.displayCountry) {
1475
+ payload.display_country_code = params.displayCountry;
1476
+ }
1465
1477
  return await this.request(API_ENDPOINTS.UPDATE_CLIENT_SESSION, {
1466
1478
  method: 'POST',
1467
1479
  body: JSON.stringify(payload),
@@ -1661,6 +1673,8 @@ class SessionService {
1661
1673
  p.baseUrl || DEFAULTS.BASE_URL,
1662
1674
  p.region || DEFAULTS.REGION,
1663
1675
  p.countryCode ?? '',
1676
+ p.displayCurrency ?? '',
1677
+ p.displayCountry ?? '',
1664
1678
  p.priceId,
1665
1679
  p.externalId,
1666
1680
  p.email,
@@ -1688,6 +1702,8 @@ class SessionService {
1688
1702
  region: p.region || DEFAULTS.REGION,
1689
1703
  clientMetadata: p.clientMetadata,
1690
1704
  countryCode: p.countryCode,
1705
+ displayCurrency: p.displayCurrency,
1706
+ displayCountry: p.displayCountry,
1691
1707
  integration: p.integration,
1692
1708
  });
1693
1709
  this.cache.set(key, req);
@@ -2458,6 +2474,8 @@ class CheckoutInstance extends EventEmitter {
2458
2474
  region: this.region,
2459
2475
  clientMetadata: this.checkoutConfig.clientMetadata,
2460
2476
  countryCode: this.checkoutConfig.customer.countryCode,
2477
+ displayCurrency: this.checkoutConfig.displayCurrency,
2478
+ displayCountry: this.checkoutConfig.displayCountry,
2461
2479
  integration: 'primer',
2462
2480
  });
2463
2481
  const sessionResponse = response;
@@ -2754,6 +2772,8 @@ class CheckoutInstance extends EventEmitter {
2754
2772
  clientToken: this.clientToken,
2755
2773
  priceId: newPriceId,
2756
2774
  clientMetadata,
2775
+ displayCurrency: this.checkoutConfig.displayCurrency,
2776
+ displayCountry: this.checkoutConfig.displayCountry,
2757
2777
  });
2758
2778
  this.checkoutConfig.priceId = newPriceId;
2759
2779
  await this.primerWrapper.refreshClientSession();
@@ -3387,7 +3407,7 @@ async function createCheckout(options) {
3387
3407
  }
3388
3408
  }
3389
3409
  async function createClientSession(params) {
3390
- const { priceId, externalId, email, clientMetadata, countryCode } = params;
3410
+ const { priceId, externalId, email, clientMetadata, countryCode, displayCurrency, displayCountry, } = params;
3391
3411
  const config = resolveConfig(params, 'createClientSession');
3392
3412
  const apiClient = new APIClient({
3393
3413
  baseUrl: config.baseUrl,
@@ -3402,6 +3422,8 @@ async function createClientSession(params) {
3402
3422
  region: config.region,
3403
3423
  clientMetadata,
3404
3424
  countryCode,
3425
+ displayCurrency,
3426
+ displayCountry,
3405
3427
  });
3406
3428
  return apiClient.processSessionResponse(sessionResponse);
3407
3429
  }
@@ -3420,6 +3442,9 @@ function buildOneClickRequest(options) {
3420
3442
  if (options.citCardNetworks !== undefined) {
3421
3443
  payload.cit_card_networks = options.citCardNetworks;
3422
3444
  }
3445
+ if (options.displayCurrency) {
3446
+ payload.display_currency_code = options.displayCurrency;
3447
+ }
3423
3448
  return payload;
3424
3449
  }
3425
3450
  function silentPurchase(options) {
@@ -3875,6 +3900,8 @@ async function initMethod(method, element, options) {
3875
3900
  },
3876
3901
  container: '',
3877
3902
  clientMetadata: options.meta,
3903
+ displayCurrency: options.displayCurrency,
3904
+ displayCountry: options.displayCountry,
3878
3905
  card: options.card,
3879
3906
  style: options.style,
3880
3907
  applePay: {
@@ -3966,6 +3993,8 @@ async function createStripeCardForm(element, params) {
3966
3993
  email: params.email,
3967
3994
  clientMetadata: params.clientMetadata,
3968
3995
  countryCode: params.countryCode,
3996
+ displayCurrency: params.displayCurrency,
3997
+ displayCountry: params.displayCountry,
3969
3998
  integration: 'stripe',
3970
3999
  };
3971
4000
  const [session, { mountStripeCardForm }] = await Promise.all([
@@ -3994,6 +4023,8 @@ async function purchaseStripeWallet(params) {
3994
4023
  email: params.email,
3995
4024
  clientMetadata: params.clientMetadata,
3996
4025
  countryCode: params.countryCode,
4026
+ displayCurrency: params.displayCurrency,
4027
+ displayCountry: params.displayCountry,
3997
4028
  integration: 'stripe',
3998
4029
  };
3999
4030
  const [session, { purchaseWallet }] = await Promise.all([
@@ -4023,6 +4054,8 @@ async function getAvailableStripeWallet(params) {
4023
4054
  email: params.email,
4024
4055
  clientMetadata: params.clientMetadata,
4025
4056
  countryCode: params.countryCode,
4057
+ displayCurrency: params.displayCurrency,
4058
+ displayCountry: params.displayCountry,
4026
4059
  integration: 'stripe',
4027
4060
  }),
4028
4061
  import('./chunk-stripe-wallet.es.js'),
@@ -4487,6 +4520,9 @@ class WalletUpsell {
4487
4520
  payment_method_token: paymentMethodToken,
4488
4521
  session_id: session.sessionId,
4489
4522
  };
4523
+ if (this.options.displayCurrency) {
4524
+ payload.display_currency_code = this.options.displayCurrency;
4525
+ }
4490
4526
  const idempotencyKey = createIdempotencyKey();
4491
4527
  if (idempotencyKey) {
4492
4528
  payload.idempotency_key = idempotencyKey;
@@ -565,7 +565,7 @@
565
565
  /**
566
566
  * @fileoverview Constants for Funnefox SDK
567
567
  */
568
- const SDK_VERSION = '0.8.0-ffb-837.55';
568
+ const SDK_VERSION = '0.8.0-ffb-805.56';
569
569
  const DEFAULTS = {
570
570
  BASE_URL: 'https://billing.funnelfox.com',
571
571
  REGION: 'default',
@@ -1456,6 +1456,12 @@
1456
1456
  if (params.countryCode !== undefined) {
1457
1457
  payload.country_code = params.countryCode;
1458
1458
  }
1459
+ if (params.displayCurrency) {
1460
+ payload.display_currency_code = params.displayCurrency;
1461
+ }
1462
+ if (params.displayCountry) {
1463
+ payload.display_country_code = params.displayCountry;
1464
+ }
1459
1465
  return (await this.request(API_ENDPOINTS.CREATE_CLIENT_SESSION, {
1460
1466
  method: 'POST',
1461
1467
  body: JSON.stringify(payload),
@@ -1468,6 +1474,12 @@
1468
1474
  pp_ident: params.priceId,
1469
1475
  client_metadata: params.clientMetadata || {},
1470
1476
  };
1477
+ if (params.displayCurrency) {
1478
+ payload.display_currency_code = params.displayCurrency;
1479
+ }
1480
+ if (params.displayCountry) {
1481
+ payload.display_country_code = params.displayCountry;
1482
+ }
1471
1483
  return await this.request(API_ENDPOINTS.UPDATE_CLIENT_SESSION, {
1472
1484
  method: 'POST',
1473
1485
  body: JSON.stringify(payload),
@@ -1667,6 +1679,8 @@
1667
1679
  p.baseUrl || DEFAULTS.BASE_URL,
1668
1680
  p.region || DEFAULTS.REGION,
1669
1681
  p.countryCode ?? '',
1682
+ p.displayCurrency ?? '',
1683
+ p.displayCountry ?? '',
1670
1684
  p.priceId,
1671
1685
  p.externalId,
1672
1686
  p.email,
@@ -1694,6 +1708,8 @@
1694
1708
  region: p.region || DEFAULTS.REGION,
1695
1709
  clientMetadata: p.clientMetadata,
1696
1710
  countryCode: p.countryCode,
1711
+ displayCurrency: p.displayCurrency,
1712
+ displayCountry: p.displayCountry,
1697
1713
  integration: p.integration,
1698
1714
  });
1699
1715
  this.cache.set(key, req);
@@ -2464,6 +2480,8 @@
2464
2480
  region: this.region,
2465
2481
  clientMetadata: this.checkoutConfig.clientMetadata,
2466
2482
  countryCode: this.checkoutConfig.customer.countryCode,
2483
+ displayCurrency: this.checkoutConfig.displayCurrency,
2484
+ displayCountry: this.checkoutConfig.displayCountry,
2467
2485
  integration: 'primer',
2468
2486
  });
2469
2487
  const sessionResponse = response;
@@ -2760,6 +2778,8 @@
2760
2778
  clientToken: this.clientToken,
2761
2779
  priceId: newPriceId,
2762
2780
  clientMetadata,
2781
+ displayCurrency: this.checkoutConfig.displayCurrency,
2782
+ displayCountry: this.checkoutConfig.displayCountry,
2763
2783
  });
2764
2784
  this.checkoutConfig.priceId = newPriceId;
2765
2785
  await this.primerWrapper.refreshClientSession();
@@ -3393,7 +3413,7 @@
3393
3413
  }
3394
3414
  }
3395
3415
  async function createClientSession(params) {
3396
- const { priceId, externalId, email, clientMetadata, countryCode } = params;
3416
+ const { priceId, externalId, email, clientMetadata, countryCode, displayCurrency, displayCountry, } = params;
3397
3417
  const config = resolveConfig(params, 'createClientSession');
3398
3418
  const apiClient = new APIClient({
3399
3419
  baseUrl: config.baseUrl,
@@ -3408,6 +3428,8 @@
3408
3428
  region: config.region,
3409
3429
  clientMetadata,
3410
3430
  countryCode,
3431
+ displayCurrency,
3432
+ displayCountry,
3411
3433
  });
3412
3434
  return apiClient.processSessionResponse(sessionResponse);
3413
3435
  }
@@ -3426,6 +3448,9 @@
3426
3448
  if (options.citCardNetworks !== undefined) {
3427
3449
  payload.cit_card_networks = options.citCardNetworks;
3428
3450
  }
3451
+ if (options.displayCurrency) {
3452
+ payload.display_currency_code = options.displayCurrency;
3453
+ }
3429
3454
  return payload;
3430
3455
  }
3431
3456
  function silentPurchase(options) {
@@ -3881,6 +3906,8 @@
3881
3906
  },
3882
3907
  container: '',
3883
3908
  clientMetadata: options.meta,
3909
+ displayCurrency: options.displayCurrency,
3910
+ displayCountry: options.displayCountry,
3884
3911
  card: options.card,
3885
3912
  style: options.style,
3886
3913
  applePay: {
@@ -3972,6 +3999,8 @@
3972
3999
  email: params.email,
3973
4000
  clientMetadata: params.clientMetadata,
3974
4001
  countryCode: params.countryCode,
4002
+ displayCurrency: params.displayCurrency,
4003
+ displayCountry: params.displayCountry,
3975
4004
  integration: 'stripe',
3976
4005
  };
3977
4006
  const [session, { mountStripeCardForm }] = await Promise.all([
@@ -4000,6 +4029,8 @@
4000
4029
  email: params.email,
4001
4030
  clientMetadata: params.clientMetadata,
4002
4031
  countryCode: params.countryCode,
4032
+ displayCurrency: params.displayCurrency,
4033
+ displayCountry: params.displayCountry,
4003
4034
  integration: 'stripe',
4004
4035
  };
4005
4036
  const [session, { purchaseWallet }] = await Promise.all([
@@ -4029,6 +4060,8 @@
4029
4060
  email: params.email,
4030
4061
  clientMetadata: params.clientMetadata,
4031
4062
  countryCode: params.countryCode,
4063
+ displayCurrency: params.displayCurrency,
4064
+ displayCountry: params.displayCountry,
4032
4065
  integration: 'stripe',
4033
4066
  }),
4034
4067
  Promise.resolve().then(function () { return stripeWallet; }),
@@ -4493,6 +4526,9 @@
4493
4526
  payment_method_token: paymentMethodToken,
4494
4527
  session_id: session.sessionId,
4495
4528
  };
4529
+ if (this.options.displayCurrency) {
4530
+ payload.display_currency_code = this.options.displayCurrency;
4531
+ }
4496
4532
  const idempotencyKey = createIdempotencyKey();
4497
4533
  if (idempotencyKey) {
4498
4534
  payload.idempotency_key = idempotencyKey;
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FunnelfoxSDK={})}(this,function(e){"use strict";class t{constructor(){this._events=new Map}on(e,t){if("function"!=typeof t)throw new Error("Event handler must be a function");return this._events.has(e)||this._events.set(e,[]),this._events.get(e).push(t),this}once(e,t){if("function"!=typeof t)throw new Error("Event handler must be a function");const n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}off(e,t=null){if(!this._events.has(e))return this;if(null===t)return this._events.delete(e),this;const n=this._events.get(e),r=n.indexOf(t);return-1!==r&&(n.splice(r,1),0===n.length&&this._events.delete(e)),this}emit(e,...t){if(!this._events.has(e))return!1;const n=this._events.get(e).slice();for(const r of n)try{r.apply(this,t)}catch(t){console.warn(`Error in event handler for "${String(e)}":`,t)}return!0}listenerCount(e){return this._events.has(e)?this._events.get(e).length:0}eventNames(){return Array.from(this._events.keys())}removeAllListeners(){return this._events.clear(),this}listeners(e){return this._events.has(e)?this._events.get(e).slice():[]}}class n extends Error{constructor(e,t=N.SDK_ERROR,r=null){super(e),this.name="FunnefoxSDKError",this.code=t,this.details=r,Error.captureStackTrace&&Error.captureStackTrace(this,n)}}class r extends n{constructor(e,t,n=null){super(`Invalid ${e}: ${t}`,N.VALIDATION_ERROR),this.name="ValidationError",this.field=e,this.value=n}}class o extends n{constructor(e,t=null,n={}){super(e,n.errorCode||N.API_ERROR),this.name="APIError",this.statusCode=t,this.errorCode=n.errorCode||null,this.errorType=n.errorType||null,this.requestId=n.requestId||null,this.response=n.response||null,this.declineCode=n.declineCode||null,this.declineCodeSource=n.declineCodeSource||null}}class i extends n{constructor(e,t=null){super(e,N.PRIMER_ERROR),this.name="PrimerError",this.primerError=t}}class a extends n{constructor(e,t=null){super(e,N.CHECKOUT_ERROR),this.name="CheckoutError",this.phase=t}}class s extends n{constructor(e,t=null){super(e,N.NETWORK_ERROR),this.name="NetworkError",this.originalError=t}}function d(e){const{id:t,src:n,async:r=!0,type:o="text/javascript",attributes:i={},integrity:a,crossOrigin:s,appendTo:d="body"}=e;return new Promise((e,l)=>{let c=null;if(t&&(c=document.getElementById(t)),c||(c=document.querySelector(`script[src="${n}"]`)),c)return void e(c);const u=document.createElement("script");t&&(u.id=t),u.type=o,u.src=n,r&&(u.async=!0),a&&(u.integrity=a),s&&(u.crossOrigin=s),Object.entries(i).forEach(([e,t])=>{u.setAttribute(e,t)}),u.onload=()=>e(u),u.onerror=()=>l(new Error(`Failed to load script: ${n}`));("head"===d?document.head:document.body).appendChild(u)})}function l(e){const{href:t,integrity:n,crossOrigin:r}=e;return new Promise((e,o)=>{const i=document.querySelector(`link[href="${t}"]`);if(i)return void e(i);const a=document.createElement("link");a.rel="stylesheet",a.href=t,n&&(a.integrity=n),r&&(a.crossOrigin=r),a.onload=()=>e(a),a.onerror=()=>o(new Error(`Failed to load stylesheet: ${t}`)),document.head.appendChild(a)})}const c="https://sdk.primer.io/web",u={"2.57.3":{js:"sha384-xq2SWkYvTlKOMpuXQUXq1QI3eZN7JiqQ3Sc72U9wY1IE30MW3HkwQWg/1n6BTMz4"}};let h=null,p=!1;async function m(e){if(p)return;if(h)return h;if("undefined"!=typeof window&&window.Primer&&"function"==typeof window.Primer.createHeadless)return void(p=!0);const t=e||"2.57.3",n=`${c}/v${t}/Primer.min.js`,r=`${c}/v${t}/Checkout.css`,o=u[t];return h=(async()=>{try{await Promise.all([l({href:r,integrity:o?.css,crossOrigin:"anonymous"}),d({src:n,integrity:o?.js,crossOrigin:"anonymous",appendTo:"head"})]),await function(e=1e4){return new Promise((t,n)=>{const r=Date.now(),o=()=>{"undefined"!=typeof window&&window.Primer&&"function"==typeof window.Primer.createHeadless?t():Date.now()-r>e?n(new Error("Timeout waiting for Primer SDK to initialize on window")):setTimeout(o,50)};o()})}(),p=!0}catch(e){throw h=null,e}})(),h}const y=new Set(["cardInvalid"]),f=new Set(["cardRequired","expiryRequired","cvvRequired"]);function C(e){return{...w(e),...g(e.tax_breakdown)}}function g(e){if(!Array.isArray(e))return{};const t=e.map(e=>({amount:e.amount,percentage:e.percentage,inclusive:e.inclusive,taxType:e.tax_type,country:e.country,subdivision:e.subdivision,taxabilityReason:e.taxability_reason})),n=t.map(e=>Number(e.percentage));if(!n.length||!n.every(Number.isFinite))return{taxBreakdown:t};return{taxBreakdown:t,taxRate:Number(n.reduce((e,t)=>e+t,0).toFixed(6))}}function w(e){const t=e.tax_behavior??((e.tax_amount??0)>0?"exclusive":void 0);return"inclusive"===t?{taxBehavior:t,taxAmount:e.tax_inclusive_amount??0}:"exclusive"===t?{taxBehavior:t,taxAmount:e.tax_amount??0}:{taxAmount:0}}function S(...e){const t={};for(const n of e)if(n&&"object"==typeof n)for(const e in n)Object.prototype.hasOwnProperty.call(n,e)&&("object"!=typeof n[e]||Array.isArray(n[e])||null===n[e]?t[e]=n[e]:t[e]=S(t[e]||{},n[e]));return t}function E(e=""){return`${e}${Date.now().toString(36)}_${Math.random().toString(36).substr(2,5)}`}function b(e){return new Promise(t=>setTimeout(t,e))}function v(e,t,n="Operation timed out"){const r=new Promise((e,r)=>{setTimeout(()=>r(new Error(n)),t)});return Promise.race([e,r])}var _;e.PaymentMethod=void 0,(_=e.PaymentMethod||(e.PaymentMethod={})).GOOGLE_PAY="GOOGLE_PAY",_.APPLE_PAY="APPLE_PAY",_.PAYPAL="PAYPAL",_.PAYMENT_CARD="PAYMENT_CARD";const P="0.8.0-ffb-837.55",M={BASE_URL:"https://billing.funnelfox.com",REGION:"default",SANDBOX:!1,REQUEST_TIMEOUT:3e4,RETRY_ATTEMPTS:3,RETRY_BASE_DELAY:1e3},I={SUCCESS:"success",ERROR:"error",STATUS_CHANGE:"status-change",DESTROY:"destroy",INPUT_ERROR:"input-error",LOADER_CHANGE:"loader-change",METHOD_RENDER:"method-render",METHOD_RENDER_ERROR:"method-render-error",START_PURCHASE:"start-purchase",PURCHASE_FAILURE:"purchase-failure",PURCHASE_COMPLETED:"purchase-completed",PURCHASE_CANCELLED:"purchase-cancelled",METHODS_AVAILABLE:"methods-available",TAX_CHANGE:"tax-change",TAX_PENDING:"tax-pending"},k="/v1/checkout/create_client_session",T="/v1/checkout/update_client_session",R="/v1/checkout/create_payment",A="/v1/checkout/resume_payment",x="/v1/checkout/one_click",D="/v1/checkout/one_click_wallet_session",L="/v1/checkout/create_simple_client_session",O="/v1/checkout/recalculate_tax",N={SDK_ERROR:"SDK_ERROR",VALIDATION_ERROR:"VALIDATION_ERROR",API_ERROR:"API_ERROR",PRIMER_ERROR:"PRIMER_ERROR",CHECKOUT_ERROR:"CHECKOUT_ERROR",CONFIGURATION_ERROR:"CONFIGURATION_ERROR",NETWORK_ERROR:"NETWORK_ERROR"},U="MANUAL",q="2.4",F=[...[e.PaymentMethod.GOOGLE_PAY,e.PaymentMethod.APPLE_PAY,e.PaymentMethod.PAYPAL],...[e.PaymentMethod.PAYMENT_CARD]],z={input:{error:{borderColor:"rgb(227, 47, 65)"},base:{borderWidth:"1px",borderStyle:"solid",borderColor:"rgb(0 0 0 / 10%)",height:"36px",paddingHorizontal:10,borderRadius:"6px"}}};z.input.base.paddingHorizontal,z.input.base.paddingHorizontal;const j=[e.PaymentMethod.APPLE_PAY,e.PaymentMethod.GOOGLE_PAY,e.PaymentMethod.PAYPAL,e.PaymentMethod.PAYMENT_CARD],H={[e.PaymentMethod.APPLE_PAY]:{buttonStyle:"black",buttonType:"continue"},[e.PaymentMethod.PAYPAL]:{buttonColor:"gold",buttonShape:"pill",buttonLabel:"pay",buttonSize:"large",buttonHeight:54,paymentFlow:"PREFER_VAULT"},[e.PaymentMethod.GOOGLE_PAY]:{buttonColor:"black",buttonSizeMode:"fill",buttonType:"pay"}},Y={requiredBillingContactFields:["emailAddress"]},B={requiredShippingContactFields:["emailAddress"]};function V(e){if("string"!=typeof e)return!1;return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}const $=["plain","buy","set-up","donate","check-out","book","subscribe"];async function G(e,t){if(!await async function(){if("undefined"==typeof window||!window.customElements)return!1;if(window.customElements.get("apple-pay-button"))return!0;try{await d({src:"https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js",crossOrigin:"anonymous",appendTo:"head"});const e=window.customElements.whenDefined("apple-pay-button").then(()=>!0),t=new Promise(e=>{setTimeout(()=>e(!1),4e3)});return await Promise.race([e,t])}catch{return!1}}())return null;if(!e.querySelector("button"))return null;const n=document.createElement("apple-pay-button");return n.setAttribute("type",t.buttonType),n.setAttribute("buttonstyle",t.buttonStyle||"black"),n.setAttribute("locale","undefined"!=typeof navigator&&navigator.language||"en-US"),n.style.cssText=["position:absolute","inset:0","width:100%","height:100%","--apple-pay-button-width:100%","--apple-pay-button-height:100%",`--apple-pay-button-border-radius:${t.borderRadius??28}px`,"display:block","cursor:pointer","z-index:1"].join(";"),e.style.position="relative",n.addEventListener("click",()=>{const t=e.querySelector("button");t?.click()}),e.appendChild(n),n}class Q{constructor(){this.isInitialized=!1,this.destroyCallbacks=[],this.currentHeadless=null,this.availableMethods=[],this.paymentMethodsInterfaces=[]}isPrimerAvailable(){return"undefined"!=typeof window&&window.Primer&&"function"==typeof window.Primer?.createHeadless}async ensurePrimerLoaded(e){if(!this.isPrimerAvailable())try{await m(e)}catch(e){throw new i("Failed to load Primer SDK",e)}}ensurePrimerAvailable(){if(!this.isPrimerAvailable())throw new i("Primer SDK not found. Please include the Primer SDK script before initializing FunnefoxSDK.")}async createHeadlessCheckout(e,t,n){return await this.ensurePrimerLoaded(),this.applePayOptions=t.applePay,this.currentHeadless=Q.headlessManager.getOrCreate(e,t,n),this.currentHeadless}disableButtons(e){if(this.paymentMethodsInterfaces)for(const t of this.paymentMethodsInterfaces)t.setDisabled(e)}async renderButton(t,{htmlNode:n,onMethodRenderError:r,onMethodRender:o}){let a;if(await this.ensurePrimerLoaded(),!this.currentHeadless)throw new i("Headless checkout not found");try{const r=await this.currentHeadless,i=await r.createPaymentMethodManager(t);if(!i)throw new Error("Payment method manager is not available");const d=document.createElement("div");d.className=E("funnefox-primer-button-wrapper");const l=document.createElement("style");document.head.appendChild(l);const c=l.sheet;c&&(c.insertRule(`\n .${d.className} {\n width: 100% !important;\n }\n `),c.insertRule(`\n .${d.className} button {\n height: 54px !important;\n border-radius: 28px !important;\n }\n `)),n.appendChild(d);const u=this.applePayOptions,h=t===e.PaymentMethod.APPLE_PAY&&u?.buttonType&&((s=u.buttonType)&&!$.includes(s))?u.buttonType:null;let p=null;h&&c&&(p=c.insertRule(`\n .${d.className} > button {\n opacity: 0 !important;\n }\n `)),a=i.createButton(),await a.render(d,{});let m=null;return h&&(m=await G(d,{buttonType:h,buttonStyle:u?.buttonStyle}),!m&&c&&null!==p&&c.deleteRule(p)),this.destroyCallbacks.push(()=>{m?.remove(),a.clean()}),o(t),{setDisabled:e=>{a.setDisabled(e),m&&(m.style.pointerEvents=e?"none":"",m.style.opacity=e?"0.5":"")},destroy:()=>{l.remove(),m?.remove(),a.clean()}}}catch(e){throw r(t),new i(`Failed to initialize Primer checkout method ${t}`,e)}var s}async initMethod(t,n,r){try{if(t===e.PaymentMethod.PAYMENT_CARD){if(!r.cardElements||!r.onSubmit||!r.onInputChange)throw new i("Card elements, onSubmit, and onInputChange are required for PAYMENT_CARD method");const e=await this.renderCardCheckoutWithElements(r.cardElements,{onSubmit:r.onSubmit,onInputChange:r.onInputChange,onMethodRenderError:r.onMethodRenderError,onMethodRender:r.onMethodRender,onCardInputValueChange:r.onCardInputValueChange,isCardholderNameRequired:r.isCardholderNameRequired,isPostalCodeRequired:r.isPostalCodeRequired});return this.paymentMethodsInterfaces.push(e),e}{const e=await this.renderButton(t,{htmlNode:n,onMethodRenderError:r.onMethodRenderError,onMethodRender:r.onMethodRender});return this.paymentMethodsInterfaces.push(e),e}}catch(e){throw new i(`Failed to initialize Primer checkout method ${t}`,e)}}async renderCardCheckoutWithElements(t,{onSubmit:n,onInputChange:r,onCardInputValueChange:o,isCardholderNameRequired:a,isPostalCodeRequired:s,onMethodRenderError:d,onMethodRender:l}){try{if(!this.currentHeadless)throw new i("Headless checkout not found");const d=await this.currentHeadless,c=await d.createPaymentMethodManager("PAYMENT_CARD");if(!c)throw new Error("Payment method manager is not available");const u=!!t.emailAddress,{cardNumberInput:h,expiryInput:p,cvvInput:m}=c.createHostedInputs(),C=async()=>{if(!c)return!1;const{valid:e,validationErrors:n}=await c.validate(),r=a?.()?n.find(e=>"cardholderName"===e.name)?.message:null;g("cardholderName",r);let o=null;if(u){const e=t.emailAddress?.value?.trim();o=V(e)?null:"Please enter a valid email address",g("emailAddress",o)}const i=w();return g("postalCode",i),e&&!o&&!r&&!i},g=(e,t)=>{r(e,t)},w=()=>{const e=t.postalCode?.value?.trim();return s?.()&&!e?"Please enter a postal code":null},S=new Set,E=e=>t=>{const n=t,r=n.active&&!S.has(e);n.active?S.add(e):S.delete(e),r||g(e,function(e){return e.error?e.errorCode&&y.has(e.errorCode)?e.error:e.active?null:e.submitted?e.error:e.errorCode&&f.has(e.errorCode)?null:e.touched?e.error:null:null}(n))},b=async e=>{c.setCardholderName(e.target.value),g("cardholderName",null)};let v;u&&(v=e=>{const t=e.target.value.trim();o?.("emailAddress",t),g("emailAddress",t&&!V(t)?"Please enter a valid email address":null)},t.emailAddress.addEventListener("input",v));const _=e=>{const t=e.target.value.trim();o?.("countryCode",t),s?.()||g("postalCode",null)},P=e=>{const t=e.target.value.trim();o?.("postalCode",t),g("postalCode",w())};t.cardholderName?.addEventListener("input",b),t.emailAddress?.addEventListener("input",v),t.countrySelector?.addEventListener("change",_),t.postalCode?.addEventListener("input",P),h.addEventListener("change",E("cardNumber")),p.addEventListener("change",E("expiryDate")),m.addEventListener("change",E("cvv"));const M=async()=>{if(await C())try{n(!0),await c.submit()}catch(e){throw new i("Failed to submit payment",e)}finally{n(!1)}};t.button?.addEventListener("click",M),await Promise.all([h.render(t.cardNumber,{placeholder:"1234 1234 1234 1234",ariaLabel:"Card number",style:z}),p.render(t.expiryDate,{placeholder:"MM/YY",ariaLabel:"Expiry date",style:z}),m.render(t.cvv,{placeholder:"123",ariaLabel:"CVV",style:z})]);const I=()=>{c.removeHostedInputs(),t.cardholderName?.removeEventListener("input",b),t.emailAddress?.removeEventListener("input",v),t.countrySelector?.removeEventListener("change",_),t.postalCode?.removeEventListener("input",P),t.button?.removeEventListener("click",M)};return this.destroyCallbacks.push(I),l(e.PaymentMethod.PAYMENT_CARD),{setDisabled:e=>{h.setDisabled(e),p.setDisabled(e),m.setDisabled(e),t.button&&(t.button.disabled=e),t.cardholderName&&(t.cardholderName.disabled=e),t.emailAddress&&(t.emailAddress.disabled=e),t.countrySelector&&(t.countrySelector.disabled=e),t.postalCode&&(t.postalCode.disabled=e)},submit:()=>M(),destroy:()=>{this.destroyCallbacks=this.destroyCallbacks.filter(e=>e!==I),I()}}}catch(t){throw d(e.PaymentMethod.PAYMENT_CARD),new i("Failed to initialize Primer checkout method PAYMENT_CARD",t)}}async initializeHeadlessCheckout(e,t,n){await this.createHeadlessCheckout(e,{...t,onTokenizeSuccess:this.wrapTokenizeHandler(t.onTokenizeSuccess),onResumeSuccess:this.wrapResumeHandler(t.onResumeSuccess),onAvailablePaymentMethodsLoad:this.wrapAvailablePaymentMethodsLoadHandler(t.onAvailablePaymentMethodsLoad)},n)}async renderCheckout(t,n,r){const{cardElements:o,paymentButtonElements:i,container:a,onSubmit:s,onInputChange:d,onMethodRender:l,onMethodRenderError:c,onMethodsAvailable:u,onCardInputValueChange:h,isCardholderNameRequired:p,isPostalCodeRequired:m}=r;await this.initializeHeadlessCheckout(t,n),u?.(this.availableMethods),await Promise.all(this.availableMethods.map(t=>{if(t===e.PaymentMethod.PAYMENT_CARD)return this.initMethod(t,a,{cardElements:o,onSubmit:s,onInputChange:d,onMethodRender:l,onMethodRenderError:c,onCardInputValueChange:h,isCardholderNameRequired:p,isPostalCodeRequired:m});{const n={[e.PaymentMethod.PAYPAL]:i.paypal,[e.PaymentMethod.GOOGLE_PAY]:i.googlePay,[e.PaymentMethod.APPLE_PAY]:i.applePay}[t];return this.initMethod(t,n,{onMethodRender:l,onMethodRenderError:c})}})),this.isInitialized=!0}wrapTokenizeHandler(e){return async(t,n)=>{try{await e(t,n)}catch(e){console.error("Error in tokenize handler:",e),n.handleFailure("Payment processing failed. Please try again.")}}}wrapResumeHandler(e){return async(t,n)=>{try{await e(t,n)}catch(e){console.error("Error in resume handler:",e),n.handleFailure("Payment processing failed. Please try again.")}}}wrapAvailablePaymentMethodsLoadHandler(t){return n=>{let r=!1;if(this.availableMethods=F.filter(t=>n.some(n=>(n.type===e.PaymentMethod.APPLE_PAY&&(r=!0),n.type===t))),r&&(this.availableMethods=this.availableMethods.filter(t=>t!==e.PaymentMethod.GOOGLE_PAY)),0===this.availableMethods.length)throw new i("No allowed payment methods found");t?.(this.availableMethods)}}async destroy(){if(this.currentHeadless&&(Q.headlessManager.remove(this.currentHeadless),this.currentHeadless=null),this.destroyCallbacks)try{Promise.all(this.destroyCallbacks.map(e=>e()))}catch(e){console.warn("Error destroying Primer checkout:",e)}this.destroyCallbacks=[],this.isInitialized=!1}createHandlers(e){return{handleSuccess:()=>{e.onSuccess&&e.onSuccess()},handleFailure:t=>{e.onError&&e.onError(new Error(t))},continueWithNewClientToken:t=>{e.onActionRequired&&e.onActionRequired(t)}}}getCurrentCheckout(){return this.destroyCallbacks}isActive(){return this.isInitialized&&this.destroyCallbacks.length>0}validateContainer(e){const t=document.querySelector(e);if(!t)throw new i(`Checkout container not found: ${e}`);return"none"===window.getComputedStyle(t).display&&console.warn("Checkout container is hidden, this may cause display issues"),t}refreshClientSession(){return this.currentHeadless?.then(e=>e.refreshClientSession())}}Q.headlessManager=new class{constructor(){this.cache=new Map,this.queue=Promise.resolve()}generateKey(e,t,n){const r={paymentHandling:t.paymentHandling,apiVersion:t.apiVersion,style:t.style,card:t.card,applePay:t.applePay,paypal:t.paypal,googlePay:t.googlePay};return`${e}:${n||"default"}:${JSON.stringify(r)}`}getOrCreate(e,t,n){const r=this.generateKey(e,t,n),o=this.cache.get(r);if(o)return o;const a=this.queue,s=(async()=>{await a;const n=S({paymentHandling:"MANUAL",apiVersion:"2.4"},t);try{const t=await window.Primer.createHeadless(e,n),r=await t;return await r.start(),r}catch(e){throw this.cache.delete(r),new i("Failed to create Primer headless checkout",e)}})();return this.cache.set(r,s),this.queue=s.catch(()=>{}),s}remove(e){for(const[t,n]of this.cache.entries())if(n===e){this.cache.delete(t);break}}clear(){this.cache.clear()}};function W(e){const t=new Error(e?.message||"Payment processing failed");if(e instanceof o)e.declineCode&&(t.declineCode=e.declineCode),e.declineCodeSource&&(t.declineCodeSource=e.declineCodeSource);else if(e instanceof Error){const n=function(e){const{type:t,code:n}=e;return"card_error"===t&&"string"==typeof n&&n?n.toUpperCase():null}(e);n&&(t.declineCode=n,t.declineCodeSource="stripe")}return t}class K{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.orgId=e.orgId,this.timeout=e.timeout||3e4,this.retryAttempts=e.retryAttempts||3}async request(e,t={}){const n=`${this.baseUrl}/${this.orgId}${e}`,r={method:"GET",headers:{"Content-Type":"application/json","X-SDK-Version":P,...t.headers||{}},...t};try{return await async function(e,t=3,n=1e3){let r;for(let o=1;o<=t;o++)try{return await e()}catch(e){if(r=e,o===t)throw r;const i=n*Math.pow(2,o-1);await b(i)}throw r}(async()=>await v(this._makeRequest(n,r),this.timeout,"Request timed out"),this.retryAttempts)}catch(e){if(e instanceof Error&&"APIError"===e.name)throw e;throw new s("Network request failed",e)}}async requestOnce(e,t={},n){const r=`${this.baseUrl}/${this.orgId}${e}`,i={method:"GET",headers:{"Content-Type":"application/json","X-SDK-Version":P,...t.headers||{}},...t};try{const e=this._makeRequest(r,i);return await(n?v(e,n,"Request timed out"):e)}catch(e){if(e instanceof o)throw e.errorCode??(e.errorCode=Z(e.response)[0]??null),e;if(e instanceof Error&&"NetworkError"===e.name)throw e;throw new s("Network request failed",e)}}async _makeRequest(e,t){let n,r;try{n=await fetch(e,t)}catch(e){if(e instanceof Error&&"NetworkError"===e.name)throw e;throw new s("Network request failed",e)}try{r=await n.json()}catch{throw new o("Invalid JSON response",n.status,{})}if(!n.ok){const e=r,t=e.error?.[0]?.msg||"Failed to create payment";throw new o(t,n.status,{response:r})}return r}async createClientSession(e){const t={region:e.region||"default",integration_type:e.integration??"primer",pp_ident:e.priceId,external_id:e.externalId,email_address:e.email,client_metadata:e.clientMetadata||{}};return void 0!==e.countryCode&&(t.country_code=e.countryCode),await this.request(k,{method:"POST",body:JSON.stringify(t)})}async updateClientSession(e){const t={order_id:e.orderId,client_token:e.clientToken,pp_ident:e.priceId,client_metadata:e.clientMetadata||{}};return await this.request(T,{method:"POST",body:JSON.stringify(t)})}async createPayment(e){const t={order_id:e.orderId,payment_method_token:e.paymentMethodToken,client_metadata:e.clientMetadata||{}};return void 0!==e.email&&(t.email_address=e.email),void 0!==e.countryCode&&(t.country_code=e.countryCode),void 0!==e.postalCode&&(t.postal_code=e.postalCode),void 0!==e.subdivision&&(t.subdivision=e.subdivision),void 0!==e.taxCalculationId&&(t.tax_calculation_id=e.taxCalculationId),await this.request(R,{method:"POST",body:JSON.stringify(t)})}async recalculateTax(e){const t={order_id:e.orderId,client_token:e.clientToken,country_code:e.countryCode};e.postalCode&&(t.postal_code=e.postalCode),e.subdivision&&(t.subdivision=e.subdivision);const n=await this.request(O,{method:"POST",body:JSON.stringify(t)});if("error"===n.status||!n.data){const e=n.error?.[0];throw new o(e?.msg||"Tax recalculation failed",null,{errorCode:e?.code,errorType:e?.type,requestId:n.req_id,response:n})}return n.data}async resumePayment(e){const t={order_id:e.orderId,resume_token:e.resumeToken};return await this.request(A,{method:"POST",body:JSON.stringify(t)})}processSessionResponse(e){if("error"===e.status){const t=e.error?.[0];throw new o(t?.msg||"Session creation failed",null,{errorCode:t?.code,errorType:t?.type,requestId:e.req_id,response:e})}const t=e.data;return{type:"session_created",orderId:t.order_id,clientToken:t.client_token}}processPaymentResponse(e){if("error"===e.status){const t=e.error?.[0];throw new o(t?.msg||"Payment request failed",null,{errorCode:t?.code,errorType:t?.type,response:e})}const t=e.data;if(t.action_required_token)return{type:"action_required",orderId:t.order_id,clientToken:t.action_required_token};if(t.checkout_status)switch(t.checkout_status){case"succeeded":return{type:"success",orderId:t.order_id,status:"succeeded"};case"failed":throw new o(t.failed_message_for_user||"Payment failed",null,{response:e,declineCode:t.decline_code,declineCodeSource:t.decline_code_source});case"cancelled":throw new o("Payment was cancelled by user",null,{response:e});case"processing":return{type:"processing",orderId:t.order_id,status:"processing"};default:throw new o(`Unhandled checkout status: ${t.checkout_status}`,null,{response:e})}throw new o("Invalid payment response format",null,{response:e})}async oneClick(e){return await this.request(x,{method:"POST",body:JSON.stringify(e)})}async oneClickOnce(e,t){return await this.requestOnce(x,{method:"POST",body:JSON.stringify(e)},t)}async oneClickWalletSession(e,t){return await this.requestOnce(D,{method:"POST",body:JSON.stringify(e)},t)}async resumePaymentOnce(e){return await this.requestOnce(A,{method:"POST",body:JSON.stringify({order_id:e.orderId,resume_token:e.resumeToken})})}async createSimpleClientSession(e){return await this.request(L,{method:"POST",body:JSON.stringify({region:"default",integration_type:"primer",...e})})}}function Z(e){const t=e?.error;return Array.isArray(t)?t.map(e=>e?.code).filter(e=>"string"==typeof e):[]}var J=new class{constructor(){this.cache=new Map}buildCacheKey(e){return[e.orgId,e.baseUrl||M.BASE_URL,e.region||M.REGION,e.countryCode??"",e.priceId,e.externalId,e.email,e.integration].join("|")}makeClient(e,t){return new K({baseUrl:t||M.BASE_URL,orgId:e,timeout:M.REQUEST_TIMEOUT,retryAttempts:M.RETRY_ATTEMPTS})}createSession(e){const t=this.buildCacheKey(e),n=this.cache.get(t);if(n)return n;const r=this.makeClient(e.orgId,e.baseUrl).createClientSession({priceId:e.priceId,externalId:e.externalId,email:e.email,region:e.region||M.REGION,clientMetadata:e.clientMetadata,countryCode:e.countryCode,integration:e.integration});this.cache.set(t,r);const o=()=>{this.cache.get(t)===r&&this.cache.delete(t)};return r.then(e=>{e&&"error"!==e.status&&e.data||o()},o),r}invalidate(e){this.cache.delete(this.buildCacheKey(e))}clearCache(){this.cache.clear()}};"undefined"!=typeof document&&(document.head.appendChild(document.createElement("style")).textContent=".ff-sdk-loader-container {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n background-color: rgba(255, 255, 255);\n z-index: 2;\n}\n\n.ff-sdk-loader {\n width: 24px;\n height: 24px;\n border: 4px solid #e32f41;\n border-top: 4px solid transparent;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n}\n\n@keyframes spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n }");const X='<div class="ff-sdk-loader-container">\n <div class="ff-sdk-loader"></div>\n</div>\n',ee={loaderContainer:".ff-sdk-loader-container"};var te,ne="https://js.stripe.com/v3",re=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,oe=function(e){var t=document.createElement("script");t.src="".concat(ne).concat("");var n=document.head||document.body;if(!n)throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");return n.appendChild(t),t},ie=null,ae=null,se=null,de=function(e){return null!==ie?ie:(ie=new Promise(function(t,n){if("undefined"!=typeof window&&"undefined"!=typeof document)if(window.Stripe)t(window.Stripe);else try{var r=function(){for(var e=document.querySelectorAll('script[src^="'.concat(ne,'"]')),t=0;t<e.length;t++){var n=e[t];if(re.test(n.src))return n}return null}();if(r&&e);else if(r){if(r&&null!==se&&null!==ae){var o;r.removeEventListener("load",se),r.removeEventListener("error",ae),null===(o=r.parentNode)||void 0===o||o.removeChild(r),r=oe()}}else r=oe();se=function(e,t){return function(){window.Stripe?e(window.Stripe):t(new Error("Stripe.js not available"))}}(t,n),ae=function(e){return function(){e(new Error("Failed to load Stripe.js"))}}(n),r.addEventListener("load",se),r.addEventListener("error",ae)}catch(e){return void n(e)}else t(null)})).catch(function(e){return ie=null,Promise.reject(e)})},le=!1,ce=function(){return te||(te=de(null).catch(function(e){return te=null,Promise.reject(e)}))};Promise.resolve().then(function(){return ce()}).catch(function(e){le||console.warn(e)});var ue=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];le=!0;var r=Date.now();return ce().then(function(e){return function(e,t,n){if(null===e)return null;var r=e.apply(void 0,t);return function(e,t){e&&e._registerWrapper&&e._registerWrapper({name:"stripe-js",version:"4.6.0",startTime:t})}(r,n),r}(e,t,r)})};"undefined"!=typeof document&&(document.head.appendChild(document.createElement("style")).textContent=".ff-sdk-error-container {\n background-color: #d1000033;\n color: #d10000;\n font-size: 14px;\n padding: 16px 12px;\n border-radius: 8px;\n}");const he='<div class="ff-sdk-error-container">\n <p class="ff-sdk-error-message">The payment form didn’t load correctly.</p>\n <p>Please refresh the page to try again.</p>\n <p>If the problem persists, please contact support.</p>\n <p class="ff-sdk-error-request-id"></p>\n</div>\n',pe={errorRequestId:".ff-sdk-error-request-id"};function me(e,t){if("undefined"==typeof document)return;const n=new URLSearchParams({message:ye(t.message,500),code:t.code||"SDK_ERROR",timestamp:Date.now().toString(),sdk_version:P});t.req_id&&fe(n,"req_id",t.req_id,1800),t.context&&Object.entries(t.context).forEach(([e,t])=>{null!=t&&fe(n,e,ye(String(t),1e3),1800)});const r=`${(t.baseUrl||M.BASE_URL).replace(/\/$/,"")}/sdk_report/${encodeURIComponent(e)}/crash?${n.toString()}`,o=new Image;o.src=r,o.style.display="none",o.onload=()=>{o.remove()},o.onerror=()=>{o.remove()},(document.body||document.documentElement)?.appendChild(o)}function ye(e,t){return e.length>t?e.slice(0,t):e}function fe(e,t,n,r){const o=new URLSearchParams(e);return o.append(t,n),!(o.toString().length>r)&&(e.append(t,n),!0)}let Ce=null;const ge=new Map,we=3e3;let Se=!1;function Ee(e){return e.enabled&&"undefined"!=typeof window&&"undefined"!=typeof document?(Ce=e,function(){if(Se||"undefined"==typeof window)return;window.addEventListener("error",be),window.addEventListener("unhandledrejection",ve),Se=!0}(),()=>{var t;t=e.id,Ce?.id===t&&(Ce=null,ge.clear(),Se&&"undefined"!=typeof window&&(window.removeEventListener("error",be),window.removeEventListener("unhandledrejection",ve),Se=!1))}):()=>{}}function be(e){_e(Pe(e.error||e.message||"Unhandled browser error","UNHANDLED_ERROR"),{event_type:"error",filename:e.filename,lineno:e.lineno,colno:e.colno})}function ve(e){_e(Pe(e.reason||"Unhandled promise rejection","UNHANDLED_REJECTION"),{event_type:"unhandledrejection"})}function _e(e,t){if(Ce&&function(e,t){const n=Date.now();!function(e){ge.forEach((t,n)=>{e-t>=we&&ge.delete(n)})}(n);const r=function(e,t){const n=e.stack?.split("\n")[0]||"";return[t||"",e.code||"",e.message||"",n].join("|")}(e,t),o=ge.get(r);if("number"==typeof o&&n-o<we)return!1;return ge.set(r,n),!0}(e,t.event_type))try{const n=Ce.getContext();me(Ce.orgId,{baseUrl:Ce.baseUrl,message:`${e.name}: ${e.message}`,code:e.code,context:{...t,order_id:n.orderId,price_id:n.priceId,page_url:Te()}})}catch{}}function Pe(e,t){if(e instanceof Error)return{name:e.name||"Error",message:e.message||"Unknown error",code:Me(e,t),stack:e.stack};if("object"==typeof e&&null!==e){const n=e;return{name:Ie(n.name)||"Error",message:Ie(n.message)||ke(e),code:Ie(n.code)||t,stack:Ie(n.stack)}}return{name:"Error",message:Ie(e)||"Unknown error",code:t}}function Me(e,t){const n=e;return"string"==typeof n.code&&n.code?n.code:t}function Ie(e){return"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e?String(e):""}function ke(e){try{return JSON.stringify(e)}catch{return"Unserializable error"}}function Te(){if("undefined"==typeof window||!window.location)return"";const e=window.location;return e.origin&&e.pathname?`${e.origin}${e.pathname}`:(e.href||"").split(/[?#]/)[0]}class Re extends t{constructor(t){super(),this.counter=0,this.cachedSessionResponse=null,this.taxRecalcSeq=0,this.isApplePaySheetOpen=!1,this.cardSessionFieldConfig={},this.isTelemetryEnabled=!1,this.telemetryCleanup=null,this.handleInputChange=(e,t)=>{this.emit(I.INPUT_ERROR,{name:e,error:t})},this.getPaymentEmailAddress=()=>{if(this.cardEmailAddress?.trim()===this.checkoutConfig.customer.email)return;const e=this.cardEmailAddress?.trim()||this.checkoutConfig.customer.email;if(!e||!V(e))return;const t=this.checkoutConfig.card?.emailAddress?.template;return t?.includes("{{email}}")?t.replace(/\{\{email\}\}/g,e):e},this.handleCardInputValueChange=(e,t)=>{"emailAddress"!==e?("countryCode"===e?(this.cardCountryCode=this.normalizeCountryCode(t),this.isPostalCodeVisible()||(this.cardPostalCode=void 0)):"postalCode"===e&&(this.cardPostalCode=t?.trim()||void 0),this.isTaxEnabled()&&this.scheduleTaxRecalc()):this.cardEmailAddress=t?.trim()||void 0},this.isTaxEnabled=()=>this.cachedSessionResponse?.data?.tax_enabled??this.checkoutConfig.enableTax??!1,this.getSessionTaxInfo=()=>{const e=this.cachedSessionResponse?.data;if(e&&null!=e.amount_total)return{amountTotal:e.amount_total,currency:e.currency??"",...C(e)}},this.emitTaxInfo=e=>{this.lastTaxInfo=e,this.checkoutConfig.onTaxChange?.(e),this.emit(I.TAX_CHANGE,e)},this.emitSessionTaxEstimate=()=>{const e=this.getSessionTaxInfo();e&&this.emitTaxInfo(e)},this.runTaxRecalc=async()=>{const e=this.orderId,t=this.getSelectedCountryCode();if(!e||!t)return;const n=++this.taxRecalcSeq;try{const r=await this.apiClient.recalculateTax({orderId:e,clientToken:this.cachedSessionResponse?.data?.client_token??"",countryCode:t,postalCode:this.cardPostalCode});if(n!==this.taxRecalcSeq)return;this.emitTaxInfo({amountTotal:r.amount_total,currency:r.currency,...C(r)})}catch(e){if(n!==this.taxRecalcSeq)return;console.warn("[funnelfox-billing] tax recalculation failed",e),this.lastTaxInfo&&this.emit(I.TAX_CHANGE,this.lastTaxInfo),this.checkoutConfig.onTaxError?.(e)}},this.scheduleTaxRecalc=()=>{this.taxRecalcDebounce&&clearTimeout(this.taxRecalcDebounce),this.checkoutConfig.onTaxPending?.(),this.emit(I.TAX_PENDING),this.taxRecalcDebounce=setTimeout(this.runTaxRecalc,600)},this.flushTaxRecalc=async()=>{this.taxRecalcDebounce&&(clearTimeout(this.taxRecalcDebounce),this.taxRecalcDebounce=void 0),this.isTaxEnabled()&&await this.runTaxRecalc()},this.handleMethodRender=e=>{this.emit(I.METHOD_RENDER,e)},this.handleMethodRenderError=e=>{this.emit(I.METHOD_RENDER_ERROR,e)},this.handleSubmit=e=>{this.onLoaderChangeWithRace(e),this._setState(e?"processing":"ready")},this.handleTokenizeSuccess=async(t,n)=>{if(this.orderId)try{this.onLoaderChangeWithRace(!0),this._setState("processing"),this.activePaymentMethodType===e.PaymentMethod.PAYMENT_CARD&&await this.flushTaxRecalc();const[r,o]=await Promise.all([this.cachedSessionResponse?.radarSessionId,this.cachedSessionResponse?.airwallexDeviceId]),i=await this.apiClient.createPayment({orderId:this.orderId,paymentMethodToken:t.token,email:this.getPaymentEmailAddress(),countryCode:this.getPaymentCountryCode(),postalCode:this.getPaymentPostalCode(),clientMetadata:{radarSessionId:r,airwallexDeviceId:o}}),a=this.apiClient.processPaymentResponse(i);await this._processPaymentResult(a,n)}catch(e){this._setState("error"),this.emit(I.PURCHASE_FAILURE,W(e)),n.handleFailure(e?.message||"Payment processing failed")}finally{this.isApplePaySheetOpen=!1,this.onLoaderChangeWithRace(!1),this._setState("ready")}else n.handleFailure("Order ID not found or checkout has been destroyed")},this.handleResumeSuccess=async(e,t)=>{if(this.orderId)try{this.onLoaderChangeWithRace(!0),this._setState("processing");const n=await this.apiClient.resumePayment({orderId:this.orderId,resumeToken:e.resumeToken}),r=this.apiClient.processPaymentResponse(n);await this._processPaymentResult(r,t)}catch(e){this._setState("error"),this.emit(I.PURCHASE_FAILURE,W(e)),t.handleFailure(e?.message||"Payment processing failed")}finally{this.isApplePaySheetOpen=!1,this.emit(I.PURCHASE_COMPLETED),this.onLoaderChangeWithRace(!1),this._setState("ready")}else t.handleFailure("Order ID not found or checkout has been destroyed")},this.handleMethodsAvailable=e=>{this.emit(I.METHODS_AVAILABLE,e)},this.onLoaderChangeWithRace=e=>{const t=!!(e?++this.counter:--this.counter);this.primerWrapper.disableButtons(t),this.emit(I.LOADER_CHANGE,t)},this.id=E("checkout_"),this.orgId=t.orgId,this.baseUrl=t.baseUrl,this.region=t.region,this.checkoutConfig={...t.checkoutConfig},this.callbacks={onSuccess:this.checkoutConfig.onSuccess,onError:this.checkoutConfig.onError,onStatusChange:this.checkoutConfig.onStatusChange,onDestroy:this.checkoutConfig.onDestroy},delete this.checkoutConfig?.onSuccess,delete this.checkoutConfig?.onError,delete this.checkoutConfig?.onStatusChange,delete this.checkoutConfig?.onDestroy,this.state="initializing",this.orderId=null,this.clientToken=null,this.primerWrapper=new Q,this.isDestroyed=!1,this.cardEmailAddress=this.checkoutConfig.customer.email,this.shouldApplySessionCardholderNameConfig=void 0===this.checkoutConfig.card?.cardholderName?.required,this.apiClient=new K({baseUrl:this.baseUrl||M.BASE_URL,orgId:this.orgId,timeout:M.REQUEST_TIMEOUT,retryAttempts:M.RETRY_ATTEMPTS}),this._setupCallbackBridges()}_setupCallbackBridges(){this.callbacks.onSuccess&&this.on(I.SUCCESS,this.callbacks.onSuccess),this.callbacks.onError&&this.on(I.ERROR,this.callbacks.onError),this.callbacks.onStatusChange&&this.on(I.STATUS_CHANGE,this.callbacks.onStatusChange),this.callbacks.onDestroy&&this.on(I.DESTROY,this.callbacks.onDestroy)}removeAllListeners(){return super.removeAllListeners()}async initialize(){try{return this.showInitializingLoader(),this._setState("initializing"),await this.createSession(),await this._initializePrimerCheckout(),this._setState("ready"),this.isTaxEnabled()&&this.emitSessionTaxEstimate(),this.startUnhandledTelemetry(),this.checkoutConfig?.onInitialized?.(),this}catch(e){throw this._setState("error"),((e,t)=>{const n=document.querySelector(e);if(n&&(n.innerHTML=he,t)){const e=n.querySelector(pe.errorRequestId);e&&(e.textContent=`Request ID: ${t}`)}})(this.checkoutConfig.container,e?.response?.req_id),this.emit(I.ERROR,e),e}finally{this.hideInitializingLoader()}}async createSession(){const e=await J.createSession({orgId:this.orgId,baseUrl:this.baseUrl,priceId:this.checkoutConfig.priceId,externalId:this.checkoutConfig.customer.externalId,email:this.checkoutConfig.customer.email,region:this.region,clientMetadata:this.checkoutConfig.clientMetadata,countryCode:this.checkoutConfig.customer.countryCode,integration:"primer"}),t=e;if(e.data?.stripe_public_key&&!t.radarSessionId){const n=e.data.stripe_public_key;t.radarSessionId=ue(n).then(e=>e?e.createRadarSession().then(e=>e?.radarSession?.id||"").catch(()=>""):"").catch(()=>"")}if(e.data?.airwallex_risk_enabled&&!t.airwallexDeviceId){const n=e.data?.is_livemode,r="undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)});t.airwallexDeviceId=async function(e,t=!0){const n=t?"https://static.airwallex.com/webapp/fraud/device-fingerprint/index.js":"https://static-demo.airwallex.com/webapp/fraud/device-fingerprint/index.js";await d({id:"airwallex-fraud-api",src:n,async:!0,attributes:{"data-order-session-id":e}})}(r,n).then(()=>r).catch(()=>r)}this.cachedSessionResponse=t,this.isTelemetryEnabled=!!t.data?.sdk_telemetry_enabled,this.isCollectingApplePayEmail=!!t.data?.collect_apple_pay_email,this.applySessionCardFieldConfig(t);const n=this.apiClient.processSessionResponse(t);this.orderId=n.orderId,this.clientToken=n.clientToken}applySessionCardFieldConfig(e){const t={...this.checkoutConfig.card||{}};void 0===t.emailAddress?.visible&&void 0!==e.data?.show_email_field&&(t.emailAddress={...t.emailAddress,visible:e.data.show_email_field}),this.shouldApplySessionCardholderNameConfig&&void 0!==e.data?.show_cardholder_name_field&&(t.cardholderName={...t.cardholderName,required:e.data.show_cardholder_name_field});const n=this.normalizeCountryFieldOverrides(e.data?.country_field_overrides),r=this.normalizeCountryCode(e.data?.detected_country_code)||this.cardCountryCode;this.cardSessionFieldConfig={...this.cardSessionFieldConfig,showCountrySelector:e.data?.show_country_selector_field??this.cardSessionFieldConfig.showCountrySelector,showPostalCode:e.data?.show_postal_code_field??this.cardSessionFieldConfig.showPostalCode,detectedCountryCode:r||this.cardSessionFieldConfig.detectedCountryCode,validCountries:e.data?.valid_countries||this.cardSessionFieldConfig.validCountries,countryFieldOverrides:n||this.cardSessionFieldConfig.countryFieldOverrides},Object.keys(t).length>0&&(this.checkoutConfig.card=t),this.cardCountryCode=this.cardSessionFieldConfig.detectedCountryCode||this.cardCountryCode,this.isPostalCodeVisible()||(this.cardPostalCode=void 0)}getPrimerCardConfig(){const e={...this.checkoutConfig.card||{}};return delete e.emailAddress,Object.keys(e).length?e:void 0}mergeApplePayCollectingEmailOptions(e){if(!this.isCollectingApplePayEmail)return e;return S(e,{applePay:{billingOptions:{requiredBillingContactFields:Array.from(new Set([...e.applePay?.billingOptions?.requiredBillingContactFields||[],...Y?.requiredBillingContactFields||[]]))},shippingOptions:{requiredShippingContactFields:Array.from(new Set([...e.applePay?.shippingOptions?.requiredShippingContactFields||[],...B?.requiredShippingContactFields||[]]))}}})}convertCardSelectorsToElements(e,t){const n=t.querySelector(e.cardNumber),r=t.querySelector(e.expiryDate),o=t.querySelector(e.cvv),i=e.cardholderName?t.querySelector(e.cardholderName):void 0,s=e.emailAddress?t.querySelector(e.emailAddress):void 0,d=t.querySelector(e.button);if(!(n&&r&&o&&d))throw new a("Required card input elements not found in container");return{cardNumber:n,expiryDate:r,cvv:o,cardholderName:i,emailAddress:s,button:d}}convertPaymentButtonSelectorsToElements(e){const t=document.querySelector(e.paypal),n=document.querySelector(e.googlePay),r=document.querySelector(e.applePay);if(!t||!n||!r)throw new a("Required payment button elements not found in container");return{paypal:t,googlePay:n,applePay:r}}async _initializePrimerCheckout(){const e=this.getContainer();if(!e)throw new a(`Checkout container not found: ${this.checkoutConfig.container}`);let t,n,r;if(this.checkoutConfig.cardSelectors&&this.checkoutConfig.paymentButtonSelectors)this.checkoutConfig.paymentMethodOrder&&console.warn("paymentMethodOrder is using only for default skin and will be ignored if you are using custom checkout"),t=this.convertCardSelectorsToElements(this.checkoutConfig.cardSelectors,e),n=this.convertPaymentButtonSelectorsToElements(this.checkoutConfig.paymentButtonSelectors),r=this.getCheckoutOptions({});else{this.checkoutConfig.paymentMethodOrder=this.checkoutConfig.paymentMethodOrder||j;const e=await this.getDefaultSkinCheckoutOptions();if(!e.cardElements||!e.paymentButtonElements)throw new a("Default skin must provide cardSelectors and paymentButtonSelectors");t=e.cardElements,n=e.paymentButtonElements,r=this.getCheckoutOptions(e)}r=this.mergeApplePayCollectingEmailOptions(r),await this.primerWrapper.renderCheckout(this.clientToken,r,{container:e,cardElements:t,paymentButtonElements:n,onSubmit:this.handleSubmit,onInputChange:this.handleInputChange,onCardInputValueChange:this.handleCardInputValueChange,isCardholderNameRequired:()=>this.isCardholderNameRequired(),isPostalCodeRequired:()=>this.isPostalCodeVisible(),onMethodRender:this.handleMethodRender,onMethodsAvailable:this.handleMethodsAvailable,onMethodRenderError:this.handleMethodRenderError})}async _processPaymentResult(e,t){switch(e.orderId&&(this.orderId=e.orderId),e.type){case"success":this._setState("completed"),this.emit(I.SUCCESS,{orderId:e.orderId,status:e.status}),t.handleSuccess();break;case"action_required":this._setState("action_required"),this.clientToken=e.clientToken,t.continueWithNewClientToken(e.clientToken);break;case"processing":this._setState("processing"),setTimeout(()=>{t.handleFailure("Payment is still processing. Please check back later.")},3e4);break;default:throw new a(`Unknown payment result type: ${e.type}`)}}getCheckoutOptions(t){let n=!1;const r={...this.checkoutConfig};return delete r.card,{...r,...t,card:S(this.getPrimerCardConfig()||{},t.card||{}),applePay:S(H[e.PaymentMethod.APPLE_PAY],t.applePay||{},this.checkoutConfig.applePay||{}),onTokenizeSuccess:this.handleTokenizeSuccess,onResumeSuccess:this.handleResumeSuccess,onResumeError:e=>{this.isApplePaySheetOpen=!1,e.stack?.includes("PROCESSOR_3DS")&&"RESUME_ERROR"===e.code&&e.message?.includes("fetch resume key")||this.emit(I.PURCHASE_FAILURE,e)},onCheckoutFail:e=>{this.isApplePaySheetOpen=!1,this.emit(I.PURCHASE_FAILURE,e)},onTokenizeError:e=>{this.isApplePaySheetOpen=!1,this.emit(I.PURCHASE_FAILURE,e)},onTokenizeStart:()=>{n=!0},onTokenizeShouldStart:t=>{if(t.paymentMethodType===e.PaymentMethod.APPLE_PAY){if(this.isApplePaySheetOpen)return!1;this.isApplePaySheetOpen=!0}return this.activePaymentMethodType=t.paymentMethodType,this.emit(I.ERROR,void 0),this.emit(I.START_PURCHASE,t.paymentMethodType),!0},onPaymentMethodAction:e=>{switch(e){case"PAYMENT_METHOD_SELECTED":this.emit(I.ERROR,void 0);break;case"PAYMENT_METHOD_UNSELECTED":this.isApplePaySheetOpen=!1,n||this.emit(I.PURCHASE_CANCELLED),n=!1}}}}async updatePrice(e,t){if(this._ensureNotDestroyed(),function(e,t){var n;if(0===(n=e,n?.trim()||"").length)throw new r(t,"must be a non-empty string",e)}(e,"priceId"),"processing"===this.state)throw new a("Cannot update price while payment is processing");try{this.onLoaderChangeWithRace(!0),this._setState("updating"),J.clearCache(),await this.apiClient.updateClientSession({orderId:this.orderId,clientToken:this.clientToken,priceId:e,clientMetadata:t}),this.checkoutConfig.priceId=e,await this.primerWrapper.refreshClientSession(),this.onLoaderChangeWithRace(!1),this._setState("ready"),this.isTaxEnabled()&&this.scheduleTaxRecalc()}catch(e){throw this.onLoaderChangeWithRace(!1),this._setState("error"),this.emit(I.ERROR,e),e}}getStatus(){return{id:this.id,state:this.state,orderId:this.orderId,priceId:this.checkoutConfig.priceId,isDestroyed:this.isDestroyed}}async destroy(){if(!this.isDestroyed)try{this.stopUnhandledTelemetry(),J.clearCache(),await this.primerWrapper.destroy(),this._setState("destroyed"),this.orderId=null,this.clientToken=null,this.isDestroyed=!0,this.emit(I.DESTROY),this.removeAllListeners()}catch(e){console.warn("Error during checkout cleanup:",e)}}_setState(e){if(this.state!==e){const t=this.state;this.state=e,this.emit(I.STATUS_CHANGE,e,t)}}_ensureNotDestroyed(){if(this.isDestroyed)throw new a("Checkout instance has been destroyed")}getContainer(){return document.querySelector(this.checkoutConfig.container)}isInState(e){return this.state===e}isReady(){return"ready"===this.state&&!this.isDestroyed}isProcessing(){return["processing","action_required"].includes(this.state)}normalizeCountryCode(e){const t=e?.trim().toUpperCase();return t||void 0}normalizeCountryFieldOverrides(e){if(e)return Object.entries(e).reduce((e,[t,n])=>{const r=this.normalizeCountryCode(t);return r&&n&&(e[r]=n),e},{})}getSelectedCountryCode(){return this.normalizeCountryCode(this.cardCountryCode)||this.normalizeCountryCode(this.cardSessionFieldConfig.detectedCountryCode)}getCountryFieldOverride(e=this.getSelectedCountryCode()){if(e)return this.cardSessionFieldConfig.countryFieldOverrides?.[e]}isCardholderNameRequired(){return!!this.checkoutConfig.card?.cardholderName?.required}isPostalCodeVisible(e=this.getSelectedCountryCode()){const t=!!this.cardSessionFieldConfig.showPostalCode,n=this.getCountryFieldOverride(e)?.show_postal_code;return null==n?t:n}getPaymentCountryCode(){return this.getSelectedCountryCode()}getPaymentPostalCode(){if(this.isPostalCodeVisible())return this.cardPostalCode?.trim()||void 0}async getDefaultSkinCheckoutOptions(){const e=(await Promise.resolve().then(function(){return kt})).default,t=await e(this.checkoutConfig,this.cardSessionFieldConfig);return this.on(I.INPUT_ERROR,t.onInputError),this.on(I.STATUS_CHANGE,t.onStatusChange),this.on(I.ERROR,e=>t.onError(e)),this.on(I.LOADER_CHANGE,t.onLoaderChange),this.on(I.DESTROY,t.onDestroy),this.on(I.SUCCESS,t.onSuccess),this.on(I.START_PURCHASE,t.onStartPurchase),this.on(I.PURCHASE_FAILURE,t.onPurchaseFailure),this.on(I.PURCHASE_COMPLETED,t.onPurchaseCompleted),this.on(I.METHODS_AVAILABLE,t.onMethodsAvailable),this.on(I.METHODS_AVAILABLE,this.hideInitializingLoader),t.getCheckoutOptions()}async getCardDefaultSkinCheckoutOptions(e){const t=new(0,(await Promise.resolve().then(function(){return Pt})).default)(e,this.checkoutConfig,this.cardSessionFieldConfig);return t.init(),this.on(I.INPUT_ERROR,t.onInputError),this.on(I.METHOD_RENDER,t.onMethodRender),this.on(I.SUCCESS,t.onDestroy),this.on(I.DESTROY,t.onDestroy),t.getCheckoutOptions()}showInitializingLoader(){(e=>{const t=document.querySelector(e);t&&(t.innerHTML=X)})(this.checkoutConfig.container)}hideInitializingLoader(){(()=>{const e=document.querySelector(ee.loaderContainer);e&&e.remove()})()}async initMethod(t,n,r){this._ensureNotDestroyed(),this.isReady()||await this.createSession(),r.onRenderSuccess&&this.on(I.METHOD_RENDER,r.onRenderSuccess),r.onRenderError&&this.on(I.METHOD_RENDER_ERROR,r.onRenderError),r.onLoaderChange&&this.on(I.LOADER_CHANGE,r.onLoaderChange),r.onPaymentSuccess&&this.on(I.SUCCESS,r.onPaymentSuccess),r.onPaymentFail&&this.on(I.PURCHASE_FAILURE,r.onPaymentFail),r.onPaymentCancel&&this.on(I.PURCHASE_CANCELLED,r.onPaymentCancel),r.onErrorMessageChange&&this.on(I.ERROR,r.onErrorMessageChange),r.onPaymentStarted&&this.on(I.START_PURCHASE,r.onPaymentStarted),r.onMethodsAvailable&&this.on(I.METHODS_AVAILABLE,r.onMethodsAvailable);let o=this.mergeApplePayCollectingEmailOptions(this.getCheckoutOptions({})),i={onMethodRender:this.handleMethodRender,onMethodRenderError:this.handleMethodRenderError};if(t===e.PaymentMethod.PAYMENT_CARD){const e=await this.getCardDefaultSkinCheckoutOptions(n);o=this.getCheckoutOptions({...e}),i={cardElements:e.cardElements,onSubmit:this.handleSubmit,onInputChange:this.handleInputChange,onCardInputValueChange:this.handleCardInputValueChange,isCardholderNameRequired:()=>this.isCardholderNameRequired(),isPostalCodeRequired:()=>this.isPostalCodeVisible(),onMethodRender:this.handleMethodRender,onMethodRenderError:this.handleMethodRenderError}}await this.primerWrapper.initializeHeadlessCheckout(this.clientToken,o,t);const a=await this.primerWrapper.initMethod(t,n,i);return this.startUnhandledTelemetry(t),this.isTaxEnabled()&&!this.lastTaxInfo&&this.emitSessionTaxEstimate(),{...a,destroy:async()=>{await a.destroy(),await this.destroy()}}}startUnhandledTelemetry(e){e&&(this.telemetryPaymentMethod=e),this.isTelemetryEnabled&&!this.telemetryCleanup&&(this.telemetryCleanup=Ee({id:this.id,orgId:this.orgId,baseUrl:this.baseUrl,enabled:this.isTelemetryEnabled,getContext:()=>({checkoutId:this.id,orderId:this.orderId,priceId:this.checkoutConfig.priceId,state:this.state,paymentMethod:this.telemetryPaymentMethod,reqId:this.cachedSessionResponse?.req_id})}))}stopUnhandledTelemetry(){this.telemetryCleanup?.(),this.telemetryCleanup=null,this.telemetryPaymentMethod=void 0}}const Ae=["3DS_AUTHENTICATION","PROCESSOR_3DS"],xe=6e5,De=6e3,Le="#primer-overlay";function Oe(e){try{const t=e.split(".");if(3!==t.length)return null;const n=t[1].replace(/-/g,"+").replace(/_/g,"/"),r=n+"=".repeat((4-n.length%4)%4),o=JSON.parse(atob(r));return"string"==typeof o?.intent?o.intent:null}catch{return null}}function Ne(e){return Boolean(e?.stack?.includes("PROCESSOR_3DS")&&"RESUME_ERROR"===e.code&&e.message?.includes("fetch resume key"))}function Ue(){if("undefined"==typeof document)return;const e=document.querySelector('[data-testid="OverlayContent.closeButton"]');e?.click()}function qe(){if("undefined"==typeof document)return()=>{};const e=document.createElement("style");return e.textContent=`${Le}{opacity:0!important;pointer-events:none!important}`,document.head.appendChild(e),()=>e.remove()}function Fe(){"undefined"==typeof document||document.querySelector(Le)||console.warn(`[FunnelfoxSDK] Primer 3DS overlay ${Le} not found`)}function ze(e,t){return t instanceof i?t:new i(e,t)}function je(e){try{e()}catch{}}let He=null;function Ye(e){He=e}function Be(){return He?.baseUrl||M.BASE_URL}function Ve(e,t){const{orgId:n,apiConfig:r}=e||{},o=n||He?.orgId;if(!o)throw new Error(`orgId is required. Pass it to ${t}() or call configure() first.`);return{orgId:o,baseUrl:r?.baseUrl||He?.baseUrl||M.BASE_URL,region:r?.region||He?.region||M.REGION}}async function $e(e){try{const{...t}=e,n=new Q;await n.ensurePrimerLoaded();const r=Ve(e,"createCheckout"),o=new Re({...r,checkoutConfig:{...t}});return await o.initialize(),o}catch(t){throw me(e.orgId,{baseUrl:e.apiConfig?.baseUrl,message:t.message,code:t.code,req_id:t?.response?.req_id}),t}}async function Ge(e){const{priceId:t,externalId:n,email:r,clientMetadata:o,countryCode:i}=e,a=Ve(e,"createClientSession"),s=new K({baseUrl:a.baseUrl,orgId:a.orgId,timeout:M.REQUEST_TIMEOUT,retryAttempts:M.RETRY_ATTEMPTS}),d=await s.createClientSession({priceId:t,externalId:n,email:r,region:a.region,clientMetadata:o,countryCode:i});return s.processSessionResponse(d)}function Qe(e){const t={pp_ident:e.priceId,external_id:e.externalId,client_metadata:e.clientMetadata};return void 0!==e.initiationType&&(t.initiation_type=e.initiationType),void 0!==e.citCardNetworks&&(t.cit_card_networks=e.citCardNetworks),t}const We="one_click_in_progress",Ke="double_purchase",Ze="idempotency_key_in_progress",Je=[1e3,2e3,4e3],Xe=25e3,et=new Set;function tt(e,t){return`${e}\0${t}`}function nt(){const e="undefined"==typeof crypto?void 0:crypto;if("function"==typeof e?.randomUUID)return e.randomUUID();if("function"!=typeof e?.getRandomValues)return null;const t=e.getRandomValues(new Uint8Array(16));t[6]=15&t[6]|64,t[8]=63&t[8]|128;const n=Array.from(t,e=>e.toString(16).padStart(2,"0"));return[n.slice(0,4).join(""),n.slice(4,6).join(""),n.slice(6,8).join(""),n.slice(8,10).join(""),n.slice(10,16).join("")].join("-")}function rt(e){return e instanceof s||e instanceof o&&null!==e.statusCode&&(e.statusCode>=500||(e.statusCode>=200&&e.statusCode<300||400===e.statusCode&&e.errorCode===Ze))}function ot(e){return!e||"object"!=typeof e||!("status"in e)}async function it(e,t){if(!t.idempotency_key)return e.oneClickOnce(t);for(const n of Je){try{const n=await e.oneClickOnce(t,Xe);if(!ot(n))return n}catch(e){if(!rt(e))throw e}await b(n)}const n=await e.oneClickOnce(t,Xe);if(ot(n))throw new s("one_click returned an empty response");return n}function at(e){return{failedMessageForUser:e.failed_message_for_user??null,declineCode:e.decline_code??null,declineCodeSource:e.decline_code_source??null}}function st(e,t){const n=e?.error?.[0];return new o(n?.msg||t,null,{errorCode:n?.code,errorType:n?.type,response:e})}function dt(e){const t=e?.data;if("success"!==e?.status||!t)return Z(e).includes(Ke)?{kind:"result",result:{outcome:"already_purchased",orderId:null,threeDSChallenged:!1}}:{kind:"result",result:{outcome:"error",orderId:t?.order_id??null,threeDSChallenged:!1,error:st(e,"One-click purchase failed"),failedRequest:"one_click"}};const n=t.order_id??null;if(t.action_required_token)return{kind:"action",orderId:n,actionToken:t.action_required_token};switch(t.checkout_status){case"succeeded":return{kind:"result",result:{outcome:"succeeded",orderId:n,threeDSChallenged:!1}};case"failed":return{kind:"result",result:{outcome:"declined",orderId:n,threeDSChallenged:!1,...at(t)}};case"processing":return{kind:"result",result:{outcome:"processing",orderId:n,threeDSChallenged:!1}};case"cancelled":return{kind:"result",result:{outcome:"error",orderId:n,threeDSChallenged:!1,error:new o("Payment was cancelled",null,{response:e})}};default:return{kind:"result",result:{outcome:"error",orderId:n,threeDSChallenged:!1,error:new o(`Unhandled checkout status: ${t.checkout_status}`,null,{response:e})}}}}function lt(e,t,r,i=null){const a=e?.data;if("success"!==e?.status||!a)return{threeDS:"error",result:{outcome:"error",orderId:t,threeDSChallenged:r,error:st(e,"Resume payment failed"),failedRequest:"resume_payment"}};if(a.action_required_token)return{threeDS:"error",result:{outcome:"error",orderId:t,threeDSChallenged:r,error:new n("resume_payment returned another action token; chained 3DS is not supported","one_click_chained_action")}};switch(a.checkout_status){case"succeeded":return{threeDS:"passed",result:{outcome:"succeeded",orderId:t,threeDSChallenged:r}};case"processing":return{threeDS:"passed",result:{outcome:"processing",orderId:t,threeDSChallenged:r}};case"failed":{const e=r&&(null===i||i.includes(a.decline_code??""));return{threeDS:e?"failed":"passed",result:{outcome:e?"3ds_failed":"declined",orderId:t,threeDSChallenged:r,...at(a)}}}default:return{threeDS:"error",result:{outcome:"error",orderId:t,threeDSChallenged:r,error:new o("cancelled"===a.checkout_status?"Payment was cancelled":`Unhandled checkout status: ${a.checkout_status}`,null,{response:e})}}}}function ct(e,t,n){if("function"==typeof t)try{t(n)}catch(t){console.error(`[FunnelfoxSDK] ${e} hook threw`,t)}}async function ut(t){try{const n=new K({baseUrl:t.baseUrl,orgId:t.orgId}),r=await n.createSimpleClientSession({countryCode:t.countryCode}),o=r?.data?.client_token;if(!o)throw new Error("Error creating simple client session");return await new Promise((t,n)=>{const r=new Q;r.initializeHeadlessCheckout(o,{onTokenizeSuccess:()=>{},onResumeSuccess:()=>{},onAvailablePaymentMethodsLoad:e=>{t(e),r.destroy()},paypal:H[e.PaymentMethod.PAYPAL]}).catch(n)})}catch(e){throw me(t.orgId,{baseUrl:t.baseUrl,message:e.message,code:e.code,req_id:e?.response?.req_id}),e}}async function ht(t){const n=Ve(t,"getAvailableStripeWallet"),[r,{getAvailableWallet:o}]=await Promise.all([J.createSession({orgId:n.orgId,baseUrl:n.baseUrl,region:n.region,priceId:t.priceId,externalId:t.externalId,email:t.email,clientMetadata:t.clientMetadata,countryCode:t.countryCode,integration:"stripe"}),Promise.resolve().then(function(){return Lt})]);new K({orgId:n.orgId,baseUrl:n.baseUrl||M.BASE_URL}).processSessionResponse(r);const i=await o(r);return"APPLE_PAY"===i?e.PaymentMethod.APPLE_PAY:"GOOGLE_PAY"===i?e.PaymentMethod.GOOGLE_PAY:null}const pt=["APPLE_PAY","GOOGLE_PAY"],mt=9e5;function yt(e){const t=e.expires_at?function(e){const t=/([zZ]|[+-]\d{2}:?\d{2})$/.test(e);return Date.parse(t?e:`${e}Z`)}(e.expires_at):NaN;if(!(pt.includes(e.wallet)&&e.client_token&&e.session_id&&e.order_id&&Number.isFinite(t)))throw new o("Invalid one_click_wallet_session response",null,{response:e});return{wallet:e.wallet,clientToken:e.client_token,sessionId:e.session_id,orderId:e.order_id,amount:e.amount??null,currency:e.currency??null,expiresAt:t}}async function ft(e,t){const n=await e.oneClickWalletSession({pp_ident:t.priceId,external_id:t.externalId,client_metadata:t.clientMetadata||{}},15e3);if("success"!==n?.status||!n.data)throw new o("one_click_wallet_session failed",null,{response:n});return null===n.data.wallet?null:yt(n.data)}function Ct(e,t){const n=t.buttonType||"plain",r=t.buttonColor||"black";return"APPLE_PAY"===e?{applePay:{buttonType:"buy"===n?"buy":"plain",buttonStyle:r}}:{googlePay:{buttonType:"continue"===n?"plain":n,buttonColor:"black"===r?"black":"white",buttonSizeMode:"fill"}}}function gt(e,t){return t instanceof n?t:new i(e,t)}function wt(e){try{e()}catch{}}function St(e,t){return e instanceof o&&(e.errorCode===t||Z(e.response).includes(t))}class Et{constructor(e,t,n){this.container=e,this.options=t,this.rendered=null,this.generation=0,this.destroyed=!1,this.finished=!1,this.disabledByCaller=!1,this.refreshing=null,this.refreshTimer=null,this.attemptRunning=!1,this.tokenizeStarted=!1,this.charging=!1,this.threeDS=null,this.onVisibilityChange=()=>{"visible"===document.visibilityState&&this.expiresSoon()&&this.refresh()},this.session=n,this.apiClient=Et.apiClientFor(t),this.inFlightKey=tt(t.orgId,t.externalId)}static apiClientFor(e){return new K({baseUrl:e.baseUrl||Be(),orgId:e.orgId,timeout:M.REQUEST_TIMEOUT,retryAttempts:M.RETRY_ATTEMPTS})}async render(){const e=++this.generation,t=this.session,n=this.options.style||{};await(new Q).ensurePrimerLoaded();let r=()=>{},o=null;const a=new Promise((e,t)=>{r=e,o=setTimeout(()=>t(new i("Primer did not report the available payment methods")),1e4)}).finally(()=>clearTimeout(o)),s=await window.Primer.createHeadless(t.clientToken,{paymentHandling:U,apiVersion:q,...Ct(t.wallet,n),onAvailablePaymentMethodsLoad:e=>r(e.map(e=>e.type)),onTokenizeShouldStart:()=>this.onTap(e),onTokenizeStart:()=>{e===this.generation&&(this.tokenizeStarted=!0)},onPaymentMethodAction:t=>{"PAYMENT_METHOD_UNSELECTED"===t&&this.onSheetClosed(e)},onTokenizeSuccess:(t,n)=>this.onTokenized(e,t,n),onTokenizeError:t=>this.onPrimerFailure(e,"Wallet tokenization failed",t),onResumeSuccess:(t,n)=>this.onResumed(e,t,n),onResumeError:t=>this.onResumeError(e,t),onCheckoutFail:t=>this.onPrimerFailure(e,"Primer checkout failed",t)});await s.start();if(!(await a).includes(t.wallet))return!1;const d=await s.createPaymentMethodManager(t.wallet);if(!d||"function"!=typeof d.createButton)throw new i(`No ${t.wallet} button manager`);const l=this.mountButton(e,d.createButton(),t.wallet,n);try{await l.button.render(l.wrapper,{}),"APPLE_PAY"===t.wallet&&null===l.nativeOverlay&&(l.nativeOverlay=await this.overlayAppleType(l,n))}catch(e){throw this.removeButton(l),e}if(this.destroyed||e!==this.generation)return this.removeButton(l),!0;const c=this.rendered;return this.rendered=l,c&&this.removeButton(c),this.applyDisabled(),this.scheduleRefresh(),!0}mountButton(e,t,n,r){const o=document.createElement("div");o.className=E("funnelfox-wallet-upsell");const i=r.height??54,a=r.borderRadius??28,s=document.createElement("style");return s.textContent=[`.${o.className}{width:100%!important}`,`.${o.className} button{height:${i}px!important;border-radius:${a}px!important}`,"APPLE_PAY"===n&&"continue"===r.buttonType?`.${o.className} > button{opacity:0!important}`:""].join("\n"),document.head.appendChild(s),this.container.appendChild(o),{generation:e,button:t,wrapper:o,styleEl:s,nativeOverlay:null}}async overlayAppleType(e,t){if("continue"!==t.buttonType)return null;const n=await G(e.wrapper,{buttonType:t.buttonType,buttonStyle:t.buttonColor||"black",borderRadius:t.borderRadius??28});return n||(e.styleEl.textContent=e.styleEl.textContent.replace(`.${e.wrapper.className} > button{opacity:0!important}`,"")),n}removeButton(e){wt(()=>e.button.clean()),e.nativeOverlay?.remove(),e.wrapper.remove(),e.styleEl.remove()}applyDisabled(){const e=this.rendered;if(!e)return;const t=this.finished||this.disabledByCaller;Promise.resolve(e.button.setDisabled(t)).catch(()=>{}),e.nativeOverlay&&(e.nativeOverlay.style.pointerEvents=t?"none":"",e.nativeOverlay.style.opacity=t?"0.5":"")}setDisabled(e){this.disabledByCaller=e,this.applyDisabled()}destroy(){this.destroyed||(this.destroyed=!0,this.generation+=1,this.attemptRunning&&!this.charging&&(this.attemptRunning=!1,et.delete(this.inFlightKey)),this.clearRefresh(),"undefined"!=typeof document&&document.removeEventListener("visibilitychange",this.onVisibilityChange),this.rendered&&(this.removeButton(this.rendered),this.rendered=null))}watchVisibility(){"undefined"!=typeof document&&document.addEventListener("visibilitychange",this.onVisibilityChange)}expiresSoon(e=9e5){return this.session.expiresAt-Date.now()<e}clearRefresh(){this.refreshTimer&&(clearTimeout(this.refreshTimer),this.refreshTimer=null)}scheduleRefresh(){if(this.clearRefresh(),this.destroyed||this.finished)return;const e=Math.max(this.session.expiresAt-mt-Date.now(),6e4);this.refreshTimer=setTimeout(()=>{this.refreshTimer=null,this.refresh()},e)}refresh(){this.refreshing||this.destroyed||this.finished||this.attemptRunning||(this.refreshing=this.replaceSession().finally(()=>{this.refreshing=null}))}async replaceSession(){let e=null;try{const t=await ft(this.apiClient,this.options);if(this.destroyed||this.finished)return;t&&t.wallet===this.session.wallet?(this.session=t,await this.render()||(e=new n("This device can no longer show the wallet","wallet_upsell_unavailable"))):e=new n("The wallet upsell is no longer available for this customer","wallet_upsell_unavailable")}catch(t){e=gt("Failed to prepare the wallet upsell again",t)}!e||this.destroyed||this.finished||this.attemptRunning||this.report({outcome:"error",orderId:null,threeDSChallenged:!1,error:e})}onTap(e){return!(e!==this.generation||this.destroyed||this.finished||this.disabledByCaller||this.refreshing||this.attemptRunning||et.has(this.inFlightKey))&&(this.expiresSoon(6e4)?(this.refresh(),!1):(this.attemptRunning=!0,this.tokenizeStarted=!1,et.add(this.inFlightKey),ct("onStart",this.options.onStart,void 0),!0))}onSheetClosed(e){e===this.generation&&this.attemptRunning&&!this.tokenizeStarted&&this.finish({outcome:"cancelled",orderId:null,threeDSChallenged:!1})}onPrimerFailure(e,t,n){if(e===this.generation&&this.attemptRunning)return this.threeDS?(this.endThreeDS("failed"),void this.finish({outcome:"3ds_failed",orderId:this.session.orderId,threeDSChallenged:this.threeDSChallenged(),error:gt("3DS authentication failed",n)})):void this.finish({outcome:"error",orderId:null,threeDSChallenged:!1,error:gt(t,n)})}onTokenized(e,t,n){e===this.generation&&this.attemptRunning&&!this.threeDS?(this.tokenizeStarted=!0,this.charging=!0,this.charge(t.token,n,!1).catch(e=>{wt(()=>n.handleFailure()),this.finish({outcome:"error",orderId:this.session.orderId,threeDSChallenged:!1,error:gt("Wallet upsell charge failed",e)})})):wt(()=>n.handleFailure())}async charge(e,t,n){const r=this.session,o={pp_ident:this.options.priceId,external_id:this.options.externalId,client_metadata:this.options.clientMetadata||{},payment_method_token:e,session_id:r.sessionId},i=nt();let a;i&&(o.idempotency_key=i);try{a=await it(this.apiClient,o)}catch(r){return!n&&St(r,"wallet_session_invalid")&&await this.sameAmountSession()?this.charge(e,t,!0):(wt(()=>t.handleFailure()),void this.finish(this.chargeFailure(r,Boolean(i))))}const s=dt(a);if("result"===s.kind){const e=s.result;return"succeeded"===e.outcome||"processing"===e.outcome?wt(()=>t.handleSuccess()):wt(()=>t.handleFailure(e.failedMessageForUser||void 0)),void this.finish(e)}this.startThreeDS(s.orderId||r.orderId,s.actionToken,t)}async sameAmountSession(){try{const e=await ft(this.apiClient,this.options);return!(!e||e.wallet!==this.session.wallet||e.amount!==this.session.amount||e.currency!==this.session.currency)&&(this.session=e,!0)}catch{return!1}}chargeFailure(e,t){return St(e,Ke)?{outcome:"already_purchased",orderId:null,threeDSChallenged:!1}:t&&rt(e)?{outcome:"processing",orderId:this.session.orderId,threeDSChallenged:!1,error:e,failedRequest:"one_click"}:{outcome:"error",orderId:null,threeDSChallenged:!1,error:e instanceof Error?e:gt("one_click failed",e),failedRequest:"one_click"}}threeDSChallenged(){return Boolean(this.threeDS?.challenged)}startThreeDS(e,t,n){const r=Oe(t);if(!r||!Ae.includes(r))return wt(()=>n.handleFailure()),void this.finish({outcome:"error",orderId:e,threeDSChallenged:!1,error:new i("Unsupported one-click action: the action token is not a Primer 3DS client token",{intent:r})});const o=xe,a={orderId:e,challenged:!1,revealTimer:null,timer:null,showOverlay:qe()};this.threeDS=a;const s=()=>{a.timer=null,a.challenged&&(this.endThreeDS("abandoned"),this.finish({outcome:"3ds_abandoned",orderId:e,threeDSChallenged:!0}),Ue())};a.timer=setTimeout(s,o),a.revealTimer=setTimeout(()=>{a.revealTimer=null,a.challenged=!0,a.showOverlay(),Fe(),ct("onThreeDSStart",this.options.onThreeDSStart,{orderId:e}),a.timer&&clearTimeout(a.timer),a.timer=setTimeout(s,o)},De),n.continueWithNewClientToken(t)}endThreeDS(e){const t=this.threeDS;t&&(t.timer&&(clearTimeout(t.timer),t.timer=null),t.revealTimer&&(clearTimeout(t.revealTimer),t.revealTimer=null),t.showOverlay(),t.challenged&&ct("onThreeDSEnd",this.options.onThreeDSEnd,{result:e}))}async onResumed(e,t,n){const r=this.threeDS;if(e!==this.generation||!this.attemptRunning||!r)return void wt(()=>n.handleFailure());let o;r.timer&&(clearTimeout(r.timer),r.timer=null),r.revealTimer&&(clearTimeout(r.revealTimer),r.revealTimer=null);try{o=await this.apiClient.resumePaymentOnce({orderId:r.orderId,resumeToken:t.resumeToken})}catch(e){return wt(()=>n.handleFailure()),this.endThreeDS("error"),void this.finish({outcome:"error",orderId:r.orderId,threeDSChallenged:r.challenged,error:e,failedRequest:"resume_payment"})}const i=lt(o,r.orderId,r.challenged);"succeeded"===i.result.outcome||"processing"===i.result.outcome?wt(()=>n.handleSuccess()):wt(()=>n.handleFailure(i.result.failedMessageForUser||void 0)),this.endThreeDS(i.threeDS),this.finish(i.result)}onResumeError(e,t){const n=this.threeDS;if(e===this.generation&&this.attemptRunning&&n){if(Ne(t))return this.endThreeDS("abandoned"),void this.finish({outcome:"3ds_abandoned",orderId:n.orderId,threeDSChallenged:n.challenged});this.endThreeDS("failed"),this.finish({outcome:"3ds_failed",orderId:n.orderId,threeDSChallenged:n.challenged,error:gt("3DS authentication failed",t)})}}finish(e){this.attemptRunning&&(this.attemptRunning=!1,this.tokenizeStarted=!1,this.charging=!1,this.threeDS=null,et.delete(this.inFlightKey),this.report(e))}report(e){if("cancelled"!==e.outcome?(this.finished=!0,this.clearRefresh(),this.applyDisabled()):this.expiresSoon()&&this.refresh(),"error"===e.outcome&&e.error){const t=e.error;me(this.options.orgId,{baseUrl:this.options.baseUrl||Be(),message:t.message,code:t.code,req_id:t.response?.req_id})}this.destroyed||ct("onResult",this.options.onResult,e)}}async function bt(e,t){let n;!function(e,t){if("undefined"==typeof HTMLElement||!(e instanceof HTMLElement))throw new r("container","must be an HTMLElement",e);for(const e of["orgId","priceId","externalId"])if(!t?.[e])throw new r(e,"is required",t?.[e]);if("function"!=typeof t.onResult)throw new r("onResult","must be a function",t.onResult)}(e,t);try{n=await ft(Et.apiClientFor(t),t)}catch(e){return{mounted:!1,reason:"error",error:e instanceof Error?e:gt("one_click_wallet_session failed",e)}}if(!n)return{mounted:!1,reason:"not_wallet"};const o=new Et(e,t,n);try{if(!await o.render())return o.destroy(),{mounted:!1,reason:"wallet_unavailable",wallet:n.wallet}}catch(e){return o.destroy(),{mounted:!1,reason:"error",error:gt("Failed to mount the wallet button",e)}}return o.watchVisibility(),{mounted:!0,wallet:n.wallet,setDisabled:e=>o.setDisabled(e),destroy:()=>o.destroy()}}const vt={configure:Ye,createCheckout:$e,createClientSession:Ge,initMethod:async function(t,n,r){try{const o=new Re({orgId:r.orgId,baseUrl:r.baseUrl,checkoutConfig:{priceId:r.priceId,customer:{externalId:r.externalId,email:r.email},container:"",clientMetadata:r.meta,card:r.card,style:r.style,applePay:{...H[e.PaymentMethod.APPLE_PAY],...r.applePay||{}},paypal:{...H[e.PaymentMethod.PAYPAL],...r.paypal||{}},googlePay:{...H[e.PaymentMethod.GOOGLE_PAY],...r.googlePay||{}},onTaxChange:r.onTaxChange,onTaxError:r.onTaxError,onTaxPending:r.onTaxPending}});return await o.initMethod(t,n,{onRenderSuccess:r.onRenderSuccess,onRenderError:r.onRenderError,onLoaderChange:r.onLoaderChange,onPaymentSuccess:r.onPaymentSuccess,onPaymentFail:r.onPaymentFail,onPaymentCancel:r.onPaymentCancel,onErrorMessageChange:r.onErrorMessageChange,onPaymentStarted:r.onPaymentStarted,onMethodsAvailable:r.onMethodsAvailable})}catch(e){throw me(r.orgId,{baseUrl:r.baseUrl,message:e.message,code:e.code,req_id:e?.response?.req_id}),e}},silentPurchase:function(e){return!0===e?.handle3DS?async function(e){for(const t of["orgId","baseUrl","priceId","externalId"])if(!e?.[t])throw new r(t,"is required",e?.[t]);const{orgId:t,baseUrl:a,externalId:d}=e,l=tt(t,d);if(et.has(l))return{outcome:"error",orderId:null,threeDSChallenged:!1,error:new n("A one-click purchase is already in progress for this customer",We)};et.add(l);try{const r=await async function(e){const t=new K({baseUrl:e.baseUrl,orgId:e.orgId,timeout:M.REQUEST_TIMEOUT,retryAttempts:M.RETRY_ATTEMPTS}),r=Qe(e),a=nt();a&&(r.idempotency_key=a);let d;try{d=await it(t,r)}catch(e){return e instanceof o&&Z(e.response).includes(Ke)?{outcome:"already_purchased",orderId:null,threeDSChallenged:!1}:a&&rt(e)?{outcome:"processing",orderId:null,threeDSChallenged:!1,error:e,failedRequest:"one_click"}:{outcome:"error",orderId:null,threeDSChallenged:!1,error:e,failedRequest:"one_click"}}const l=dt(d);if("result"===l.kind)return l.result;const{orderId:c,actionToken:u}=l;let h=!1,p=!1;const m=t=>{h&&!p&&(p=!0,ct("onThreeDSEnd",e.onThreeDSEnd,{result:t}))};try{const n=await async function(e){const{apiClient:t,region:n,priceId:r,externalId:o,orderId:a,actionToken:d}=e,l=Oe(d);if(!l||!Ae.includes(l))return{kind:"error",error:new i("Unsupported one-click action: the action token is not a Primer 3DS client token",{intent:l})};const c=Number.isFinite(e.timeoutMs)&&e.timeoutMs>0?e.timeoutMs:xe;return new Promise(l=>{let u=!1,h=!1,p=!1,m=null,y=()=>{},f=!1,C=null,g=null;const w=e=>{u||(u=!0,C&&(clearTimeout(C),C=null),m&&(clearTimeout(m),m=null),y(),g=null,l(e))},S=()=>{if(C=null,p)return w({kind:"abandoned"}),void Ue();f?w({kind:"error",error:new s("create_client_session did not respond within threeDSTimeoutMs"),failedRequest:"create_client_session"}):h||w({kind:"error",error:new i("Timed out before the 3DS challenge was shown (threeDSTimeoutMs)")})};C=setTimeout(S,c);const E=(t,n)=>{u||h?je(()=>n.handleFailure()):(h=!0,y=qe(),m=setTimeout(()=>{m=null,p=!0,y(),Fe(),je(e.onChallengeShown),C&&clearTimeout(C),C=setTimeout(S,c)},e.revealDelayMs),n.continueWithNewClientToken(d))},b=async(e,n)=>{if(u)return void je(()=>n.handleFailure());let r;C&&(clearTimeout(C),C=null),m&&(clearTimeout(m),m=null);try{r=await t.resumePaymentOnce({orderId:a,resumeToken:e.resumeToken})}catch(e){return je(()=>n.handleFailure()),void w({kind:"error",error:e,failedRequest:"resume_payment"})}const o=r?.data;"success"!==r?.status||"succeeded"!==o?.checkout_status||o.action_required_token?je(()=>n.handleFailure(o?.failed_message_for_user||void 0)):je(()=>n.handleSuccess()),w({kind:"resumed",response:r})},v=e=>{Ne(e)?w({kind:"abandoned"}):w({kind:"failed",error:ze("3DS authentication failed",e)})},_=e=>{w(h?{kind:"failed",error:ze("3DS authentication failed",e)}:{kind:"error",error:ze("Primer checkout failed before the 3DS challenge",e)})},P=e=>{w({kind:"error",error:ze("Failed to tokenize the saved payment method",e)})};(async()=>{if(await(new Q).ensurePrimerLoaded(),u)return;let e;f=!0;try{const i=await t.createClientSession({priceId:r,externalId:o,region:n,clientMetadata:{}});e=t.processSessionResponse(i).clientToken,f=!1}catch(e){return f=!1,void w({kind:"error",error:e,failedRequest:"create_client_session"})}if(u)return;const a=await window.Primer.createHeadless(e,{paymentHandling:U,apiVersion:q,onAvailablePaymentMethodsLoad:()=>{},onTokenizeSuccess:E,onTokenizeError:P,onResumeSuccess:b,onResumeError:v,onCheckoutFail:_});if(g=await a,await g.start(),u)return;const s=g.createVaultManager(),d=(l=await s.fetchVaultedPaymentMethods())&&0!==l.length?l.find(e=>"PAYMENT_CARD"===e.paymentInstrumentType)||l[0]:null;var l;d?u||await s.startPaymentFlow(d.id):w({kind:"error",error:new i("No saved payment method found for the one-click 3DS challenge")})})().catch(e=>{w({kind:"error",error:ze("Failed to start the one-click 3DS challenge",e)})})})}({apiClient:t,region:He?.region||M.REGION,priceId:e.priceId,externalId:e.externalId,orderId:c,actionToken:u,timeoutMs:e.threeDSTimeoutMs??xe,revealDelayMs:De,onChallengeShown:()=>{h=!0,ct("onThreeDSStart",e.onThreeDSStart,{orderId:c})}}),r=function(e,t,n){switch(e.kind){case"resumed":return lt(e.response,t,n);case"failed":return{threeDS:"failed",result:{outcome:"3ds_failed",orderId:t,threeDSChallenged:n,error:e.error}};case"abandoned":return{threeDS:"abandoned",result:{outcome:"3ds_abandoned",orderId:t,threeDSChallenged:n}};default:{const r={outcome:"error",orderId:t,threeDSChallenged:n,error:e.error};return e.failedRequest&&(r.failedRequest=e.failedRequest),{threeDS:"error",result:r}}}}(n,c,h);return m(r.threeDS),r.result}catch(e){return m("error"),{outcome:"error",orderId:c,threeDSChallenged:h,error:e instanceof Error?e:new n("One-click 3DS step failed",void 0,e)}}}(e);if("error"===r.outcome&&r.error){const e=r.error;me(t,{baseUrl:a,message:e.message,code:e.code,req_id:e.response?.req_id})}return r}finally{et.delete(l)}}(e):async function(e){const{orgId:t,baseUrl:n}=e,r=new K({baseUrl:n,orgId:t,timeout:M.REQUEST_TIMEOUT,retryAttempts:M.RETRY_ATTEMPTS});"cit"===e.initiationType&&console.warn('[FunnelfoxSDK] silentPurchase: initiationType "cit" can trigger a 3DS challenge, which only silentPurchase({ handle3DS: true }) handles.');try{const t=await r.oneClick(Qe(e));if("success"!==t.status&&t.error.some(({code:e})=>"double_purchase"===e))throw new o("This product was already purchased");return"success"===t.status}catch(e){throw me(t,{baseUrl:n,message:e.message,code:e.code,req_id:e?.response?.req_id}),e}}(e)},mountWalletUpsell:bt,getAvailablePaymentMethods:ut,stripe:{createCardForm:async function(e,t){const n=Ve(t,"createStripeCardForm"),r={orgId:n.orgId,baseUrl:n.baseUrl,region:n.region,priceId:t.priceId,externalId:t.externalId,email:t.email,clientMetadata:t.clientMetadata,countryCode:t.countryCode,integration:"stripe"},[o,{mountStripeCardForm:i}]=await Promise.all([J.createSession(r),Promise.resolve().then(function(){return At})]),a=new K({orgId:n.orgId,baseUrl:n.baseUrl||M.BASE_URL});return a.processSessionResponse(o),i(e,o,{...t,apiClient:a,invalidateSession:()=>J.invalidate(r)})},purchaseWallet:async function(e){const t=Ve(e,"purchaseStripeWallet"),n={orgId:t.orgId,baseUrl:t.baseUrl,region:t.region,priceId:e.priceId,externalId:e.externalId,email:e.email,clientMetadata:e.clientMetadata,countryCode:e.countryCode,integration:"stripe"},[r,{purchaseWallet:o}]=await Promise.all([J.createSession(n),Promise.resolve().then(function(){return Lt})]),i=new K({orgId:t.orgId,baseUrl:t.baseUrl||M.BASE_URL});return i.processSessionResponse(r),o(r,{...e,apiClient:i,invalidateSession:()=>J.invalidate(n)})},getAvailableWallet:ht,getAvailablePaymentMethods:async function(t){const n=await ht(t);return n?[e.PaymentMethod.PAYMENT_CARD,n]:[e.PaymentMethod.PAYMENT_CARD]}}};"undefined"!=typeof window&&(window.Billing=vt),console.debug("Billing SDK inited");"undefined"!=typeof document&&(document.head.appendChild(document.createElement("style")).textContent="/* Main container */\n.ff-skin-default {\n display: flex;\n flex-direction: column;\n text-align: left;\n gap: 8px;\n width: 100%;\n max-width: 400px;\n margin: 0 auto;\n color: #000000;\n}\n\n/* Payment method cards */\n.ff-payment-method-card {\n display: none;\n border: 1px solid #e0e0e0;\n border-radius: 8px;\n background-color: #ffffff;\n padding: 20px;\n transition: border-color 0.2s ease;\n height: auto;\n box-shadow: 0px 0px 10px 0px #eee;\n}\n\n.ff-payment-method-card.visible {\n display: block;\n}\n\n.payment-errors-container {\n background-color: #d1000033;\n color: #d10000;\n font-size: 14px;\n padding: 16px 12px;\n border-radius: 8px;\n}\n.payment-errors-container:empty {\n display: none;\n}\n\n/* Label wrapper */\n.ff-payment-method-label {\n display: flex;\n align-items: flex-start;\n gap: 16px;\n cursor: pointer;\n width: 100%;\n}\n\n.ff-google-pay-header {\n align-items: center;\n}\n\n/* Custom radio button styling */\n.ff-payment-method-radio {\n appearance: none;\n -webkit-appearance: none;\n -moz-appearance: none;\n width: 24px;\n height: 24px;\n min-width: 24px;\n min-height: 24px;\n border: 1px solid #9e9e9e;\n border-radius: 50%;\n background-color: #ffffff;\n cursor: pointer;\n position: relative;\n margin: 0;\n flex-shrink: 0;\n transition: border-color 0.2s ease;\n}\n\n.ff-card-form-submit-button {\n display: block;\n cursor: pointer;\n width: 100%;\n padding: 16px 0;\n border-radius: 16px;\n background-color: #000000;\n color: #ffffff;\n border: none;\n font-size: 16px;\n margin: 12px 0 16px;\n}\n\n.ff-payment-method-radio:checked {\n border-color: #e32f41;\n background-color: #ffffff;\n}\n\n.ff-payment-method-radio:checked::after {\n content: '';\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 16px;\n height: 16px;\n border-radius: 50%;\n background-color: #e32f41;\n}\n\n/* Payment method content */\n.ff-payment-method-content {\n flex: 1;\n display: flex;\n flex-direction: column;\n gap: 16px;\n max-height: 0;\n height: 0;\n overflow: hidden;\n opacity: 0;\n transition:\n opacity 0.3s ease,\n margin-top 0.3s ease;\n margin-top: 0;\n}\n\n.ff-payment-method-card.expanded .ff-payment-method-content {\n max-height: 2000px;\n height: auto;\n opacity: 1;\n margin-top: 16px;\n}\n.ff-payment-method-card.expanded .ff-payment-method-label {\n margin-bottom: 16px;\n}\n\n/* Payment method header */\n.ff-payment-method-header {\n display: flex;\n align-items: center;\n}\n\n/* Google Pay Logo */\n.ff-google-pay-logo {\n display: flex;\n align-items: center;\n gap: 4px;\n font-weight: 500;\n font-size: 18px;\n}\n.ff-google-pay-logo img {\n height: 38px;\n}\n\n/* Payment features list */\n.ff-payment-features {\n list-style: none;\n padding: 0;\n margin: 0;\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n.ff-payment-feature {\n display: flex;\n align-items: baseline;\n text-align: left;\n gap: 8px;\n}\n\n.ff-checkmark-icon {\n width: 20px;\n height: 20px;\n min-width: 20px;\n color: #e32f41;\n flex-shrink: 0;\n margin-top: 2px;\n}\n\n.ff-payment-feature span {\n color: #333333;\n font-size: 14px;\n line-height: 1.5;\n}\n\n/* Google Pay button container */\n.ff-google-pay-button-container {\n display: flex;\n justify-content: center;\n}\n\n/* Security message */\n.ff-security-message {\n text-align: center;\n color: #999999;\n font-size: 14px;\n padding: 0;\n margin: 0\n}\n\n/* Card logos container */\n.ff-card-logos {\n display: flex;\n align-items: center;\n gap: 12px;\n flex-wrap: wrap;\n}\n\n/* Card form container */\n.ff-card-form-container {\n position: relative;\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n.loader-container {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n background-color: rgba(255, 255, 255);\n z-index: 2;\n}\n\n.payment-button-loader {\n position: relative;\n height: 50px;\n}\n\n.loader {\n width: 24px;\n height: 24px;\n border: 4px solid #e32f41;\n border-top: 4px solid transparent;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n}\n\n@keyframes spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n\n/* Responsive adjustments */\n@media (max-width: 768px) {\n .ff-payment-method-card {\n padding: 16px;\n }\n\n .ff-payment-method-label {\n gap: 12px;\n }\n\n .ff-card-logos {\n gap: 8px;\n }\n}\n\n.ff-payment-container {\n position: relative;\n}\n\n.success {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: 16px;\n}\n");"undefined"!=typeof document&&(document.head.appendChild(document.createElement("style")).textContent="\n\n.ff-card-form-label {\n display: block;\n font-size: 16px;\n margin-bottom: 5px;\n }\n \n .card-form-row {\n display: grid;\n grid-template-columns: repeat(2, minmax(0, 1fr));\n grid-template-rows: repeat(3, auto);\n grid-auto-flow: column;\n column-gap: 10px;\n }\n\n /* Label, input and error of both columns share grid rows, so a label that wraps in one column\n moves both inputs down together, and an error under one input does not move the other. */\n .card-form-row > div {\n display: contents;\n }\n \n .ff-card-form-text-input {\n margin: 0 0 3px;\n padding-left: 10px;\n padding-right: 10px;\n box-sizing: border-box;\n height: 36px;\n width: 100%;\n font-size: 1rem;\n background-color: transparent;\n border: 1px solid rgb(0 0 0 / 10%);\n border-radius: 6px;\n transition: all 0.3s ease;\n box-shadow: none;\n outline: none;\n }\n .ff-card-form-text-input.error {\n border-color: #e32f41;\n }\n\n.ff-select-wrap {\n position: relative;\n}\n\n.ff-card-form-select {\n padding-right: 34px;\n appearance: none;\n -webkit-appearance: none;\n -moz-appearance: none;\n background-image: none;\n}\n\n.ff-card-form-select::-ms-expand {\n display: none;\n}\n\n.ff-card-form-select:disabled {\n color: #6b7280;\n cursor: not-allowed;\n}\n\n.ff-select-arrow {\n position: absolute;\n top: 50%;\n right: 12px;\n width: 8px;\n height: 8px;\n border-right: 1.5px solid #6b7280;\n border-bottom: 1.5px solid #6b7280;\n transform: translateY(-65%) rotate(45deg);\n pointer-events: none;\n}\n\n.ff-select-wrap:focus-within .ff-select-arrow {\n border-right-color: #111827;\n border-bottom-color: #111827;\n}\n \n .errorContainer:not(:empty) {\n color: #df1b41;\n font-size: 15px;\n line-height: 1.15;\n margin: 4px 0 10px;\n }\n\n #cvvInput {\n position: relative;\n }\n\n #cvvInput > svg {\n z-index: 1;\n position: absolute;\n top: 5px;\n right: 5px;\n width: 26px;\n height: 26px;\n }\n");class _t{constructor(e,t,n){if(this.onInputError=e=>{const{name:t,error:n}=e,r=this.getCardInputElements(),o={cardNumber:r.cardNumber.parentElement,expiryDate:r.expiryDate.parentElement,cvv:r.cvv.parentElement,cardholderName:r.cardholderName?.parentElement,emailAddress:r.emailAddress?.parentElement,postalCode:r.postalCode?.parentElement},i=o[t]?.querySelector(".errorContainer");if(i&&(i.textContent=n||""),"cardholderName"===t||"emailAddress"===t||"postalCode"===t){const e="cardholderName"===t?r.cardholderName:"emailAddress"===t?r.emailAddress:r.postalCode;n?e?.classList?.add("error"):e?.classList?.remove("error")}},this.onMethodRender=()=>{this.containerEl.style.display="block"},this.onDestroy=()=>{this.containerEl.innerHTML&&(this.containerEl.innerHTML="")},!e)throw new Error("Container element not found");this.containerEl=e,this.checkoutConfig=t,this.cardSessionFieldConfig=n,this.containerEl.style.display="none"}normalizeCountryCode(e){const t=e?.trim().toUpperCase();return t||void 0}getSelectedCountryCode(){const e=this.containerEl.querySelector("#countrySelectorInput");return this.normalizeCountryCode(e?.value)||this.normalizeCountryCode(this.cardSessionFieldConfig?.detectedCountryCode)}getCountryFieldOverride(e=this.getSelectedCountryCode()){if(e)return this.cardSessionFieldConfig?.countryFieldOverrides?.[e]}isCountrySelectorVisible(){return!!this.cardSessionFieldConfig?.showCountrySelector}isCardholderNameVisible(){return!!this.checkoutConfig.card?.cardholderName?.required}isPostalCodeVisible(e=this.getSelectedCountryCode()){const t=!!this.cardSessionFieldConfig?.showPostalCode,n=this.getCountryFieldOverride(e)?.show_postal_code;return null==n?t:n}setFieldVisibility(e,t){const n=this.containerEl.querySelector(`#${e}`);n?.parentElement&&(n.parentElement.style.display=t?"":"none")}setContainerVisibility(e,t){const n=this.containerEl.querySelector(`#${e}`);n&&(n.style.display=t?"":"none")}populateCountrySelector(e){const t=this.cardSessionFieldConfig?.validCountries||[],n=this.getSelectedCountryCode();if(e.innerHTML="",e.disabled=!1,!t.length){const t=document.createElement("option");return t.value=n||"",t.textContent=n?`Detected country: ${n}`:"Country unavailable",e.appendChild(t),void(e.disabled=!0)}const r=document.createElement("option");r.value="",r.textContent="Select country",e.appendChild(r),t.forEach(t=>{const n=document.createElement("option");n.value=t.code,n.textContent=t.name,e.appendChild(n)}),n&&(e.value=n)}updateDynamicFieldVisibility(e=this.getSelectedCountryCode()){this.setFieldVisibility("cardHolderInput",this.isCardholderNameVisible()),this.setFieldVisibility("postalCodeInput",this.isPostalCodeVisible(e));const t=this.containerEl.querySelector("#postalCodeInput");!this.isPostalCodeVisible(e)&&t&&(t.value="")}wireCardInputs(){const e=this.containerEl.querySelector("#cardNumberInput"),t=this.containerEl.querySelector("#expiryInput"),n=this.containerEl.querySelector("#cvvInput"),r=this.containerEl.querySelector("#cardHolderInput"),o=!!this.checkoutConfig?.card?.emailAddress?.visible;let i;o?(i=this.containerEl.querySelector("#emailAddressInput"),i&&(i.value=this.checkoutConfig.customer.email||"")):this.containerEl.querySelector("#emailAddressInput").parentElement.style.display="none";const a=this.containerEl.querySelector("#countrySelectorInput"),s=this.containerEl.querySelector("#postalCodeInput");if(a&&(this.populateCountrySelector(a),a.addEventListener("change",()=>{this.updateDynamicFieldVisibility(this.normalizeCountryCode(a.value))})),this.setContainerVisibility("countrySelectorField",this.isCountrySelectorVisible()),this.updateDynamicFieldVisibility(),!e||!t||!n||!r||o&&!i||!a||!s)throw new Error("One or more card input elements are missing in the default skin");this.cardInputElements={cardNumber:e,expiryDate:t,cvv:n,cardholderName:r,emailAddress:i,countrySelector:a,postalCode:s}}async init(){this.containerEl.insertAdjacentHTML("afterbegin",'<div>\n <label class="ff-card-form-label" for="cardNumberInput">Card number</label>\n <div id="cardNumberInput"></div>\n <div class="errorContainer"></div>\n</div>\n<div class="card-form-row">\n <div>\n <label class="ff-card-form-label" for="expiryInput">Expiration date</label>\n <div id="expiryInput"></div>\n <div class="errorContainer"></div>\n </div>\n <div>\n <label class="ff-card-form-label" for="cvvInput">Security code</label>\n <div id="cvvInput">\n <svg width="200" height="200" viewBox="0 0 200 200" fill="none" xmlns="http://www.w3.org/2000/svg">\n <rect width="200" height="200" fill="transparent"/>\n <g clip-path="url(#clip0_0_1)">\n <path d="M157.555 23C168.279 23.0002 177 31.7394 177 42.4854V80.5889C171.946 72.0151 164.749 64.8558 156.146 59.8457H166.394V42.4854C166.393 37.6004 162.43 33.6291 157.555 33.6289H27.4453C22.5704 33.6291 18.6066 37.6004 18.6064 42.4854V59.8457H97.8535C88.9153 65.0512 81.4954 72.5771 76.4189 81.5986H18.6064V127.515C18.6066 132.4 22.5704 136.371 27.4453 136.371H75.3281C77.2742 140.177 79.6285 143.739 82.333 147H27.4453C16.7215 147 8.00019 138.261 8 127.515V42.4854C8.0002 31.7394 16.7215 23.0002 27.4453 23H157.555Z" fill="#93939A"/>\n <mask id="path-2-outside-1_0_1" maskUnits="userSpaceOnUse" x="68.5012" y="52.0311" width="135" height="135" fill="black">\n <rect fill="white" x="68.5012" y="52.0311" width="135" height="135"/>\n <path d="M190.242 160.457L170.136 140.351C166.533 145.552 162.023 150.063 156.821 153.666L176.927 173.772C178.693 175.538 181.088 176.53 183.585 176.53C186.082 176.53 188.477 175.538 190.242 173.772C192.008 172.007 193 169.612 193 167.115C193 164.618 192.008 162.223 190.242 160.457ZM126.436 157.901C116.955 157.901 107.688 155.089 99.8048 149.822C91.922 144.555 85.7781 137.069 82.15 128.31C78.5219 119.551 77.5727 109.913 79.4222 100.614C81.2718 91.3158 85.8371 82.7746 92.5409 76.0708C99.2447 69.367 107.786 64.8017 117.084 62.9521C126.383 61.1026 136.021 62.0518 144.78 65.6799C153.539 69.308 161.025 75.4519 166.292 83.3347C171.559 91.2175 174.371 100.485 174.371 109.966C174.371 122.679 169.32 134.871 160.331 143.861C151.341 152.85 139.149 157.901 126.436 157.901ZM163.719 109.966C163.719 102.592 161.532 95.3838 157.435 89.2527C153.339 83.1216 147.516 78.343 140.703 75.5212C133.891 72.6994 126.395 71.9611 119.162 73.3996C111.93 74.8382 105.287 78.389 100.073 83.6031C94.8591 88.8171 91.3083 95.4602 89.8697 102.692C88.4312 109.924 89.1695 117.421 91.9913 124.233C94.8131 131.046 99.5918 136.869 105.723 140.965C111.854 145.062 119.062 147.248 126.436 147.248C136.324 147.248 145.807 143.32 152.799 136.329C159.791 129.337 163.719 119.854 163.719 109.966ZM133.645 102.757C133.398 102.51 133.104 102.313 132.781 102.179C132.458 102.046 132.112 101.977 131.762 101.977C131.412 101.977 131.066 102.046 130.743 102.179C130.42 102.313 130.126 102.51 129.879 102.757L126.436 106.2L122.993 102.757C122.49 102.272 121.818 102.003 121.119 102.01C120.421 102.016 119.753 102.296 119.26 102.789C118.766 103.283 118.486 103.951 118.48 104.649C118.474 105.348 118.742 106.02 119.227 106.523L122.67 109.966L119.227 113.409C118.973 113.655 118.77 113.949 118.63 114.274C118.491 114.598 118.417 114.948 118.414 115.301C118.411 115.655 118.479 116.006 118.612 116.333C118.746 116.66 118.944 116.958 119.194 117.208C119.444 117.458 119.741 117.655 120.069 117.789C120.396 117.923 120.747 117.991 121.1 117.988C121.454 117.985 121.803 117.911 122.128 117.771C122.453 117.632 122.747 117.429 122.993 117.175L126.436 113.732L129.879 117.175C130.382 117.66 131.054 117.928 131.752 117.922C132.451 117.916 133.119 117.636 133.612 117.142C134.106 116.648 134.386 115.981 134.392 115.282C134.398 114.584 134.13 113.911 133.645 113.409L130.202 109.966L133.645 106.523C133.892 106.275 134.088 105.982 134.222 105.659C134.356 105.336 134.425 104.989 134.425 104.64C134.425 104.29 134.356 103.944 134.222 103.621C134.088 103.298 133.892 103.004 133.645 102.757ZM112.34 102.757C112.093 102.51 111.8 102.313 111.477 102.179C111.154 102.046 110.807 101.977 110.458 101.977C110.108 101.977 109.762 102.046 109.439 102.179C109.116 102.313 108.822 102.51 108.575 102.757L105.132 106.2L101.688 102.757C101.186 102.272 100.513 102.003 99.8151 102.01C99.1169 102.016 98.4489 102.296 97.9552 102.789C97.4614 103.283 97.1814 103.951 97.1753 104.649C97.1692 105.348 97.4377 106.02 97.9227 106.523L101.366 109.966L97.9227 113.409C97.6684 113.655 97.4655 113.949 97.326 114.274C97.1864 114.598 97.1129 114.948 97.1098 115.301C97.1068 115.655 97.1742 116.006 97.3081 116.333C97.442 116.66 97.6397 116.958 97.8897 117.208C98.1398 117.458 98.4371 117.655 98.7644 117.789C99.0917 117.923 99.4423 117.991 99.7959 117.988C100.15 117.985 100.499 117.911 100.824 117.771C101.149 117.632 101.443 117.429 101.688 117.175L105.132 113.732L108.575 117.175C109.077 117.66 109.75 117.928 110.448 117.922C111.146 117.916 111.814 117.636 112.308 117.142C112.802 116.648 113.082 115.981 113.088 115.282C113.094 114.584 112.826 113.911 112.34 113.409L108.897 109.966L112.34 106.523C112.588 106.275 112.784 105.982 112.918 105.659C113.052 105.336 113.121 104.989 113.121 104.64C113.121 104.29 113.052 103.944 112.918 103.621C112.784 103.298 112.588 103.004 112.34 102.757ZM151.506 109.966L154.949 106.523C155.434 106.02 155.703 105.348 155.697 104.649C155.691 103.951 155.41 103.283 154.917 102.789C154.423 102.296 153.755 102.016 153.057 102.01C152.359 102.003 151.686 102.272 151.184 102.757L147.74 106.2L144.297 102.757C143.795 102.272 143.122 102.003 142.424 102.01C141.726 102.016 141.058 102.296 140.564 102.789C140.07 103.283 139.79 103.951 139.784 104.649C139.778 105.348 140.046 106.02 140.531 106.523L143.974 109.966L140.531 113.409C140.277 113.655 140.074 113.949 139.935 114.274C139.795 114.598 139.722 114.948 139.719 115.301C139.715 115.655 139.783 116.006 139.917 116.333C140.051 116.66 140.248 116.958 140.498 117.208C140.748 117.458 141.046 117.655 141.373 117.789C141.7 117.923 142.051 117.991 142.405 117.988C142.758 117.985 143.108 117.911 143.433 117.771C143.757 117.632 144.051 117.429 144.297 117.175L147.74 113.732L151.184 117.175C151.686 117.66 152.359 117.928 153.057 117.922C153.755 117.916 154.423 117.636 154.917 117.142C155.41 116.648 155.691 115.981 155.697 115.282C155.703 114.584 155.434 113.911 154.949 113.409L151.506 109.966Z"/>\n </mask>\n <path d="M190.242 160.457L170.136 140.351C166.533 145.552 162.023 150.063 156.821 153.666L176.927 173.772C178.693 175.538 181.088 176.53 183.585 176.53C186.082 176.53 188.477 175.538 190.242 173.772C192.008 172.007 193 169.612 193 167.115C193 164.618 192.008 162.223 190.242 160.457ZM126.436 157.901C116.955 157.901 107.688 155.089 99.8048 149.822C91.922 144.555 85.7781 137.069 82.15 128.31C78.5219 119.551 77.5727 109.913 79.4222 100.614C81.2718 91.3158 85.8371 82.7746 92.5409 76.0708C99.2447 69.367 107.786 64.8017 117.084 62.9521C126.383 61.1026 136.021 62.0518 144.78 65.6799C153.539 69.308 161.025 75.4519 166.292 83.3347C171.559 91.2175 174.371 100.485 174.371 109.966C174.371 122.679 169.32 134.871 160.331 143.861C151.341 152.85 139.149 157.901 126.436 157.901ZM163.719 109.966C163.719 102.592 161.532 95.3838 157.435 89.2527C153.339 83.1216 147.516 78.343 140.703 75.5212C133.891 72.6994 126.395 71.9611 119.162 73.3996C111.93 74.8382 105.287 78.389 100.073 83.6031C94.8591 88.8171 91.3083 95.4602 89.8697 102.692C88.4312 109.924 89.1695 117.421 91.9913 124.233C94.8131 131.046 99.5918 136.869 105.723 140.965C111.854 145.062 119.062 147.248 126.436 147.248C136.324 147.248 145.807 143.32 152.799 136.329C159.791 129.337 163.719 119.854 163.719 109.966ZM133.645 102.757C133.398 102.51 133.104 102.313 132.781 102.179C132.458 102.046 132.112 101.977 131.762 101.977C131.412 101.977 131.066 102.046 130.743 102.179C130.42 102.313 130.126 102.51 129.879 102.757L126.436 106.2L122.993 102.757C122.49 102.272 121.818 102.003 121.119 102.01C120.421 102.016 119.753 102.296 119.26 102.789C118.766 103.283 118.486 103.951 118.48 104.649C118.474 105.348 118.742 106.02 119.227 106.523L122.67 109.966L119.227 113.409C118.973 113.655 118.77 113.949 118.63 114.274C118.491 114.598 118.417 114.948 118.414 115.301C118.411 115.655 118.479 116.006 118.612 116.333C118.746 116.66 118.944 116.958 119.194 117.208C119.444 117.458 119.741 117.655 120.069 117.789C120.396 117.923 120.747 117.991 121.1 117.988C121.454 117.985 121.803 117.911 122.128 117.771C122.453 117.632 122.747 117.429 122.993 117.175L126.436 113.732L129.879 117.175C130.382 117.66 131.054 117.928 131.752 117.922C132.451 117.916 133.119 117.636 133.612 117.142C134.106 116.648 134.386 115.981 134.392 115.282C134.398 114.584 134.13 113.911 133.645 113.409L130.202 109.966L133.645 106.523C133.892 106.275 134.088 105.982 134.222 105.659C134.356 105.336 134.425 104.989 134.425 104.64C134.425 104.29 134.356 103.944 134.222 103.621C134.088 103.298 133.892 103.004 133.645 102.757ZM112.34 102.757C112.093 102.51 111.8 102.313 111.477 102.179C111.154 102.046 110.807 101.977 110.458 101.977C110.108 101.977 109.762 102.046 109.439 102.179C109.116 102.313 108.822 102.51 108.575 102.757L105.132 106.2L101.688 102.757C101.186 102.272 100.513 102.003 99.8151 102.01C99.1169 102.016 98.4489 102.296 97.9552 102.789C97.4614 103.283 97.1814 103.951 97.1753 104.649C97.1692 105.348 97.4377 106.02 97.9227 106.523L101.366 109.966L97.9227 113.409C97.6684 113.655 97.4655 113.949 97.326 114.274C97.1864 114.598 97.1129 114.948 97.1098 115.301C97.1068 115.655 97.1742 116.006 97.3081 116.333C97.442 116.66 97.6397 116.958 97.8897 117.208C98.1398 117.458 98.4371 117.655 98.7644 117.789C99.0917 117.923 99.4423 117.991 99.7959 117.988C100.15 117.985 100.499 117.911 100.824 117.771C101.149 117.632 101.443 117.429 101.688 117.175L105.132 113.732L108.575 117.175C109.077 117.66 109.75 117.928 110.448 117.922C111.146 117.916 111.814 117.636 112.308 117.142C112.802 116.648 113.082 115.981 113.088 115.282C113.094 114.584 112.826 113.911 112.34 113.409L108.897 109.966L112.34 106.523C112.588 106.275 112.784 105.982 112.918 105.659C113.052 105.336 113.121 104.989 113.121 104.64C113.121 104.29 113.052 103.944 112.918 103.621C112.784 103.298 112.588 103.004 112.34 102.757ZM151.506 109.966L154.949 106.523C155.434 106.02 155.703 105.348 155.697 104.649C155.691 103.951 155.41 103.283 154.917 102.789C154.423 102.296 153.755 102.016 153.057 102.01C152.359 102.003 151.686 102.272 151.184 102.757L147.74 106.2L144.297 102.757C143.795 102.272 143.122 102.003 142.424 102.01C141.726 102.016 141.058 102.296 140.564 102.789C140.07 103.283 139.79 103.951 139.784 104.649C139.778 105.348 140.046 106.02 140.531 106.523L143.974 109.966L140.531 113.409C140.277 113.655 140.074 113.949 139.935 114.274C139.795 114.598 139.722 114.948 139.719 115.301C139.715 115.655 139.783 116.006 139.917 116.333C140.051 116.66 140.248 116.958 140.498 117.208C140.748 117.458 141.046 117.655 141.373 117.789C141.7 117.923 142.051 117.991 142.405 117.988C142.758 117.985 143.108 117.911 143.433 117.771C143.757 117.632 144.051 117.429 144.297 117.175L147.74 113.732L151.184 117.175C151.686 117.66 152.359 117.928 153.057 117.922C153.755 117.916 154.423 117.636 154.917 117.142C155.41 116.648 155.691 115.981 155.697 115.282C155.703 114.584 155.434 113.911 154.949 113.409L151.506 109.966Z" fill="#93939A"/>\n <path d="M190.242 160.457L170.136 140.351C166.533 145.552 162.023 150.063 156.821 153.666L176.927 173.772C178.693 175.538 181.088 176.53 183.585 176.53C186.082 176.53 188.477 175.538 190.242 173.772C192.008 172.007 193 169.612 193 167.115C193 164.618 192.008 162.223 190.242 160.457ZM126.436 157.901C116.955 157.901 107.688 155.089 99.8048 149.822C91.922 144.555 85.7781 137.069 82.15 128.31C78.5219 119.551 77.5727 109.913 79.4222 100.614C81.2718 91.3158 85.8371 82.7746 92.5409 76.0708C99.2447 69.367 107.786 64.8017 117.084 62.9521C126.383 61.1026 136.021 62.0518 144.78 65.6799C153.539 69.308 161.025 75.4519 166.292 83.3347C171.559 91.2175 174.371 100.485 174.371 109.966C174.371 122.679 169.32 134.871 160.331 143.861C151.341 152.85 139.149 157.901 126.436 157.901ZM163.719 109.966C163.719 102.592 161.532 95.3838 157.435 89.2527C153.339 83.1216 147.516 78.343 140.703 75.5212C133.891 72.6994 126.395 71.9611 119.162 73.3996C111.93 74.8382 105.287 78.389 100.073 83.6031C94.8591 88.8171 91.3083 95.4602 89.8697 102.692C88.4312 109.924 89.1695 117.421 91.9913 124.233C94.8131 131.046 99.5918 136.869 105.723 140.965C111.854 145.062 119.062 147.248 126.436 147.248C136.324 147.248 145.807 143.32 152.799 136.329C159.791 129.337 163.719 119.854 163.719 109.966ZM133.645 102.757C133.398 102.51 133.104 102.313 132.781 102.179C132.458 102.046 132.112 101.977 131.762 101.977C131.412 101.977 131.066 102.046 130.743 102.179C130.42 102.313 130.126 102.51 129.879 102.757L126.436 106.2L122.993 102.757C122.49 102.272 121.818 102.003 121.119 102.01C120.421 102.016 119.753 102.296 119.26 102.789C118.766 103.283 118.486 103.951 118.48 104.649C118.474 105.348 118.742 106.02 119.227 106.523L122.67 109.966L119.227 113.409C118.973 113.655 118.77 113.949 118.63 114.274C118.491 114.598 118.417 114.948 118.414 115.301C118.411 115.655 118.479 116.006 118.612 116.333C118.746 116.66 118.944 116.958 119.194 117.208C119.444 117.458 119.741 117.655 120.069 117.789C120.396 117.923 120.747 117.991 121.1 117.988C121.454 117.985 121.803 117.911 122.128 117.771C122.453 117.632 122.747 117.429 122.993 117.175L126.436 113.732L129.879 117.175C130.382 117.66 131.054 117.928 131.752 117.922C132.451 117.916 133.119 117.636 133.612 117.142C134.106 116.648 134.386 115.981 134.392 115.282C134.398 114.584 134.13 113.911 133.645 113.409L130.202 109.966L133.645 106.523C133.892 106.275 134.088 105.982 134.222 105.659C134.356 105.336 134.425 104.989 134.425 104.64C134.425 104.29 134.356 103.944 134.222 103.621C134.088 103.298 133.892 103.004 133.645 102.757ZM112.34 102.757C112.093 102.51 111.8 102.313 111.477 102.179C111.154 102.046 110.807 101.977 110.458 101.977C110.108 101.977 109.762 102.046 109.439 102.179C109.116 102.313 108.822 102.51 108.575 102.757L105.132 106.2L101.688 102.757C101.186 102.272 100.513 102.003 99.8151 102.01C99.1169 102.016 98.4489 102.296 97.9552 102.789C97.4614 103.283 97.1814 103.951 97.1753 104.649C97.1692 105.348 97.4377 106.02 97.9227 106.523L101.366 109.966L97.9227 113.409C97.6684 113.655 97.4655 113.949 97.326 114.274C97.1864 114.598 97.1129 114.948 97.1098 115.301C97.1068 115.655 97.1742 116.006 97.3081 116.333C97.442 116.66 97.6397 116.958 97.8897 117.208C98.1398 117.458 98.4371 117.655 98.7644 117.789C99.0917 117.923 99.4423 117.991 99.7959 117.988C100.15 117.985 100.499 117.911 100.824 117.771C101.149 117.632 101.443 117.429 101.688 117.175L105.132 113.732L108.575 117.175C109.077 117.66 109.75 117.928 110.448 117.922C111.146 117.916 111.814 117.636 112.308 117.142C112.802 116.648 113.082 115.981 113.088 115.282C113.094 114.584 112.826 113.911 112.34 113.409L108.897 109.966L112.34 106.523C112.588 106.275 112.784 105.982 112.918 105.659C113.052 105.336 113.121 104.989 113.121 104.64C113.121 104.29 113.052 103.944 112.918 103.621C112.784 103.298 112.588 103.004 112.34 102.757ZM151.506 109.966L154.949 106.523C155.434 106.02 155.703 105.348 155.697 104.649C155.691 103.951 155.41 103.283 154.917 102.789C154.423 102.296 153.755 102.016 153.057 102.01C152.359 102.003 151.686 102.272 151.184 102.757L147.74 106.2L144.297 102.757C143.795 102.272 143.122 102.003 142.424 102.01C141.726 102.016 141.058 102.296 140.564 102.789C140.07 103.283 139.79 103.951 139.784 104.649C139.778 105.348 140.046 106.02 140.531 106.523L143.974 109.966L140.531 113.409C140.277 113.655 140.074 113.949 139.935 114.274C139.795 114.598 139.722 114.948 139.719 115.301C139.715 115.655 139.783 116.006 139.917 116.333C140.051 116.66 140.248 116.958 140.498 117.208C140.748 117.458 141.046 117.655 141.373 117.789C141.7 117.923 142.051 117.991 142.405 117.988C142.758 117.985 143.108 117.911 143.433 117.771C143.757 117.632 144.051 117.429 144.297 117.175L147.74 113.732L151.184 117.175C151.686 117.66 152.359 117.928 153.057 117.922C153.755 117.916 154.423 117.636 154.917 117.142C155.41 116.648 155.691 115.981 155.697 115.282C155.703 114.584 155.434 113.911 154.949 113.409L151.506 109.966Z" stroke="transparent" stroke-width="20" mask="url(#path-2-outside-1_0_1)"/>\n </g>\n <defs>\n <clipPath id="clip0_0_1">\n <rect width="200" height="200" fill="white"/>\n </clipPath>\n </defs>\n </svg>\n </div>\n <div class="errorContainer"></div>\n </div>\n</div>\n<div>\n <label class="ff-card-form-label" for="cardHolderInput">Cardholder name</label>\n <input class="ff-card-form-text-input" id="cardHolderInput" type="text" pattern="[A-Za-z\\s]+" placeholder="Full name on card">\n <div class="errorContainer"></div>\n</div>\n<div>\n <label class="ff-card-form-label" for="emailAddressInput">Email</label>\n <input class="ff-card-form-text-input" id="emailAddressInput" placeholder="Email" type="email">\n <div class="errorContainer"></div>\n</div>\n<div id="countrySelectorField">\n <label class="ff-card-form-label" for="countrySelectorInput">Country</label>\n <div class="ff-select-wrap">\n <select class="ff-card-form-text-input ff-card-form-select" id="countrySelectorInput"></select>\n <div class="ff-select-arrow" aria-hidden="true"></div>\n </div>\n</div>\n<div>\n <label class="ff-card-form-label" for="postalCodeInput">Zip code</label>\n <input class="ff-card-form-text-input" id="postalCodeInput" placeholder="12345">\n <div class="errorContainer"></div>\n</div>\n'),this.wireCardInputs()}renderCardForm(){}getCardInputElements(){return this.cardInputElements}getCheckoutOptions(){return{cardElements:this.getCardInputElements()}}}var Pt=Object.freeze({__proto__:null,default:_t});const Mt={[e.PaymentMethod.PAYMENT_CARD]:'\x3c!-- Card Payments Section --\x3e\n<div class="ff-payment-method-card ff-payment-method-payment-card">\n <label class="ff-payment-method-label">\n <input type="radio" name="payment-method" value="PAYMENT_CARD" class="ff-payment-method-radio">\n <div class="ff-payment-method-header">\n <div class="ff-card-logos">\n <img class="payment-method-icon" style="max-height: 30px" src="https://assets.fnlfx.com/common/checkout/cards.webp" alt="visa, mastercard">\n </div>\n </div>\n </label>\n <div class="ff-payment-method-content">\n <div class="ff-card-form-container ff-payment-container" id="cardForm">\n <div class="loader-container">\n <div class="loader"></div>\n </div>\n <div class="payment-errors-container"></div>\n <button class="ff-card-form-submit-button" id="submitButton">\n Continue\n </button>\n <p class="ff-security-message">\n Your payment information is secure with SSL/TLS encryption\n </p>\n </div>\n </div>\n</div>\n',[e.PaymentMethod.PAYPAL]:'<div class="ff-payment-method-card ff-payment-method-paypal">\n <label class="ff-payment-method-label">\n <input type="radio" name="payment-method" value="PAYPAL" class="ff-payment-method-radio">\n <div class="ff-payment-method-header">\n <div class="ff-payment-logo ff-paypal-logo">\n <img class="payment-method-icon" style="max-height: 22px" src="https://assets.fnlfx.com/common/checkout/paypal.webp" alt="PayPal logo">\n </div>\n </div>\n </label>\n <div class="ff-payment-method-content">\n <ul class="ff-payment-features">\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span> Fast, convenient payment option </span>\n </li>\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span> Keeps your financial info safe with end-to-end encryption </span>\n </li>\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span> Backed by PayPal’s industry-leading fraud protection </span>\n </li>\n </ul>\n <div class="ff-paypal-button-container ff-payment-container" id="paypalButton"></div>\n <div class="loader-container payment-button-loader">\n <div class="loader"></div>\n </div>\n <div class="payment-errors-container"></div>\n <p class="ff-security-message">\n Your payment information is secure with SSL/TLS encryption\n </p>\n </div>\n</div>\n',[e.PaymentMethod.GOOGLE_PAY]:'\x3c!-- Google Pay Section --\x3e\n<div class="ff-payment-method-card ff-payment-method-google-pay">\n <label class="ff-payment-method-label ff-google-pay-header">\n <input type="radio" name="payment-method" value="GOOGLE_PAY" class="ff-payment-method-radio" checked="checked">\n <div class="ff-payment-method-header">\n <div class="ff-payment-logo ff-google-pay-logo">\n <img src="https://developers.google.com/static/pay/api/images/brand-guidelines/google-pay-mark.png" alt="Google Pay">\n </div>\n </div>\n </label>\n <div class="ff-payment-method-content">\n <ul class="ff-payment-features">\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span>Easy and private payments with Face/Touch ID</span>\n </li>\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span>Keeps your financial info safe with end-to-end encryption</span>\n </li>\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span>Protected by Google Pay\'s unique Device Account Number</span>\n </li>\n </ul>\n <div class="ff-google-pay-button-container ff-payment-container" id="googlePayButton"></div>\n <div class="loader-container payment-button-loader">\n <div class="loader"></div>\n </div>\n <div class="payment-errors-container"></div>\n <p class="ff-security-message">\n Your payment information is secure with SSL/TLS encryption\n </p>\n </div>\n</div>\n',[e.PaymentMethod.APPLE_PAY]:'\x3c!-- Apple Pay Section --\x3e\n<div class="ff-payment-method-card ff-payment-method-apple-pay">\n <label class="ff-payment-method-label">\n <input type="radio" name="payment-method" value="APPLE_PAY" class="ff-payment-method-radio">\n <div class="ff-payment-method-header">\n <div class="ff-payment-logo ff-apple-pay-logo">\n <svg class="payment-method-icon" height="26" viewBox="0 0 63 26" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path fill-rule="evenodd" clip-rule="evenodd" d="M8.41022 4.82398C9.5916 4.92293 10.773 4.23026 11.5113 3.35205C12.2374 2.4491 12.7173 1.23692 12.5943 0C11.5483 0.0494767 10.2561 0.692674 9.51777 1.59562C8.84093 2.37488 8.26255 3.63654 8.41022 4.82398ZM22.4638 20.7555V1.47193H29.6628C33.3793 1.47193 35.9758 4.04471 35.9758 7.80494C35.9758 11.5652 33.33 14.1627 29.5644 14.1627H25.4418V20.7555H22.4638ZM12.5819 5.05898C11.5411 4.99877 10.5914 5.37358 9.82438 5.67633C9.33075 5.87116 8.91274 6.03614 8.59472 6.03614C8.23784 6.03614 7.80257 5.86234 7.31387 5.66719C6.6735 5.4115 5.94138 5.11916 5.17364 5.13319C3.41387 5.15793 1.77716 6.15983 0.878819 7.75545C-0.967091 10.9467 0.398882 15.6717 2.18326 18.2693C3.05699 19.5556 4.10301 20.9657 5.48129 20.9163C6.08765 20.8933 6.52383 20.7072 6.97524 20.5147C7.49492 20.293 8.0348 20.0628 8.87776 20.0628C9.69151 20.0628 10.2078 20.287 10.7033 20.5023C11.1746 20.707 11.6271 20.9036 12.2989 20.8915C13.7264 20.8668 14.6247 19.6051 15.4984 18.3187C16.4413 16.9381 16.8557 15.5906 16.9186 15.3861C16.9222 15.3745 16.9246 15.3665 16.9259 15.3625C16.9244 15.361 16.9128 15.3556 16.8922 15.3462C16.577 15.2011 14.1679 14.0926 14.1448 11.1199C14.1216 8.62473 16.0556 7.36054 16.3601 7.16153C16.3786 7.14944 16.3911 7.14125 16.3968 7.137C15.1662 5.30636 13.2464 5.10845 12.5819 5.05898ZM41.4153 20.9039C43.2858 20.9039 45.0209 19.9515 45.8085 18.4424H45.8701V20.7555H48.6266V11.157C48.6266 8.37393 46.4115 6.5804 43.0027 6.5804C39.8401 6.5804 37.5019 8.39866 37.4158 10.8972H40.0985C40.32 9.70979 41.4153 8.93054 42.9166 8.93054C44.7379 8.93054 45.7593 9.78401 45.7593 11.3549V12.4186L42.0429 12.6413C38.5849 12.8516 36.7143 14.274 36.7143 16.7479C36.7143 19.2464 38.6464 20.9039 41.4153 20.9039ZM42.215 18.6156C40.6275 18.6156 39.6184 17.8487 39.6184 16.6736C39.6184 15.4615 40.5906 14.7564 42.4488 14.6451L45.7591 14.4348V15.5233C45.7591 17.3292 44.2332 18.6156 42.215 18.6156ZM57.7699 21.51C56.5762 24.8868 55.2103 26 52.306 26C52.0845 26 51.3461 25.9753 51.1739 25.9258V23.6127C51.3585 23.6375 51.8138 23.6622 52.0476 23.6622C53.3643 23.6622 54.1027 23.1056 54.558 21.6584L54.8288 20.8049L49.7833 6.76594H52.8967L56.4039 18.1579H56.4655L59.9727 6.76594H63L57.7699 21.51ZM25.4416 3.99524H28.875C31.4592 3.99524 32.936 5.38059 32.936 7.81731C32.936 10.254 31.4592 11.6518 28.8627 11.6518H25.4416V3.99524Z" fill="currentColor"/>\n </svg>\n </div>\n </div>\n </label>\n <div class="ff-payment-method-content">\n <ul class="ff-payment-features">\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span>Easy and private payments with Face/Touch ID</span>\n </li>\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span>Keeps your financial info safe with end-to-end encryption</span>\n </li>\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span>Protected by Apple Pay’s unique Device Account Number</span>\n </li>\n </ul>\n <div class="ff-apple-pay-button-container ff-payment-container" id="applePayButton"></div>\n <div class="loader-container payment-button-loader">\n <div class="loader"></div>\n </div>\n <div class="payment-errors-container"></div>\n <p class="ff-security-message">\n Your payment information is secure with Apple Pay encryption\n </p>\n </div>\n</div>\n'};class It{constructor(t,n){this.onLoaderChange=e=>{document.querySelectorAll(`${this.containerSelector} .loader-container`)?.forEach(t=>{t.style.display=e?"flex":"none"})},this.onError=(e,t)=>{if(!e)return void this.containerEl.querySelectorAll(".payment-errors-container")?.forEach(e=>{e.innerHTML=""});let n=null;if(t){const e=t.replace("_","-").toLowerCase();n=this.containerEl.querySelector(`.ff-payment-method-${e} .payment-errors-container`)}n&&(n.textContent=e?.message||"")},this.onStatusChange=(e,t)=>{["initializing"].includes(e)||"initializing"!==t||this.onLoaderChange(!1),"updating"===e&&this.onLoaderChange(!0),"ready"===e&&"updating"===t&&this.onLoaderChange(!1)},this.onSuccess=()=>{const e=document.querySelector("#success-screen")?.innerHTML;document.querySelectorAll(".ff-payment-container").forEach(t=>{t.innerHTML=e}),this.onLoaderChange(!1)},this.onDestroy=()=>{this.containerEl.innerHTML&&(this.containerEl.innerHTML="")},this.onInputError=e=>{this.cardInstance.onInputError(e)},this.onMethodRender=t=>{const n=t.replace("_","-").toLowerCase(),r=this.containerEl.querySelector(`.ff-payment-method-${n}`);t===e.PaymentMethod.PAYMENT_CARD&&this.cardInstance.onMethodRender(),r&&r.classList.add("visible")},this.onMethodsAvailable=e=>{this.availableMethods=e,this.initAccordion(),e.forEach(this.onMethodRender)},this.onStartPurchase=e=>{this.currentPurchaseMethod=e},this.onPurchaseFailure=e=>{this.currentPurchaseMethod&&this.onError(e,this.currentPurchaseMethod),this.currentPurchaseMethod=null},this.onPurchaseCompleted=()=>{this.currentPurchaseMethod=null},this.containerSelector=t.container,this.paymentMethodOrder=t.paymentMethodOrder;const r=document.querySelector(this.containerSelector);if(!r)throw new Error(`Container element not found for selector: ${this.containerSelector}`);this.containerEl=r,this.checkoutConfig=t,this.cardSessionFieldConfig=n}initAccordion(){const e=this.containerEl.querySelectorAll(".ff-payment-method-card"),t=this.containerEl.querySelectorAll(".ff-payment-method-radio"),n=t=>{e.forEach(e=>{const n=e.querySelector(".ff-payment-method-radio");n===t&&n?.checked?e.classList.add("expanded"):e.classList.remove("expanded")})},r=Array.from(t).find(e=>this.availableMethods.includes(e.value));if(!r)throw new Error("Default skin accordion initialization error: No radio button found");setTimeout(()=>{r.checked=!0,n(r)},0),t.forEach(e=>{e.addEventListener("change",()=>{e.checked&&n(e)})})}wireCardInputs(){this.cardInstance.wireCardInputs();const e=this.containerEl.querySelector("#submitButton");if(!e)throw new Error("One or more card input elements are missing in the default skin");this.cardInputElements={...this.cardInstance.getCardInputElements(),button:e}}async init(){this.containerEl.insertAdjacentHTML("beforeend",'<div class="ff-skin-default" id="ff-payment-method-containers">\n <div id="success-screen" style="display: none">\n <div class="success">\n <img alt="Loading" src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTAiIGhlaWdodD0iNTAiIHZpZXdCb3g9IjAgMCA1MCA1MCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTI1IDAuMTExMzI4QzIwLjA3NzQgMC4xMTEzMjggMTUuMjY1NCAxLjU3MTA0IDExLjE3MjUgNC4zMDU4NkM3LjA3OTUyIDcuMDQwNjkgMy44ODk0NSAxMC45Mjc4IDIuMDA1NjYgMTUuNDc1N0MwLjEyMTg4MyAyMC4wMjM1IC0wLjM3MSAyNS4wMjc4IDAuNTg5MzQzIDI5Ljg1NThDMS41NDk2OSAzNC42ODM4IDMuOTIwMTIgMzkuMTE4NSA3LjQwMDkgNDIuNTk5M0MxMC44ODE3IDQ2LjA4MDEgMTUuMzE2NCA0OC40NTA1IDIwLjE0NDQgNDkuNDEwOUMyNC45NzI0IDUwLjM3MTIgMjkuOTc2NyA0OS44NzgzIDM0LjUyNDYgNDcuOTk0NkMzOS4wNzI0IDQ2LjExMDggNDIuOTU5NSA0Mi45MjA3IDQ1LjY5NDQgMzguODI3N0M0OC40MjkyIDM0LjczNDggNDkuODg4OSAyOS45MjI4IDQ5Ljg4ODkgMjUuMDAwMkM0OS44ODg5IDE4LjM5OTMgNDcuMjY2NyAxMi4wNjg3IDQyLjU5OTEgNy40MDExMkMzNy45MzE1IDIuNzMzNTQgMzEuNjAwOSAwLjExMTMyOCAyNSAwLjExMTMyOFpNNDEuMjU1NiAxNi42NDY5TDIwLjgxNTYgMzcuMDcxM0w4Ljc0NDQ0IDI1LjAwMDJDOC4zMzE4OCAyNC41ODc3IDguMTAwMTEgMjQuMDI4MSA4LjEwMDExIDIzLjQ0NDdDOC4xMDAxMSAyMi44NjEyIDguMzMxODggMjIuMzAxNyA4Ljc0NDQ0IDIxLjg4OTFDOS4xNTcgMjEuNDc2NSA5LjcxNjU1IDIxLjI0NDggMTAuMyAyMS4yNDQ4QzEwLjg4MzQgMjEuMjQ0OCAxMS40NDMgMjEuNDc2NSAxMS44NTU2IDIxLjg4OTFMMjAuODQ2NyAzMC44ODAyTDM4LjE3NTYgMTMuNTY2OUMzOC4zNzk4IDEzLjM2MjYgMzguNjIyMyAxMy4yMDA2IDM4Ljg4OTIgMTMuMDlDMzkuMTU2MiAxMi45Nzk1IDM5LjQ0MjIgMTIuOTIyNiAzOS43MzExIDEyLjkyMjZDNDAuMDIgMTIuOTIyNiA0MC4zMDYxIDEyLjk3OTUgNDAuNTczIDEzLjA5QzQwLjgzOTkgMTMuMjAwNiA0MS4wODI0IDEzLjM2MjYgNDEuMjg2NyAxMy41NjY5QzQxLjQ5MDkgMTMuNzcxMiA0MS42NTMgMTQuMDEzNyA0MS43NjM1IDE0LjI4MDZDNDEuODc0MSAxNC41NDc1IDQxLjkzMSAxNC44MzM1IDQxLjkzMSAxNS4xMjI0QzQxLjkzMSAxNS40MTEzIDQxLjg3NDEgMTUuNjk3NCA0MS43NjM1IDE1Ljk2NDNDNDEuNjUzIDE2LjIzMTIgNDEuNDkwOSAxNi40NzM3IDQxLjI4NjcgMTYuNjc4TDQxLjI1NTYgMTYuNjQ2OVoiIGZpbGw9IiM4RURGQzIiLz4KPC9zdmc+Cg==">\n <div>Payment completed successfully</div>\n </div>\n </div>\n</div>\n');const e=this.containerEl.querySelector("#ff-payment-method-containers");this.paymentMethodOrder.forEach(t=>{e.insertAdjacentHTML("beforeend",Mt[t])}),this.cardInstance=new _t(document.querySelector("#cardForm"),this.checkoutConfig,this.cardSessionFieldConfig),this.cardInstance.init(),this.wireCardInputs()}renderCardForm(){}getCardInputElements(){return{...this.cardInstance.getCardInputElements(),button:this.cardInputElements.button}}getPaymentButtonElements(){return{paypal:this.containerEl.querySelector("#paypalButton"),googlePay:this.containerEl.querySelector("#googlePayButton"),applePay:this.containerEl.querySelector("#applePayButton")}}getCheckoutOptions(){return{...this.cardInstance.getCheckoutOptions(),cardElements:this.getCardInputElements(),paymentButtonElements:this.getPaymentButtonElements(),applePay:H[e.PaymentMethod.APPLE_PAY],paypal:H[e.PaymentMethod.PAYPAL],googlePay:H[e.PaymentMethod.GOOGLE_PAY]}}}var kt=Object.freeze({__proto__:null,default:async(e,t)=>{const n=new It(e,t);return await n.init(),n}});const Tt=new Map;function Rt(e){return Tt.has(e)||Tt.set(e,ue(e)),Tt.get(e)}var At=Object.freeze({__proto__:null,mountStripeCardForm:async function(e,t,n){const{stripe_public_key:r,amount:o,currency:i,order_id:a,is_link_enabled:s,amount_total:d}=t.data,l=t.data.tax_enabled??n.enableTax??!1,c=await Rt(r);if(!c)throw new Error("Failed to load Stripe");e.replaceChildren();const u=c.elements({mode:"subscription",amount:o,currency:i,paymentMethodCreation:"manual",paymentMethodTypes:s?["card","link"]:["card"],appearance:n.appearance}),h=t.data.show_country_selector_field??!1,p=t.data.show_postal_code_field??!1,m=h||p,y=u.create("payment",{layout:"tabs",wallets:{applePay:n.showWallets?"auto":"never",googlePay:n.showWallets?"auto":"never"},terms:{card:"never"},fields:{billingDetails:{address:{line1:"never",line2:"never",city:"never",state:"never",country:h?"auto":"never",postalCode:p?"auto":"never"}}},...t.data.detected_country_code&&h?{defaultValues:{billingDetails:{address:{country:t.data.detected_country_code}}}}:{}}),f={line1:"",line2:"",city:"",state:""};let g;h||(f.country=t.data.detected_country_code??""),p||(f.postal_code="");let w=0;l&&t.data.tax_calculation_id&&(g={id:t.data.tax_calculation_id,country:t.data.detected_country_code??void 0,postal:void 0});let S={},E=async()=>{};const b=async()=>{const e=S.country,r=S.postalCode;if(!e)return;const o=++w;try{const i=await n.apiClient.recalculateTax({orderId:a,clientToken:t.data.client_token,countryCode:e,postalCode:r});if(o!==w)return;g={id:i.tax_calculation_id,country:e,postal:r},n.onTaxChange?.({amountTotal:i.amount_total,currency:i.currency,...C(i)})}catch(t){if(o!==w)return;g&&g.country===e&&g.postal===r||(g=void 0,n.onTaxError?.(t))}};if(y.mount(e),l&&m){let e;S={country:t.data.detected_country_code||void 0},E=async()=>{e&&(clearTimeout(e),e=void 0),await b()},y.on("change",n=>{const r=n.value.billingDetails?.address;S={country:r?.country||t.data.detected_country_code||void 0,postalCode:r?.postalCode||void 0},S.country&&(e&&clearTimeout(e),e=setTimeout(b,600))})}return l&&null!=d&&n.onTaxChange?.({amountTotal:d,currency:i,...C(t.data)}),l&&m&&b(),await new Promise((e,t)=>{y.once("ready",()=>e()),y.once("loaderror",e=>t(e.error))}),n.onRenderSuccess?.(),{submit:async()=>{n.onLoaderChange?.(!0);try{l&&m&&await E();const{error:e}=await u.submit();if(e)throw e;const{error:r,paymentMethod:o}=await c.createPaymentMethod({elements:u,params:{billing_details:{address:f}}});if(r)throw r;const i=l?(m?S.country:t.data.detected_country_code)??n.countryCode:n.countryCode,s=l&&m?S.postalCode:void 0,d=l&&g&&g.country===i&&g.postal===s,h=await n.apiClient.createPayment({orderId:a,paymentMethodToken:o.id,email:n.email,countryCode:i,postalCode:s,taxCalculationId:d?g.id:void 0,clientMetadata:n.clientMetadata}),p=n.apiClient.processPaymentResponse(h);if("action_required"===p.type){const{error:e}=await c.handleNextAction({clientSecret:p.clientToken});if(e)throw e}n.invalidateSession?.(),n.onPaymentSuccess?.(o,a)}catch(e){throw n.onPaymentFail?.(W(e)),e}finally{n.onLoaderChange?.(!1)}}}}});const xt=new WeakMap;function Dt(e,t,n){const r=t.apple_pay_recurring_payment_request;if(r){const e=e=>{e.recurringPaymentStartDate&&Object.assign(e,{recurringPaymentStartDate:new Date(e.recurringPaymentStartDate)}),e.recurringPaymentEndDate&&Object.assign(e,{recurringPaymentEndDate:new Date(e.recurringPaymentEndDate)})};e(r.regularBilling),r.trialBilling&&e(r.trialBilling)}const o=r?{recurringPaymentRequest:r}:void 0,i=t.amount,a=t.tax_amount??0,s=t.amount_total??i;return e.paymentRequest({country:t.country,currency:t.currency,total:{label:n?.trim()||"Total",amount:s},displayItems:a>0?[{label:"Subtotal",amount:i},{label:"Tax",amount:a}]:void 0,requestPayerName:!1,requestPayerEmail:!1,applePay:o})}var Lt=Object.freeze({__proto__:null,getAvailableWallet:async function(e){const{stripe_public_key:t}=e.data,n=await Rt(t);if(!n)throw new Error("Failed to load Stripe");const r=Dt(n,e.data),o=await r.canMakePayment();return o?(xt.set(e.data,{paymentRequest:r,canMakePayment:o}),o.applePay?"APPLE_PAY":o.googlePay?"GOOGLE_PAY":null):null},purchaseWallet:async function(e,t){const{stripe_public_key:n,order_id:r}=e.data,o=e.data.tax_enabled??!1,i=await Rt(n);if(!i)throw new Error("Failed to load Stripe");const a=xt.get(e.data);let s;if(xt.delete(e.data),a){s=a.paymentRequest;const n=Dt(i,e.data);n.canMakePayment().catch(()=>{}),xt.set(e.data,{paymentRequest:n,canMakePayment:a.canMakePayment});const r=t.totalLabel?.trim();if(r){const t=e.data.amount_total??e.data.amount;s.update({total:{label:r,amount:t}})}}else{s=Dt(i,e.data,t.totalLabel);if(!await s.canMakePayment())throw new Error("No wallet payment method available")}return o&&null!=e.data.amount_total&&t.onTaxChange?.({amountTotal:e.data.amount_total,currency:e.data.currency,...C(e.data)}),new Promise((n,a)=>{s.on("paymentmethod",async s=>{let d=!1;const l=e=>{if(!d){d=!0;try{s.complete(e)}catch{return}}};t.onLoaderChange?.(!0);try{const a=o?s.paymentMethod.billing_details.address:void 0,d=await t.apiClient.createPayment({orderId:r,paymentMethodToken:s.paymentMethod.id,email:t.email,countryCode:o&&(a?.country||e.data.detected_country_code)||t.countryCode,postalCode:o&&a?.postal_code||void 0,taxCalculationId:o?e.data.tax_calculation_id:void 0,clientMetadata:t.clientMetadata}),c=t.apiClient.processPaymentResponse(d);if("action_required"===c.type){const{error:e}=await i.handleNextAction({clientSecret:c.clientToken});if(e)throw e}l("success"),t.invalidateSession?.(),t.onPaymentSuccess?.(s.paymentMethod,r),n()}catch(e){l("fail"),t.onPaymentFail?.(W(e)),a(e)}finally{t.onLoaderChange?.(!1)}}),s.on("cancel",()=>{t.onPaymentCancel?.(),n()}),s.show()})}});e.APIError=o,e.Billing=vt,e.CHECKOUT_STATES={INITIALIZING:"initializing",READY:"ready",PROCESSING:"processing",ACTION_REQUIRED:"action_required",UPDATING:"updating",COMPLETED:"completed",ERROR:"error",DESTROYED:"destroyed"},e.CheckoutError=a,e.ConfigurationError=class extends n{constructor(e){super(e,N.CONFIGURATION_ERROR),this.name="ConfigurationError"}},e.DEFAULTS=M,e.ERROR_CODES=N,e.EVENTS=I,e.FunnefoxSDKError=n,e.NetworkError=s,e.PrimerError=i,e.SDK_VERSION=P,e.ValidationError=r,e.configure=Ye,e.createCheckout=$e,e.createClientSession=Ge,e.default=vt,e.getAvailablePaymentMethods=ut,e.mountWalletUpsell=bt,Object.defineProperty(e,"__esModule",{value:!0})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FunnelfoxSDK={})}(this,function(e){"use strict";class t{constructor(){this._events=new Map}on(e,t){if("function"!=typeof t)throw new Error("Event handler must be a function");return this._events.has(e)||this._events.set(e,[]),this._events.get(e).push(t),this}once(e,t){if("function"!=typeof t)throw new Error("Event handler must be a function");const n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}off(e,t=null){if(!this._events.has(e))return this;if(null===t)return this._events.delete(e),this;const n=this._events.get(e),r=n.indexOf(t);return-1!==r&&(n.splice(r,1),0===n.length&&this._events.delete(e)),this}emit(e,...t){if(!this._events.has(e))return!1;const n=this._events.get(e).slice();for(const r of n)try{r.apply(this,t)}catch(t){console.warn(`Error in event handler for "${String(e)}":`,t)}return!0}listenerCount(e){return this._events.has(e)?this._events.get(e).length:0}eventNames(){return Array.from(this._events.keys())}removeAllListeners(){return this._events.clear(),this}listeners(e){return this._events.has(e)?this._events.get(e).slice():[]}}class n extends Error{constructor(e,t=N.SDK_ERROR,r=null){super(e),this.name="FunnefoxSDKError",this.code=t,this.details=r,Error.captureStackTrace&&Error.captureStackTrace(this,n)}}class r extends n{constructor(e,t,n=null){super(`Invalid ${e}: ${t}`,N.VALIDATION_ERROR),this.name="ValidationError",this.field=e,this.value=n}}class o extends n{constructor(e,t=null,n={}){super(e,n.errorCode||N.API_ERROR),this.name="APIError",this.statusCode=t,this.errorCode=n.errorCode||null,this.errorType=n.errorType||null,this.requestId=n.requestId||null,this.response=n.response||null,this.declineCode=n.declineCode||null,this.declineCodeSource=n.declineCodeSource||null}}class i extends n{constructor(e,t=null){super(e,N.PRIMER_ERROR),this.name="PrimerError",this.primerError=t}}class a extends n{constructor(e,t=null){super(e,N.CHECKOUT_ERROR),this.name="CheckoutError",this.phase=t}}class s extends n{constructor(e,t=null){super(e,N.NETWORK_ERROR),this.name="NetworkError",this.originalError=t}}function d(e){const{id:t,src:n,async:r=!0,type:o="text/javascript",attributes:i={},integrity:a,crossOrigin:s,appendTo:d="body"}=e;return new Promise((e,l)=>{let c=null;if(t&&(c=document.getElementById(t)),c||(c=document.querySelector(`script[src="${n}"]`)),c)return void e(c);const u=document.createElement("script");t&&(u.id=t),u.type=o,u.src=n,r&&(u.async=!0),a&&(u.integrity=a),s&&(u.crossOrigin=s),Object.entries(i).forEach(([e,t])=>{u.setAttribute(e,t)}),u.onload=()=>e(u),u.onerror=()=>l(new Error(`Failed to load script: ${n}`));("head"===d?document.head:document.body).appendChild(u)})}function l(e){const{href:t,integrity:n,crossOrigin:r}=e;return new Promise((e,o)=>{const i=document.querySelector(`link[href="${t}"]`);if(i)return void e(i);const a=document.createElement("link");a.rel="stylesheet",a.href=t,n&&(a.integrity=n),r&&(a.crossOrigin=r),a.onload=()=>e(a),a.onerror=()=>o(new Error(`Failed to load stylesheet: ${t}`)),document.head.appendChild(a)})}const c="https://sdk.primer.io/web",u={"2.57.3":{js:"sha384-xq2SWkYvTlKOMpuXQUXq1QI3eZN7JiqQ3Sc72U9wY1IE30MW3HkwQWg/1n6BTMz4"}};let h=null,p=!1;async function m(e){if(p)return;if(h)return h;if("undefined"!=typeof window&&window.Primer&&"function"==typeof window.Primer.createHeadless)return void(p=!0);const t=e||"2.57.3",n=`${c}/v${t}/Primer.min.js`,r=`${c}/v${t}/Checkout.css`,o=u[t];return h=(async()=>{try{await Promise.all([l({href:r,integrity:o?.css,crossOrigin:"anonymous"}),d({src:n,integrity:o?.js,crossOrigin:"anonymous",appendTo:"head"})]),await function(e=1e4){return new Promise((t,n)=>{const r=Date.now(),o=()=>{"undefined"!=typeof window&&window.Primer&&"function"==typeof window.Primer.createHeadless?t():Date.now()-r>e?n(new Error("Timeout waiting for Primer SDK to initialize on window")):setTimeout(o,50)};o()})}(),p=!0}catch(e){throw h=null,e}})(),h}const y=new Set(["cardInvalid"]),f=new Set(["cardRequired","expiryRequired","cvvRequired"]);function C(e){return{...w(e),...g(e.tax_breakdown)}}function g(e){if(!Array.isArray(e))return{};const t=e.map(e=>({amount:e.amount,percentage:e.percentage,inclusive:e.inclusive,taxType:e.tax_type,country:e.country,subdivision:e.subdivision,taxabilityReason:e.taxability_reason})),n=t.map(e=>Number(e.percentage));if(!n.length||!n.every(Number.isFinite))return{taxBreakdown:t};return{taxBreakdown:t,taxRate:Number(n.reduce((e,t)=>e+t,0).toFixed(6))}}function w(e){const t=e.tax_behavior??((e.tax_amount??0)>0?"exclusive":void 0);return"inclusive"===t?{taxBehavior:t,taxAmount:e.tax_inclusive_amount??0}:"exclusive"===t?{taxBehavior:t,taxAmount:e.tax_amount??0}:{taxAmount:0}}function S(...e){const t={};for(const n of e)if(n&&"object"==typeof n)for(const e in n)Object.prototype.hasOwnProperty.call(n,e)&&("object"!=typeof n[e]||Array.isArray(n[e])||null===n[e]?t[e]=n[e]:t[e]=S(t[e]||{},n[e]));return t}function E(e=""){return`${e}${Date.now().toString(36)}_${Math.random().toString(36).substr(2,5)}`}function b(e){return new Promise(t=>setTimeout(t,e))}function v(e,t,n="Operation timed out"){const r=new Promise((e,r)=>{setTimeout(()=>r(new Error(n)),t)});return Promise.race([e,r])}var _;e.PaymentMethod=void 0,(_=e.PaymentMethod||(e.PaymentMethod={})).GOOGLE_PAY="GOOGLE_PAY",_.APPLE_PAY="APPLE_PAY",_.PAYPAL="PAYPAL",_.PAYMENT_CARD="PAYMENT_CARD";const P="0.8.0-ffb-805.56",M={BASE_URL:"https://billing.funnelfox.com",REGION:"default",SANDBOX:!1,REQUEST_TIMEOUT:3e4,RETRY_ATTEMPTS:3,RETRY_BASE_DELAY:1e3},I={SUCCESS:"success",ERROR:"error",STATUS_CHANGE:"status-change",DESTROY:"destroy",INPUT_ERROR:"input-error",LOADER_CHANGE:"loader-change",METHOD_RENDER:"method-render",METHOD_RENDER_ERROR:"method-render-error",START_PURCHASE:"start-purchase",PURCHASE_FAILURE:"purchase-failure",PURCHASE_COMPLETED:"purchase-completed",PURCHASE_CANCELLED:"purchase-cancelled",METHODS_AVAILABLE:"methods-available",TAX_CHANGE:"tax-change",TAX_PENDING:"tax-pending"},k="/v1/checkout/create_client_session",T="/v1/checkout/update_client_session",R="/v1/checkout/create_payment",A="/v1/checkout/resume_payment",x="/v1/checkout/one_click",D="/v1/checkout/one_click_wallet_session",L="/v1/checkout/create_simple_client_session",O="/v1/checkout/recalculate_tax",N={SDK_ERROR:"SDK_ERROR",VALIDATION_ERROR:"VALIDATION_ERROR",API_ERROR:"API_ERROR",PRIMER_ERROR:"PRIMER_ERROR",CHECKOUT_ERROR:"CHECKOUT_ERROR",CONFIGURATION_ERROR:"CONFIGURATION_ERROR",NETWORK_ERROR:"NETWORK_ERROR"},U="MANUAL",q="2.4",F=[...[e.PaymentMethod.GOOGLE_PAY,e.PaymentMethod.APPLE_PAY,e.PaymentMethod.PAYPAL],...[e.PaymentMethod.PAYMENT_CARD]],z={input:{error:{borderColor:"rgb(227, 47, 65)"},base:{borderWidth:"1px",borderStyle:"solid",borderColor:"rgb(0 0 0 / 10%)",height:"36px",paddingHorizontal:10,borderRadius:"6px"}}};z.input.base.paddingHorizontal,z.input.base.paddingHorizontal;const j=[e.PaymentMethod.APPLE_PAY,e.PaymentMethod.GOOGLE_PAY,e.PaymentMethod.PAYPAL,e.PaymentMethod.PAYMENT_CARD],H={[e.PaymentMethod.APPLE_PAY]:{buttonStyle:"black",buttonType:"continue"},[e.PaymentMethod.PAYPAL]:{buttonColor:"gold",buttonShape:"pill",buttonLabel:"pay",buttonSize:"large",buttonHeight:54,paymentFlow:"PREFER_VAULT"},[e.PaymentMethod.GOOGLE_PAY]:{buttonColor:"black",buttonSizeMode:"fill",buttonType:"pay"}},Y={requiredBillingContactFields:["emailAddress"]},B={requiredShippingContactFields:["emailAddress"]};function V(e){if("string"!=typeof e)return!1;return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}const $=["plain","buy","set-up","donate","check-out","book","subscribe"];async function G(e,t){if(!await async function(){if("undefined"==typeof window||!window.customElements)return!1;if(window.customElements.get("apple-pay-button"))return!0;try{await d({src:"https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js",crossOrigin:"anonymous",appendTo:"head"});const e=window.customElements.whenDefined("apple-pay-button").then(()=>!0),t=new Promise(e=>{setTimeout(()=>e(!1),4e3)});return await Promise.race([e,t])}catch{return!1}}())return null;if(!e.querySelector("button"))return null;const n=document.createElement("apple-pay-button");return n.setAttribute("type",t.buttonType),n.setAttribute("buttonstyle",t.buttonStyle||"black"),n.setAttribute("locale","undefined"!=typeof navigator&&navigator.language||"en-US"),n.style.cssText=["position:absolute","inset:0","width:100%","height:100%","--apple-pay-button-width:100%","--apple-pay-button-height:100%",`--apple-pay-button-border-radius:${t.borderRadius??28}px`,"display:block","cursor:pointer","z-index:1"].join(";"),e.style.position="relative",n.addEventListener("click",()=>{const t=e.querySelector("button");t?.click()}),e.appendChild(n),n}class Q{constructor(){this.isInitialized=!1,this.destroyCallbacks=[],this.currentHeadless=null,this.availableMethods=[],this.paymentMethodsInterfaces=[]}isPrimerAvailable(){return"undefined"!=typeof window&&window.Primer&&"function"==typeof window.Primer?.createHeadless}async ensurePrimerLoaded(e){if(!this.isPrimerAvailable())try{await m(e)}catch(e){throw new i("Failed to load Primer SDK",e)}}ensurePrimerAvailable(){if(!this.isPrimerAvailable())throw new i("Primer SDK not found. Please include the Primer SDK script before initializing FunnefoxSDK.")}async createHeadlessCheckout(e,t,n){return await this.ensurePrimerLoaded(),this.applePayOptions=t.applePay,this.currentHeadless=Q.headlessManager.getOrCreate(e,t,n),this.currentHeadless}disableButtons(e){if(this.paymentMethodsInterfaces)for(const t of this.paymentMethodsInterfaces)t.setDisabled(e)}async renderButton(t,{htmlNode:n,onMethodRenderError:r,onMethodRender:o}){let a;if(await this.ensurePrimerLoaded(),!this.currentHeadless)throw new i("Headless checkout not found");try{const r=await this.currentHeadless,i=await r.createPaymentMethodManager(t);if(!i)throw new Error("Payment method manager is not available");const d=document.createElement("div");d.className=E("funnefox-primer-button-wrapper");const l=document.createElement("style");document.head.appendChild(l);const c=l.sheet;c&&(c.insertRule(`\n .${d.className} {\n width: 100% !important;\n }\n `),c.insertRule(`\n .${d.className} button {\n height: 54px !important;\n border-radius: 28px !important;\n }\n `)),n.appendChild(d);const u=this.applePayOptions,h=t===e.PaymentMethod.APPLE_PAY&&u?.buttonType&&((s=u.buttonType)&&!$.includes(s))?u.buttonType:null;let p=null;h&&c&&(p=c.insertRule(`\n .${d.className} > button {\n opacity: 0 !important;\n }\n `)),a=i.createButton(),await a.render(d,{});let m=null;return h&&(m=await G(d,{buttonType:h,buttonStyle:u?.buttonStyle}),!m&&c&&null!==p&&c.deleteRule(p)),this.destroyCallbacks.push(()=>{m?.remove(),a.clean()}),o(t),{setDisabled:e=>{a.setDisabled(e),m&&(m.style.pointerEvents=e?"none":"",m.style.opacity=e?"0.5":"")},destroy:()=>{l.remove(),m?.remove(),a.clean()}}}catch(e){throw r(t),new i(`Failed to initialize Primer checkout method ${t}`,e)}var s}async initMethod(t,n,r){try{if(t===e.PaymentMethod.PAYMENT_CARD){if(!r.cardElements||!r.onSubmit||!r.onInputChange)throw new i("Card elements, onSubmit, and onInputChange are required for PAYMENT_CARD method");const e=await this.renderCardCheckoutWithElements(r.cardElements,{onSubmit:r.onSubmit,onInputChange:r.onInputChange,onMethodRenderError:r.onMethodRenderError,onMethodRender:r.onMethodRender,onCardInputValueChange:r.onCardInputValueChange,isCardholderNameRequired:r.isCardholderNameRequired,isPostalCodeRequired:r.isPostalCodeRequired});return this.paymentMethodsInterfaces.push(e),e}{const e=await this.renderButton(t,{htmlNode:n,onMethodRenderError:r.onMethodRenderError,onMethodRender:r.onMethodRender});return this.paymentMethodsInterfaces.push(e),e}}catch(e){throw new i(`Failed to initialize Primer checkout method ${t}`,e)}}async renderCardCheckoutWithElements(t,{onSubmit:n,onInputChange:r,onCardInputValueChange:o,isCardholderNameRequired:a,isPostalCodeRequired:s,onMethodRenderError:d,onMethodRender:l}){try{if(!this.currentHeadless)throw new i("Headless checkout not found");const d=await this.currentHeadless,c=await d.createPaymentMethodManager("PAYMENT_CARD");if(!c)throw new Error("Payment method manager is not available");const u=!!t.emailAddress,{cardNumberInput:h,expiryInput:p,cvvInput:m}=c.createHostedInputs(),C=async()=>{if(!c)return!1;const{valid:e,validationErrors:n}=await c.validate(),r=a?.()?n.find(e=>"cardholderName"===e.name)?.message:null;g("cardholderName",r);let o=null;if(u){const e=t.emailAddress?.value?.trim();o=V(e)?null:"Please enter a valid email address",g("emailAddress",o)}const i=w();return g("postalCode",i),e&&!o&&!r&&!i},g=(e,t)=>{r(e,t)},w=()=>{const e=t.postalCode?.value?.trim();return s?.()&&!e?"Please enter a postal code":null},S=new Set,E=e=>t=>{const n=t,r=n.active&&!S.has(e);n.active?S.add(e):S.delete(e),r||g(e,function(e){return e.error?e.errorCode&&y.has(e.errorCode)?e.error:e.active?null:e.submitted?e.error:e.errorCode&&f.has(e.errorCode)?null:e.touched?e.error:null:null}(n))},b=async e=>{c.setCardholderName(e.target.value),g("cardholderName",null)};let v;u&&(v=e=>{const t=e.target.value.trim();o?.("emailAddress",t),g("emailAddress",t&&!V(t)?"Please enter a valid email address":null)},t.emailAddress.addEventListener("input",v));const _=e=>{const t=e.target.value.trim();o?.("countryCode",t),s?.()||g("postalCode",null)},P=e=>{const t=e.target.value.trim();o?.("postalCode",t),g("postalCode",w())};t.cardholderName?.addEventListener("input",b),t.emailAddress?.addEventListener("input",v),t.countrySelector?.addEventListener("change",_),t.postalCode?.addEventListener("input",P),h.addEventListener("change",E("cardNumber")),p.addEventListener("change",E("expiryDate")),m.addEventListener("change",E("cvv"));const M=async()=>{if(await C())try{n(!0),await c.submit()}catch(e){throw new i("Failed to submit payment",e)}finally{n(!1)}};t.button?.addEventListener("click",M),await Promise.all([h.render(t.cardNumber,{placeholder:"1234 1234 1234 1234",ariaLabel:"Card number",style:z}),p.render(t.expiryDate,{placeholder:"MM/YY",ariaLabel:"Expiry date",style:z}),m.render(t.cvv,{placeholder:"123",ariaLabel:"CVV",style:z})]);const I=()=>{c.removeHostedInputs(),t.cardholderName?.removeEventListener("input",b),t.emailAddress?.removeEventListener("input",v),t.countrySelector?.removeEventListener("change",_),t.postalCode?.removeEventListener("input",P),t.button?.removeEventListener("click",M)};return this.destroyCallbacks.push(I),l(e.PaymentMethod.PAYMENT_CARD),{setDisabled:e=>{h.setDisabled(e),p.setDisabled(e),m.setDisabled(e),t.button&&(t.button.disabled=e),t.cardholderName&&(t.cardholderName.disabled=e),t.emailAddress&&(t.emailAddress.disabled=e),t.countrySelector&&(t.countrySelector.disabled=e),t.postalCode&&(t.postalCode.disabled=e)},submit:()=>M(),destroy:()=>{this.destroyCallbacks=this.destroyCallbacks.filter(e=>e!==I),I()}}}catch(t){throw d(e.PaymentMethod.PAYMENT_CARD),new i("Failed to initialize Primer checkout method PAYMENT_CARD",t)}}async initializeHeadlessCheckout(e,t,n){await this.createHeadlessCheckout(e,{...t,onTokenizeSuccess:this.wrapTokenizeHandler(t.onTokenizeSuccess),onResumeSuccess:this.wrapResumeHandler(t.onResumeSuccess),onAvailablePaymentMethodsLoad:this.wrapAvailablePaymentMethodsLoadHandler(t.onAvailablePaymentMethodsLoad)},n)}async renderCheckout(t,n,r){const{cardElements:o,paymentButtonElements:i,container:a,onSubmit:s,onInputChange:d,onMethodRender:l,onMethodRenderError:c,onMethodsAvailable:u,onCardInputValueChange:h,isCardholderNameRequired:p,isPostalCodeRequired:m}=r;await this.initializeHeadlessCheckout(t,n),u?.(this.availableMethods),await Promise.all(this.availableMethods.map(t=>{if(t===e.PaymentMethod.PAYMENT_CARD)return this.initMethod(t,a,{cardElements:o,onSubmit:s,onInputChange:d,onMethodRender:l,onMethodRenderError:c,onCardInputValueChange:h,isCardholderNameRequired:p,isPostalCodeRequired:m});{const n={[e.PaymentMethod.PAYPAL]:i.paypal,[e.PaymentMethod.GOOGLE_PAY]:i.googlePay,[e.PaymentMethod.APPLE_PAY]:i.applePay}[t];return this.initMethod(t,n,{onMethodRender:l,onMethodRenderError:c})}})),this.isInitialized=!0}wrapTokenizeHandler(e){return async(t,n)=>{try{await e(t,n)}catch(e){console.error("Error in tokenize handler:",e),n.handleFailure("Payment processing failed. Please try again.")}}}wrapResumeHandler(e){return async(t,n)=>{try{await e(t,n)}catch(e){console.error("Error in resume handler:",e),n.handleFailure("Payment processing failed. Please try again.")}}}wrapAvailablePaymentMethodsLoadHandler(t){return n=>{let r=!1;if(this.availableMethods=F.filter(t=>n.some(n=>(n.type===e.PaymentMethod.APPLE_PAY&&(r=!0),n.type===t))),r&&(this.availableMethods=this.availableMethods.filter(t=>t!==e.PaymentMethod.GOOGLE_PAY)),0===this.availableMethods.length)throw new i("No allowed payment methods found");t?.(this.availableMethods)}}async destroy(){if(this.currentHeadless&&(Q.headlessManager.remove(this.currentHeadless),this.currentHeadless=null),this.destroyCallbacks)try{Promise.all(this.destroyCallbacks.map(e=>e()))}catch(e){console.warn("Error destroying Primer checkout:",e)}this.destroyCallbacks=[],this.isInitialized=!1}createHandlers(e){return{handleSuccess:()=>{e.onSuccess&&e.onSuccess()},handleFailure:t=>{e.onError&&e.onError(new Error(t))},continueWithNewClientToken:t=>{e.onActionRequired&&e.onActionRequired(t)}}}getCurrentCheckout(){return this.destroyCallbacks}isActive(){return this.isInitialized&&this.destroyCallbacks.length>0}validateContainer(e){const t=document.querySelector(e);if(!t)throw new i(`Checkout container not found: ${e}`);return"none"===window.getComputedStyle(t).display&&console.warn("Checkout container is hidden, this may cause display issues"),t}refreshClientSession(){return this.currentHeadless?.then(e=>e.refreshClientSession())}}Q.headlessManager=new class{constructor(){this.cache=new Map,this.queue=Promise.resolve()}generateKey(e,t,n){const r={paymentHandling:t.paymentHandling,apiVersion:t.apiVersion,style:t.style,card:t.card,applePay:t.applePay,paypal:t.paypal,googlePay:t.googlePay};return`${e}:${n||"default"}:${JSON.stringify(r)}`}getOrCreate(e,t,n){const r=this.generateKey(e,t,n),o=this.cache.get(r);if(o)return o;const a=this.queue,s=(async()=>{await a;const n=S({paymentHandling:"MANUAL",apiVersion:"2.4"},t);try{const t=await window.Primer.createHeadless(e,n),r=await t;return await r.start(),r}catch(e){throw this.cache.delete(r),new i("Failed to create Primer headless checkout",e)}})();return this.cache.set(r,s),this.queue=s.catch(()=>{}),s}remove(e){for(const[t,n]of this.cache.entries())if(n===e){this.cache.delete(t);break}}clear(){this.cache.clear()}};function W(e){const t=new Error(e?.message||"Payment processing failed");if(e instanceof o)e.declineCode&&(t.declineCode=e.declineCode),e.declineCodeSource&&(t.declineCodeSource=e.declineCodeSource);else if(e instanceof Error){const n=function(e){const{type:t,code:n}=e;return"card_error"===t&&"string"==typeof n&&n?n.toUpperCase():null}(e);n&&(t.declineCode=n,t.declineCodeSource="stripe")}return t}class K{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.orgId=e.orgId,this.timeout=e.timeout||3e4,this.retryAttempts=e.retryAttempts||3}async request(e,t={}){const n=`${this.baseUrl}/${this.orgId}${e}`,r={method:"GET",headers:{"Content-Type":"application/json","X-SDK-Version":P,...t.headers||{}},...t};try{return await async function(e,t=3,n=1e3){let r;for(let o=1;o<=t;o++)try{return await e()}catch(e){if(r=e,o===t)throw r;const i=n*Math.pow(2,o-1);await b(i)}throw r}(async()=>await v(this._makeRequest(n,r),this.timeout,"Request timed out"),this.retryAttempts)}catch(e){if(e instanceof Error&&"APIError"===e.name)throw e;throw new s("Network request failed",e)}}async requestOnce(e,t={},n){const r=`${this.baseUrl}/${this.orgId}${e}`,i={method:"GET",headers:{"Content-Type":"application/json","X-SDK-Version":P,...t.headers||{}},...t};try{const e=this._makeRequest(r,i);return await(n?v(e,n,"Request timed out"):e)}catch(e){if(e instanceof o)throw e.errorCode??(e.errorCode=Z(e.response)[0]??null),e;if(e instanceof Error&&"NetworkError"===e.name)throw e;throw new s("Network request failed",e)}}async _makeRequest(e,t){let n,r;try{n=await fetch(e,t)}catch(e){if(e instanceof Error&&"NetworkError"===e.name)throw e;throw new s("Network request failed",e)}try{r=await n.json()}catch{throw new o("Invalid JSON response",n.status,{})}if(!n.ok){const e=r,t=e.error?.[0]?.msg||"Failed to create payment";throw new o(t,n.status,{response:r})}return r}async createClientSession(e){const t={region:e.region||"default",integration_type:e.integration??"primer",pp_ident:e.priceId,external_id:e.externalId,email_address:e.email,client_metadata:e.clientMetadata||{}};return void 0!==e.countryCode&&(t.country_code=e.countryCode),e.displayCurrency&&(t.display_currency_code=e.displayCurrency),e.displayCountry&&(t.display_country_code=e.displayCountry),await this.request(k,{method:"POST",body:JSON.stringify(t)})}async updateClientSession(e){const t={order_id:e.orderId,client_token:e.clientToken,pp_ident:e.priceId,client_metadata:e.clientMetadata||{}};return e.displayCurrency&&(t.display_currency_code=e.displayCurrency),e.displayCountry&&(t.display_country_code=e.displayCountry),await this.request(T,{method:"POST",body:JSON.stringify(t)})}async createPayment(e){const t={order_id:e.orderId,payment_method_token:e.paymentMethodToken,client_metadata:e.clientMetadata||{}};return void 0!==e.email&&(t.email_address=e.email),void 0!==e.countryCode&&(t.country_code=e.countryCode),void 0!==e.postalCode&&(t.postal_code=e.postalCode),void 0!==e.subdivision&&(t.subdivision=e.subdivision),void 0!==e.taxCalculationId&&(t.tax_calculation_id=e.taxCalculationId),await this.request(R,{method:"POST",body:JSON.stringify(t)})}async recalculateTax(e){const t={order_id:e.orderId,client_token:e.clientToken,country_code:e.countryCode};e.postalCode&&(t.postal_code=e.postalCode),e.subdivision&&(t.subdivision=e.subdivision);const n=await this.request(O,{method:"POST",body:JSON.stringify(t)});if("error"===n.status||!n.data){const e=n.error?.[0];throw new o(e?.msg||"Tax recalculation failed",null,{errorCode:e?.code,errorType:e?.type,requestId:n.req_id,response:n})}return n.data}async resumePayment(e){const t={order_id:e.orderId,resume_token:e.resumeToken};return await this.request(A,{method:"POST",body:JSON.stringify(t)})}processSessionResponse(e){if("error"===e.status){const t=e.error?.[0];throw new o(t?.msg||"Session creation failed",null,{errorCode:t?.code,errorType:t?.type,requestId:e.req_id,response:e})}const t=e.data;return{type:"session_created",orderId:t.order_id,clientToken:t.client_token}}processPaymentResponse(e){if("error"===e.status){const t=e.error?.[0];throw new o(t?.msg||"Payment request failed",null,{errorCode:t?.code,errorType:t?.type,response:e})}const t=e.data;if(t.action_required_token)return{type:"action_required",orderId:t.order_id,clientToken:t.action_required_token};if(t.checkout_status)switch(t.checkout_status){case"succeeded":return{type:"success",orderId:t.order_id,status:"succeeded"};case"failed":throw new o(t.failed_message_for_user||"Payment failed",null,{response:e,declineCode:t.decline_code,declineCodeSource:t.decline_code_source});case"cancelled":throw new o("Payment was cancelled by user",null,{response:e});case"processing":return{type:"processing",orderId:t.order_id,status:"processing"};default:throw new o(`Unhandled checkout status: ${t.checkout_status}`,null,{response:e})}throw new o("Invalid payment response format",null,{response:e})}async oneClick(e){return await this.request(x,{method:"POST",body:JSON.stringify(e)})}async oneClickOnce(e,t){return await this.requestOnce(x,{method:"POST",body:JSON.stringify(e)},t)}async oneClickWalletSession(e,t){return await this.requestOnce(D,{method:"POST",body:JSON.stringify(e)},t)}async resumePaymentOnce(e){return await this.requestOnce(A,{method:"POST",body:JSON.stringify({order_id:e.orderId,resume_token:e.resumeToken})})}async createSimpleClientSession(e){return await this.request(L,{method:"POST",body:JSON.stringify({region:"default",integration_type:"primer",...e})})}}function Z(e){const t=e?.error;return Array.isArray(t)?t.map(e=>e?.code).filter(e=>"string"==typeof e):[]}var J=new class{constructor(){this.cache=new Map}buildCacheKey(e){return[e.orgId,e.baseUrl||M.BASE_URL,e.region||M.REGION,e.countryCode??"",e.displayCurrency??"",e.displayCountry??"",e.priceId,e.externalId,e.email,e.integration].join("|")}makeClient(e,t){return new K({baseUrl:t||M.BASE_URL,orgId:e,timeout:M.REQUEST_TIMEOUT,retryAttempts:M.RETRY_ATTEMPTS})}createSession(e){const t=this.buildCacheKey(e),n=this.cache.get(t);if(n)return n;const r=this.makeClient(e.orgId,e.baseUrl).createClientSession({priceId:e.priceId,externalId:e.externalId,email:e.email,region:e.region||M.REGION,clientMetadata:e.clientMetadata,countryCode:e.countryCode,displayCurrency:e.displayCurrency,displayCountry:e.displayCountry,integration:e.integration});this.cache.set(t,r);const o=()=>{this.cache.get(t)===r&&this.cache.delete(t)};return r.then(e=>{e&&"error"!==e.status&&e.data||o()},o),r}invalidate(e){this.cache.delete(this.buildCacheKey(e))}clearCache(){this.cache.clear()}};"undefined"!=typeof document&&(document.head.appendChild(document.createElement("style")).textContent=".ff-sdk-loader-container {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n background-color: rgba(255, 255, 255);\n z-index: 2;\n}\n\n.ff-sdk-loader {\n width: 24px;\n height: 24px;\n border: 4px solid #e32f41;\n border-top: 4px solid transparent;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n}\n\n@keyframes spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n }");const X='<div class="ff-sdk-loader-container">\n <div class="ff-sdk-loader"></div>\n</div>\n',ee={loaderContainer:".ff-sdk-loader-container"};var te,ne="https://js.stripe.com/v3",re=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,oe=function(e){var t=document.createElement("script");t.src="".concat(ne).concat("");var n=document.head||document.body;if(!n)throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");return n.appendChild(t),t},ie=null,ae=null,se=null,de=function(e){return null!==ie?ie:(ie=new Promise(function(t,n){if("undefined"!=typeof window&&"undefined"!=typeof document)if(window.Stripe)t(window.Stripe);else try{var r=function(){for(var e=document.querySelectorAll('script[src^="'.concat(ne,'"]')),t=0;t<e.length;t++){var n=e[t];if(re.test(n.src))return n}return null}();if(r&&e);else if(r){if(r&&null!==se&&null!==ae){var o;r.removeEventListener("load",se),r.removeEventListener("error",ae),null===(o=r.parentNode)||void 0===o||o.removeChild(r),r=oe()}}else r=oe();se=function(e,t){return function(){window.Stripe?e(window.Stripe):t(new Error("Stripe.js not available"))}}(t,n),ae=function(e){return function(){e(new Error("Failed to load Stripe.js"))}}(n),r.addEventListener("load",se),r.addEventListener("error",ae)}catch(e){return void n(e)}else t(null)})).catch(function(e){return ie=null,Promise.reject(e)})},le=!1,ce=function(){return te||(te=de(null).catch(function(e){return te=null,Promise.reject(e)}))};Promise.resolve().then(function(){return ce()}).catch(function(e){le||console.warn(e)});var ue=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];le=!0;var r=Date.now();return ce().then(function(e){return function(e,t,n){if(null===e)return null;var r=e.apply(void 0,t);return function(e,t){e&&e._registerWrapper&&e._registerWrapper({name:"stripe-js",version:"4.6.0",startTime:t})}(r,n),r}(e,t,r)})};"undefined"!=typeof document&&(document.head.appendChild(document.createElement("style")).textContent=".ff-sdk-error-container {\n background-color: #d1000033;\n color: #d10000;\n font-size: 14px;\n padding: 16px 12px;\n border-radius: 8px;\n}");const he='<div class="ff-sdk-error-container">\n <p class="ff-sdk-error-message">The payment form didn’t load correctly.</p>\n <p>Please refresh the page to try again.</p>\n <p>If the problem persists, please contact support.</p>\n <p class="ff-sdk-error-request-id"></p>\n</div>\n',pe={errorRequestId:".ff-sdk-error-request-id"};function me(e,t){if("undefined"==typeof document)return;const n=new URLSearchParams({message:ye(t.message,500),code:t.code||"SDK_ERROR",timestamp:Date.now().toString(),sdk_version:P});t.req_id&&fe(n,"req_id",t.req_id,1800),t.context&&Object.entries(t.context).forEach(([e,t])=>{null!=t&&fe(n,e,ye(String(t),1e3),1800)});const r=`${(t.baseUrl||M.BASE_URL).replace(/\/$/,"")}/sdk_report/${encodeURIComponent(e)}/crash?${n.toString()}`,o=new Image;o.src=r,o.style.display="none",o.onload=()=>{o.remove()},o.onerror=()=>{o.remove()},(document.body||document.documentElement)?.appendChild(o)}function ye(e,t){return e.length>t?e.slice(0,t):e}function fe(e,t,n,r){const o=new URLSearchParams(e);return o.append(t,n),!(o.toString().length>r)&&(e.append(t,n),!0)}let Ce=null;const ge=new Map,we=3e3;let Se=!1;function Ee(e){return e.enabled&&"undefined"!=typeof window&&"undefined"!=typeof document?(Ce=e,function(){if(Se||"undefined"==typeof window)return;window.addEventListener("error",be),window.addEventListener("unhandledrejection",ve),Se=!0}(),()=>{var t;t=e.id,Ce?.id===t&&(Ce=null,ge.clear(),Se&&"undefined"!=typeof window&&(window.removeEventListener("error",be),window.removeEventListener("unhandledrejection",ve),Se=!1))}):()=>{}}function be(e){_e(Pe(e.error||e.message||"Unhandled browser error","UNHANDLED_ERROR"),{event_type:"error",filename:e.filename,lineno:e.lineno,colno:e.colno})}function ve(e){_e(Pe(e.reason||"Unhandled promise rejection","UNHANDLED_REJECTION"),{event_type:"unhandledrejection"})}function _e(e,t){if(Ce&&function(e,t){const n=Date.now();!function(e){ge.forEach((t,n)=>{e-t>=we&&ge.delete(n)})}(n);const r=function(e,t){const n=e.stack?.split("\n")[0]||"";return[t||"",e.code||"",e.message||"",n].join("|")}(e,t),o=ge.get(r);if("number"==typeof o&&n-o<we)return!1;return ge.set(r,n),!0}(e,t.event_type))try{const n=Ce.getContext();me(Ce.orgId,{baseUrl:Ce.baseUrl,message:`${e.name}: ${e.message}`,code:e.code,context:{...t,order_id:n.orderId,price_id:n.priceId,page_url:Te()}})}catch{}}function Pe(e,t){if(e instanceof Error)return{name:e.name||"Error",message:e.message||"Unknown error",code:Me(e,t),stack:e.stack};if("object"==typeof e&&null!==e){const n=e;return{name:Ie(n.name)||"Error",message:Ie(n.message)||ke(e),code:Ie(n.code)||t,stack:Ie(n.stack)}}return{name:"Error",message:Ie(e)||"Unknown error",code:t}}function Me(e,t){const n=e;return"string"==typeof n.code&&n.code?n.code:t}function Ie(e){return"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e?String(e):""}function ke(e){try{return JSON.stringify(e)}catch{return"Unserializable error"}}function Te(){if("undefined"==typeof window||!window.location)return"";const e=window.location;return e.origin&&e.pathname?`${e.origin}${e.pathname}`:(e.href||"").split(/[?#]/)[0]}class Re extends t{constructor(t){super(),this.counter=0,this.cachedSessionResponse=null,this.taxRecalcSeq=0,this.isApplePaySheetOpen=!1,this.cardSessionFieldConfig={},this.isTelemetryEnabled=!1,this.telemetryCleanup=null,this.handleInputChange=(e,t)=>{this.emit(I.INPUT_ERROR,{name:e,error:t})},this.getPaymentEmailAddress=()=>{if(this.cardEmailAddress?.trim()===this.checkoutConfig.customer.email)return;const e=this.cardEmailAddress?.trim()||this.checkoutConfig.customer.email;if(!e||!V(e))return;const t=this.checkoutConfig.card?.emailAddress?.template;return t?.includes("{{email}}")?t.replace(/\{\{email\}\}/g,e):e},this.handleCardInputValueChange=(e,t)=>{"emailAddress"!==e?("countryCode"===e?(this.cardCountryCode=this.normalizeCountryCode(t),this.isPostalCodeVisible()||(this.cardPostalCode=void 0)):"postalCode"===e&&(this.cardPostalCode=t?.trim()||void 0),this.isTaxEnabled()&&this.scheduleTaxRecalc()):this.cardEmailAddress=t?.trim()||void 0},this.isTaxEnabled=()=>this.cachedSessionResponse?.data?.tax_enabled??this.checkoutConfig.enableTax??!1,this.getSessionTaxInfo=()=>{const e=this.cachedSessionResponse?.data;if(e&&null!=e.amount_total)return{amountTotal:e.amount_total,currency:e.currency??"",...C(e)}},this.emitTaxInfo=e=>{this.lastTaxInfo=e,this.checkoutConfig.onTaxChange?.(e),this.emit(I.TAX_CHANGE,e)},this.emitSessionTaxEstimate=()=>{const e=this.getSessionTaxInfo();e&&this.emitTaxInfo(e)},this.runTaxRecalc=async()=>{const e=this.orderId,t=this.getSelectedCountryCode();if(!e||!t)return;const n=++this.taxRecalcSeq;try{const r=await this.apiClient.recalculateTax({orderId:e,clientToken:this.cachedSessionResponse?.data?.client_token??"",countryCode:t,postalCode:this.cardPostalCode});if(n!==this.taxRecalcSeq)return;this.emitTaxInfo({amountTotal:r.amount_total,currency:r.currency,...C(r)})}catch(e){if(n!==this.taxRecalcSeq)return;console.warn("[funnelfox-billing] tax recalculation failed",e),this.lastTaxInfo&&this.emit(I.TAX_CHANGE,this.lastTaxInfo),this.checkoutConfig.onTaxError?.(e)}},this.scheduleTaxRecalc=()=>{this.taxRecalcDebounce&&clearTimeout(this.taxRecalcDebounce),this.checkoutConfig.onTaxPending?.(),this.emit(I.TAX_PENDING),this.taxRecalcDebounce=setTimeout(this.runTaxRecalc,600)},this.flushTaxRecalc=async()=>{this.taxRecalcDebounce&&(clearTimeout(this.taxRecalcDebounce),this.taxRecalcDebounce=void 0),this.isTaxEnabled()&&await this.runTaxRecalc()},this.handleMethodRender=e=>{this.emit(I.METHOD_RENDER,e)},this.handleMethodRenderError=e=>{this.emit(I.METHOD_RENDER_ERROR,e)},this.handleSubmit=e=>{this.onLoaderChangeWithRace(e),this._setState(e?"processing":"ready")},this.handleTokenizeSuccess=async(t,n)=>{if(this.orderId)try{this.onLoaderChangeWithRace(!0),this._setState("processing"),this.activePaymentMethodType===e.PaymentMethod.PAYMENT_CARD&&await this.flushTaxRecalc();const[r,o]=await Promise.all([this.cachedSessionResponse?.radarSessionId,this.cachedSessionResponse?.airwallexDeviceId]),i=await this.apiClient.createPayment({orderId:this.orderId,paymentMethodToken:t.token,email:this.getPaymentEmailAddress(),countryCode:this.getPaymentCountryCode(),postalCode:this.getPaymentPostalCode(),clientMetadata:{radarSessionId:r,airwallexDeviceId:o}}),a=this.apiClient.processPaymentResponse(i);await this._processPaymentResult(a,n)}catch(e){this._setState("error"),this.emit(I.PURCHASE_FAILURE,W(e)),n.handleFailure(e?.message||"Payment processing failed")}finally{this.isApplePaySheetOpen=!1,this.onLoaderChangeWithRace(!1),this._setState("ready")}else n.handleFailure("Order ID not found or checkout has been destroyed")},this.handleResumeSuccess=async(e,t)=>{if(this.orderId)try{this.onLoaderChangeWithRace(!0),this._setState("processing");const n=await this.apiClient.resumePayment({orderId:this.orderId,resumeToken:e.resumeToken}),r=this.apiClient.processPaymentResponse(n);await this._processPaymentResult(r,t)}catch(e){this._setState("error"),this.emit(I.PURCHASE_FAILURE,W(e)),t.handleFailure(e?.message||"Payment processing failed")}finally{this.isApplePaySheetOpen=!1,this.emit(I.PURCHASE_COMPLETED),this.onLoaderChangeWithRace(!1),this._setState("ready")}else t.handleFailure("Order ID not found or checkout has been destroyed")},this.handleMethodsAvailable=e=>{this.emit(I.METHODS_AVAILABLE,e)},this.onLoaderChangeWithRace=e=>{const t=!!(e?++this.counter:--this.counter);this.primerWrapper.disableButtons(t),this.emit(I.LOADER_CHANGE,t)},this.id=E("checkout_"),this.orgId=t.orgId,this.baseUrl=t.baseUrl,this.region=t.region,this.checkoutConfig={...t.checkoutConfig},this.callbacks={onSuccess:this.checkoutConfig.onSuccess,onError:this.checkoutConfig.onError,onStatusChange:this.checkoutConfig.onStatusChange,onDestroy:this.checkoutConfig.onDestroy},delete this.checkoutConfig?.onSuccess,delete this.checkoutConfig?.onError,delete this.checkoutConfig?.onStatusChange,delete this.checkoutConfig?.onDestroy,this.state="initializing",this.orderId=null,this.clientToken=null,this.primerWrapper=new Q,this.isDestroyed=!1,this.cardEmailAddress=this.checkoutConfig.customer.email,this.shouldApplySessionCardholderNameConfig=void 0===this.checkoutConfig.card?.cardholderName?.required,this.apiClient=new K({baseUrl:this.baseUrl||M.BASE_URL,orgId:this.orgId,timeout:M.REQUEST_TIMEOUT,retryAttempts:M.RETRY_ATTEMPTS}),this._setupCallbackBridges()}_setupCallbackBridges(){this.callbacks.onSuccess&&this.on(I.SUCCESS,this.callbacks.onSuccess),this.callbacks.onError&&this.on(I.ERROR,this.callbacks.onError),this.callbacks.onStatusChange&&this.on(I.STATUS_CHANGE,this.callbacks.onStatusChange),this.callbacks.onDestroy&&this.on(I.DESTROY,this.callbacks.onDestroy)}removeAllListeners(){return super.removeAllListeners()}async initialize(){try{return this.showInitializingLoader(),this._setState("initializing"),await this.createSession(),await this._initializePrimerCheckout(),this._setState("ready"),this.isTaxEnabled()&&this.emitSessionTaxEstimate(),this.startUnhandledTelemetry(),this.checkoutConfig?.onInitialized?.(),this}catch(e){throw this._setState("error"),((e,t)=>{const n=document.querySelector(e);if(n&&(n.innerHTML=he,t)){const e=n.querySelector(pe.errorRequestId);e&&(e.textContent=`Request ID: ${t}`)}})(this.checkoutConfig.container,e?.response?.req_id),this.emit(I.ERROR,e),e}finally{this.hideInitializingLoader()}}async createSession(){const e=await J.createSession({orgId:this.orgId,baseUrl:this.baseUrl,priceId:this.checkoutConfig.priceId,externalId:this.checkoutConfig.customer.externalId,email:this.checkoutConfig.customer.email,region:this.region,clientMetadata:this.checkoutConfig.clientMetadata,countryCode:this.checkoutConfig.customer.countryCode,displayCurrency:this.checkoutConfig.displayCurrency,displayCountry:this.checkoutConfig.displayCountry,integration:"primer"}),t=e;if(e.data?.stripe_public_key&&!t.radarSessionId){const n=e.data.stripe_public_key;t.radarSessionId=ue(n).then(e=>e?e.createRadarSession().then(e=>e?.radarSession?.id||"").catch(()=>""):"").catch(()=>"")}if(e.data?.airwallex_risk_enabled&&!t.airwallexDeviceId){const n=e.data?.is_livemode,r="undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)});t.airwallexDeviceId=async function(e,t=!0){const n=t?"https://static.airwallex.com/webapp/fraud/device-fingerprint/index.js":"https://static-demo.airwallex.com/webapp/fraud/device-fingerprint/index.js";await d({id:"airwallex-fraud-api",src:n,async:!0,attributes:{"data-order-session-id":e}})}(r,n).then(()=>r).catch(()=>r)}this.cachedSessionResponse=t,this.isTelemetryEnabled=!!t.data?.sdk_telemetry_enabled,this.isCollectingApplePayEmail=!!t.data?.collect_apple_pay_email,this.applySessionCardFieldConfig(t);const n=this.apiClient.processSessionResponse(t);this.orderId=n.orderId,this.clientToken=n.clientToken}applySessionCardFieldConfig(e){const t={...this.checkoutConfig.card||{}};void 0===t.emailAddress?.visible&&void 0!==e.data?.show_email_field&&(t.emailAddress={...t.emailAddress,visible:e.data.show_email_field}),this.shouldApplySessionCardholderNameConfig&&void 0!==e.data?.show_cardholder_name_field&&(t.cardholderName={...t.cardholderName,required:e.data.show_cardholder_name_field});const n=this.normalizeCountryFieldOverrides(e.data?.country_field_overrides),r=this.normalizeCountryCode(e.data?.detected_country_code)||this.cardCountryCode;this.cardSessionFieldConfig={...this.cardSessionFieldConfig,showCountrySelector:e.data?.show_country_selector_field??this.cardSessionFieldConfig.showCountrySelector,showPostalCode:e.data?.show_postal_code_field??this.cardSessionFieldConfig.showPostalCode,detectedCountryCode:r||this.cardSessionFieldConfig.detectedCountryCode,validCountries:e.data?.valid_countries||this.cardSessionFieldConfig.validCountries,countryFieldOverrides:n||this.cardSessionFieldConfig.countryFieldOverrides},Object.keys(t).length>0&&(this.checkoutConfig.card=t),this.cardCountryCode=this.cardSessionFieldConfig.detectedCountryCode||this.cardCountryCode,this.isPostalCodeVisible()||(this.cardPostalCode=void 0)}getPrimerCardConfig(){const e={...this.checkoutConfig.card||{}};return delete e.emailAddress,Object.keys(e).length?e:void 0}mergeApplePayCollectingEmailOptions(e){if(!this.isCollectingApplePayEmail)return e;return S(e,{applePay:{billingOptions:{requiredBillingContactFields:Array.from(new Set([...e.applePay?.billingOptions?.requiredBillingContactFields||[],...Y?.requiredBillingContactFields||[]]))},shippingOptions:{requiredShippingContactFields:Array.from(new Set([...e.applePay?.shippingOptions?.requiredShippingContactFields||[],...B?.requiredShippingContactFields||[]]))}}})}convertCardSelectorsToElements(e,t){const n=t.querySelector(e.cardNumber),r=t.querySelector(e.expiryDate),o=t.querySelector(e.cvv),i=e.cardholderName?t.querySelector(e.cardholderName):void 0,s=e.emailAddress?t.querySelector(e.emailAddress):void 0,d=t.querySelector(e.button);if(!(n&&r&&o&&d))throw new a("Required card input elements not found in container");return{cardNumber:n,expiryDate:r,cvv:o,cardholderName:i,emailAddress:s,button:d}}convertPaymentButtonSelectorsToElements(e){const t=document.querySelector(e.paypal),n=document.querySelector(e.googlePay),r=document.querySelector(e.applePay);if(!t||!n||!r)throw new a("Required payment button elements not found in container");return{paypal:t,googlePay:n,applePay:r}}async _initializePrimerCheckout(){const e=this.getContainer();if(!e)throw new a(`Checkout container not found: ${this.checkoutConfig.container}`);let t,n,r;if(this.checkoutConfig.cardSelectors&&this.checkoutConfig.paymentButtonSelectors)this.checkoutConfig.paymentMethodOrder&&console.warn("paymentMethodOrder is using only for default skin and will be ignored if you are using custom checkout"),t=this.convertCardSelectorsToElements(this.checkoutConfig.cardSelectors,e),n=this.convertPaymentButtonSelectorsToElements(this.checkoutConfig.paymentButtonSelectors),r=this.getCheckoutOptions({});else{this.checkoutConfig.paymentMethodOrder=this.checkoutConfig.paymentMethodOrder||j;const e=await this.getDefaultSkinCheckoutOptions();if(!e.cardElements||!e.paymentButtonElements)throw new a("Default skin must provide cardSelectors and paymentButtonSelectors");t=e.cardElements,n=e.paymentButtonElements,r=this.getCheckoutOptions(e)}r=this.mergeApplePayCollectingEmailOptions(r),await this.primerWrapper.renderCheckout(this.clientToken,r,{container:e,cardElements:t,paymentButtonElements:n,onSubmit:this.handleSubmit,onInputChange:this.handleInputChange,onCardInputValueChange:this.handleCardInputValueChange,isCardholderNameRequired:()=>this.isCardholderNameRequired(),isPostalCodeRequired:()=>this.isPostalCodeVisible(),onMethodRender:this.handleMethodRender,onMethodsAvailable:this.handleMethodsAvailable,onMethodRenderError:this.handleMethodRenderError})}async _processPaymentResult(e,t){switch(e.orderId&&(this.orderId=e.orderId),e.type){case"success":this._setState("completed"),this.emit(I.SUCCESS,{orderId:e.orderId,status:e.status}),t.handleSuccess();break;case"action_required":this._setState("action_required"),this.clientToken=e.clientToken,t.continueWithNewClientToken(e.clientToken);break;case"processing":this._setState("processing"),setTimeout(()=>{t.handleFailure("Payment is still processing. Please check back later.")},3e4);break;default:throw new a(`Unknown payment result type: ${e.type}`)}}getCheckoutOptions(t){let n=!1;const r={...this.checkoutConfig};return delete r.card,{...r,...t,card:S(this.getPrimerCardConfig()||{},t.card||{}),applePay:S(H[e.PaymentMethod.APPLE_PAY],t.applePay||{},this.checkoutConfig.applePay||{}),onTokenizeSuccess:this.handleTokenizeSuccess,onResumeSuccess:this.handleResumeSuccess,onResumeError:e=>{this.isApplePaySheetOpen=!1,e.stack?.includes("PROCESSOR_3DS")&&"RESUME_ERROR"===e.code&&e.message?.includes("fetch resume key")||this.emit(I.PURCHASE_FAILURE,e)},onCheckoutFail:e=>{this.isApplePaySheetOpen=!1,this.emit(I.PURCHASE_FAILURE,e)},onTokenizeError:e=>{this.isApplePaySheetOpen=!1,this.emit(I.PURCHASE_FAILURE,e)},onTokenizeStart:()=>{n=!0},onTokenizeShouldStart:t=>{if(t.paymentMethodType===e.PaymentMethod.APPLE_PAY){if(this.isApplePaySheetOpen)return!1;this.isApplePaySheetOpen=!0}return this.activePaymentMethodType=t.paymentMethodType,this.emit(I.ERROR,void 0),this.emit(I.START_PURCHASE,t.paymentMethodType),!0},onPaymentMethodAction:e=>{switch(e){case"PAYMENT_METHOD_SELECTED":this.emit(I.ERROR,void 0);break;case"PAYMENT_METHOD_UNSELECTED":this.isApplePaySheetOpen=!1,n||this.emit(I.PURCHASE_CANCELLED),n=!1}}}}async updatePrice(e,t){if(this._ensureNotDestroyed(),function(e,t){var n;if(0===(n=e,n?.trim()||"").length)throw new r(t,"must be a non-empty string",e)}(e,"priceId"),"processing"===this.state)throw new a("Cannot update price while payment is processing");try{this.onLoaderChangeWithRace(!0),this._setState("updating"),J.clearCache(),await this.apiClient.updateClientSession({orderId:this.orderId,clientToken:this.clientToken,priceId:e,clientMetadata:t,displayCurrency:this.checkoutConfig.displayCurrency,displayCountry:this.checkoutConfig.displayCountry}),this.checkoutConfig.priceId=e,await this.primerWrapper.refreshClientSession(),this.onLoaderChangeWithRace(!1),this._setState("ready"),this.isTaxEnabled()&&this.scheduleTaxRecalc()}catch(e){throw this.onLoaderChangeWithRace(!1),this._setState("error"),this.emit(I.ERROR,e),e}}getStatus(){return{id:this.id,state:this.state,orderId:this.orderId,priceId:this.checkoutConfig.priceId,isDestroyed:this.isDestroyed}}async destroy(){if(!this.isDestroyed)try{this.stopUnhandledTelemetry(),J.clearCache(),await this.primerWrapper.destroy(),this._setState("destroyed"),this.orderId=null,this.clientToken=null,this.isDestroyed=!0,this.emit(I.DESTROY),this.removeAllListeners()}catch(e){console.warn("Error during checkout cleanup:",e)}}_setState(e){if(this.state!==e){const t=this.state;this.state=e,this.emit(I.STATUS_CHANGE,e,t)}}_ensureNotDestroyed(){if(this.isDestroyed)throw new a("Checkout instance has been destroyed")}getContainer(){return document.querySelector(this.checkoutConfig.container)}isInState(e){return this.state===e}isReady(){return"ready"===this.state&&!this.isDestroyed}isProcessing(){return["processing","action_required"].includes(this.state)}normalizeCountryCode(e){const t=e?.trim().toUpperCase();return t||void 0}normalizeCountryFieldOverrides(e){if(e)return Object.entries(e).reduce((e,[t,n])=>{const r=this.normalizeCountryCode(t);return r&&n&&(e[r]=n),e},{})}getSelectedCountryCode(){return this.normalizeCountryCode(this.cardCountryCode)||this.normalizeCountryCode(this.cardSessionFieldConfig.detectedCountryCode)}getCountryFieldOverride(e=this.getSelectedCountryCode()){if(e)return this.cardSessionFieldConfig.countryFieldOverrides?.[e]}isCardholderNameRequired(){return!!this.checkoutConfig.card?.cardholderName?.required}isPostalCodeVisible(e=this.getSelectedCountryCode()){const t=!!this.cardSessionFieldConfig.showPostalCode,n=this.getCountryFieldOverride(e)?.show_postal_code;return null==n?t:n}getPaymentCountryCode(){return this.getSelectedCountryCode()}getPaymentPostalCode(){if(this.isPostalCodeVisible())return this.cardPostalCode?.trim()||void 0}async getDefaultSkinCheckoutOptions(){const e=(await Promise.resolve().then(function(){return kt})).default,t=await e(this.checkoutConfig,this.cardSessionFieldConfig);return this.on(I.INPUT_ERROR,t.onInputError),this.on(I.STATUS_CHANGE,t.onStatusChange),this.on(I.ERROR,e=>t.onError(e)),this.on(I.LOADER_CHANGE,t.onLoaderChange),this.on(I.DESTROY,t.onDestroy),this.on(I.SUCCESS,t.onSuccess),this.on(I.START_PURCHASE,t.onStartPurchase),this.on(I.PURCHASE_FAILURE,t.onPurchaseFailure),this.on(I.PURCHASE_COMPLETED,t.onPurchaseCompleted),this.on(I.METHODS_AVAILABLE,t.onMethodsAvailable),this.on(I.METHODS_AVAILABLE,this.hideInitializingLoader),t.getCheckoutOptions()}async getCardDefaultSkinCheckoutOptions(e){const t=new(0,(await Promise.resolve().then(function(){return Pt})).default)(e,this.checkoutConfig,this.cardSessionFieldConfig);return t.init(),this.on(I.INPUT_ERROR,t.onInputError),this.on(I.METHOD_RENDER,t.onMethodRender),this.on(I.SUCCESS,t.onDestroy),this.on(I.DESTROY,t.onDestroy),t.getCheckoutOptions()}showInitializingLoader(){(e=>{const t=document.querySelector(e);t&&(t.innerHTML=X)})(this.checkoutConfig.container)}hideInitializingLoader(){(()=>{const e=document.querySelector(ee.loaderContainer);e&&e.remove()})()}async initMethod(t,n,r){this._ensureNotDestroyed(),this.isReady()||await this.createSession(),r.onRenderSuccess&&this.on(I.METHOD_RENDER,r.onRenderSuccess),r.onRenderError&&this.on(I.METHOD_RENDER_ERROR,r.onRenderError),r.onLoaderChange&&this.on(I.LOADER_CHANGE,r.onLoaderChange),r.onPaymentSuccess&&this.on(I.SUCCESS,r.onPaymentSuccess),r.onPaymentFail&&this.on(I.PURCHASE_FAILURE,r.onPaymentFail),r.onPaymentCancel&&this.on(I.PURCHASE_CANCELLED,r.onPaymentCancel),r.onErrorMessageChange&&this.on(I.ERROR,r.onErrorMessageChange),r.onPaymentStarted&&this.on(I.START_PURCHASE,r.onPaymentStarted),r.onMethodsAvailable&&this.on(I.METHODS_AVAILABLE,r.onMethodsAvailable);let o=this.mergeApplePayCollectingEmailOptions(this.getCheckoutOptions({})),i={onMethodRender:this.handleMethodRender,onMethodRenderError:this.handleMethodRenderError};if(t===e.PaymentMethod.PAYMENT_CARD){const e=await this.getCardDefaultSkinCheckoutOptions(n);o=this.getCheckoutOptions({...e}),i={cardElements:e.cardElements,onSubmit:this.handleSubmit,onInputChange:this.handleInputChange,onCardInputValueChange:this.handleCardInputValueChange,isCardholderNameRequired:()=>this.isCardholderNameRequired(),isPostalCodeRequired:()=>this.isPostalCodeVisible(),onMethodRender:this.handleMethodRender,onMethodRenderError:this.handleMethodRenderError}}await this.primerWrapper.initializeHeadlessCheckout(this.clientToken,o,t);const a=await this.primerWrapper.initMethod(t,n,i);return this.startUnhandledTelemetry(t),this.isTaxEnabled()&&!this.lastTaxInfo&&this.emitSessionTaxEstimate(),{...a,destroy:async()=>{await a.destroy(),await this.destroy()}}}startUnhandledTelemetry(e){e&&(this.telemetryPaymentMethod=e),this.isTelemetryEnabled&&!this.telemetryCleanup&&(this.telemetryCleanup=Ee({id:this.id,orgId:this.orgId,baseUrl:this.baseUrl,enabled:this.isTelemetryEnabled,getContext:()=>({checkoutId:this.id,orderId:this.orderId,priceId:this.checkoutConfig.priceId,state:this.state,paymentMethod:this.telemetryPaymentMethod,reqId:this.cachedSessionResponse?.req_id})}))}stopUnhandledTelemetry(){this.telemetryCleanup?.(),this.telemetryCleanup=null,this.telemetryPaymentMethod=void 0}}const Ae=["3DS_AUTHENTICATION","PROCESSOR_3DS"],xe=6e5,De=6e3,Le="#primer-overlay";function Oe(e){try{const t=e.split(".");if(3!==t.length)return null;const n=t[1].replace(/-/g,"+").replace(/_/g,"/"),r=n+"=".repeat((4-n.length%4)%4),o=JSON.parse(atob(r));return"string"==typeof o?.intent?o.intent:null}catch{return null}}function Ne(e){return Boolean(e?.stack?.includes("PROCESSOR_3DS")&&"RESUME_ERROR"===e.code&&e.message?.includes("fetch resume key"))}function Ue(){if("undefined"==typeof document)return;const e=document.querySelector('[data-testid="OverlayContent.closeButton"]');e?.click()}function qe(){if("undefined"==typeof document)return()=>{};const e=document.createElement("style");return e.textContent=`${Le}{opacity:0!important;pointer-events:none!important}`,document.head.appendChild(e),()=>e.remove()}function Fe(){"undefined"==typeof document||document.querySelector(Le)||console.warn(`[FunnelfoxSDK] Primer 3DS overlay ${Le} not found`)}function ze(e,t){return t instanceof i?t:new i(e,t)}function je(e){try{e()}catch{}}let He=null;function Ye(e){He=e}function Be(){return He?.baseUrl||M.BASE_URL}function Ve(e,t){const{orgId:n,apiConfig:r}=e||{},o=n||He?.orgId;if(!o)throw new Error(`orgId is required. Pass it to ${t}() or call configure() first.`);return{orgId:o,baseUrl:r?.baseUrl||He?.baseUrl||M.BASE_URL,region:r?.region||He?.region||M.REGION}}async function $e(e){try{const{...t}=e,n=new Q;await n.ensurePrimerLoaded();const r=Ve(e,"createCheckout"),o=new Re({...r,checkoutConfig:{...t}});return await o.initialize(),o}catch(t){throw me(e.orgId,{baseUrl:e.apiConfig?.baseUrl,message:t.message,code:t.code,req_id:t?.response?.req_id}),t}}async function Ge(e){const{priceId:t,externalId:n,email:r,clientMetadata:o,countryCode:i,displayCurrency:a,displayCountry:s}=e,d=Ve(e,"createClientSession"),l=new K({baseUrl:d.baseUrl,orgId:d.orgId,timeout:M.REQUEST_TIMEOUT,retryAttempts:M.RETRY_ATTEMPTS}),c=await l.createClientSession({priceId:t,externalId:n,email:r,region:d.region,clientMetadata:o,countryCode:i,displayCurrency:a,displayCountry:s});return l.processSessionResponse(c)}function Qe(e){const t={pp_ident:e.priceId,external_id:e.externalId,client_metadata:e.clientMetadata};return void 0!==e.initiationType&&(t.initiation_type=e.initiationType),void 0!==e.citCardNetworks&&(t.cit_card_networks=e.citCardNetworks),e.displayCurrency&&(t.display_currency_code=e.displayCurrency),t}const We="one_click_in_progress",Ke="double_purchase",Ze="idempotency_key_in_progress",Je=[1e3,2e3,4e3],Xe=25e3,et=new Set;function tt(e,t){return`${e}\0${t}`}function nt(){const e="undefined"==typeof crypto?void 0:crypto;if("function"==typeof e?.randomUUID)return e.randomUUID();if("function"!=typeof e?.getRandomValues)return null;const t=e.getRandomValues(new Uint8Array(16));t[6]=15&t[6]|64,t[8]=63&t[8]|128;const n=Array.from(t,e=>e.toString(16).padStart(2,"0"));return[n.slice(0,4).join(""),n.slice(4,6).join(""),n.slice(6,8).join(""),n.slice(8,10).join(""),n.slice(10,16).join("")].join("-")}function rt(e){return e instanceof s||e instanceof o&&null!==e.statusCode&&(e.statusCode>=500||(e.statusCode>=200&&e.statusCode<300||400===e.statusCode&&e.errorCode===Ze))}function ot(e){return!e||"object"!=typeof e||!("status"in e)}async function it(e,t){if(!t.idempotency_key)return e.oneClickOnce(t);for(const n of Je){try{const n=await e.oneClickOnce(t,Xe);if(!ot(n))return n}catch(e){if(!rt(e))throw e}await b(n)}const n=await e.oneClickOnce(t,Xe);if(ot(n))throw new s("one_click returned an empty response");return n}function at(e){return{failedMessageForUser:e.failed_message_for_user??null,declineCode:e.decline_code??null,declineCodeSource:e.decline_code_source??null}}function st(e,t){const n=e?.error?.[0];return new o(n?.msg||t,null,{errorCode:n?.code,errorType:n?.type,response:e})}function dt(e){const t=e?.data;if("success"!==e?.status||!t)return Z(e).includes(Ke)?{kind:"result",result:{outcome:"already_purchased",orderId:null,threeDSChallenged:!1}}:{kind:"result",result:{outcome:"error",orderId:t?.order_id??null,threeDSChallenged:!1,error:st(e,"One-click purchase failed"),failedRequest:"one_click"}};const n=t.order_id??null;if(t.action_required_token)return{kind:"action",orderId:n,actionToken:t.action_required_token};switch(t.checkout_status){case"succeeded":return{kind:"result",result:{outcome:"succeeded",orderId:n,threeDSChallenged:!1}};case"failed":return{kind:"result",result:{outcome:"declined",orderId:n,threeDSChallenged:!1,...at(t)}};case"processing":return{kind:"result",result:{outcome:"processing",orderId:n,threeDSChallenged:!1}};case"cancelled":return{kind:"result",result:{outcome:"error",orderId:n,threeDSChallenged:!1,error:new o("Payment was cancelled",null,{response:e})}};default:return{kind:"result",result:{outcome:"error",orderId:n,threeDSChallenged:!1,error:new o(`Unhandled checkout status: ${t.checkout_status}`,null,{response:e})}}}}function lt(e,t,r,i=null){const a=e?.data;if("success"!==e?.status||!a)return{threeDS:"error",result:{outcome:"error",orderId:t,threeDSChallenged:r,error:st(e,"Resume payment failed"),failedRequest:"resume_payment"}};if(a.action_required_token)return{threeDS:"error",result:{outcome:"error",orderId:t,threeDSChallenged:r,error:new n("resume_payment returned another action token; chained 3DS is not supported","one_click_chained_action")}};switch(a.checkout_status){case"succeeded":return{threeDS:"passed",result:{outcome:"succeeded",orderId:t,threeDSChallenged:r}};case"processing":return{threeDS:"passed",result:{outcome:"processing",orderId:t,threeDSChallenged:r}};case"failed":{const e=r&&(null===i||i.includes(a.decline_code??""));return{threeDS:e?"failed":"passed",result:{outcome:e?"3ds_failed":"declined",orderId:t,threeDSChallenged:r,...at(a)}}}default:return{threeDS:"error",result:{outcome:"error",orderId:t,threeDSChallenged:r,error:new o("cancelled"===a.checkout_status?"Payment was cancelled":`Unhandled checkout status: ${a.checkout_status}`,null,{response:e})}}}}function ct(e,t,n){if("function"==typeof t)try{t(n)}catch(t){console.error(`[FunnelfoxSDK] ${e} hook threw`,t)}}async function ut(t){try{const n=new K({baseUrl:t.baseUrl,orgId:t.orgId}),r=await n.createSimpleClientSession({countryCode:t.countryCode}),o=r?.data?.client_token;if(!o)throw new Error("Error creating simple client session");return await new Promise((t,n)=>{const r=new Q;r.initializeHeadlessCheckout(o,{onTokenizeSuccess:()=>{},onResumeSuccess:()=>{},onAvailablePaymentMethodsLoad:e=>{t(e),r.destroy()},paypal:H[e.PaymentMethod.PAYPAL]}).catch(n)})}catch(e){throw me(t.orgId,{baseUrl:t.baseUrl,message:e.message,code:e.code,req_id:e?.response?.req_id}),e}}async function ht(t){const n=Ve(t,"getAvailableStripeWallet"),[r,{getAvailableWallet:o}]=await Promise.all([J.createSession({orgId:n.orgId,baseUrl:n.baseUrl,region:n.region,priceId:t.priceId,externalId:t.externalId,email:t.email,clientMetadata:t.clientMetadata,countryCode:t.countryCode,displayCurrency:t.displayCurrency,displayCountry:t.displayCountry,integration:"stripe"}),Promise.resolve().then(function(){return Lt})]);new K({orgId:n.orgId,baseUrl:n.baseUrl||M.BASE_URL}).processSessionResponse(r);const i=await o(r);return"APPLE_PAY"===i?e.PaymentMethod.APPLE_PAY:"GOOGLE_PAY"===i?e.PaymentMethod.GOOGLE_PAY:null}const pt=["APPLE_PAY","GOOGLE_PAY"],mt=9e5;function yt(e){const t=e.expires_at?function(e){const t=/([zZ]|[+-]\d{2}:?\d{2})$/.test(e);return Date.parse(t?e:`${e}Z`)}(e.expires_at):NaN;if(!(pt.includes(e.wallet)&&e.client_token&&e.session_id&&e.order_id&&Number.isFinite(t)))throw new o("Invalid one_click_wallet_session response",null,{response:e});return{wallet:e.wallet,clientToken:e.client_token,sessionId:e.session_id,orderId:e.order_id,amount:e.amount??null,currency:e.currency??null,expiresAt:t}}async function ft(e,t){const n=await e.oneClickWalletSession({pp_ident:t.priceId,external_id:t.externalId,client_metadata:t.clientMetadata||{}},15e3);if("success"!==n?.status||!n.data)throw new o("one_click_wallet_session failed",null,{response:n});return null===n.data.wallet?null:yt(n.data)}function Ct(e,t){const n=t.buttonType||"plain",r=t.buttonColor||"black";return"APPLE_PAY"===e?{applePay:{buttonType:"buy"===n?"buy":"plain",buttonStyle:r}}:{googlePay:{buttonType:"continue"===n?"plain":n,buttonColor:"black"===r?"black":"white",buttonSizeMode:"fill"}}}function gt(e,t){return t instanceof n?t:new i(e,t)}function wt(e){try{e()}catch{}}function St(e,t){return e instanceof o&&(e.errorCode===t||Z(e.response).includes(t))}class Et{constructor(e,t,n){this.container=e,this.options=t,this.rendered=null,this.generation=0,this.destroyed=!1,this.finished=!1,this.disabledByCaller=!1,this.refreshing=null,this.refreshTimer=null,this.attemptRunning=!1,this.tokenizeStarted=!1,this.charging=!1,this.threeDS=null,this.onVisibilityChange=()=>{"visible"===document.visibilityState&&this.expiresSoon()&&this.refresh()},this.session=n,this.apiClient=Et.apiClientFor(t),this.inFlightKey=tt(t.orgId,t.externalId)}static apiClientFor(e){return new K({baseUrl:e.baseUrl||Be(),orgId:e.orgId,timeout:M.REQUEST_TIMEOUT,retryAttempts:M.RETRY_ATTEMPTS})}async render(){const e=++this.generation,t=this.session,n=this.options.style||{};await(new Q).ensurePrimerLoaded();let r=()=>{},o=null;const a=new Promise((e,t)=>{r=e,o=setTimeout(()=>t(new i("Primer did not report the available payment methods")),1e4)}).finally(()=>clearTimeout(o)),s=await window.Primer.createHeadless(t.clientToken,{paymentHandling:U,apiVersion:q,...Ct(t.wallet,n),onAvailablePaymentMethodsLoad:e=>r(e.map(e=>e.type)),onTokenizeShouldStart:()=>this.onTap(e),onTokenizeStart:()=>{e===this.generation&&(this.tokenizeStarted=!0)},onPaymentMethodAction:t=>{"PAYMENT_METHOD_UNSELECTED"===t&&this.onSheetClosed(e)},onTokenizeSuccess:(t,n)=>this.onTokenized(e,t,n),onTokenizeError:t=>this.onPrimerFailure(e,"Wallet tokenization failed",t),onResumeSuccess:(t,n)=>this.onResumed(e,t,n),onResumeError:t=>this.onResumeError(e,t),onCheckoutFail:t=>this.onPrimerFailure(e,"Primer checkout failed",t)});await s.start();if(!(await a).includes(t.wallet))return!1;const d=await s.createPaymentMethodManager(t.wallet);if(!d||"function"!=typeof d.createButton)throw new i(`No ${t.wallet} button manager`);const l=this.mountButton(e,d.createButton(),t.wallet,n);try{await l.button.render(l.wrapper,{}),"APPLE_PAY"===t.wallet&&null===l.nativeOverlay&&(l.nativeOverlay=await this.overlayAppleType(l,n))}catch(e){throw this.removeButton(l),e}if(this.destroyed||e!==this.generation)return this.removeButton(l),!0;const c=this.rendered;return this.rendered=l,c&&this.removeButton(c),this.applyDisabled(),this.scheduleRefresh(),!0}mountButton(e,t,n,r){const o=document.createElement("div");o.className=E("funnelfox-wallet-upsell");const i=r.height??54,a=r.borderRadius??28,s=document.createElement("style");return s.textContent=[`.${o.className}{width:100%!important}`,`.${o.className} button{height:${i}px!important;border-radius:${a}px!important}`,"APPLE_PAY"===n&&"continue"===r.buttonType?`.${o.className} > button{opacity:0!important}`:""].join("\n"),document.head.appendChild(s),this.container.appendChild(o),{generation:e,button:t,wrapper:o,styleEl:s,nativeOverlay:null}}async overlayAppleType(e,t){if("continue"!==t.buttonType)return null;const n=await G(e.wrapper,{buttonType:t.buttonType,buttonStyle:t.buttonColor||"black",borderRadius:t.borderRadius??28});return n||(e.styleEl.textContent=e.styleEl.textContent.replace(`.${e.wrapper.className} > button{opacity:0!important}`,"")),n}removeButton(e){wt(()=>e.button.clean()),e.nativeOverlay?.remove(),e.wrapper.remove(),e.styleEl.remove()}applyDisabled(){const e=this.rendered;if(!e)return;const t=this.finished||this.disabledByCaller;Promise.resolve(e.button.setDisabled(t)).catch(()=>{}),e.nativeOverlay&&(e.nativeOverlay.style.pointerEvents=t?"none":"",e.nativeOverlay.style.opacity=t?"0.5":"")}setDisabled(e){this.disabledByCaller=e,this.applyDisabled()}destroy(){this.destroyed||(this.destroyed=!0,this.generation+=1,this.attemptRunning&&!this.charging&&(this.attemptRunning=!1,et.delete(this.inFlightKey)),this.clearRefresh(),"undefined"!=typeof document&&document.removeEventListener("visibilitychange",this.onVisibilityChange),this.rendered&&(this.removeButton(this.rendered),this.rendered=null))}watchVisibility(){"undefined"!=typeof document&&document.addEventListener("visibilitychange",this.onVisibilityChange)}expiresSoon(e=9e5){return this.session.expiresAt-Date.now()<e}clearRefresh(){this.refreshTimer&&(clearTimeout(this.refreshTimer),this.refreshTimer=null)}scheduleRefresh(){if(this.clearRefresh(),this.destroyed||this.finished)return;const e=Math.max(this.session.expiresAt-mt-Date.now(),6e4);this.refreshTimer=setTimeout(()=>{this.refreshTimer=null,this.refresh()},e)}refresh(){this.refreshing||this.destroyed||this.finished||this.attemptRunning||(this.refreshing=this.replaceSession().finally(()=>{this.refreshing=null}))}async replaceSession(){let e=null;try{const t=await ft(this.apiClient,this.options);if(this.destroyed||this.finished)return;t&&t.wallet===this.session.wallet?(this.session=t,await this.render()||(e=new n("This device can no longer show the wallet","wallet_upsell_unavailable"))):e=new n("The wallet upsell is no longer available for this customer","wallet_upsell_unavailable")}catch(t){e=gt("Failed to prepare the wallet upsell again",t)}!e||this.destroyed||this.finished||this.attemptRunning||this.report({outcome:"error",orderId:null,threeDSChallenged:!1,error:e})}onTap(e){return!(e!==this.generation||this.destroyed||this.finished||this.disabledByCaller||this.refreshing||this.attemptRunning||et.has(this.inFlightKey))&&(this.expiresSoon(6e4)?(this.refresh(),!1):(this.attemptRunning=!0,this.tokenizeStarted=!1,et.add(this.inFlightKey),ct("onStart",this.options.onStart,void 0),!0))}onSheetClosed(e){e===this.generation&&this.attemptRunning&&!this.tokenizeStarted&&this.finish({outcome:"cancelled",orderId:null,threeDSChallenged:!1})}onPrimerFailure(e,t,n){if(e===this.generation&&this.attemptRunning)return this.threeDS?(this.endThreeDS("failed"),void this.finish({outcome:"3ds_failed",orderId:this.session.orderId,threeDSChallenged:this.threeDSChallenged(),error:gt("3DS authentication failed",n)})):void this.finish({outcome:"error",orderId:null,threeDSChallenged:!1,error:gt(t,n)})}onTokenized(e,t,n){e===this.generation&&this.attemptRunning&&!this.threeDS?(this.tokenizeStarted=!0,this.charging=!0,this.charge(t.token,n,!1).catch(e=>{wt(()=>n.handleFailure()),this.finish({outcome:"error",orderId:this.session.orderId,threeDSChallenged:!1,error:gt("Wallet upsell charge failed",e)})})):wt(()=>n.handleFailure())}async charge(e,t,n){const r=this.session,o={pp_ident:this.options.priceId,external_id:this.options.externalId,client_metadata:this.options.clientMetadata||{},payment_method_token:e,session_id:r.sessionId};this.options.displayCurrency&&(o.display_currency_code=this.options.displayCurrency);const i=nt();let a;i&&(o.idempotency_key=i);try{a=await it(this.apiClient,o)}catch(r){return!n&&St(r,"wallet_session_invalid")&&await this.sameAmountSession()?this.charge(e,t,!0):(wt(()=>t.handleFailure()),void this.finish(this.chargeFailure(r,Boolean(i))))}const s=dt(a);if("result"===s.kind){const e=s.result;return"succeeded"===e.outcome||"processing"===e.outcome?wt(()=>t.handleSuccess()):wt(()=>t.handleFailure(e.failedMessageForUser||void 0)),void this.finish(e)}this.startThreeDS(s.orderId||r.orderId,s.actionToken,t)}async sameAmountSession(){try{const e=await ft(this.apiClient,this.options);return!(!e||e.wallet!==this.session.wallet||e.amount!==this.session.amount||e.currency!==this.session.currency)&&(this.session=e,!0)}catch{return!1}}chargeFailure(e,t){return St(e,Ke)?{outcome:"already_purchased",orderId:null,threeDSChallenged:!1}:t&&rt(e)?{outcome:"processing",orderId:this.session.orderId,threeDSChallenged:!1,error:e,failedRequest:"one_click"}:{outcome:"error",orderId:null,threeDSChallenged:!1,error:e instanceof Error?e:gt("one_click failed",e),failedRequest:"one_click"}}threeDSChallenged(){return Boolean(this.threeDS?.challenged)}startThreeDS(e,t,n){const r=Oe(t);if(!r||!Ae.includes(r))return wt(()=>n.handleFailure()),void this.finish({outcome:"error",orderId:e,threeDSChallenged:!1,error:new i("Unsupported one-click action: the action token is not a Primer 3DS client token",{intent:r})});const o=xe,a={orderId:e,challenged:!1,revealTimer:null,timer:null,showOverlay:qe()};this.threeDS=a;const s=()=>{a.timer=null,a.challenged&&(this.endThreeDS("abandoned"),this.finish({outcome:"3ds_abandoned",orderId:e,threeDSChallenged:!0}),Ue())};a.timer=setTimeout(s,o),a.revealTimer=setTimeout(()=>{a.revealTimer=null,a.challenged=!0,a.showOverlay(),Fe(),ct("onThreeDSStart",this.options.onThreeDSStart,{orderId:e}),a.timer&&clearTimeout(a.timer),a.timer=setTimeout(s,o)},De),n.continueWithNewClientToken(t)}endThreeDS(e){const t=this.threeDS;t&&(t.timer&&(clearTimeout(t.timer),t.timer=null),t.revealTimer&&(clearTimeout(t.revealTimer),t.revealTimer=null),t.showOverlay(),t.challenged&&ct("onThreeDSEnd",this.options.onThreeDSEnd,{result:e}))}async onResumed(e,t,n){const r=this.threeDS;if(e!==this.generation||!this.attemptRunning||!r)return void wt(()=>n.handleFailure());let o;r.timer&&(clearTimeout(r.timer),r.timer=null),r.revealTimer&&(clearTimeout(r.revealTimer),r.revealTimer=null);try{o=await this.apiClient.resumePaymentOnce({orderId:r.orderId,resumeToken:t.resumeToken})}catch(e){return wt(()=>n.handleFailure()),this.endThreeDS("error"),void this.finish({outcome:"error",orderId:r.orderId,threeDSChallenged:r.challenged,error:e,failedRequest:"resume_payment"})}const i=lt(o,r.orderId,r.challenged);"succeeded"===i.result.outcome||"processing"===i.result.outcome?wt(()=>n.handleSuccess()):wt(()=>n.handleFailure(i.result.failedMessageForUser||void 0)),this.endThreeDS(i.threeDS),this.finish(i.result)}onResumeError(e,t){const n=this.threeDS;if(e===this.generation&&this.attemptRunning&&n){if(Ne(t))return this.endThreeDS("abandoned"),void this.finish({outcome:"3ds_abandoned",orderId:n.orderId,threeDSChallenged:n.challenged});this.endThreeDS("failed"),this.finish({outcome:"3ds_failed",orderId:n.orderId,threeDSChallenged:n.challenged,error:gt("3DS authentication failed",t)})}}finish(e){this.attemptRunning&&(this.attemptRunning=!1,this.tokenizeStarted=!1,this.charging=!1,this.threeDS=null,et.delete(this.inFlightKey),this.report(e))}report(e){if("cancelled"!==e.outcome?(this.finished=!0,this.clearRefresh(),this.applyDisabled()):this.expiresSoon()&&this.refresh(),"error"===e.outcome&&e.error){const t=e.error;me(this.options.orgId,{baseUrl:this.options.baseUrl||Be(),message:t.message,code:t.code,req_id:t.response?.req_id})}this.destroyed||ct("onResult",this.options.onResult,e)}}async function bt(e,t){let n;!function(e,t){if("undefined"==typeof HTMLElement||!(e instanceof HTMLElement))throw new r("container","must be an HTMLElement",e);for(const e of["orgId","priceId","externalId"])if(!t?.[e])throw new r(e,"is required",t?.[e]);if("function"!=typeof t.onResult)throw new r("onResult","must be a function",t.onResult)}(e,t);try{n=await ft(Et.apiClientFor(t),t)}catch(e){return{mounted:!1,reason:"error",error:e instanceof Error?e:gt("one_click_wallet_session failed",e)}}if(!n)return{mounted:!1,reason:"not_wallet"};const o=new Et(e,t,n);try{if(!await o.render())return o.destroy(),{mounted:!1,reason:"wallet_unavailable",wallet:n.wallet}}catch(e){return o.destroy(),{mounted:!1,reason:"error",error:gt("Failed to mount the wallet button",e)}}return o.watchVisibility(),{mounted:!0,wallet:n.wallet,setDisabled:e=>o.setDisabled(e),destroy:()=>o.destroy()}}const vt={configure:Ye,createCheckout:$e,createClientSession:Ge,initMethod:async function(t,n,r){try{const o=new Re({orgId:r.orgId,baseUrl:r.baseUrl,checkoutConfig:{priceId:r.priceId,customer:{externalId:r.externalId,email:r.email},container:"",clientMetadata:r.meta,displayCurrency:r.displayCurrency,displayCountry:r.displayCountry,card:r.card,style:r.style,applePay:{...H[e.PaymentMethod.APPLE_PAY],...r.applePay||{}},paypal:{...H[e.PaymentMethod.PAYPAL],...r.paypal||{}},googlePay:{...H[e.PaymentMethod.GOOGLE_PAY],...r.googlePay||{}},onTaxChange:r.onTaxChange,onTaxError:r.onTaxError,onTaxPending:r.onTaxPending}});return await o.initMethod(t,n,{onRenderSuccess:r.onRenderSuccess,onRenderError:r.onRenderError,onLoaderChange:r.onLoaderChange,onPaymentSuccess:r.onPaymentSuccess,onPaymentFail:r.onPaymentFail,onPaymentCancel:r.onPaymentCancel,onErrorMessageChange:r.onErrorMessageChange,onPaymentStarted:r.onPaymentStarted,onMethodsAvailable:r.onMethodsAvailable})}catch(e){throw me(r.orgId,{baseUrl:r.baseUrl,message:e.message,code:e.code,req_id:e?.response?.req_id}),e}},silentPurchase:function(e){return!0===e?.handle3DS?async function(e){for(const t of["orgId","baseUrl","priceId","externalId"])if(!e?.[t])throw new r(t,"is required",e?.[t]);const{orgId:t,baseUrl:a,externalId:d}=e,l=tt(t,d);if(et.has(l))return{outcome:"error",orderId:null,threeDSChallenged:!1,error:new n("A one-click purchase is already in progress for this customer",We)};et.add(l);try{const r=await async function(e){const t=new K({baseUrl:e.baseUrl,orgId:e.orgId,timeout:M.REQUEST_TIMEOUT,retryAttempts:M.RETRY_ATTEMPTS}),r=Qe(e),a=nt();a&&(r.idempotency_key=a);let d;try{d=await it(t,r)}catch(e){return e instanceof o&&Z(e.response).includes(Ke)?{outcome:"already_purchased",orderId:null,threeDSChallenged:!1}:a&&rt(e)?{outcome:"processing",orderId:null,threeDSChallenged:!1,error:e,failedRequest:"one_click"}:{outcome:"error",orderId:null,threeDSChallenged:!1,error:e,failedRequest:"one_click"}}const l=dt(d);if("result"===l.kind)return l.result;const{orderId:c,actionToken:u}=l;let h=!1,p=!1;const m=t=>{h&&!p&&(p=!0,ct("onThreeDSEnd",e.onThreeDSEnd,{result:t}))};try{const n=await async function(e){const{apiClient:t,region:n,priceId:r,externalId:o,orderId:a,actionToken:d}=e,l=Oe(d);if(!l||!Ae.includes(l))return{kind:"error",error:new i("Unsupported one-click action: the action token is not a Primer 3DS client token",{intent:l})};const c=Number.isFinite(e.timeoutMs)&&e.timeoutMs>0?e.timeoutMs:xe;return new Promise(l=>{let u=!1,h=!1,p=!1,m=null,y=()=>{},f=!1,C=null,g=null;const w=e=>{u||(u=!0,C&&(clearTimeout(C),C=null),m&&(clearTimeout(m),m=null),y(),g=null,l(e))},S=()=>{if(C=null,p)return w({kind:"abandoned"}),void Ue();f?w({kind:"error",error:new s("create_client_session did not respond within threeDSTimeoutMs"),failedRequest:"create_client_session"}):h||w({kind:"error",error:new i("Timed out before the 3DS challenge was shown (threeDSTimeoutMs)")})};C=setTimeout(S,c);const E=(t,n)=>{u||h?je(()=>n.handleFailure()):(h=!0,y=qe(),m=setTimeout(()=>{m=null,p=!0,y(),Fe(),je(e.onChallengeShown),C&&clearTimeout(C),C=setTimeout(S,c)},e.revealDelayMs),n.continueWithNewClientToken(d))},b=async(e,n)=>{if(u)return void je(()=>n.handleFailure());let r;C&&(clearTimeout(C),C=null),m&&(clearTimeout(m),m=null);try{r=await t.resumePaymentOnce({orderId:a,resumeToken:e.resumeToken})}catch(e){return je(()=>n.handleFailure()),void w({kind:"error",error:e,failedRequest:"resume_payment"})}const o=r?.data;"success"!==r?.status||"succeeded"!==o?.checkout_status||o.action_required_token?je(()=>n.handleFailure(o?.failed_message_for_user||void 0)):je(()=>n.handleSuccess()),w({kind:"resumed",response:r})},v=e=>{Ne(e)?w({kind:"abandoned"}):w({kind:"failed",error:ze("3DS authentication failed",e)})},_=e=>{w(h?{kind:"failed",error:ze("3DS authentication failed",e)}:{kind:"error",error:ze("Primer checkout failed before the 3DS challenge",e)})},P=e=>{w({kind:"error",error:ze("Failed to tokenize the saved payment method",e)})};(async()=>{if(await(new Q).ensurePrimerLoaded(),u)return;let e;f=!0;try{const i=await t.createClientSession({priceId:r,externalId:o,region:n,clientMetadata:{}});e=t.processSessionResponse(i).clientToken,f=!1}catch(e){return f=!1,void w({kind:"error",error:e,failedRequest:"create_client_session"})}if(u)return;const a=await window.Primer.createHeadless(e,{paymentHandling:U,apiVersion:q,onAvailablePaymentMethodsLoad:()=>{},onTokenizeSuccess:E,onTokenizeError:P,onResumeSuccess:b,onResumeError:v,onCheckoutFail:_});if(g=await a,await g.start(),u)return;const s=g.createVaultManager(),d=(l=await s.fetchVaultedPaymentMethods())&&0!==l.length?l.find(e=>"PAYMENT_CARD"===e.paymentInstrumentType)||l[0]:null;var l;d?u||await s.startPaymentFlow(d.id):w({kind:"error",error:new i("No saved payment method found for the one-click 3DS challenge")})})().catch(e=>{w({kind:"error",error:ze("Failed to start the one-click 3DS challenge",e)})})})}({apiClient:t,region:He?.region||M.REGION,priceId:e.priceId,externalId:e.externalId,orderId:c,actionToken:u,timeoutMs:e.threeDSTimeoutMs??xe,revealDelayMs:De,onChallengeShown:()=>{h=!0,ct("onThreeDSStart",e.onThreeDSStart,{orderId:c})}}),r=function(e,t,n){switch(e.kind){case"resumed":return lt(e.response,t,n);case"failed":return{threeDS:"failed",result:{outcome:"3ds_failed",orderId:t,threeDSChallenged:n,error:e.error}};case"abandoned":return{threeDS:"abandoned",result:{outcome:"3ds_abandoned",orderId:t,threeDSChallenged:n}};default:{const r={outcome:"error",orderId:t,threeDSChallenged:n,error:e.error};return e.failedRequest&&(r.failedRequest=e.failedRequest),{threeDS:"error",result:r}}}}(n,c,h);return m(r.threeDS),r.result}catch(e){return m("error"),{outcome:"error",orderId:c,threeDSChallenged:h,error:e instanceof Error?e:new n("One-click 3DS step failed",void 0,e)}}}(e);if("error"===r.outcome&&r.error){const e=r.error;me(t,{baseUrl:a,message:e.message,code:e.code,req_id:e.response?.req_id})}return r}finally{et.delete(l)}}(e):async function(e){const{orgId:t,baseUrl:n}=e,r=new K({baseUrl:n,orgId:t,timeout:M.REQUEST_TIMEOUT,retryAttempts:M.RETRY_ATTEMPTS});"cit"===e.initiationType&&console.warn('[FunnelfoxSDK] silentPurchase: initiationType "cit" can trigger a 3DS challenge, which only silentPurchase({ handle3DS: true }) handles.');try{const t=await r.oneClick(Qe(e));if("success"!==t.status&&t.error.some(({code:e})=>"double_purchase"===e))throw new o("This product was already purchased");return"success"===t.status}catch(e){throw me(t,{baseUrl:n,message:e.message,code:e.code,req_id:e?.response?.req_id}),e}}(e)},mountWalletUpsell:bt,getAvailablePaymentMethods:ut,stripe:{createCardForm:async function(e,t){const n=Ve(t,"createStripeCardForm"),r={orgId:n.orgId,baseUrl:n.baseUrl,region:n.region,priceId:t.priceId,externalId:t.externalId,email:t.email,clientMetadata:t.clientMetadata,countryCode:t.countryCode,displayCurrency:t.displayCurrency,displayCountry:t.displayCountry,integration:"stripe"},[o,{mountStripeCardForm:i}]=await Promise.all([J.createSession(r),Promise.resolve().then(function(){return At})]),a=new K({orgId:n.orgId,baseUrl:n.baseUrl||M.BASE_URL});return a.processSessionResponse(o),i(e,o,{...t,apiClient:a,invalidateSession:()=>J.invalidate(r)})},purchaseWallet:async function(e){const t=Ve(e,"purchaseStripeWallet"),n={orgId:t.orgId,baseUrl:t.baseUrl,region:t.region,priceId:e.priceId,externalId:e.externalId,email:e.email,clientMetadata:e.clientMetadata,countryCode:e.countryCode,displayCurrency:e.displayCurrency,displayCountry:e.displayCountry,integration:"stripe"},[r,{purchaseWallet:o}]=await Promise.all([J.createSession(n),Promise.resolve().then(function(){return Lt})]),i=new K({orgId:t.orgId,baseUrl:t.baseUrl||M.BASE_URL});return i.processSessionResponse(r),o(r,{...e,apiClient:i,invalidateSession:()=>J.invalidate(n)})},getAvailableWallet:ht,getAvailablePaymentMethods:async function(t){const n=await ht(t);return n?[e.PaymentMethod.PAYMENT_CARD,n]:[e.PaymentMethod.PAYMENT_CARD]}}};"undefined"!=typeof window&&(window.Billing=vt),console.debug("Billing SDK inited");"undefined"!=typeof document&&(document.head.appendChild(document.createElement("style")).textContent="/* Main container */\n.ff-skin-default {\n display: flex;\n flex-direction: column;\n text-align: left;\n gap: 8px;\n width: 100%;\n max-width: 400px;\n margin: 0 auto;\n color: #000000;\n}\n\n/* Payment method cards */\n.ff-payment-method-card {\n display: none;\n border: 1px solid #e0e0e0;\n border-radius: 8px;\n background-color: #ffffff;\n padding: 20px;\n transition: border-color 0.2s ease;\n height: auto;\n box-shadow: 0px 0px 10px 0px #eee;\n}\n\n.ff-payment-method-card.visible {\n display: block;\n}\n\n.payment-errors-container {\n background-color: #d1000033;\n color: #d10000;\n font-size: 14px;\n padding: 16px 12px;\n border-radius: 8px;\n}\n.payment-errors-container:empty {\n display: none;\n}\n\n/* Label wrapper */\n.ff-payment-method-label {\n display: flex;\n align-items: flex-start;\n gap: 16px;\n cursor: pointer;\n width: 100%;\n}\n\n.ff-google-pay-header {\n align-items: center;\n}\n\n/* Custom radio button styling */\n.ff-payment-method-radio {\n appearance: none;\n -webkit-appearance: none;\n -moz-appearance: none;\n width: 24px;\n height: 24px;\n min-width: 24px;\n min-height: 24px;\n border: 1px solid #9e9e9e;\n border-radius: 50%;\n background-color: #ffffff;\n cursor: pointer;\n position: relative;\n margin: 0;\n flex-shrink: 0;\n transition: border-color 0.2s ease;\n}\n\n.ff-card-form-submit-button {\n display: block;\n cursor: pointer;\n width: 100%;\n padding: 16px 0;\n border-radius: 16px;\n background-color: #000000;\n color: #ffffff;\n border: none;\n font-size: 16px;\n margin: 12px 0 16px;\n}\n\n.ff-payment-method-radio:checked {\n border-color: #e32f41;\n background-color: #ffffff;\n}\n\n.ff-payment-method-radio:checked::after {\n content: '';\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 16px;\n height: 16px;\n border-radius: 50%;\n background-color: #e32f41;\n}\n\n/* Payment method content */\n.ff-payment-method-content {\n flex: 1;\n display: flex;\n flex-direction: column;\n gap: 16px;\n max-height: 0;\n height: 0;\n overflow: hidden;\n opacity: 0;\n transition:\n opacity 0.3s ease,\n margin-top 0.3s ease;\n margin-top: 0;\n}\n\n.ff-payment-method-card.expanded .ff-payment-method-content {\n max-height: 2000px;\n height: auto;\n opacity: 1;\n margin-top: 16px;\n}\n.ff-payment-method-card.expanded .ff-payment-method-label {\n margin-bottom: 16px;\n}\n\n/* Payment method header */\n.ff-payment-method-header {\n display: flex;\n align-items: center;\n}\n\n/* Google Pay Logo */\n.ff-google-pay-logo {\n display: flex;\n align-items: center;\n gap: 4px;\n font-weight: 500;\n font-size: 18px;\n}\n.ff-google-pay-logo img {\n height: 38px;\n}\n\n/* Payment features list */\n.ff-payment-features {\n list-style: none;\n padding: 0;\n margin: 0;\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n.ff-payment-feature {\n display: flex;\n align-items: baseline;\n text-align: left;\n gap: 8px;\n}\n\n.ff-checkmark-icon {\n width: 20px;\n height: 20px;\n min-width: 20px;\n color: #e32f41;\n flex-shrink: 0;\n margin-top: 2px;\n}\n\n.ff-payment-feature span {\n color: #333333;\n font-size: 14px;\n line-height: 1.5;\n}\n\n/* Google Pay button container */\n.ff-google-pay-button-container {\n display: flex;\n justify-content: center;\n}\n\n/* Security message */\n.ff-security-message {\n text-align: center;\n color: #999999;\n font-size: 14px;\n padding: 0;\n margin: 0\n}\n\n/* Card logos container */\n.ff-card-logos {\n display: flex;\n align-items: center;\n gap: 12px;\n flex-wrap: wrap;\n}\n\n/* Card form container */\n.ff-card-form-container {\n position: relative;\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n.loader-container {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n background-color: rgba(255, 255, 255);\n z-index: 2;\n}\n\n.payment-button-loader {\n position: relative;\n height: 50px;\n}\n\n.loader {\n width: 24px;\n height: 24px;\n border: 4px solid #e32f41;\n border-top: 4px solid transparent;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n}\n\n@keyframes spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n\n/* Responsive adjustments */\n@media (max-width: 768px) {\n .ff-payment-method-card {\n padding: 16px;\n }\n\n .ff-payment-method-label {\n gap: 12px;\n }\n\n .ff-card-logos {\n gap: 8px;\n }\n}\n\n.ff-payment-container {\n position: relative;\n}\n\n.success {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: 16px;\n}\n");"undefined"!=typeof document&&(document.head.appendChild(document.createElement("style")).textContent="\n\n.ff-card-form-label {\n display: block;\n font-size: 16px;\n margin-bottom: 5px;\n }\n \n .card-form-row {\n display: grid;\n grid-template-columns: repeat(2, minmax(0, 1fr));\n grid-template-rows: repeat(3, auto);\n grid-auto-flow: column;\n column-gap: 10px;\n }\n\n /* Label, input and error of both columns share grid rows, so a label that wraps in one column\n moves both inputs down together, and an error under one input does not move the other. */\n .card-form-row > div {\n display: contents;\n }\n \n .ff-card-form-text-input {\n margin: 0 0 3px;\n padding-left: 10px;\n padding-right: 10px;\n box-sizing: border-box;\n height: 36px;\n width: 100%;\n font-size: 1rem;\n background-color: transparent;\n border: 1px solid rgb(0 0 0 / 10%);\n border-radius: 6px;\n transition: all 0.3s ease;\n box-shadow: none;\n outline: none;\n }\n .ff-card-form-text-input.error {\n border-color: #e32f41;\n }\n\n.ff-select-wrap {\n position: relative;\n}\n\n.ff-card-form-select {\n padding-right: 34px;\n appearance: none;\n -webkit-appearance: none;\n -moz-appearance: none;\n background-image: none;\n}\n\n.ff-card-form-select::-ms-expand {\n display: none;\n}\n\n.ff-card-form-select:disabled {\n color: #6b7280;\n cursor: not-allowed;\n}\n\n.ff-select-arrow {\n position: absolute;\n top: 50%;\n right: 12px;\n width: 8px;\n height: 8px;\n border-right: 1.5px solid #6b7280;\n border-bottom: 1.5px solid #6b7280;\n transform: translateY(-65%) rotate(45deg);\n pointer-events: none;\n}\n\n.ff-select-wrap:focus-within .ff-select-arrow {\n border-right-color: #111827;\n border-bottom-color: #111827;\n}\n \n .errorContainer:not(:empty) {\n color: #df1b41;\n font-size: 15px;\n line-height: 1.15;\n margin: 4px 0 10px;\n }\n\n #cvvInput {\n position: relative;\n }\n\n #cvvInput > svg {\n z-index: 1;\n position: absolute;\n top: 5px;\n right: 5px;\n width: 26px;\n height: 26px;\n }\n");class _t{constructor(e,t,n){if(this.onInputError=e=>{const{name:t,error:n}=e,r=this.getCardInputElements(),o={cardNumber:r.cardNumber.parentElement,expiryDate:r.expiryDate.parentElement,cvv:r.cvv.parentElement,cardholderName:r.cardholderName?.parentElement,emailAddress:r.emailAddress?.parentElement,postalCode:r.postalCode?.parentElement},i=o[t]?.querySelector(".errorContainer");if(i&&(i.textContent=n||""),"cardholderName"===t||"emailAddress"===t||"postalCode"===t){const e="cardholderName"===t?r.cardholderName:"emailAddress"===t?r.emailAddress:r.postalCode;n?e?.classList?.add("error"):e?.classList?.remove("error")}},this.onMethodRender=()=>{this.containerEl.style.display="block"},this.onDestroy=()=>{this.containerEl.innerHTML&&(this.containerEl.innerHTML="")},!e)throw new Error("Container element not found");this.containerEl=e,this.checkoutConfig=t,this.cardSessionFieldConfig=n,this.containerEl.style.display="none"}normalizeCountryCode(e){const t=e?.trim().toUpperCase();return t||void 0}getSelectedCountryCode(){const e=this.containerEl.querySelector("#countrySelectorInput");return this.normalizeCountryCode(e?.value)||this.normalizeCountryCode(this.cardSessionFieldConfig?.detectedCountryCode)}getCountryFieldOverride(e=this.getSelectedCountryCode()){if(e)return this.cardSessionFieldConfig?.countryFieldOverrides?.[e]}isCountrySelectorVisible(){return!!this.cardSessionFieldConfig?.showCountrySelector}isCardholderNameVisible(){return!!this.checkoutConfig.card?.cardholderName?.required}isPostalCodeVisible(e=this.getSelectedCountryCode()){const t=!!this.cardSessionFieldConfig?.showPostalCode,n=this.getCountryFieldOverride(e)?.show_postal_code;return null==n?t:n}setFieldVisibility(e,t){const n=this.containerEl.querySelector(`#${e}`);n?.parentElement&&(n.parentElement.style.display=t?"":"none")}setContainerVisibility(e,t){const n=this.containerEl.querySelector(`#${e}`);n&&(n.style.display=t?"":"none")}populateCountrySelector(e){const t=this.cardSessionFieldConfig?.validCountries||[],n=this.getSelectedCountryCode();if(e.innerHTML="",e.disabled=!1,!t.length){const t=document.createElement("option");return t.value=n||"",t.textContent=n?`Detected country: ${n}`:"Country unavailable",e.appendChild(t),void(e.disabled=!0)}const r=document.createElement("option");r.value="",r.textContent="Select country",e.appendChild(r),t.forEach(t=>{const n=document.createElement("option");n.value=t.code,n.textContent=t.name,e.appendChild(n)}),n&&(e.value=n)}updateDynamicFieldVisibility(e=this.getSelectedCountryCode()){this.setFieldVisibility("cardHolderInput",this.isCardholderNameVisible()),this.setFieldVisibility("postalCodeInput",this.isPostalCodeVisible(e));const t=this.containerEl.querySelector("#postalCodeInput");!this.isPostalCodeVisible(e)&&t&&(t.value="")}wireCardInputs(){const e=this.containerEl.querySelector("#cardNumberInput"),t=this.containerEl.querySelector("#expiryInput"),n=this.containerEl.querySelector("#cvvInput"),r=this.containerEl.querySelector("#cardHolderInput"),o=!!this.checkoutConfig?.card?.emailAddress?.visible;let i;o?(i=this.containerEl.querySelector("#emailAddressInput"),i&&(i.value=this.checkoutConfig.customer.email||"")):this.containerEl.querySelector("#emailAddressInput").parentElement.style.display="none";const a=this.containerEl.querySelector("#countrySelectorInput"),s=this.containerEl.querySelector("#postalCodeInput");if(a&&(this.populateCountrySelector(a),a.addEventListener("change",()=>{this.updateDynamicFieldVisibility(this.normalizeCountryCode(a.value))})),this.setContainerVisibility("countrySelectorField",this.isCountrySelectorVisible()),this.updateDynamicFieldVisibility(),!e||!t||!n||!r||o&&!i||!a||!s)throw new Error("One or more card input elements are missing in the default skin");this.cardInputElements={cardNumber:e,expiryDate:t,cvv:n,cardholderName:r,emailAddress:i,countrySelector:a,postalCode:s}}async init(){this.containerEl.insertAdjacentHTML("afterbegin",'<div>\n <label class="ff-card-form-label" for="cardNumberInput">Card number</label>\n <div id="cardNumberInput"></div>\n <div class="errorContainer"></div>\n</div>\n<div class="card-form-row">\n <div>\n <label class="ff-card-form-label" for="expiryInput">Expiration date</label>\n <div id="expiryInput"></div>\n <div class="errorContainer"></div>\n </div>\n <div>\n <label class="ff-card-form-label" for="cvvInput">Security code</label>\n <div id="cvvInput">\n <svg width="200" height="200" viewBox="0 0 200 200" fill="none" xmlns="http://www.w3.org/2000/svg">\n <rect width="200" height="200" fill="transparent"/>\n <g clip-path="url(#clip0_0_1)">\n <path d="M157.555 23C168.279 23.0002 177 31.7394 177 42.4854V80.5889C171.946 72.0151 164.749 64.8558 156.146 59.8457H166.394V42.4854C166.393 37.6004 162.43 33.6291 157.555 33.6289H27.4453C22.5704 33.6291 18.6066 37.6004 18.6064 42.4854V59.8457H97.8535C88.9153 65.0512 81.4954 72.5771 76.4189 81.5986H18.6064V127.515C18.6066 132.4 22.5704 136.371 27.4453 136.371H75.3281C77.2742 140.177 79.6285 143.739 82.333 147H27.4453C16.7215 147 8.00019 138.261 8 127.515V42.4854C8.0002 31.7394 16.7215 23.0002 27.4453 23H157.555Z" fill="#93939A"/>\n <mask id="path-2-outside-1_0_1" maskUnits="userSpaceOnUse" x="68.5012" y="52.0311" width="135" height="135" fill="black">\n <rect fill="white" x="68.5012" y="52.0311" width="135" height="135"/>\n <path d="M190.242 160.457L170.136 140.351C166.533 145.552 162.023 150.063 156.821 153.666L176.927 173.772C178.693 175.538 181.088 176.53 183.585 176.53C186.082 176.53 188.477 175.538 190.242 173.772C192.008 172.007 193 169.612 193 167.115C193 164.618 192.008 162.223 190.242 160.457ZM126.436 157.901C116.955 157.901 107.688 155.089 99.8048 149.822C91.922 144.555 85.7781 137.069 82.15 128.31C78.5219 119.551 77.5727 109.913 79.4222 100.614C81.2718 91.3158 85.8371 82.7746 92.5409 76.0708C99.2447 69.367 107.786 64.8017 117.084 62.9521C126.383 61.1026 136.021 62.0518 144.78 65.6799C153.539 69.308 161.025 75.4519 166.292 83.3347C171.559 91.2175 174.371 100.485 174.371 109.966C174.371 122.679 169.32 134.871 160.331 143.861C151.341 152.85 139.149 157.901 126.436 157.901ZM163.719 109.966C163.719 102.592 161.532 95.3838 157.435 89.2527C153.339 83.1216 147.516 78.343 140.703 75.5212C133.891 72.6994 126.395 71.9611 119.162 73.3996C111.93 74.8382 105.287 78.389 100.073 83.6031C94.8591 88.8171 91.3083 95.4602 89.8697 102.692C88.4312 109.924 89.1695 117.421 91.9913 124.233C94.8131 131.046 99.5918 136.869 105.723 140.965C111.854 145.062 119.062 147.248 126.436 147.248C136.324 147.248 145.807 143.32 152.799 136.329C159.791 129.337 163.719 119.854 163.719 109.966ZM133.645 102.757C133.398 102.51 133.104 102.313 132.781 102.179C132.458 102.046 132.112 101.977 131.762 101.977C131.412 101.977 131.066 102.046 130.743 102.179C130.42 102.313 130.126 102.51 129.879 102.757L126.436 106.2L122.993 102.757C122.49 102.272 121.818 102.003 121.119 102.01C120.421 102.016 119.753 102.296 119.26 102.789C118.766 103.283 118.486 103.951 118.48 104.649C118.474 105.348 118.742 106.02 119.227 106.523L122.67 109.966L119.227 113.409C118.973 113.655 118.77 113.949 118.63 114.274C118.491 114.598 118.417 114.948 118.414 115.301C118.411 115.655 118.479 116.006 118.612 116.333C118.746 116.66 118.944 116.958 119.194 117.208C119.444 117.458 119.741 117.655 120.069 117.789C120.396 117.923 120.747 117.991 121.1 117.988C121.454 117.985 121.803 117.911 122.128 117.771C122.453 117.632 122.747 117.429 122.993 117.175L126.436 113.732L129.879 117.175C130.382 117.66 131.054 117.928 131.752 117.922C132.451 117.916 133.119 117.636 133.612 117.142C134.106 116.648 134.386 115.981 134.392 115.282C134.398 114.584 134.13 113.911 133.645 113.409L130.202 109.966L133.645 106.523C133.892 106.275 134.088 105.982 134.222 105.659C134.356 105.336 134.425 104.989 134.425 104.64C134.425 104.29 134.356 103.944 134.222 103.621C134.088 103.298 133.892 103.004 133.645 102.757ZM112.34 102.757C112.093 102.51 111.8 102.313 111.477 102.179C111.154 102.046 110.807 101.977 110.458 101.977C110.108 101.977 109.762 102.046 109.439 102.179C109.116 102.313 108.822 102.51 108.575 102.757L105.132 106.2L101.688 102.757C101.186 102.272 100.513 102.003 99.8151 102.01C99.1169 102.016 98.4489 102.296 97.9552 102.789C97.4614 103.283 97.1814 103.951 97.1753 104.649C97.1692 105.348 97.4377 106.02 97.9227 106.523L101.366 109.966L97.9227 113.409C97.6684 113.655 97.4655 113.949 97.326 114.274C97.1864 114.598 97.1129 114.948 97.1098 115.301C97.1068 115.655 97.1742 116.006 97.3081 116.333C97.442 116.66 97.6397 116.958 97.8897 117.208C98.1398 117.458 98.4371 117.655 98.7644 117.789C99.0917 117.923 99.4423 117.991 99.7959 117.988C100.15 117.985 100.499 117.911 100.824 117.771C101.149 117.632 101.443 117.429 101.688 117.175L105.132 113.732L108.575 117.175C109.077 117.66 109.75 117.928 110.448 117.922C111.146 117.916 111.814 117.636 112.308 117.142C112.802 116.648 113.082 115.981 113.088 115.282C113.094 114.584 112.826 113.911 112.34 113.409L108.897 109.966L112.34 106.523C112.588 106.275 112.784 105.982 112.918 105.659C113.052 105.336 113.121 104.989 113.121 104.64C113.121 104.29 113.052 103.944 112.918 103.621C112.784 103.298 112.588 103.004 112.34 102.757ZM151.506 109.966L154.949 106.523C155.434 106.02 155.703 105.348 155.697 104.649C155.691 103.951 155.41 103.283 154.917 102.789C154.423 102.296 153.755 102.016 153.057 102.01C152.359 102.003 151.686 102.272 151.184 102.757L147.74 106.2L144.297 102.757C143.795 102.272 143.122 102.003 142.424 102.01C141.726 102.016 141.058 102.296 140.564 102.789C140.07 103.283 139.79 103.951 139.784 104.649C139.778 105.348 140.046 106.02 140.531 106.523L143.974 109.966L140.531 113.409C140.277 113.655 140.074 113.949 139.935 114.274C139.795 114.598 139.722 114.948 139.719 115.301C139.715 115.655 139.783 116.006 139.917 116.333C140.051 116.66 140.248 116.958 140.498 117.208C140.748 117.458 141.046 117.655 141.373 117.789C141.7 117.923 142.051 117.991 142.405 117.988C142.758 117.985 143.108 117.911 143.433 117.771C143.757 117.632 144.051 117.429 144.297 117.175L147.74 113.732L151.184 117.175C151.686 117.66 152.359 117.928 153.057 117.922C153.755 117.916 154.423 117.636 154.917 117.142C155.41 116.648 155.691 115.981 155.697 115.282C155.703 114.584 155.434 113.911 154.949 113.409L151.506 109.966Z"/>\n </mask>\n <path d="M190.242 160.457L170.136 140.351C166.533 145.552 162.023 150.063 156.821 153.666L176.927 173.772C178.693 175.538 181.088 176.53 183.585 176.53C186.082 176.53 188.477 175.538 190.242 173.772C192.008 172.007 193 169.612 193 167.115C193 164.618 192.008 162.223 190.242 160.457ZM126.436 157.901C116.955 157.901 107.688 155.089 99.8048 149.822C91.922 144.555 85.7781 137.069 82.15 128.31C78.5219 119.551 77.5727 109.913 79.4222 100.614C81.2718 91.3158 85.8371 82.7746 92.5409 76.0708C99.2447 69.367 107.786 64.8017 117.084 62.9521C126.383 61.1026 136.021 62.0518 144.78 65.6799C153.539 69.308 161.025 75.4519 166.292 83.3347C171.559 91.2175 174.371 100.485 174.371 109.966C174.371 122.679 169.32 134.871 160.331 143.861C151.341 152.85 139.149 157.901 126.436 157.901ZM163.719 109.966C163.719 102.592 161.532 95.3838 157.435 89.2527C153.339 83.1216 147.516 78.343 140.703 75.5212C133.891 72.6994 126.395 71.9611 119.162 73.3996C111.93 74.8382 105.287 78.389 100.073 83.6031C94.8591 88.8171 91.3083 95.4602 89.8697 102.692C88.4312 109.924 89.1695 117.421 91.9913 124.233C94.8131 131.046 99.5918 136.869 105.723 140.965C111.854 145.062 119.062 147.248 126.436 147.248C136.324 147.248 145.807 143.32 152.799 136.329C159.791 129.337 163.719 119.854 163.719 109.966ZM133.645 102.757C133.398 102.51 133.104 102.313 132.781 102.179C132.458 102.046 132.112 101.977 131.762 101.977C131.412 101.977 131.066 102.046 130.743 102.179C130.42 102.313 130.126 102.51 129.879 102.757L126.436 106.2L122.993 102.757C122.49 102.272 121.818 102.003 121.119 102.01C120.421 102.016 119.753 102.296 119.26 102.789C118.766 103.283 118.486 103.951 118.48 104.649C118.474 105.348 118.742 106.02 119.227 106.523L122.67 109.966L119.227 113.409C118.973 113.655 118.77 113.949 118.63 114.274C118.491 114.598 118.417 114.948 118.414 115.301C118.411 115.655 118.479 116.006 118.612 116.333C118.746 116.66 118.944 116.958 119.194 117.208C119.444 117.458 119.741 117.655 120.069 117.789C120.396 117.923 120.747 117.991 121.1 117.988C121.454 117.985 121.803 117.911 122.128 117.771C122.453 117.632 122.747 117.429 122.993 117.175L126.436 113.732L129.879 117.175C130.382 117.66 131.054 117.928 131.752 117.922C132.451 117.916 133.119 117.636 133.612 117.142C134.106 116.648 134.386 115.981 134.392 115.282C134.398 114.584 134.13 113.911 133.645 113.409L130.202 109.966L133.645 106.523C133.892 106.275 134.088 105.982 134.222 105.659C134.356 105.336 134.425 104.989 134.425 104.64C134.425 104.29 134.356 103.944 134.222 103.621C134.088 103.298 133.892 103.004 133.645 102.757ZM112.34 102.757C112.093 102.51 111.8 102.313 111.477 102.179C111.154 102.046 110.807 101.977 110.458 101.977C110.108 101.977 109.762 102.046 109.439 102.179C109.116 102.313 108.822 102.51 108.575 102.757L105.132 106.2L101.688 102.757C101.186 102.272 100.513 102.003 99.8151 102.01C99.1169 102.016 98.4489 102.296 97.9552 102.789C97.4614 103.283 97.1814 103.951 97.1753 104.649C97.1692 105.348 97.4377 106.02 97.9227 106.523L101.366 109.966L97.9227 113.409C97.6684 113.655 97.4655 113.949 97.326 114.274C97.1864 114.598 97.1129 114.948 97.1098 115.301C97.1068 115.655 97.1742 116.006 97.3081 116.333C97.442 116.66 97.6397 116.958 97.8897 117.208C98.1398 117.458 98.4371 117.655 98.7644 117.789C99.0917 117.923 99.4423 117.991 99.7959 117.988C100.15 117.985 100.499 117.911 100.824 117.771C101.149 117.632 101.443 117.429 101.688 117.175L105.132 113.732L108.575 117.175C109.077 117.66 109.75 117.928 110.448 117.922C111.146 117.916 111.814 117.636 112.308 117.142C112.802 116.648 113.082 115.981 113.088 115.282C113.094 114.584 112.826 113.911 112.34 113.409L108.897 109.966L112.34 106.523C112.588 106.275 112.784 105.982 112.918 105.659C113.052 105.336 113.121 104.989 113.121 104.64C113.121 104.29 113.052 103.944 112.918 103.621C112.784 103.298 112.588 103.004 112.34 102.757ZM151.506 109.966L154.949 106.523C155.434 106.02 155.703 105.348 155.697 104.649C155.691 103.951 155.41 103.283 154.917 102.789C154.423 102.296 153.755 102.016 153.057 102.01C152.359 102.003 151.686 102.272 151.184 102.757L147.74 106.2L144.297 102.757C143.795 102.272 143.122 102.003 142.424 102.01C141.726 102.016 141.058 102.296 140.564 102.789C140.07 103.283 139.79 103.951 139.784 104.649C139.778 105.348 140.046 106.02 140.531 106.523L143.974 109.966L140.531 113.409C140.277 113.655 140.074 113.949 139.935 114.274C139.795 114.598 139.722 114.948 139.719 115.301C139.715 115.655 139.783 116.006 139.917 116.333C140.051 116.66 140.248 116.958 140.498 117.208C140.748 117.458 141.046 117.655 141.373 117.789C141.7 117.923 142.051 117.991 142.405 117.988C142.758 117.985 143.108 117.911 143.433 117.771C143.757 117.632 144.051 117.429 144.297 117.175L147.74 113.732L151.184 117.175C151.686 117.66 152.359 117.928 153.057 117.922C153.755 117.916 154.423 117.636 154.917 117.142C155.41 116.648 155.691 115.981 155.697 115.282C155.703 114.584 155.434 113.911 154.949 113.409L151.506 109.966Z" fill="#93939A"/>\n <path d="M190.242 160.457L170.136 140.351C166.533 145.552 162.023 150.063 156.821 153.666L176.927 173.772C178.693 175.538 181.088 176.53 183.585 176.53C186.082 176.53 188.477 175.538 190.242 173.772C192.008 172.007 193 169.612 193 167.115C193 164.618 192.008 162.223 190.242 160.457ZM126.436 157.901C116.955 157.901 107.688 155.089 99.8048 149.822C91.922 144.555 85.7781 137.069 82.15 128.31C78.5219 119.551 77.5727 109.913 79.4222 100.614C81.2718 91.3158 85.8371 82.7746 92.5409 76.0708C99.2447 69.367 107.786 64.8017 117.084 62.9521C126.383 61.1026 136.021 62.0518 144.78 65.6799C153.539 69.308 161.025 75.4519 166.292 83.3347C171.559 91.2175 174.371 100.485 174.371 109.966C174.371 122.679 169.32 134.871 160.331 143.861C151.341 152.85 139.149 157.901 126.436 157.901ZM163.719 109.966C163.719 102.592 161.532 95.3838 157.435 89.2527C153.339 83.1216 147.516 78.343 140.703 75.5212C133.891 72.6994 126.395 71.9611 119.162 73.3996C111.93 74.8382 105.287 78.389 100.073 83.6031C94.8591 88.8171 91.3083 95.4602 89.8697 102.692C88.4312 109.924 89.1695 117.421 91.9913 124.233C94.8131 131.046 99.5918 136.869 105.723 140.965C111.854 145.062 119.062 147.248 126.436 147.248C136.324 147.248 145.807 143.32 152.799 136.329C159.791 129.337 163.719 119.854 163.719 109.966ZM133.645 102.757C133.398 102.51 133.104 102.313 132.781 102.179C132.458 102.046 132.112 101.977 131.762 101.977C131.412 101.977 131.066 102.046 130.743 102.179C130.42 102.313 130.126 102.51 129.879 102.757L126.436 106.2L122.993 102.757C122.49 102.272 121.818 102.003 121.119 102.01C120.421 102.016 119.753 102.296 119.26 102.789C118.766 103.283 118.486 103.951 118.48 104.649C118.474 105.348 118.742 106.02 119.227 106.523L122.67 109.966L119.227 113.409C118.973 113.655 118.77 113.949 118.63 114.274C118.491 114.598 118.417 114.948 118.414 115.301C118.411 115.655 118.479 116.006 118.612 116.333C118.746 116.66 118.944 116.958 119.194 117.208C119.444 117.458 119.741 117.655 120.069 117.789C120.396 117.923 120.747 117.991 121.1 117.988C121.454 117.985 121.803 117.911 122.128 117.771C122.453 117.632 122.747 117.429 122.993 117.175L126.436 113.732L129.879 117.175C130.382 117.66 131.054 117.928 131.752 117.922C132.451 117.916 133.119 117.636 133.612 117.142C134.106 116.648 134.386 115.981 134.392 115.282C134.398 114.584 134.13 113.911 133.645 113.409L130.202 109.966L133.645 106.523C133.892 106.275 134.088 105.982 134.222 105.659C134.356 105.336 134.425 104.989 134.425 104.64C134.425 104.29 134.356 103.944 134.222 103.621C134.088 103.298 133.892 103.004 133.645 102.757ZM112.34 102.757C112.093 102.51 111.8 102.313 111.477 102.179C111.154 102.046 110.807 101.977 110.458 101.977C110.108 101.977 109.762 102.046 109.439 102.179C109.116 102.313 108.822 102.51 108.575 102.757L105.132 106.2L101.688 102.757C101.186 102.272 100.513 102.003 99.8151 102.01C99.1169 102.016 98.4489 102.296 97.9552 102.789C97.4614 103.283 97.1814 103.951 97.1753 104.649C97.1692 105.348 97.4377 106.02 97.9227 106.523L101.366 109.966L97.9227 113.409C97.6684 113.655 97.4655 113.949 97.326 114.274C97.1864 114.598 97.1129 114.948 97.1098 115.301C97.1068 115.655 97.1742 116.006 97.3081 116.333C97.442 116.66 97.6397 116.958 97.8897 117.208C98.1398 117.458 98.4371 117.655 98.7644 117.789C99.0917 117.923 99.4423 117.991 99.7959 117.988C100.15 117.985 100.499 117.911 100.824 117.771C101.149 117.632 101.443 117.429 101.688 117.175L105.132 113.732L108.575 117.175C109.077 117.66 109.75 117.928 110.448 117.922C111.146 117.916 111.814 117.636 112.308 117.142C112.802 116.648 113.082 115.981 113.088 115.282C113.094 114.584 112.826 113.911 112.34 113.409L108.897 109.966L112.34 106.523C112.588 106.275 112.784 105.982 112.918 105.659C113.052 105.336 113.121 104.989 113.121 104.64C113.121 104.29 113.052 103.944 112.918 103.621C112.784 103.298 112.588 103.004 112.34 102.757ZM151.506 109.966L154.949 106.523C155.434 106.02 155.703 105.348 155.697 104.649C155.691 103.951 155.41 103.283 154.917 102.789C154.423 102.296 153.755 102.016 153.057 102.01C152.359 102.003 151.686 102.272 151.184 102.757L147.74 106.2L144.297 102.757C143.795 102.272 143.122 102.003 142.424 102.01C141.726 102.016 141.058 102.296 140.564 102.789C140.07 103.283 139.79 103.951 139.784 104.649C139.778 105.348 140.046 106.02 140.531 106.523L143.974 109.966L140.531 113.409C140.277 113.655 140.074 113.949 139.935 114.274C139.795 114.598 139.722 114.948 139.719 115.301C139.715 115.655 139.783 116.006 139.917 116.333C140.051 116.66 140.248 116.958 140.498 117.208C140.748 117.458 141.046 117.655 141.373 117.789C141.7 117.923 142.051 117.991 142.405 117.988C142.758 117.985 143.108 117.911 143.433 117.771C143.757 117.632 144.051 117.429 144.297 117.175L147.74 113.732L151.184 117.175C151.686 117.66 152.359 117.928 153.057 117.922C153.755 117.916 154.423 117.636 154.917 117.142C155.41 116.648 155.691 115.981 155.697 115.282C155.703 114.584 155.434 113.911 154.949 113.409L151.506 109.966Z" stroke="transparent" stroke-width="20" mask="url(#path-2-outside-1_0_1)"/>\n </g>\n <defs>\n <clipPath id="clip0_0_1">\n <rect width="200" height="200" fill="white"/>\n </clipPath>\n </defs>\n </svg>\n </div>\n <div class="errorContainer"></div>\n </div>\n</div>\n<div>\n <label class="ff-card-form-label" for="cardHolderInput">Cardholder name</label>\n <input class="ff-card-form-text-input" id="cardHolderInput" type="text" pattern="[A-Za-z\\s]+" placeholder="Full name on card">\n <div class="errorContainer"></div>\n</div>\n<div>\n <label class="ff-card-form-label" for="emailAddressInput">Email</label>\n <input class="ff-card-form-text-input" id="emailAddressInput" placeholder="Email" type="email">\n <div class="errorContainer"></div>\n</div>\n<div id="countrySelectorField">\n <label class="ff-card-form-label" for="countrySelectorInput">Country</label>\n <div class="ff-select-wrap">\n <select class="ff-card-form-text-input ff-card-form-select" id="countrySelectorInput"></select>\n <div class="ff-select-arrow" aria-hidden="true"></div>\n </div>\n</div>\n<div>\n <label class="ff-card-form-label" for="postalCodeInput">Zip code</label>\n <input class="ff-card-form-text-input" id="postalCodeInput" placeholder="12345">\n <div class="errorContainer"></div>\n</div>\n'),this.wireCardInputs()}renderCardForm(){}getCardInputElements(){return this.cardInputElements}getCheckoutOptions(){return{cardElements:this.getCardInputElements()}}}var Pt=Object.freeze({__proto__:null,default:_t});const Mt={[e.PaymentMethod.PAYMENT_CARD]:'\x3c!-- Card Payments Section --\x3e\n<div class="ff-payment-method-card ff-payment-method-payment-card">\n <label class="ff-payment-method-label">\n <input type="radio" name="payment-method" value="PAYMENT_CARD" class="ff-payment-method-radio">\n <div class="ff-payment-method-header">\n <div class="ff-card-logos">\n <img class="payment-method-icon" style="max-height: 30px" src="https://assets.fnlfx.com/common/checkout/cards.webp" alt="visa, mastercard">\n </div>\n </div>\n </label>\n <div class="ff-payment-method-content">\n <div class="ff-card-form-container ff-payment-container" id="cardForm">\n <div class="loader-container">\n <div class="loader"></div>\n </div>\n <div class="payment-errors-container"></div>\n <button class="ff-card-form-submit-button" id="submitButton">\n Continue\n </button>\n <p class="ff-security-message">\n Your payment information is secure with SSL/TLS encryption\n </p>\n </div>\n </div>\n</div>\n',[e.PaymentMethod.PAYPAL]:'<div class="ff-payment-method-card ff-payment-method-paypal">\n <label class="ff-payment-method-label">\n <input type="radio" name="payment-method" value="PAYPAL" class="ff-payment-method-radio">\n <div class="ff-payment-method-header">\n <div class="ff-payment-logo ff-paypal-logo">\n <img class="payment-method-icon" style="max-height: 22px" src="https://assets.fnlfx.com/common/checkout/paypal.webp" alt="PayPal logo">\n </div>\n </div>\n </label>\n <div class="ff-payment-method-content">\n <ul class="ff-payment-features">\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span> Fast, convenient payment option </span>\n </li>\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span> Keeps your financial info safe with end-to-end encryption </span>\n </li>\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span> Backed by PayPal’s industry-leading fraud protection </span>\n </li>\n </ul>\n <div class="ff-paypal-button-container ff-payment-container" id="paypalButton"></div>\n <div class="loader-container payment-button-loader">\n <div class="loader"></div>\n </div>\n <div class="payment-errors-container"></div>\n <p class="ff-security-message">\n Your payment information is secure with SSL/TLS encryption\n </p>\n </div>\n</div>\n',[e.PaymentMethod.GOOGLE_PAY]:'\x3c!-- Google Pay Section --\x3e\n<div class="ff-payment-method-card ff-payment-method-google-pay">\n <label class="ff-payment-method-label ff-google-pay-header">\n <input type="radio" name="payment-method" value="GOOGLE_PAY" class="ff-payment-method-radio" checked="checked">\n <div class="ff-payment-method-header">\n <div class="ff-payment-logo ff-google-pay-logo">\n <img src="https://developers.google.com/static/pay/api/images/brand-guidelines/google-pay-mark.png" alt="Google Pay">\n </div>\n </div>\n </label>\n <div class="ff-payment-method-content">\n <ul class="ff-payment-features">\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span>Easy and private payments with Face/Touch ID</span>\n </li>\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span>Keeps your financial info safe with end-to-end encryption</span>\n </li>\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span>Protected by Google Pay\'s unique Device Account Number</span>\n </li>\n </ul>\n <div class="ff-google-pay-button-container ff-payment-container" id="googlePayButton"></div>\n <div class="loader-container payment-button-loader">\n <div class="loader"></div>\n </div>\n <div class="payment-errors-container"></div>\n <p class="ff-security-message">\n Your payment information is secure with SSL/TLS encryption\n </p>\n </div>\n</div>\n',[e.PaymentMethod.APPLE_PAY]:'\x3c!-- Apple Pay Section --\x3e\n<div class="ff-payment-method-card ff-payment-method-apple-pay">\n <label class="ff-payment-method-label">\n <input type="radio" name="payment-method" value="APPLE_PAY" class="ff-payment-method-radio">\n <div class="ff-payment-method-header">\n <div class="ff-payment-logo ff-apple-pay-logo">\n <svg class="payment-method-icon" height="26" viewBox="0 0 63 26" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path fill-rule="evenodd" clip-rule="evenodd" d="M8.41022 4.82398C9.5916 4.92293 10.773 4.23026 11.5113 3.35205C12.2374 2.4491 12.7173 1.23692 12.5943 0C11.5483 0.0494767 10.2561 0.692674 9.51777 1.59562C8.84093 2.37488 8.26255 3.63654 8.41022 4.82398ZM22.4638 20.7555V1.47193H29.6628C33.3793 1.47193 35.9758 4.04471 35.9758 7.80494C35.9758 11.5652 33.33 14.1627 29.5644 14.1627H25.4418V20.7555H22.4638ZM12.5819 5.05898C11.5411 4.99877 10.5914 5.37358 9.82438 5.67633C9.33075 5.87116 8.91274 6.03614 8.59472 6.03614C8.23784 6.03614 7.80257 5.86234 7.31387 5.66719C6.6735 5.4115 5.94138 5.11916 5.17364 5.13319C3.41387 5.15793 1.77716 6.15983 0.878819 7.75545C-0.967091 10.9467 0.398882 15.6717 2.18326 18.2693C3.05699 19.5556 4.10301 20.9657 5.48129 20.9163C6.08765 20.8933 6.52383 20.7072 6.97524 20.5147C7.49492 20.293 8.0348 20.0628 8.87776 20.0628C9.69151 20.0628 10.2078 20.287 10.7033 20.5023C11.1746 20.707 11.6271 20.9036 12.2989 20.8915C13.7264 20.8668 14.6247 19.6051 15.4984 18.3187C16.4413 16.9381 16.8557 15.5906 16.9186 15.3861C16.9222 15.3745 16.9246 15.3665 16.9259 15.3625C16.9244 15.361 16.9128 15.3556 16.8922 15.3462C16.577 15.2011 14.1679 14.0926 14.1448 11.1199C14.1216 8.62473 16.0556 7.36054 16.3601 7.16153C16.3786 7.14944 16.3911 7.14125 16.3968 7.137C15.1662 5.30636 13.2464 5.10845 12.5819 5.05898ZM41.4153 20.9039C43.2858 20.9039 45.0209 19.9515 45.8085 18.4424H45.8701V20.7555H48.6266V11.157C48.6266 8.37393 46.4115 6.5804 43.0027 6.5804C39.8401 6.5804 37.5019 8.39866 37.4158 10.8972H40.0985C40.32 9.70979 41.4153 8.93054 42.9166 8.93054C44.7379 8.93054 45.7593 9.78401 45.7593 11.3549V12.4186L42.0429 12.6413C38.5849 12.8516 36.7143 14.274 36.7143 16.7479C36.7143 19.2464 38.6464 20.9039 41.4153 20.9039ZM42.215 18.6156C40.6275 18.6156 39.6184 17.8487 39.6184 16.6736C39.6184 15.4615 40.5906 14.7564 42.4488 14.6451L45.7591 14.4348V15.5233C45.7591 17.3292 44.2332 18.6156 42.215 18.6156ZM57.7699 21.51C56.5762 24.8868 55.2103 26 52.306 26C52.0845 26 51.3461 25.9753 51.1739 25.9258V23.6127C51.3585 23.6375 51.8138 23.6622 52.0476 23.6622C53.3643 23.6622 54.1027 23.1056 54.558 21.6584L54.8288 20.8049L49.7833 6.76594H52.8967L56.4039 18.1579H56.4655L59.9727 6.76594H63L57.7699 21.51ZM25.4416 3.99524H28.875C31.4592 3.99524 32.936 5.38059 32.936 7.81731C32.936 10.254 31.4592 11.6518 28.8627 11.6518H25.4416V3.99524Z" fill="currentColor"/>\n </svg>\n </div>\n </div>\n </label>\n <div class="ff-payment-method-content">\n <ul class="ff-payment-features">\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span>Easy and private payments with Face/Touch ID</span>\n </li>\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span>Keeps your financial info safe with end-to-end encryption</span>\n </li>\n <li class="ff-payment-feature">\n <svg width="13" height="11" viewBox="0 0 13 11" fill="none">\n <path stroke="#F8545D" d="M11.1997 1.80133L6.99269 8.63774C6.68226 9.14218 5.9932 9.24721 5.54659 8.85815L2.19971 5.94254" stroke-width="2.66667" stroke-linecap="round"></path>\n </svg>\n <span>Protected by Apple Pay’s unique Device Account Number</span>\n </li>\n </ul>\n <div class="ff-apple-pay-button-container ff-payment-container" id="applePayButton"></div>\n <div class="loader-container payment-button-loader">\n <div class="loader"></div>\n </div>\n <div class="payment-errors-container"></div>\n <p class="ff-security-message">\n Your payment information is secure with Apple Pay encryption\n </p>\n </div>\n</div>\n'};class It{constructor(t,n){this.onLoaderChange=e=>{document.querySelectorAll(`${this.containerSelector} .loader-container`)?.forEach(t=>{t.style.display=e?"flex":"none"})},this.onError=(e,t)=>{if(!e)return void this.containerEl.querySelectorAll(".payment-errors-container")?.forEach(e=>{e.innerHTML=""});let n=null;if(t){const e=t.replace("_","-").toLowerCase();n=this.containerEl.querySelector(`.ff-payment-method-${e} .payment-errors-container`)}n&&(n.textContent=e?.message||"")},this.onStatusChange=(e,t)=>{["initializing"].includes(e)||"initializing"!==t||this.onLoaderChange(!1),"updating"===e&&this.onLoaderChange(!0),"ready"===e&&"updating"===t&&this.onLoaderChange(!1)},this.onSuccess=()=>{const e=document.querySelector("#success-screen")?.innerHTML;document.querySelectorAll(".ff-payment-container").forEach(t=>{t.innerHTML=e}),this.onLoaderChange(!1)},this.onDestroy=()=>{this.containerEl.innerHTML&&(this.containerEl.innerHTML="")},this.onInputError=e=>{this.cardInstance.onInputError(e)},this.onMethodRender=t=>{const n=t.replace("_","-").toLowerCase(),r=this.containerEl.querySelector(`.ff-payment-method-${n}`);t===e.PaymentMethod.PAYMENT_CARD&&this.cardInstance.onMethodRender(),r&&r.classList.add("visible")},this.onMethodsAvailable=e=>{this.availableMethods=e,this.initAccordion(),e.forEach(this.onMethodRender)},this.onStartPurchase=e=>{this.currentPurchaseMethod=e},this.onPurchaseFailure=e=>{this.currentPurchaseMethod&&this.onError(e,this.currentPurchaseMethod),this.currentPurchaseMethod=null},this.onPurchaseCompleted=()=>{this.currentPurchaseMethod=null},this.containerSelector=t.container,this.paymentMethodOrder=t.paymentMethodOrder;const r=document.querySelector(this.containerSelector);if(!r)throw new Error(`Container element not found for selector: ${this.containerSelector}`);this.containerEl=r,this.checkoutConfig=t,this.cardSessionFieldConfig=n}initAccordion(){const e=this.containerEl.querySelectorAll(".ff-payment-method-card"),t=this.containerEl.querySelectorAll(".ff-payment-method-radio"),n=t=>{e.forEach(e=>{const n=e.querySelector(".ff-payment-method-radio");n===t&&n?.checked?e.classList.add("expanded"):e.classList.remove("expanded")})},r=Array.from(t).find(e=>this.availableMethods.includes(e.value));if(!r)throw new Error("Default skin accordion initialization error: No radio button found");setTimeout(()=>{r.checked=!0,n(r)},0),t.forEach(e=>{e.addEventListener("change",()=>{e.checked&&n(e)})})}wireCardInputs(){this.cardInstance.wireCardInputs();const e=this.containerEl.querySelector("#submitButton");if(!e)throw new Error("One or more card input elements are missing in the default skin");this.cardInputElements={...this.cardInstance.getCardInputElements(),button:e}}async init(){this.containerEl.insertAdjacentHTML("beforeend",'<div class="ff-skin-default" id="ff-payment-method-containers">\n <div id="success-screen" style="display: none">\n <div class="success">\n <img alt="Loading" src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTAiIGhlaWdodD0iNTAiIHZpZXdCb3g9IjAgMCA1MCA1MCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTI1IDAuMTExMzI4QzIwLjA3NzQgMC4xMTEzMjggMTUuMjY1NCAxLjU3MTA0IDExLjE3MjUgNC4zMDU4NkM3LjA3OTUyIDcuMDQwNjkgMy44ODk0NSAxMC45Mjc4IDIuMDA1NjYgMTUuNDc1N0MwLjEyMTg4MyAyMC4wMjM1IC0wLjM3MSAyNS4wMjc4IDAuNTg5MzQzIDI5Ljg1NThDMS41NDk2OSAzNC42ODM4IDMuOTIwMTIgMzkuMTE4NSA3LjQwMDkgNDIuNTk5M0MxMC44ODE3IDQ2LjA4MDEgMTUuMzE2NCA0OC40NTA1IDIwLjE0NDQgNDkuNDEwOUMyNC45NzI0IDUwLjM3MTIgMjkuOTc2NyA0OS44NzgzIDM0LjUyNDYgNDcuOTk0NkMzOS4wNzI0IDQ2LjExMDggNDIuOTU5NSA0Mi45MjA3IDQ1LjY5NDQgMzguODI3N0M0OC40MjkyIDM0LjczNDggNDkuODg4OSAyOS45MjI4IDQ5Ljg4ODkgMjUuMDAwMkM0OS44ODg5IDE4LjM5OTMgNDcuMjY2NyAxMi4wNjg3IDQyLjU5OTEgNy40MDExMkMzNy45MzE1IDIuNzMzNTQgMzEuNjAwOSAwLjExMTMyOCAyNSAwLjExMTMyOFpNNDEuMjU1NiAxNi42NDY5TDIwLjgxNTYgMzcuMDcxM0w4Ljc0NDQ0IDI1LjAwMDJDOC4zMzE4OCAyNC41ODc3IDguMTAwMTEgMjQuMDI4MSA4LjEwMDExIDIzLjQ0NDdDOC4xMDAxMSAyMi44NjEyIDguMzMxODggMjIuMzAxNyA4Ljc0NDQ0IDIxLjg4OTFDOS4xNTcgMjEuNDc2NSA5LjcxNjU1IDIxLjI0NDggMTAuMyAyMS4yNDQ4QzEwLjg4MzQgMjEuMjQ0OCAxMS40NDMgMjEuNDc2NSAxMS44NTU2IDIxLjg4OTFMMjAuODQ2NyAzMC44ODAyTDM4LjE3NTYgMTMuNTY2OUMzOC4zNzk4IDEzLjM2MjYgMzguNjIyMyAxMy4yMDA2IDM4Ljg4OTIgMTMuMDlDMzkuMTU2MiAxMi45Nzk1IDM5LjQ0MjIgMTIuOTIyNiAzOS43MzExIDEyLjkyMjZDNDAuMDIgMTIuOTIyNiA0MC4zMDYxIDEyLjk3OTUgNDAuNTczIDEzLjA5QzQwLjgzOTkgMTMuMjAwNiA0MS4wODI0IDEzLjM2MjYgNDEuMjg2NyAxMy41NjY5QzQxLjQ5MDkgMTMuNzcxMiA0MS42NTMgMTQuMDEzNyA0MS43NjM1IDE0LjI4MDZDNDEuODc0MSAxNC41NDc1IDQxLjkzMSAxNC44MzM1IDQxLjkzMSAxNS4xMjI0QzQxLjkzMSAxNS40MTEzIDQxLjg3NDEgMTUuNjk3NCA0MS43NjM1IDE1Ljk2NDNDNDEuNjUzIDE2LjIzMTIgNDEuNDkwOSAxNi40NzM3IDQxLjI4NjcgMTYuNjc4TDQxLjI1NTYgMTYuNjQ2OVoiIGZpbGw9IiM4RURGQzIiLz4KPC9zdmc+Cg==">\n <div>Payment completed successfully</div>\n </div>\n </div>\n</div>\n');const e=this.containerEl.querySelector("#ff-payment-method-containers");this.paymentMethodOrder.forEach(t=>{e.insertAdjacentHTML("beforeend",Mt[t])}),this.cardInstance=new _t(document.querySelector("#cardForm"),this.checkoutConfig,this.cardSessionFieldConfig),this.cardInstance.init(),this.wireCardInputs()}renderCardForm(){}getCardInputElements(){return{...this.cardInstance.getCardInputElements(),button:this.cardInputElements.button}}getPaymentButtonElements(){return{paypal:this.containerEl.querySelector("#paypalButton"),googlePay:this.containerEl.querySelector("#googlePayButton"),applePay:this.containerEl.querySelector("#applePayButton")}}getCheckoutOptions(){return{...this.cardInstance.getCheckoutOptions(),cardElements:this.getCardInputElements(),paymentButtonElements:this.getPaymentButtonElements(),applePay:H[e.PaymentMethod.APPLE_PAY],paypal:H[e.PaymentMethod.PAYPAL],googlePay:H[e.PaymentMethod.GOOGLE_PAY]}}}var kt=Object.freeze({__proto__:null,default:async(e,t)=>{const n=new It(e,t);return await n.init(),n}});const Tt=new Map;function Rt(e){return Tt.has(e)||Tt.set(e,ue(e)),Tt.get(e)}var At=Object.freeze({__proto__:null,mountStripeCardForm:async function(e,t,n){const{stripe_public_key:r,amount:o,currency:i,order_id:a,is_link_enabled:s,amount_total:d}=t.data,l=t.data.tax_enabled??n.enableTax??!1,c=await Rt(r);if(!c)throw new Error("Failed to load Stripe");e.replaceChildren();const u=c.elements({mode:"subscription",amount:o,currency:i,paymentMethodCreation:"manual",paymentMethodTypes:s?["card","link"]:["card"],appearance:n.appearance}),h=t.data.show_country_selector_field??!1,p=t.data.show_postal_code_field??!1,m=h||p,y=u.create("payment",{layout:"tabs",wallets:{applePay:n.showWallets?"auto":"never",googlePay:n.showWallets?"auto":"never"},terms:{card:"never"},fields:{billingDetails:{address:{line1:"never",line2:"never",city:"never",state:"never",country:h?"auto":"never",postalCode:p?"auto":"never"}}},...t.data.detected_country_code&&h?{defaultValues:{billingDetails:{address:{country:t.data.detected_country_code}}}}:{}}),f={line1:"",line2:"",city:"",state:""};let g;h||(f.country=t.data.detected_country_code??""),p||(f.postal_code="");let w=0;l&&t.data.tax_calculation_id&&(g={id:t.data.tax_calculation_id,country:t.data.detected_country_code??void 0,postal:void 0});let S={},E=async()=>{};const b=async()=>{const e=S.country,r=S.postalCode;if(!e)return;const o=++w;try{const i=await n.apiClient.recalculateTax({orderId:a,clientToken:t.data.client_token,countryCode:e,postalCode:r});if(o!==w)return;g={id:i.tax_calculation_id,country:e,postal:r},n.onTaxChange?.({amountTotal:i.amount_total,currency:i.currency,...C(i)})}catch(t){if(o!==w)return;g&&g.country===e&&g.postal===r||(g=void 0,n.onTaxError?.(t))}};if(y.mount(e),l&&m){let e;S={country:t.data.detected_country_code||void 0},E=async()=>{e&&(clearTimeout(e),e=void 0),await b()},y.on("change",n=>{const r=n.value.billingDetails?.address;S={country:r?.country||t.data.detected_country_code||void 0,postalCode:r?.postalCode||void 0},S.country&&(e&&clearTimeout(e),e=setTimeout(b,600))})}return l&&null!=d&&n.onTaxChange?.({amountTotal:d,currency:i,...C(t.data)}),l&&m&&b(),await new Promise((e,t)=>{y.once("ready",()=>e()),y.once("loaderror",e=>t(e.error))}),n.onRenderSuccess?.(),{submit:async()=>{n.onLoaderChange?.(!0);try{l&&m&&await E();const{error:e}=await u.submit();if(e)throw e;const{error:r,paymentMethod:o}=await c.createPaymentMethod({elements:u,params:{billing_details:{address:f}}});if(r)throw r;const i=l?(m?S.country:t.data.detected_country_code)??n.countryCode:n.countryCode,s=l&&m?S.postalCode:void 0,d=l&&g&&g.country===i&&g.postal===s,h=await n.apiClient.createPayment({orderId:a,paymentMethodToken:o.id,email:n.email,countryCode:i,postalCode:s,taxCalculationId:d?g.id:void 0,clientMetadata:n.clientMetadata}),p=n.apiClient.processPaymentResponse(h);if("action_required"===p.type){const{error:e}=await c.handleNextAction({clientSecret:p.clientToken});if(e)throw e}n.invalidateSession?.(),n.onPaymentSuccess?.(o,a)}catch(e){throw n.onPaymentFail?.(W(e)),e}finally{n.onLoaderChange?.(!1)}}}}});const xt=new WeakMap;function Dt(e,t,n){const r=t.apple_pay_recurring_payment_request;if(r){const e=e=>{e.recurringPaymentStartDate&&Object.assign(e,{recurringPaymentStartDate:new Date(e.recurringPaymentStartDate)}),e.recurringPaymentEndDate&&Object.assign(e,{recurringPaymentEndDate:new Date(e.recurringPaymentEndDate)})};e(r.regularBilling),r.trialBilling&&e(r.trialBilling)}const o=r?{recurringPaymentRequest:r}:void 0,i=t.amount,a=t.tax_amount??0,s=t.amount_total??i;return e.paymentRequest({country:t.country,currency:t.currency,total:{label:n?.trim()||"Total",amount:s},displayItems:a>0?[{label:"Subtotal",amount:i},{label:"Tax",amount:a}]:void 0,requestPayerName:!1,requestPayerEmail:!1,applePay:o})}var Lt=Object.freeze({__proto__:null,getAvailableWallet:async function(e){const{stripe_public_key:t}=e.data,n=await Rt(t);if(!n)throw new Error("Failed to load Stripe");const r=Dt(n,e.data),o=await r.canMakePayment();return o?(xt.set(e.data,{paymentRequest:r,canMakePayment:o}),o.applePay?"APPLE_PAY":o.googlePay?"GOOGLE_PAY":null):null},purchaseWallet:async function(e,t){const{stripe_public_key:n,order_id:r}=e.data,o=e.data.tax_enabled??!1,i=await Rt(n);if(!i)throw new Error("Failed to load Stripe");const a=xt.get(e.data);let s;if(xt.delete(e.data),a){s=a.paymentRequest;const n=Dt(i,e.data);n.canMakePayment().catch(()=>{}),xt.set(e.data,{paymentRequest:n,canMakePayment:a.canMakePayment});const r=t.totalLabel?.trim();if(r){const t=e.data.amount_total??e.data.amount;s.update({total:{label:r,amount:t}})}}else{s=Dt(i,e.data,t.totalLabel);if(!await s.canMakePayment())throw new Error("No wallet payment method available")}return o&&null!=e.data.amount_total&&t.onTaxChange?.({amountTotal:e.data.amount_total,currency:e.data.currency,...C(e.data)}),new Promise((n,a)=>{s.on("paymentmethod",async s=>{let d=!1;const l=e=>{if(!d){d=!0;try{s.complete(e)}catch{return}}};t.onLoaderChange?.(!0);try{const a=o?s.paymentMethod.billing_details.address:void 0,d=await t.apiClient.createPayment({orderId:r,paymentMethodToken:s.paymentMethod.id,email:t.email,countryCode:o&&(a?.country||e.data.detected_country_code)||t.countryCode,postalCode:o&&a?.postal_code||void 0,taxCalculationId:o?e.data.tax_calculation_id:void 0,clientMetadata:t.clientMetadata}),c=t.apiClient.processPaymentResponse(d);if("action_required"===c.type){const{error:e}=await i.handleNextAction({clientSecret:c.clientToken});if(e)throw e}l("success"),t.invalidateSession?.(),t.onPaymentSuccess?.(s.paymentMethod,r),n()}catch(e){l("fail"),t.onPaymentFail?.(W(e)),a(e)}finally{t.onLoaderChange?.(!1)}}),s.on("cancel",()=>{t.onPaymentCancel?.(),n()}),s.show()})}});e.APIError=o,e.Billing=vt,e.CHECKOUT_STATES={INITIALIZING:"initializing",READY:"ready",PROCESSING:"processing",ACTION_REQUIRED:"action_required",UPDATING:"updating",COMPLETED:"completed",ERROR:"error",DESTROYED:"destroyed"},e.CheckoutError=a,e.ConfigurationError=class extends n{constructor(e){super(e,N.CONFIGURATION_ERROR),this.name="ConfigurationError"}},e.DEFAULTS=M,e.ERROR_CODES=N,e.EVENTS=I,e.FunnefoxSDKError=n,e.NetworkError=s,e.PrimerError=i,e.SDK_VERSION=P,e.ValidationError=r,e.configure=Ye,e.createCheckout=$e,e.createClientSession=Ge,e.default=vt,e.getAvailablePaymentMethods=ut,e.mountWalletUpsell=bt,Object.defineProperty(e,"__esModule",{value:!0})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelfox/billing",
3
- "version": "0.8.0-ffb-837.55",
3
+ "version": "0.8.0-ffb-805.56",
4
4
  "license": "MIT",
5
5
  "author": "Funnelfox",
6
6
  "description": "JavaScript SDK for Funnelfox billing with Primer integration",
@@ -26,7 +26,7 @@
26
26
  "scripts": {
27
27
  "build": "rm -rf dist && rollup -c",
28
28
  "build:watch": "rollup -c -w",
29
- "build:examples": "npm run build && npm pack && npm i ./funnelfox-billing-0.8.0-ffb-837.55.tgz --prefix examples/basic && npm run build --prefix examples/basic",
29
+ "build:examples": "npm run build && npm pack && npm i ./funnelfox-billing-0.8.0-ffb-805.56.tgz --prefix examples/basic && npm run build --prefix examples/basic",
30
30
  "version": "node scripts/sync-version.js",
31
31
  "release:patch": "npm version patch --no-git-tag-version",
32
32
  "release:minor": "npm version minor --no-git-tag-version",
package/src/types.d.ts CHANGED
@@ -50,6 +50,16 @@ export interface APIConfig {
50
50
  region?: string;
51
51
  }
52
52
 
53
+ export interface DisplayLocaleOptions {
54
+ /**
55
+ * ISO 4217 currency the page showed the price in. Billing charges it when the price point
56
+ * offers it, else the price point's own currency.
57
+ */
58
+ displayCurrency?: string;
59
+ /** ISO 3166-1 alpha-2 country the page resolved that currency for. */
60
+ displayCountry?: string;
61
+ }
62
+
53
63
  export interface Customer {
54
64
  email: string;
55
65
  externalId: string;
@@ -112,7 +122,8 @@ export interface PrimerCheckoutConfig extends Pick<
112
122
  cardSelectors?: CardInputSelectors;
113
123
  paymentButtonSelectors?: PaymentButtonSelectors;
114
124
  }
115
- export interface CheckoutConfig extends PrimerCheckoutConfig {
125
+ export interface CheckoutConfig
126
+ extends PrimerCheckoutConfig, DisplayLocaleOptions {
116
127
  customer: Customer;
117
128
  priceId: string;
118
129
  container: string;
@@ -368,7 +379,7 @@ export declare function createCheckout(
368
379
  options: CreateCheckoutOptions
369
380
  ): Promise<CheckoutInstance>;
370
381
 
371
- export interface CreateClientSessionOptions {
382
+ export interface CreateClientSessionOptions extends DisplayLocaleOptions {
372
383
  region?: string;
373
384
  priceId: string;
374
385
  externalId: string;
@@ -435,7 +446,8 @@ export interface InitMethodOptions
435
446
  >,
436
447
  'card'
437
448
  >,
438
- InitMethodCallbacks {
449
+ InitMethodCallbacks,
450
+ DisplayLocaleOptions {
439
451
  applePay?: BillingApplePayOptions;
440
452
  card?: BillingCardOptions;
441
453
  orgId: string;
@@ -484,6 +496,8 @@ export interface SilentPurchaseOptions {
484
496
  initiationType?: 'cit' | 'mit';
485
497
  /** CIT card networks (sent only when set). `[]` = all networks. */
486
498
  citCardNetworks?: string[];
499
+ /** The currency the upsell page showed; omitted = the customer's purchase currency, else the default. */
500
+ displayCurrency?: string;
487
501
  /**
488
502
  * @deprecated Not sent any more: a saved Google Pay token is never charged as CIT, and the
489
503
  * backend ignores the field. Wallet buyers confirm the upsell again with `mountWalletUpsell`.
@@ -557,6 +571,8 @@ export interface MountWalletUpsellOptions {
557
571
  orgId: string;
558
572
  priceId: string;
559
573
  externalId: string;
574
+ /** As in `silentPurchase`. */
575
+ displayCurrency?: string;
560
576
  clientMetadata?: Record<string, unknown>;
561
577
  /** Default: the `configure()` value, else https://billing.funnelfox.com. */
562
578
  baseUrl?: string;
@@ -750,6 +766,8 @@ export interface CreateClientSessionRequest {
750
766
  external_id: string;
751
767
  email_address?: string;
752
768
  country_code?: string;
769
+ display_currency_code?: string;
770
+ display_country_code?: string;
753
771
  client_metadata?: MetadataType;
754
772
  }
755
773
 
@@ -905,6 +923,7 @@ export interface OneClickRequest {
905
923
  client_metadata: Record<string, string | number | boolean>;
906
924
  initiation_type?: 'cit' | 'mit';
907
925
  cit_card_networks?: string[];
926
+ display_currency_code?: string;
908
927
  idempotency_key?: string;
909
928
  /** Wallet re-auth: the single-use token of the confirmed wallet sheet, with `session_id`. */
910
929
  payment_method_token?: string;