swell-js 5.4.0 → 5.5.0

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/dist/swell.cjs CHANGED
@@ -6612,6 +6612,7 @@ const SCRIPT_HANDLERS = {
6612
6612
  'braintree-google-payment': loadBraintreeGoogle,
6613
6613
  'braintree-apple-payment': loadBraintreeApple,
6614
6614
  'amazon-checkout': loadAmazonCheckout,
6615
+ 'convesiopay-js': loadConvesioPay,
6615
6616
  'sezzle-sdk': loadSezzleCheckout,
6616
6617
  };
6617
6618
 
@@ -6780,6 +6781,16 @@ async function loadAmazonCheckout() {
6780
6781
  }
6781
6782
  }
6782
6783
 
6784
+ async function loadConvesioPay() {
6785
+ if (!window.ConvesioPay) {
6786
+ await loadScript('convesiopay-js', 'https://js.convesiopay.com/v1/');
6787
+ }
6788
+
6789
+ if (!window.ConvesioPay) {
6790
+ console.error('Warning: ConvesioPay was not loaded');
6791
+ }
6792
+ }
6793
+
6783
6794
  async function loadSezzleCheckout() {
6784
6795
  if (!window.Checkout) {
6785
6796
  await loadScript(
@@ -7151,6 +7162,8 @@ class Payment {
7151
7162
  /** @typedef {import('@stripe/stripe-js').StripeCardNumberElement} StripeCardNumberElement */
7152
7163
  /** @typedef {import('@stripe/stripe-js').CreateSourceData} CreateSourceData */
7153
7164
 
7165
+ /** @typedef {import('../../types').Cart} Cart */
7166
+
7154
7167
  // https://stripe.com/docs/currencies#minimum-and-maximum-charge-amounts
7155
7168
  const MINIMUM_CHARGE_AMOUNT = {
7156
7169
  USD: 0.5,
@@ -7205,6 +7218,10 @@ function mapValues(fieldsMap, data) {
7205
7218
  return result;
7206
7219
  }
7207
7220
 
7221
+ /**
7222
+ * @param {Cart} cart
7223
+ * @returns {object}
7224
+ */
7208
7225
  function getBillingDetails(cart) {
7209
7226
  const details = {
7210
7227
  ...mapValues(billingFieldsMap, cart.billing),
@@ -7249,7 +7266,7 @@ function createElement(type, elements, params) {
7249
7266
  /**
7250
7267
  * @param {Stripe} stripe
7251
7268
  * @param {StripeCardElement | StripeCardNumberElement} cardElement
7252
- * @param {object} cart
7269
+ * @param {Cart} cart
7253
7270
  */
7254
7271
  async function createPaymentMethod(stripe, cardElement, cart) {
7255
7272
  const billingDetails = getBillingDetails(cart);
@@ -7277,7 +7294,7 @@ async function createPaymentMethod(stripe, cardElement, cart) {
7277
7294
  /**
7278
7295
  * @param {Stripe} stripe
7279
7296
  * @param {import('@stripe/stripe-js').StripeIdealBankElement} element
7280
- * @param {object} cart
7297
+ * @param {Cart} cart
7281
7298
  */
7282
7299
  async function createIDealPaymentMethod(stripe, element, cart) {
7283
7300
  const billingDetails = getBillingDetails(cart);
@@ -7288,6 +7305,10 @@ async function createIDealPaymentMethod(stripe, element, cart) {
7288
7305
  });
7289
7306
  }
7290
7307
 
7308
+ /**
7309
+ * @param {Cart} cart
7310
+ * @returns {object}
7311
+ */
7291
7312
  function getKlarnaIntentDetails(cart) {
7292
7313
  const { account, currency, capture_total } = cart;
7293
7314
  const stripeCustomer = account && account.stripe_customer;
@@ -7308,7 +7329,7 @@ function getKlarnaIntentDetails(cart) {
7308
7329
  }
7309
7330
 
7310
7331
  /**
7311
- * @param {object} cart
7332
+ * @param {Cart} cart
7312
7333
  * @returns {import('@stripe/stripe-js').ConfirmKlarnaPaymentData}
7313
7334
  */
7314
7335
  function getKlarnaConfirmationDetails(cart) {
@@ -7328,7 +7349,7 @@ function getKlarnaConfirmationDetails(cart) {
7328
7349
  /**
7329
7350
  * Returns Bancontact Setup Intent confirmation details.
7330
7351
  *
7331
- * @param {object} cart
7352
+ * @param {Cart} cart
7332
7353
  * @returns {import('@stripe/stripe-js').ConfirmBancontactPaymentData}
7333
7354
  */
7334
7355
  function getBancontactConfirmationDetails(cart) {
@@ -7346,7 +7367,7 @@ function getBancontactConfirmationDetails(cart) {
7346
7367
  }
7347
7368
 
7348
7369
  /**
7349
- * @param {object} cart
7370
+ * @param {Cart} cart
7350
7371
  * @param {object} params
7351
7372
  * @returns {import('@stripe/stripe-js').PaymentRequestOptions}
7352
7373
  */
@@ -7430,6 +7451,11 @@ const zeroDecimalCurrencies = new Set([
7430
7451
  'XOF', // West African Cfa Franc
7431
7452
  ]);
7432
7453
 
7454
+ /**
7455
+ * @param {string} currency
7456
+ * @param {number} amount
7457
+ * @returns {number}
7458
+ */
7433
7459
  function stripeAmountByCurrency(currency, amount) {
7434
7460
  if (zeroDecimalCurrencies.has(currency.toUpperCase())) {
7435
7461
  return amount;
@@ -7438,6 +7464,11 @@ function stripeAmountByCurrency(currency, amount) {
7438
7464
  return Math.round(amount * 100);
7439
7465
  }
7440
7466
 
7467
+ /**
7468
+ * @param {number} amount
7469
+ * @param {string} currency
7470
+ * @returns {boolean}
7471
+ */
7441
7472
  function isStripeChargeableAmount(amount, currency) {
7442
7473
  const minAmount = MINIMUM_CHARGE_AMOUNT[currency];
7443
7474
  return !minAmount || amount >= minAmount;
@@ -8666,6 +8697,44 @@ function getDiscountLabel(discount, cart) {
8666
8697
  return discount.id;
8667
8698
  }
8668
8699
 
8700
+ /** @type {Map<string, number>} */
8701
+ const CURRENCIES_CENTS = new Map();
8702
+
8703
+ /**
8704
+ * @param {string} currency
8705
+ * @returns {number}
8706
+ */
8707
+ function getCurrencyCents(currency) {
8708
+ let cents = CURRENCIES_CENTS.get(currency);
8709
+
8710
+ if (cents !== undefined) {
8711
+ return cents;
8712
+ }
8713
+
8714
+ const formatter = new Intl.NumberFormat('en-US', {
8715
+ style: 'currency',
8716
+ currency,
8717
+ });
8718
+
8719
+ const options = formatter.resolvedOptions();
8720
+ const decimals = options.maximumFractionDigits ?? 2;
8721
+
8722
+ cents = 10 ** decimals;
8723
+
8724
+ CURRENCIES_CENTS.set(currency, cents);
8725
+
8726
+ return cents;
8727
+ }
8728
+
8729
+ /**
8730
+ * @param {string} currency
8731
+ * @param {number} amount
8732
+ * @returns {number}
8733
+ */
8734
+ function amountInCents$1(currency, amount) {
8735
+ return Math.round(amount * getCurrencyCents(currency));
8736
+ }
8737
+
8669
8738
  /** @typedef {import('./payment').default} Payment */
8670
8739
  /** @typedef {import('../../types').Cart} Cart */
8671
8740
  /** @typedef {import('../../types').Address} Address */
@@ -9237,29 +9306,16 @@ class BraintreeGooglePayment extends Payment {
9237
9306
  /** @typedef {import('../../types').Address} Address */
9238
9307
 
9239
9308
  /**
9240
- * Handles Apple Pay shipping contact selection event
9241
- *
9242
- * IMPORTANT: This event fires automatically when the Apple Pay sheet opens
9243
- * with the user's default address. This is expected Apple Pay behavior.
9244
- *
9245
- * The flow:
9246
- * 1. Apple Pay sheet opens → This event fires with default address
9247
- * 2. User changes address → This event fires again with new address
9248
- * 3. Each time, we:
9249
- * - Send the address to Swell to calculate shipping/tax
9250
- * - Return updated totals and available shipping methods
9251
- *
9252
9309
  * @this {Payment}
9253
- * @param {ApplePaySession} session
9254
- * @param {ApplePayJS.ApplePayShippingContactSelectedEvent} event
9255
- * @returns {void}
9310
+ * @param {ApplePayJS.ApplePayPaymentContact} shippingContact
9311
+ * @returns {Promise<ApplePayJS.ApplePayShippingContactUpdate>}
9256
9312
  */
9257
- async function onShippingContactSelected(session, event) {
9313
+ async function onShippingAddressChange(shippingContact) {
9258
9314
  try {
9259
9315
  // Update cart with Apple Pay shipping address to get shipping options and tax
9260
9316
  // This happens immediately when the sheet opens with the default address
9261
9317
  const cart = await this.updateCart({
9262
- shipping: convertToSwellAddress$1(event.shippingContact),
9318
+ shipping: convertToSwellAddress$1(shippingContact),
9263
9319
  });
9264
9320
 
9265
9321
  if (!cart.shipment_rating?.services?.length) {
@@ -9267,69 +9323,104 @@ async function onShippingContactSelected(session, event) {
9267
9323
  cart.shipment_rating?.errors?.find(Boolean)?.message ??
9268
9324
  'Shipping is not available for the provided address.';
9269
9325
 
9270
- return session.completeShippingContactSelection({
9326
+ return {
9271
9327
  newTotal: getTotal(cart),
9272
- newLineItems: getLineItems(cart),
9328
+ newLineItems: getLineItems$1(cart),
9273
9329
  newShippingMethods: [], // REQUIRED: Must always provide this, even as empty array
9274
9330
  errors: [
9275
9331
  new ApplePayError('addressUnserviceable', 'postalAddress', message),
9276
9332
  ],
9277
- });
9333
+ };
9278
9334
  }
9279
9335
 
9280
9336
  // Success: Return updated totals and shipping methods
9281
- session.completeShippingContactSelection({
9337
+ return {
9282
9338
  newTotal: getTotal(cart),
9283
- newLineItems: getLineItems(cart),
9284
- newShippingMethods: getShippingMethods(cart),
9285
- });
9339
+ newLineItems: getLineItems$1(cart),
9340
+ newShippingMethods: getShippingMethods$1(cart),
9341
+ };
9286
9342
  } catch (err) {
9287
9343
  const cartData = await this.getCart();
9288
9344
 
9289
- session.completeShippingContactSelection({
9345
+ return {
9290
9346
  newTotal: getTotal(cartData),
9291
- newLineItems: getLineItems(cartData),
9347
+ newLineItems: getLineItems$1(cartData),
9292
9348
  newShippingMethods: [], // REQUIRED: Must always provide this, even as empty array
9293
9349
  errors: [new ApplePayError('unknown', undefined, err.message)],
9294
- });
9350
+ };
9295
9351
  }
9296
9352
  }
9297
9353
 
9298
9354
  /**
9299
- * Handles Apple Pay shipping method selection
9355
+ * Handles Apple Pay shipping contact selection event
9300
9356
  *
9301
- * Triggered when the user selects a shipping method from the available options.
9302
- * We update the cart with the selected shipping service and return the updated
9303
- * total and line items (which now include the shipping cost).
9357
+ * IMPORTANT: This event fires automatically when the Apple Pay sheet opens
9358
+ * with the user's default address. This is expected Apple Pay behavior.
9304
9359
  *
9305
- * After this event, the total changes from type 'pending' to 'final' and shows
9306
- * the actual final amount to the user.
9360
+ * The flow:
9361
+ * 1. Apple Pay sheet opens This event fires with default address
9362
+ * 2. User changes address → This event fires again with new address
9363
+ * 3. Each time, we:
9364
+ * - Send the address to Swell to calculate shipping/tax
9365
+ * - Return updated totals and available shipping methods
9307
9366
  *
9308
9367
  * @this {Payment}
9309
9368
  * @param {ApplePaySession} session
9310
- * @param {ApplePayJS.ApplePayShippingMethodSelectedEvent} event
9369
+ * @param {ApplePayJS.ApplePayShippingContactSelectedEvent} event
9311
9370
  * @returns {void}
9312
9371
  */
9313
- async function onShippingMethodSelected(session, event) {
9372
+ async function onShippingContactSelected(session, event) {
9373
+ session.completeShippingContactSelection(
9374
+ await onShippingAddressChange.call(this, event.shippingContact),
9375
+ );
9376
+ }
9377
+
9378
+ /**
9379
+ * @this {Payment}
9380
+ * @param {ApplePayJS.ApplePayShippingMethod} shippingMethod
9381
+ * @returns {Promise<ApplePayJS.ApplePayShippingMethodUpdate>}
9382
+ */
9383
+ async function onShippingMethodChange(shippingMethod) {
9314
9384
  try {
9315
9385
  const cart = await this.updateCart({
9316
9386
  shipping: {
9317
- service: event.shippingMethod.identifier,
9387
+ service: shippingMethod.identifier,
9318
9388
  },
9319
9389
  });
9320
9390
 
9321
- session.completeShippingMethodSelection({
9391
+ return {
9322
9392
  newTotal: getTotal(cart),
9323
- newLineItems: getLineItems(cart),
9324
- });
9393
+ newLineItems: getLineItems$1(cart),
9394
+ };
9325
9395
  } catch (err) {
9326
- session.completeShippingMethodSelection({
9396
+ return {
9327
9397
  newTotal: getTotal(await this.getCart()),
9328
9398
  errors: [new ApplePayError('unknown', undefined, err.message)],
9329
- });
9399
+ };
9330
9400
  }
9331
9401
  }
9332
9402
 
9403
+ /**
9404
+ * Handles Apple Pay shipping method selection
9405
+ *
9406
+ * Triggered when the user selects a shipping method from the available options.
9407
+ * We update the cart with the selected shipping service and return the updated
9408
+ * total and line items (which now include the shipping cost).
9409
+ *
9410
+ * After this event, the total changes from type 'pending' to 'final' and shows
9411
+ * the actual final amount to the user.
9412
+ *
9413
+ * @this {Payment}
9414
+ * @param {ApplePaySession} session
9415
+ * @param {ApplePayJS.ApplePayShippingMethodSelectedEvent} event
9416
+ * @returns {void}
9417
+ */
9418
+ async function onShippingMethodSelected(session, event) {
9419
+ session.completeShippingMethodSelection(
9420
+ await onShippingMethodChange.call(this, event.shippingMethod),
9421
+ );
9422
+ }
9423
+
9333
9424
  /**
9334
9425
  * Handles Apple Pay coupon code changes
9335
9426
  *
@@ -9350,7 +9441,7 @@ async function onCouponCodeChanged(session, event) {
9350
9441
  // Valid coupon applied successfully
9351
9442
  session.completeCouponCodeChange({
9352
9443
  newTotal: getTotal(cart),
9353
- newLineItems: getLineItems(cart),
9444
+ newLineItems: getLineItems$1(cart),
9354
9445
  });
9355
9446
  } catch (err) {
9356
9447
  // HTTP 400 error from invalid coupon - get fresh cart state
@@ -9358,7 +9449,7 @@ async function onCouponCodeChanged(session, event) {
9358
9449
 
9359
9450
  session.completeCouponCodeChange({
9360
9451
  newTotal: getTotal(currentCart),
9361
- newLineItems: getLineItems(currentCart),
9452
+ newLineItems: getLineItems$1(currentCart),
9362
9453
  errors: [new ApplePayError('couponCodeInvalid', undefined, err.message)],
9363
9454
  });
9364
9455
  }
@@ -9412,7 +9503,7 @@ function getTotal(cart) {
9412
9503
  * @param {Cart} cart
9413
9504
  * @returns {ApplePayJS.ApplePayLineItem[]}
9414
9505
  */
9415
- function getLineItems(cart) {
9506
+ function getLineItems$1(cart) {
9416
9507
  const { sub_total, shipment_price, discount_total, tax_total } = cart;
9417
9508
 
9418
9509
  /** @type {ApplePayJS.ApplePayLineItem[]} */
@@ -9458,7 +9549,7 @@ function getLineItems(cart) {
9458
9549
  * @param {Cart} cart
9459
9550
  * @returns {ApplePayJS.ApplePayShippingMethod[]}
9460
9551
  */
9461
- function getShippingMethods(cart) {
9552
+ function getShippingMethods$1(cart) {
9462
9553
  const { shipment_delivery, shipment_rating } = cart;
9463
9554
 
9464
9555
  if (!shipment_delivery) {
@@ -10111,7 +10202,7 @@ class AuthorizeNetApplePayment extends Payment {
10111
10202
  requiredShippingContactFields,
10112
10203
  requiredBillingContactFields,
10113
10204
  supportsCouponCode: true,
10114
- lineItems: getLineItems(cart),
10205
+ lineItems: getLineItems$1(cart),
10115
10206
  };
10116
10207
  }
10117
10208
 
@@ -10371,6 +10462,298 @@ class QuickpayCardPayment extends Payment {
10371
10462
  }
10372
10463
  }
10373
10464
 
10465
+ class ConvesioCardPayment extends Payment {
10466
+ static convesioPay = null;
10467
+ static convesioPayComponent = null;
10468
+
10469
+ constructor(api, options, params, methods) {
10470
+ super(api, options, params, methods.card);
10471
+ }
10472
+
10473
+ get scripts() {
10474
+ return ['convesiopay-js'];
10475
+ }
10476
+
10477
+ get convesioPay() {
10478
+ if (ConvesioCardPayment.convesioPay === null) {
10479
+ if (window.ConvesioPay) {
10480
+ this.convesioPay = window.ConvesioPay(this.method.public_key);
10481
+ }
10482
+
10483
+ if (!ConvesioCardPayment.convesioPay) {
10484
+ throw new LibraryNotLoadedError('ConvesioPay');
10485
+ }
10486
+ }
10487
+
10488
+ return ConvesioCardPayment.convesioPay;
10489
+ }
10490
+
10491
+ set convesioPay(convesioPay) {
10492
+ ConvesioCardPayment.convesioPay = convesioPay;
10493
+ }
10494
+
10495
+ get convesioPayComponent() {
10496
+ return ConvesioCardPayment.convesioPayComponent;
10497
+ }
10498
+
10499
+ set convesioPayComponent(convesioPayComponent) {
10500
+ ConvesioCardPayment.convesioPayComponent = convesioPayComponent;
10501
+ }
10502
+
10503
+ async createElements(cart) {
10504
+ await this.loadScripts(this.scripts);
10505
+
10506
+ const component = this.convesioPay.component({
10507
+ environment: isLiveMode(this.method.mode) ? 'live' : 'test',
10508
+ integration: this.method.integration,
10509
+ customerEmail: cart.account?.email,
10510
+ express: false,
10511
+ disabledPaymentMethods: {
10512
+ btcpay: true,
10513
+ applePay: true,
10514
+ googlePay: true,
10515
+ },
10516
+ });
10517
+
10518
+ this.convesioPayComponent = component;
10519
+
10520
+ component.mount(`#${this.params.elementId || 'card-element'}`);
10521
+ }
10522
+
10523
+ async tokenize() {
10524
+ if (!this.convesioPayComponent) {
10525
+ throw new Error('ConvesioPay element is not defined');
10526
+ }
10527
+
10528
+ const token = await this.convesioPayComponent.createToken();
10529
+
10530
+ await this.updateCart({
10531
+ billing: {
10532
+ method: 'card',
10533
+ account_card_id: null,
10534
+ card: {
10535
+ gateway: 'convesiopay',
10536
+ token,
10537
+ last4: '????',
10538
+ brand: null,
10539
+ exp_month: null,
10540
+ exp_year: null,
10541
+ },
10542
+ convesiopay: {
10543
+ return_url: this.params.returnUrl,
10544
+ },
10545
+ },
10546
+ });
10547
+
10548
+ return this.onSuccess();
10549
+ }
10550
+ }
10551
+
10552
+ /** @typedef {import('../../../types').Cart} Cart */
10553
+
10554
+ class ConvesioPayApplePayment extends Payment {
10555
+ static convesioPay = null;
10556
+ static convesioPayComponent = null;
10557
+
10558
+ constructor(api, options, params, methods) {
10559
+ if (!methods.card) {
10560
+ throw new PaymentMethodDisabledError('Credit cards');
10561
+ }
10562
+
10563
+ super(api, options, params, methods.apple);
10564
+
10565
+ this.convesiopay = methods.card;
10566
+ }
10567
+
10568
+ get scripts() {
10569
+ return ['convesiopay-js'];
10570
+ }
10571
+
10572
+ get convesioPay() {
10573
+ if (ConvesioPayApplePayment.convesioPay === null) {
10574
+ if (window.ConvesioPay) {
10575
+ this.convesioPay = window.ConvesioPay(this.convesiopay.public_key);
10576
+ }
10577
+
10578
+ if (!ConvesioPayApplePayment.convesioPay) {
10579
+ throw new LibraryNotLoadedError('ConvesioPay');
10580
+ }
10581
+ }
10582
+
10583
+ return ConvesioPayApplePayment.convesioPay;
10584
+ }
10585
+
10586
+ set convesioPay(convesioPay) {
10587
+ ConvesioPayApplePayment.convesioPay = convesioPay;
10588
+ }
10589
+
10590
+ get convesioPayComponent() {
10591
+ return ConvesioPayApplePayment.convesioPayComponent;
10592
+ }
10593
+
10594
+ set convesioPayComponent(convesioPayComponent) {
10595
+ ConvesioPayApplePayment.convesioPayComponent = convesioPayComponent;
10596
+ }
10597
+
10598
+ /**
10599
+ * Creates the Apple Pay button element
10600
+ *
10601
+ * @param {Cart} cart
10602
+ */
10603
+ async createElements(cart) {
10604
+ const { elementId = 'applepay-button' } = this.params;
10605
+
10606
+ this.setElementContainer(elementId);
10607
+ await this.loadScripts(this.scripts);
10608
+
10609
+ this.convesioPayComponent = this.convesioPay.component({
10610
+ environment: isLiveMode(this.method.mode) ? 'live' : 'test',
10611
+ integration: this.convesiopay.integration,
10612
+ customerEmail: cart.account?.email,
10613
+ express: true,
10614
+ disabledPaymentMethods: {
10615
+ cards: true,
10616
+ btcpay: true,
10617
+ googlePay: true,
10618
+ },
10619
+ });
10620
+
10621
+ // When initiating a payment request,
10622
+ // we should not display the shipping cost, as it will be calculated later.
10623
+ cart = { ...cart };
10624
+ cart.shipment_price = 0;
10625
+ cart.shipping = {};
10626
+
10627
+ this.sessionOptions = {
10628
+ integration: this.convesiopay.integration,
10629
+ returnUrl: this.params.returnUrl,
10630
+ amount: amountInCents$1(cart.currency, cart.capture_total),
10631
+ currency: cart.currency,
10632
+ shippingMethods: getShippingMethods(cart),
10633
+ lineItems: getLineItems(cart),
10634
+ };
10635
+ }
10636
+
10637
+ /**
10638
+ * Mounts the Apple Pay button to the DOM
10639
+ */
10640
+ mountElements() {
10641
+ const { classes = {} } = this.params;
10642
+ const container = this.elementContainer;
10643
+
10644
+ this.convesioPayComponent.mount(`#${container.id}`);
10645
+
10646
+ if (classes.base) {
10647
+ container.classList.add(classes.base);
10648
+ }
10649
+
10650
+ this.convesioPayComponent.createApplePaySession({
10651
+ ...this.sessionOptions,
10652
+ onShippingAddressChange: onShippingAddressChange.bind(this),
10653
+ onShippingMethodChange: onShippingMethodChange.bind(this),
10654
+ onPaymentMethodChange: async (_paymentMethod) => {
10655
+ const currentCart = await this.getCart();
10656
+
10657
+ return {
10658
+ newTotal: getTotal(currentCart),
10659
+ newLineItems: getLineItems$1(currentCart),
10660
+ };
10661
+ },
10662
+ });
10663
+
10664
+ this.convesioPayComponent.on('change', async (event) => {
10665
+ if (event.type === 'applepay') {
10666
+ if (event.isSuccessful) {
10667
+ const { token, shippingContact, billingContact } = event;
10668
+ const { require: { shipping: requireShipping } = {} } = this.params;
10669
+
10670
+ await this.updateCart({
10671
+ account: {
10672
+ email: shippingContact.emailAddress,
10673
+ },
10674
+ billing: {
10675
+ method: 'apple',
10676
+ account_card_id: null,
10677
+ card: null,
10678
+ apple: {
10679
+ token,
10680
+ gateway: 'convesiopay',
10681
+ },
10682
+ ...convertToSwellAddress$1(billingContact),
10683
+ },
10684
+ ...(requireShipping && {
10685
+ shipping: convertToSwellAddress$1(shippingContact),
10686
+ }),
10687
+ });
10688
+ }
10689
+ }
10690
+ });
10691
+ }
10692
+ }
10693
+
10694
+ /**
10695
+ * @param {Cart} cart
10696
+ * @returns {object[]}
10697
+ */
10698
+ function getLineItems(cart) {
10699
+ const { sub_total, shipment_price, discount_total, tax_total, currency } =
10700
+ cart;
10701
+
10702
+ /** @type {ApplePayJS.ApplePayLineItem[]} */
10703
+ const lineItems = [
10704
+ {
10705
+ label: 'Subtotal',
10706
+ amount: amountInCents$1(currency, sub_total || 0),
10707
+ },
10708
+ ];
10709
+
10710
+ if (shipment_price) {
10711
+ lineItems.push({
10712
+ label: 'Shipping',
10713
+ amount: amountInCents$1(currency, shipment_price),
10714
+ });
10715
+ }
10716
+
10717
+ if (discount_total) {
10718
+ lineItems.push({
10719
+ label: 'Discount',
10720
+ amount: amountInCents$1(currency, -discount_total),
10721
+ });
10722
+ }
10723
+
10724
+ if (tax_total) {
10725
+ lineItems.push({
10726
+ label: 'Taxes',
10727
+ amount: amountInCents$1(currency, tax_total),
10728
+ });
10729
+ }
10730
+
10731
+ return lineItems;
10732
+ }
10733
+
10734
+ /**
10735
+ * @param {Cart} cart
10736
+ * @returns {object[]}
10737
+ */
10738
+ function getShippingMethods(cart) {
10739
+ const { shipment_delivery, shipment_rating, currency } = cart;
10740
+
10741
+ if (!shipment_delivery) {
10742
+ return [];
10743
+ }
10744
+
10745
+ if (!shipment_rating?.services?.length) {
10746
+ return [];
10747
+ }
10748
+
10749
+ return shipment_rating.services.map((service, index) => ({
10750
+ label: service.name || `Shipping ${index + 1}`,
10751
+ detail: service.description || '',
10752
+ amount: amountInCents$1(currency, service.price || 0),
10753
+ identifier: service.id,
10754
+ }));
10755
+ }
10756
+
10374
10757
  function createPaysafecardPaymentData(cart) {
10375
10758
  const returnUrl = window.location.origin + window.location.pathname;
10376
10759
  const url = `${returnUrl}?gateway=paysafecard`;
@@ -11747,6 +12130,8 @@ class PaymentController {
11747
12130
  return StripeCardPayment;
11748
12131
  case 'quickpay':
11749
12132
  return QuickpayCardPayment;
12133
+ case 'convesiopay':
12134
+ return ConvesioCardPayment;
11750
12135
  default:
11751
12136
  return null;
11752
12137
  }
@@ -11818,6 +12203,8 @@ class PaymentController {
11818
12203
  return BraintreeApplePayment;
11819
12204
  case 'authorizenet':
11820
12205
  return AuthorizeNetApplePayment;
12206
+ case 'convesiopay':
12207
+ return ConvesioPayApplePayment;
11821
12208
  default:
11822
12209
  return null;
11823
12210
  }
@@ -12172,7 +12559,7 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
12172
12559
  const api = {};
12173
12560
 
12174
12561
  Object.assign(api, {
12175
- version: '5.4.0',
12562
+ version: '5.5.0',
12176
12563
  options,
12177
12564
  request,
12178
12565