swell-js 3.22.0 → 3.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4220,7 +4220,6 @@
4220
4220
  };
4221
4221
 
4222
4222
  var isArray$2 = Array.isArray;
4223
- var split = String.prototype.split;
4224
4223
  var push = Array.prototype.push;
4225
4224
  var pushToArray = function (arr, valueOrArray) {
4226
4225
  push.apply(arr, isArray$2(valueOrArray) ? valueOrArray : [valueOrArray]);
@@ -4263,6 +4262,7 @@
4263
4262
  object,
4264
4263
  prefix,
4265
4264
  generateArrayPrefix,
4265
+ commaRoundTrip,
4266
4266
  strictNullHandling,
4267
4267
  skipNulls,
4268
4268
  encoder,
@@ -4321,14 +4321,6 @@
4321
4321
  if (isNonNullishPrimitive(obj) || utils$2.isBuffer(obj)) {
4322
4322
  if (encoder) {
4323
4323
  var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults$1.encoder, charset, 'key', format);
4324
- if (generateArrayPrefix === 'comma' && encodeValuesOnly) {
4325
- var valuesArray = split.call(String(obj), ',');
4326
- var valuesJoined = '';
4327
- for (var i = 0; i < valuesArray.length; ++i) {
4328
- valuesJoined += (i === 0 ? '' : ',') + formatter(encoder(valuesArray[i], defaults$1.encoder, charset, 'value', format));
4329
- }
4330
- return [formatter(keyValue) + '=' + valuesJoined];
4331
- }
4332
4324
  return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults$1.encoder, charset, 'value', format))];
4333
4325
  }
4334
4326
  return [formatter(prefix) + '=' + formatter(String(obj))];
@@ -4343,6 +4335,9 @@
4343
4335
  var objKeys;
4344
4336
  if (generateArrayPrefix === 'comma' && isArray$2(obj)) {
4345
4337
  // we need to join elements in
4338
+ if (encodeValuesOnly && encoder) {
4339
+ obj = utils$2.maybeMap(obj, encoder);
4340
+ }
4346
4341
  objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
4347
4342
  } else if (isArray$2(filter)) {
4348
4343
  objKeys = filter;
@@ -4351,6 +4346,8 @@
4351
4346
  objKeys = sort ? keys.sort(sort) : keys;
4352
4347
  }
4353
4348
 
4349
+ var adjustedPrefix = commaRoundTrip && isArray$2(obj) && obj.length === 1 ? prefix + '[]' : prefix;
4350
+
4354
4351
  for (var j = 0; j < objKeys.length; ++j) {
4355
4352
  var key = objKeys[j];
4356
4353
  var value = typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key];
@@ -4360,8 +4357,8 @@
4360
4357
  }
4361
4358
 
4362
4359
  var keyPrefix = isArray$2(obj)
4363
- ? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(prefix, key) : prefix
4364
- : prefix + (allowDots ? '.' + key : '[' + key + ']');
4360
+ ? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(adjustedPrefix, key) : adjustedPrefix
4361
+ : adjustedPrefix + (allowDots ? '.' + key : '[' + key + ']');
4365
4362
 
4366
4363
  sideChannel.set(object, step);
4367
4364
  var valueSideChannel = getSideChannel();
@@ -4370,9 +4367,10 @@
4370
4367
  value,
4371
4368
  keyPrefix,
4372
4369
  generateArrayPrefix,
4370
+ commaRoundTrip,
4373
4371
  strictNullHandling,
4374
4372
  skipNulls,
4375
- encoder,
4373
+ generateArrayPrefix === 'comma' && encodeValuesOnly && isArray$2(obj) ? null : encoder,
4376
4374
  filter,
4377
4375
  sort,
4378
4376
  allowDots,
@@ -4466,6 +4464,10 @@
4466
4464
  }
4467
4465
 
4468
4466
  var generateArrayPrefix = arrayPrefixGenerators[arrayFormat];
4467
+ if (opts && 'commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {
4468
+ throw new TypeError('`commaRoundTrip` must be a boolean, or absent');
4469
+ }
4470
+ var commaRoundTrip = generateArrayPrefix === 'comma' && opts && opts.commaRoundTrip;
4469
4471
 
4470
4472
  if (!objKeys) {
4471
4473
  objKeys = Object.keys(obj);
@@ -4486,6 +4488,7 @@
4486
4488
  obj[key],
4487
4489
  key,
4488
4490
  generateArrayPrefix,
4491
+ commaRoundTrip,
4489
4492
  options.strictNullHandling,
4490
4493
  options.skipNulls,
4491
4494
  options.encode ? options.encoder : null,
@@ -9264,7 +9267,7 @@
9264
9267
  function getEnumerableOwnPropertySymbols(target) {
9265
9268
  return Object.getOwnPropertySymbols
9266
9269
  ? Object.getOwnPropertySymbols(target).filter(function(symbol) {
9267
- return target.propertyIsEnumerable(symbol)
9270
+ return Object.propertyIsEnumerable.call(target, symbol)
9268
9271
  })
9269
9272
  : []
9270
9273
  }
@@ -9723,19 +9726,19 @@
9723
9726
  }
9724
9727
  };
9725
9728
 
9726
- var __defProp$k = Object.defineProperty;
9727
- var __getOwnPropSymbols$k = Object.getOwnPropertySymbols;
9728
- var __hasOwnProp$k = Object.prototype.hasOwnProperty;
9729
- var __propIsEnum$k = Object.prototype.propertyIsEnumerable;
9730
- var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9731
- var __spreadValues$k = (a, b) => {
9729
+ var __defProp$l = Object.defineProperty;
9730
+ var __getOwnPropSymbols$l = Object.getOwnPropertySymbols;
9731
+ var __hasOwnProp$l = Object.prototype.hasOwnProperty;
9732
+ var __propIsEnum$l = Object.prototype.propertyIsEnumerable;
9733
+ var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9734
+ var __spreadValues$l = (a, b) => {
9732
9735
  for (var prop in b || (b = {}))
9733
- if (__hasOwnProp$k.call(b, prop))
9734
- __defNormalProp$k(a, prop, b[prop]);
9735
- if (__getOwnPropSymbols$k)
9736
- for (var prop of __getOwnPropSymbols$k(b)) {
9737
- if (__propIsEnum$k.call(b, prop))
9738
- __defNormalProp$k(a, prop, b[prop]);
9736
+ if (__hasOwnProp$l.call(b, prop))
9737
+ __defNormalProp$l(a, prop, b[prop]);
9738
+ if (__getOwnPropSymbols$l)
9739
+ for (var prop of __getOwnPropSymbols$l(b)) {
9740
+ if (__propIsEnum$l.call(b, prop))
9741
+ __defNormalProp$l(a, prop, b[prop]);
9739
9742
  }
9740
9743
  return a;
9741
9744
  };
@@ -9755,7 +9758,7 @@
9755
9758
  if (isServer()) {
9756
9759
  return;
9757
9760
  }
9758
- options = __spreadValues$k({
9761
+ options = __spreadValues$l({
9759
9762
  path: "/",
9760
9763
  "max-age": COOKIE_MAX_AGE,
9761
9764
  samesite: "lax"
@@ -9774,19 +9777,19 @@
9774
9777
  document.cookie = updatedCookie;
9775
9778
  }
9776
9779
 
9777
- var __defProp$j = Object.defineProperty;
9778
- var __getOwnPropSymbols$j = Object.getOwnPropertySymbols;
9779
- var __hasOwnProp$j = Object.prototype.hasOwnProperty;
9780
- var __propIsEnum$j = Object.prototype.propertyIsEnumerable;
9781
- var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9782
- var __spreadValues$j = (a, b) => {
9780
+ var __defProp$k = Object.defineProperty;
9781
+ var __getOwnPropSymbols$k = Object.getOwnPropertySymbols;
9782
+ var __hasOwnProp$k = Object.prototype.hasOwnProperty;
9783
+ var __propIsEnum$k = Object.prototype.propertyIsEnumerable;
9784
+ var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9785
+ var __spreadValues$k = (a, b) => {
9783
9786
  for (var prop in b || (b = {}))
9784
- if (__hasOwnProp$j.call(b, prop))
9785
- __defNormalProp$j(a, prop, b[prop]);
9786
- if (__getOwnPropSymbols$j)
9787
- for (var prop of __getOwnPropSymbols$j(b)) {
9788
- if (__propIsEnum$j.call(b, prop))
9789
- __defNormalProp$j(a, prop, b[prop]);
9787
+ if (__hasOwnProp$k.call(b, prop))
9788
+ __defNormalProp$k(a, prop, b[prop]);
9789
+ if (__getOwnPropSymbols$k)
9790
+ for (var prop of __getOwnPropSymbols$k(b)) {
9791
+ if (__propIsEnum$k.call(b, prop))
9792
+ __defNormalProp$k(a, prop, b[prop]);
9790
9793
  }
9791
9794
  return a;
9792
9795
  };
@@ -9834,7 +9837,7 @@
9834
9837
  value = toCamel(value);
9835
9838
  }
9836
9839
  if (path || value instanceof Array) {
9837
- let upData = __spreadValues$j({}, data || {});
9840
+ let upData = __spreadValues$k({}, data || {});
9838
9841
  let upPath = useCamelCase ? toCamelPath(path) : path;
9839
9842
  set(upData, upPath || "", value);
9840
9843
  data = upData;
@@ -9923,21 +9926,21 @@
9923
9926
  };
9924
9927
  }
9925
9928
 
9926
- var __defProp$i = Object.defineProperty;
9929
+ var __defProp$j = Object.defineProperty;
9927
9930
  var __defProps$a = Object.defineProperties;
9928
9931
  var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
9929
- var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
9930
- var __hasOwnProp$i = Object.prototype.hasOwnProperty;
9931
- var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
9932
- var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9933
- var __spreadValues$i = (a, b) => {
9932
+ var __getOwnPropSymbols$j = Object.getOwnPropertySymbols;
9933
+ var __hasOwnProp$j = Object.prototype.hasOwnProperty;
9934
+ var __propIsEnum$j = Object.prototype.propertyIsEnumerable;
9935
+ var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9936
+ var __spreadValues$j = (a, b) => {
9934
9937
  for (var prop in b || (b = {}))
9935
- if (__hasOwnProp$i.call(b, prop))
9936
- __defNormalProp$i(a, prop, b[prop]);
9937
- if (__getOwnPropSymbols$i)
9938
- for (var prop of __getOwnPropSymbols$i(b)) {
9939
- if (__propIsEnum$i.call(b, prop))
9940
- __defNormalProp$i(a, prop, b[prop]);
9938
+ if (__hasOwnProp$j.call(b, prop))
9939
+ __defNormalProp$j(a, prop, b[prop]);
9940
+ if (__getOwnPropSymbols$j)
9941
+ for (var prop of __getOwnPropSymbols$j(b)) {
9942
+ if (__propIsEnum$j.call(b, prop))
9943
+ __defNormalProp$j(a, prop, b[prop]);
9941
9944
  }
9942
9945
  return a;
9943
9946
  };
@@ -9969,15 +9972,15 @@
9969
9972
  (acc, op) => {
9970
9973
  const values = reduce(
9971
9974
  op.values,
9972
- (acc2, val) => __spreadProps$a(__spreadValues$i({}, acc2), {
9973
- [val.id]: __spreadProps$a(__spreadValues$i({}, val), { id: val.id }),
9974
- [val.name]: __spreadProps$a(__spreadValues$i({}, val), { id: val.id })
9975
+ (acc2, val) => __spreadProps$a(__spreadValues$j({}, acc2), {
9976
+ [val.id]: __spreadProps$a(__spreadValues$j({}, val), { id: val.id }),
9977
+ [val.name]: __spreadProps$a(__spreadValues$j({}, val), { id: val.id })
9975
9978
  }),
9976
9979
  {}
9977
9980
  );
9978
- return __spreadProps$a(__spreadValues$i({}, acc), {
9979
- [op.id]: __spreadProps$a(__spreadValues$i({}, op), { values }),
9980
- [op.name]: __spreadProps$a(__spreadValues$i({}, op), { values })
9981
+ return __spreadProps$a(__spreadValues$j({}, acc), {
9982
+ [op.id]: __spreadProps$a(__spreadValues$j({}, op), { values }),
9983
+ [op.name]: __spreadProps$a(__spreadValues$j({}, op), { values })
9981
9984
  });
9982
9985
  },
9983
9986
  {}
@@ -10020,7 +10023,7 @@
10020
10023
  function calculateVariation(input, options, purchaseOption) {
10021
10024
  const product = OPTIONS.useCamelCase ? toSnake(input) : input;
10022
10025
  const purchaseOp = findPurchaseOption(product, purchaseOption);
10023
- const variation = __spreadProps$a(__spreadValues$i({}, product), {
10026
+ const variation = __spreadProps$a(__spreadValues$j({}, product), {
10024
10027
  price: typeof purchaseOp.price !== "number" ? null : purchaseOp.price,
10025
10028
  sale_price: purchaseOp.sale_price,
10026
10029
  orig_price: purchaseOp.orig_price,
@@ -10102,7 +10105,7 @@
10102
10105
  option = option.plans[0];
10103
10106
  }
10104
10107
  }
10105
- return __spreadProps$a(__spreadValues$i({}, option), {
10108
+ return __spreadProps$a(__spreadValues$j({}, option), {
10106
10109
  price: typeof option.price === "number" ? option.price : product.price,
10107
10110
  sale_price: typeof option.sale_price === "number" ? option.sale_price : product.sale_price,
10108
10111
  orig_price: typeof option.orig_price === "number" ? option.orig_price : product.orig_price
@@ -10120,7 +10123,7 @@
10120
10123
  request).list({
10121
10124
  filterable: true
10122
10125
  });
10123
- return getFilters(products, __spreadProps$a(__spreadValues$i({}, options), { filterableAttributes }));
10126
+ return getFilters(products, __spreadProps$a(__spreadValues$j({}, options), { filterableAttributes }));
10124
10127
  }
10125
10128
  function getFilters(products, options = {}) {
10126
10129
  let attributes = (options.attributes || options.attributes === void 0) && getAttributes(products);
@@ -10224,7 +10227,7 @@
10224
10227
  ...value instanceof Array ? value : [value]
10225
10228
  ]);
10226
10229
  } else {
10227
- attributes.push(__spreadProps$a(__spreadValues$i({}, product.attributes[id]), {
10230
+ attributes.push(__spreadProps$a(__spreadValues$j({}, product.attributes[id]), {
10228
10231
  value: void 0,
10229
10232
  values: [...value instanceof Array ? value : [value]]
10230
10233
  }));
@@ -10277,21 +10280,21 @@
10277
10280
  };
10278
10281
  }
10279
10282
 
10280
- var __defProp$h = Object.defineProperty;
10283
+ var __defProp$i = Object.defineProperty;
10281
10284
  var __defProps$9 = Object.defineProperties;
10282
10285
  var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
10283
- var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
10284
- var __hasOwnProp$h = Object.prototype.hasOwnProperty;
10285
- var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
10286
- var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10287
- var __spreadValues$h = (a, b) => {
10286
+ var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
10287
+ var __hasOwnProp$i = Object.prototype.hasOwnProperty;
10288
+ var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
10289
+ var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10290
+ var __spreadValues$i = (a, b) => {
10288
10291
  for (var prop in b || (b = {}))
10289
- if (__hasOwnProp$h.call(b, prop))
10290
- __defNormalProp$h(a, prop, b[prop]);
10291
- if (__getOwnPropSymbols$h)
10292
- for (var prop of __getOwnPropSymbols$h(b)) {
10293
- if (__propIsEnum$h.call(b, prop))
10294
- __defNormalProp$h(a, prop, b[prop]);
10292
+ if (__hasOwnProp$i.call(b, prop))
10293
+ __defNormalProp$i(a, prop, b[prop]);
10294
+ if (__getOwnPropSymbols$i)
10295
+ for (var prop of __getOwnPropSymbols$i(b)) {
10296
+ if (__propIsEnum$i.call(b, prop))
10297
+ __defNormalProp$i(a, prop, b[prop]);
10295
10298
  }
10296
10299
  return a;
10297
10300
  };
@@ -10303,7 +10306,7 @@
10303
10306
  settings: null,
10304
10307
  requested: false,
10305
10308
  pendingRequests: [],
10306
- cacheClear: null,
10309
+ cacheClear: false,
10307
10310
  async requestStateChange(method, url, id, data) {
10308
10311
  return this.requestStateSync(async () => {
10309
10312
  const result = await request(method, url, id, data);
@@ -10314,22 +10317,29 @@
10314
10317
  return result;
10315
10318
  });
10316
10319
  },
10320
+ nextRequest() {
10321
+ if (this.pendingRequests.length <= 0) {
10322
+ this.requested = false;
10323
+ return;
10324
+ }
10325
+ const { handler, resolve, reject } = this.pendingRequests.shift();
10326
+ return Promise.resolve().then(handler).then(resolve, reject).finally(() => {
10327
+ this.nextRequest();
10328
+ });
10329
+ },
10317
10330
  async requestStateSync(handler) {
10318
- if (this.state) {
10319
- return await handler();
10320
- } else if (this.requested) {
10321
- return new Promise((resolve) => {
10322
- this.pendingRequests.push({ handler, resolve });
10331
+ if (this.requested) {
10332
+ return new Promise((resolve, reject) => {
10333
+ this.pendingRequests.push({ handler, resolve, reject });
10323
10334
  });
10324
10335
  }
10325
10336
  this.requested = true;
10326
- const result = await handler();
10327
- this.requested = false;
10328
- while (this.pendingRequests.length > 0) {
10329
- const { handler: handler2, resolve } = this.pendingRequests.shift();
10330
- resolve(handler2());
10337
+ try {
10338
+ const result = await handler();
10339
+ return result;
10340
+ } finally {
10341
+ this.nextRequest();
10331
10342
  }
10332
- return result;
10333
10343
  },
10334
10344
  get() {
10335
10345
  if (options.getCart) {
@@ -10337,7 +10347,7 @@
10337
10347
  }
10338
10348
  let data;
10339
10349
  if (this.cacheClear) {
10340
- this.cacheClear = null;
10350
+ this.cacheClear = false;
10341
10351
  data = { $cache: false };
10342
10352
  }
10343
10353
  return this.requestStateChange("get", "/cart", void 0, data);
@@ -10348,7 +10358,7 @@
10348
10358
  getItemData(item, data = {}) {
10349
10359
  let result = cloneDeep(item);
10350
10360
  if (typeof item === "string") {
10351
- result = __spreadProps$9(__spreadValues$h({}, data || {}), {
10361
+ result = __spreadProps$9(__spreadValues$i({}, data || {}), {
10352
10362
  product_id: item
10353
10363
  });
10354
10364
  }
@@ -10387,7 +10397,7 @@
10387
10397
  update(input) {
10388
10398
  let data = input;
10389
10399
  if (data.items && data.items.map) {
10390
- data = __spreadProps$9(__spreadValues$h({}, data), {
10400
+ data = __spreadProps$9(__spreadValues$i({}, data), {
10391
10401
  items: data.items.map(this.getItemData)
10392
10402
  });
10393
10403
  }
@@ -10413,7 +10423,7 @@
10413
10423
  return this.state[options.useCamelCase ? "shipmentRating" : "shipment_rating"];
10414
10424
  },
10415
10425
  async submitOrder() {
10416
- const result = await request("post", "/cart/order");
10426
+ const result = await this.requestStateChange("post", "/cart/order");
10417
10427
  if (result.errors) {
10418
10428
  return result;
10419
10429
  }
@@ -10596,19 +10606,19 @@
10596
10606
  };
10597
10607
  }
10598
10608
 
10599
- var __defProp$g = Object.defineProperty;
10600
- var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
10601
- var __hasOwnProp$g = Object.prototype.hasOwnProperty;
10602
- var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
10603
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10604
- var __spreadValues$g = (a, b) => {
10609
+ var __defProp$h = Object.defineProperty;
10610
+ var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
10611
+ var __hasOwnProp$h = Object.prototype.hasOwnProperty;
10612
+ var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
10613
+ var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10614
+ var __spreadValues$h = (a, b) => {
10605
10615
  for (var prop in b || (b = {}))
10606
- if (__hasOwnProp$g.call(b, prop))
10607
- __defNormalProp$g(a, prop, b[prop]);
10608
- if (__getOwnPropSymbols$g)
10609
- for (var prop of __getOwnPropSymbols$g(b)) {
10610
- if (__propIsEnum$g.call(b, prop))
10611
- __defNormalProp$g(a, prop, b[prop]);
10616
+ if (__hasOwnProp$h.call(b, prop))
10617
+ __defNormalProp$h(a, prop, b[prop]);
10618
+ if (__getOwnPropSymbols$h)
10619
+ for (var prop of __getOwnPropSymbols$h(b)) {
10620
+ if (__propIsEnum$h.call(b, prop))
10621
+ __defNormalProp$h(a, prop, b[prop]);
10612
10622
  }
10613
10623
  return a;
10614
10624
  };
@@ -10618,7 +10628,7 @@
10618
10628
  return cacheApi.getFetch(
10619
10629
  `content_${type}`,
10620
10630
  id,
10621
- () => request("get", `/content/${type}`, id, __spreadValues$g({
10631
+ () => request("get", `/content/${type}`, id, __spreadValues$h({
10622
10632
  $preview: opt.previewContent
10623
10633
  }, query || {}))
10624
10634
  );
@@ -10627,21 +10637,21 @@
10627
10637
  };
10628
10638
  }
10629
10639
 
10630
- var __defProp$f = Object.defineProperty;
10640
+ var __defProp$g = Object.defineProperty;
10631
10641
  var __defProps$8 = Object.defineProperties;
10632
10642
  var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
10633
- var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
10634
- var __hasOwnProp$f = Object.prototype.hasOwnProperty;
10635
- var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
10636
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10637
- var __spreadValues$f = (a, b) => {
10643
+ var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
10644
+ var __hasOwnProp$g = Object.prototype.hasOwnProperty;
10645
+ var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
10646
+ var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10647
+ var __spreadValues$g = (a, b) => {
10638
10648
  for (var prop in b || (b = {}))
10639
- if (__hasOwnProp$f.call(b, prop))
10640
- __defNormalProp$f(a, prop, b[prop]);
10641
- if (__getOwnPropSymbols$f)
10642
- for (var prop of __getOwnPropSymbols$f(b)) {
10643
- if (__propIsEnum$f.call(b, prop))
10644
- __defNormalProp$f(a, prop, b[prop]);
10649
+ if (__hasOwnProp$g.call(b, prop))
10650
+ __defNormalProp$g(a, prop, b[prop]);
10651
+ if (__getOwnPropSymbols$g)
10652
+ for (var prop of __getOwnPropSymbols$g(b)) {
10653
+ if (__propIsEnum$g.call(b, prop))
10654
+ __defNormalProp$g(a, prop, b[prop]);
10645
10655
  }
10646
10656
  return a;
10647
10657
  };
@@ -10754,7 +10764,7 @@
10754
10764
  let configs = this.getStoreLocales();
10755
10765
  if (configs) {
10756
10766
  configs = configs.reduce(
10757
- (acc, config) => __spreadProps$8(__spreadValues$f({}, acc), {
10767
+ (acc, config) => __spreadProps$8(__spreadValues$g({}, acc), {
10758
10768
  [config.code]: config
10759
10769
  }),
10760
10770
  {}
@@ -10845,14 +10855,14 @@
10845
10855
  while (fallbackKey) {
10846
10856
  fallbackKeys = fallbackKeys || [];
10847
10857
  fallbackKeys.push(fallbackKey);
10848
- fallbackValues = __spreadValues$f(__spreadValues$f({}, values[key][fallbackKey] || {}), fallbackValues);
10858
+ fallbackValues = __spreadValues$g(__spreadValues$g({}, values[key][fallbackKey] || {}), fallbackValues);
10849
10859
  fallbackKey = configs[fallbackKey] && configs[fallbackKey].fallback;
10850
10860
  if (origFallbackKey === fallbackKey) {
10851
10861
  break;
10852
10862
  }
10853
10863
  }
10854
10864
  }
10855
- let localeValues = __spreadValues$f(__spreadValues$f({}, fallbackValues), values[key][returnLocaleKey] || {});
10865
+ let localeValues = __spreadValues$g(__spreadValues$g({}, fallbackValues), values[key][returnLocaleKey] || {});
10856
10866
  const valueKeys = Object.keys(localeValues);
10857
10867
  for (let valueKey of valueKeys) {
10858
10868
  const hasValue = localeValues[valueKey] !== null && localeValues[valueKey] !== "";
@@ -11036,32 +11046,102 @@
11036
11046
  await new Promise((resolve) => setTimeout(resolve, 1e3));
11037
11047
  }
11038
11048
 
11039
- var __defProp$e = Object.defineProperty;
11049
+ class PaymentMethodDisabledError extends Error {
11050
+ constructor(method) {
11051
+ const message = `${method} payments are disabled. See Payment settings in the Swell dashboard for details`;
11052
+ super(message);
11053
+ }
11054
+ }
11055
+ class UnsupportedPaymentMethodError extends Error {
11056
+ constructor(method, gateway) {
11057
+ let message = `Unsupported payment method: ${method}`;
11058
+ if (gateway) {
11059
+ message += ` (${gateway})`;
11060
+ }
11061
+ super(message);
11062
+ }
11063
+ }
11064
+ class UnableAuthenticatePaymentMethodError extends Error {
11065
+ constructor() {
11066
+ const message = "We are unable to authenticate your payment method. Please choose a different payment method and try again";
11067
+ super(message);
11068
+ }
11069
+ }
11070
+ class LibraryNotLoadedError extends Error {
11071
+ constructor(library) {
11072
+ const message = `${library} was not loaded`;
11073
+ super(message);
11074
+ }
11075
+ }
11076
+ class MethodPropertyMissingError extends Error {
11077
+ constructor(method, property) {
11078
+ const message = `${method} ${property} is missing`;
11079
+ super(message);
11080
+ }
11081
+ }
11082
+ class DomElementNotFoundError extends Error {
11083
+ constructor(elementId) {
11084
+ const message = `DOM element with '${elementId}' ID not found`;
11085
+ super(message);
11086
+ }
11087
+ }
11088
+ class PaymentElementNotCreatedError extends Error {
11089
+ constructor(methodName) {
11090
+ const message = `The ${methodName} payment element was not created`;
11091
+ super(message);
11092
+ }
11093
+ }
11094
+
11095
+ var __defProp$f = Object.defineProperty;
11040
11096
  var __defProps$7 = Object.defineProperties;
11041
11097
  var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
11042
- var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
11043
- var __hasOwnProp$e = Object.prototype.hasOwnProperty;
11044
- var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
11045
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11046
- var __spreadValues$e = (a, b) => {
11098
+ var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
11099
+ var __hasOwnProp$f = Object.prototype.hasOwnProperty;
11100
+ var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
11101
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11102
+ var __spreadValues$f = (a, b) => {
11047
11103
  for (var prop in b || (b = {}))
11048
- if (__hasOwnProp$e.call(b, prop))
11049
- __defNormalProp$e(a, prop, b[prop]);
11050
- if (__getOwnPropSymbols$e)
11051
- for (var prop of __getOwnPropSymbols$e(b)) {
11052
- if (__propIsEnum$e.call(b, prop))
11053
- __defNormalProp$e(a, prop, b[prop]);
11104
+ if (__hasOwnProp$f.call(b, prop))
11105
+ __defNormalProp$f(a, prop, b[prop]);
11106
+ if (__getOwnPropSymbols$f)
11107
+ for (var prop of __getOwnPropSymbols$f(b)) {
11108
+ if (__propIsEnum$f.call(b, prop))
11109
+ __defNormalProp$f(a, prop, b[prop]);
11054
11110
  }
11055
11111
  return a;
11056
11112
  };
11057
11113
  var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
11114
+ var __publicField = (obj, key, value) => {
11115
+ __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
11116
+ return value;
11117
+ };
11058
11118
  class Payment {
11059
11119
  constructor(request, options, params, method) {
11120
+ __publicField(this, "_element", null);
11121
+ __publicField(this, "_elementContainer", null);
11060
11122
  this.request = request;
11061
11123
  this.options = options;
11062
11124
  this.params = params;
11063
11125
  this.method = method;
11064
11126
  }
11127
+ get element() {
11128
+ if (!this._element) {
11129
+ throw new PaymentElementNotCreatedError(this.method.name);
11130
+ }
11131
+ return this._element;
11132
+ }
11133
+ set element(element) {
11134
+ this._element = element;
11135
+ }
11136
+ get elementContainer() {
11137
+ return this._elementContainer;
11138
+ }
11139
+ setElementContainer(elementId) {
11140
+ this._elementContainer = document.getElementById(elementId);
11141
+ if (!this.elementContainer) {
11142
+ throw new DomElementNotFoundError(elementId);
11143
+ }
11144
+ }
11065
11145
  async loadScripts(scripts) {
11066
11146
  await this._populateScriptsParams(scripts);
11067
11147
  await loadScripts(scripts);
@@ -11126,7 +11206,7 @@
11126
11206
  return cart;
11127
11207
  }
11128
11208
  const settings = await this.getSettings();
11129
- return __spreadProps$7(__spreadValues$e({}, cart), { settings: __spreadValues$e({}, settings.store) });
11209
+ return __spreadProps$7(__spreadValues$f({}, cart), { settings: __spreadValues$f({}, settings.store) });
11130
11210
  }
11131
11211
  async _vaultRequest(method, url, data) {
11132
11212
  const response = await vaultRequest(method, url, data);
@@ -11151,24 +11231,24 @@
11151
11231
  return;
11152
11232
  }
11153
11233
  const cart = await this.getCart();
11154
- script.params = __spreadValues$e(__spreadValues$e({}, script.params), pick(cart, cartParams));
11234
+ script.params = __spreadValues$f(__spreadValues$f({}, script.params), pick(cart, cartParams));
11155
11235
  delete script.params.cart;
11156
11236
  }
11157
11237
  }
11158
11238
 
11159
- var __defProp$d = Object.defineProperty;
11160
- var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
11161
- var __hasOwnProp$d = Object.prototype.hasOwnProperty;
11162
- var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
11163
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11164
- var __spreadValues$d = (a, b) => {
11239
+ var __defProp$e = Object.defineProperty;
11240
+ var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
11241
+ var __hasOwnProp$e = Object.prototype.hasOwnProperty;
11242
+ var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
11243
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11244
+ var __spreadValues$e = (a, b) => {
11165
11245
  for (var prop in b || (b = {}))
11166
- if (__hasOwnProp$d.call(b, prop))
11167
- __defNormalProp$d(a, prop, b[prop]);
11168
- if (__getOwnPropSymbols$d)
11169
- for (var prop of __getOwnPropSymbols$d(b)) {
11170
- if (__propIsEnum$d.call(b, prop))
11171
- __defNormalProp$d(a, prop, b[prop]);
11246
+ if (__hasOwnProp$e.call(b, prop))
11247
+ __defNormalProp$e(a, prop, b[prop]);
11248
+ if (__getOwnPropSymbols$e)
11249
+ for (var prop of __getOwnPropSymbols$e(b)) {
11250
+ if (__propIsEnum$e.call(b, prop))
11251
+ __defNormalProp$e(a, prop, b[prop]);
11172
11252
  }
11173
11253
  return a;
11174
11254
  };
@@ -11222,7 +11302,7 @@
11222
11302
  return result;
11223
11303
  }
11224
11304
  function getBillingDetails(cart) {
11225
- const details = __spreadValues$d({}, mapValues(billingFieldsMap, cart.billing));
11305
+ const details = __spreadValues$e({}, mapValues(billingFieldsMap, cart.billing));
11226
11306
  if (cart.account && cart.account.email) {
11227
11307
  details.email = cart.account.email;
11228
11308
  }
@@ -11245,9 +11325,9 @@
11245
11325
  {}
11246
11326
  );
11247
11327
  const { account = {}, billing, shipping } = data;
11248
- const billingData = __spreadValues$d(__spreadValues$d(__spreadValues$d(__spreadValues$d({}, account.shipping), account.billing), shipping), billing);
11328
+ const billingData = __spreadValues$e(__spreadValues$e(__spreadValues$e(__spreadValues$e({}, account.shipping), account.billing), shipping), billing);
11249
11329
  const billingAddress = fillValues(addressFieldsMap$1, billingData);
11250
- source.owner = __spreadValues$d(__spreadValues$d({
11330
+ source.owner = __spreadValues$e(__spreadValues$e({
11251
11331
  email: account.email,
11252
11332
  name: billingData.name || account.name
11253
11333
  }, billingData.phone ? { phone: billingData.phone } : account.phone ? { phone: account.phone } : {}), !isEmpty(billingAddress) ? { address: billingAddress } : {});
@@ -11255,6 +11335,7 @@
11255
11335
  function createElement(type, elements, params) {
11256
11336
  const elementParams = params[type] || params;
11257
11337
  const elementOptions = elementParams.options || {};
11338
+ const elementId = elementParams.elementId || `${type}-element`;
11258
11339
  const element = elements.create(type, elementOptions);
11259
11340
  elementParams.onChange && element.on("change", elementParams.onChange);
11260
11341
  elementParams.onReady && element.on("ready", elementParams.onReady);
@@ -11262,7 +11343,7 @@
11262
11343
  elementParams.onBlur && element.on("blur", elementParams.onBlur);
11263
11344
  elementParams.onEscape && element.on("escape", elementParams.onEscape);
11264
11345
  elementParams.onClick && element.on("click", elementParams.onClick);
11265
- element.mount(elementParams.elementId || `#${type}-element`);
11346
+ element.mount(`#${elementId}`);
11266
11347
  return element;
11267
11348
  }
11268
11349
  async function createPaymentMethod(stripe, cardElement, cart) {
@@ -11285,7 +11366,7 @@
11285
11366
  }
11286
11367
  async function createIDealPaymentMethod(stripe, element, cart) {
11287
11368
  const billingDetails = getBillingDetails(cart);
11288
- return await stripe.createPaymentMethod(__spreadValues$d({
11369
+ return await stripe.createPaymentMethod(__spreadValues$e({
11289
11370
  type: "ideal",
11290
11371
  ideal: element
11291
11372
  }, billingDetails ? { billing_details: billingDetails } : {}));
@@ -11357,59 +11438,19 @@
11357
11438
  return !minAmount || amount >= minAmount;
11358
11439
  }
11359
11440
 
11360
- class PaymentMethodDisabledError extends Error {
11361
- constructor(method) {
11362
- const message = `${method} payments are disabled. See Payment settings in the Swell dashboard for details`;
11363
- super(message);
11364
- }
11365
- }
11366
- class UnsupportedPaymentMethodError extends Error {
11367
- constructor(method, gateway) {
11368
- let message = `Unsupported payment method: ${method}`;
11369
- if (gateway) {
11370
- message += ` (${gateway})`;
11371
- }
11372
- super(message);
11373
- }
11374
- }
11375
- class UnableAuthenticatePaymentMethodError extends Error {
11376
- constructor() {
11377
- const message = "We are unable to authenticate your payment method. Please choose a different payment method and try again";
11378
- super(message);
11379
- }
11380
- }
11381
- class LibraryNotLoadedError extends Error {
11382
- constructor(library) {
11383
- const message = `${library} was not loaded`;
11384
- super(message);
11385
- }
11386
- }
11387
- class MethodPropertyMissingError extends Error {
11388
- constructor(method, property) {
11389
- const message = `${method} ${property} is missing`;
11390
- super(message);
11391
- }
11392
- }
11393
- class DomElementNotFoundError extends Error {
11394
- constructor(elementId) {
11395
- const message = `DOM element with '${elementId}' ID not found`;
11396
- super(message);
11397
- }
11398
- }
11399
-
11400
- var __defProp$c = Object.defineProperty;
11401
- var __getOwnPropSymbols$c = Object.getOwnPropertySymbols;
11402
- var __hasOwnProp$c = Object.prototype.hasOwnProperty;
11403
- var __propIsEnum$c = Object.prototype.propertyIsEnumerable;
11404
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11405
- var __spreadValues$c = (a, b) => {
11441
+ var __defProp$d = Object.defineProperty;
11442
+ var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
11443
+ var __hasOwnProp$d = Object.prototype.hasOwnProperty;
11444
+ var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
11445
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11446
+ var __spreadValues$d = (a, b) => {
11406
11447
  for (var prop in b || (b = {}))
11407
- if (__hasOwnProp$c.call(b, prop))
11408
- __defNormalProp$c(a, prop, b[prop]);
11409
- if (__getOwnPropSymbols$c)
11410
- for (var prop of __getOwnPropSymbols$c(b)) {
11411
- if (__propIsEnum$c.call(b, prop))
11412
- __defNormalProp$c(a, prop, b[prop]);
11448
+ if (__hasOwnProp$d.call(b, prop))
11449
+ __defNormalProp$d(a, prop, b[prop]);
11450
+ if (__getOwnPropSymbols$d)
11451
+ for (var prop of __getOwnPropSymbols$d(b)) {
11452
+ if (__propIsEnum$d.call(b, prop))
11453
+ __defNormalProp$d(a, prop, b[prop]);
11413
11454
  }
11414
11455
  return a;
11415
11456
  };
@@ -11441,6 +11482,7 @@
11441
11482
  StripeCardPayment.stripeElement = stripeElement;
11442
11483
  }
11443
11484
  async createElements() {
11485
+ await this.loadScripts(this.scripts);
11444
11486
  const elements = this.stripe.elements(this.params.config);
11445
11487
  if (this.params.separateElements) {
11446
11488
  this.stripeElement = createElement("cardNumber", elements, this.params);
@@ -11454,6 +11496,7 @@
11454
11496
  if (!this.stripeElement) {
11455
11497
  throw new Error("Stripe payment element is not defined");
11456
11498
  }
11499
+ await this.loadScripts(this.scripts);
11457
11500
  const cart = await this.getCart();
11458
11501
  const paymentMethod = await createPaymentMethod(
11459
11502
  this.stripe,
@@ -11478,7 +11521,7 @@
11478
11521
  method: "card",
11479
11522
  card: paymentMethod,
11480
11523
  intent: {
11481
- stripe: __spreadValues$c({
11524
+ stripe: __spreadValues$d({
11482
11525
  id: intent.id
11483
11526
  }, Boolean(cart.auth_total) && {
11484
11527
  auth_amount: cart.auth_total
@@ -11497,6 +11540,7 @@
11497
11540
  if (intent.error) {
11498
11541
  throw new Error(intent.error.message);
11499
11542
  }
11543
+ await this.loadScripts(this.scripts);
11500
11544
  return this._confirmCardPayment(intent);
11501
11545
  }
11502
11546
  async _createIntent(cart, paymentMethod) {
@@ -11506,7 +11550,7 @@
11506
11550
  const amount = stripeAmountByCurrency(currency, capture_total + auth_total);
11507
11551
  const intent = await this.createIntent({
11508
11552
  gateway: "stripe",
11509
- intent: __spreadValues$c({
11553
+ intent: __spreadValues$d({
11510
11554
  amount,
11511
11555
  currency: stripeCurrency,
11512
11556
  payment_method: paymentMethod.token,
@@ -11536,21 +11580,21 @@
11536
11580
  }
11537
11581
  }
11538
11582
 
11539
- var __defProp$b = Object.defineProperty;
11583
+ var __defProp$c = Object.defineProperty;
11540
11584
  var __defProps$6 = Object.defineProperties;
11541
11585
  var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
11542
- var __getOwnPropSymbols$b = Object.getOwnPropertySymbols;
11543
- var __hasOwnProp$b = Object.prototype.hasOwnProperty;
11544
- var __propIsEnum$b = Object.prototype.propertyIsEnumerable;
11545
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11546
- var __spreadValues$b = (a, b) => {
11586
+ var __getOwnPropSymbols$c = Object.getOwnPropertySymbols;
11587
+ var __hasOwnProp$c = Object.prototype.hasOwnProperty;
11588
+ var __propIsEnum$c = Object.prototype.propertyIsEnumerable;
11589
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11590
+ var __spreadValues$c = (a, b) => {
11547
11591
  for (var prop in b || (b = {}))
11548
- if (__hasOwnProp$b.call(b, prop))
11549
- __defNormalProp$b(a, prop, b[prop]);
11550
- if (__getOwnPropSymbols$b)
11551
- for (var prop of __getOwnPropSymbols$b(b)) {
11552
- if (__propIsEnum$b.call(b, prop))
11553
- __defNormalProp$b(a, prop, b[prop]);
11592
+ if (__hasOwnProp$c.call(b, prop))
11593
+ __defNormalProp$c(a, prop, b[prop]);
11594
+ if (__getOwnPropSymbols$c)
11595
+ for (var prop of __getOwnPropSymbols$c(b)) {
11596
+ if (__propIsEnum$c.call(b, prop))
11597
+ __defNormalProp$c(a, prop, b[prop]);
11554
11598
  }
11555
11599
  return a;
11556
11600
  };
@@ -11560,7 +11604,7 @@
11560
11604
  if (!methods.card) {
11561
11605
  throw new PaymentMethodDisabledError("Credit cards");
11562
11606
  }
11563
- const method = __spreadProps$6(__spreadValues$b({}, methods.ideal), {
11607
+ const method = __spreadProps$6(__spreadValues$c({}, methods.ideal), {
11564
11608
  publishable_key: methods.card.publishable_key
11565
11609
  });
11566
11610
  super(request, options, params, method);
@@ -11589,6 +11633,7 @@
11589
11633
  StripeIDealPayment.stripeElement = stripeElement;
11590
11634
  }
11591
11635
  async createElements() {
11636
+ await this.loadScripts(this.scripts);
11592
11637
  const elements = this.stripe.elements(this.params.config);
11593
11638
  this.stripeElement = createElement("idealBank", elements, this.params);
11594
11639
  }
@@ -11596,6 +11641,7 @@
11596
11641
  if (!this.stripeElement) {
11597
11642
  throw new Error("Stripe payment element is not defined");
11598
11643
  }
11644
+ await this.loadScripts(this.scripts);
11599
11645
  const cart = await this.getCart();
11600
11646
  const { paymentMethod, error: paymentMethodError } = await createIDealPaymentMethod(this.stripe, this.stripeElement, cart);
11601
11647
  if (paymentMethodError) {
@@ -11643,21 +11689,21 @@
11643
11689
  }
11644
11690
  }
11645
11691
 
11646
- var __defProp$a = Object.defineProperty;
11692
+ var __defProp$b = Object.defineProperty;
11647
11693
  var __defProps$5 = Object.defineProperties;
11648
11694
  var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
11649
- var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
11650
- var __hasOwnProp$a = Object.prototype.hasOwnProperty;
11651
- var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
11652
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11653
- var __spreadValues$a = (a, b) => {
11695
+ var __getOwnPropSymbols$b = Object.getOwnPropertySymbols;
11696
+ var __hasOwnProp$b = Object.prototype.hasOwnProperty;
11697
+ var __propIsEnum$b = Object.prototype.propertyIsEnumerable;
11698
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11699
+ var __spreadValues$b = (a, b) => {
11654
11700
  for (var prop in b || (b = {}))
11655
- if (__hasOwnProp$a.call(b, prop))
11656
- __defNormalProp$a(a, prop, b[prop]);
11657
- if (__getOwnPropSymbols$a)
11658
- for (var prop of __getOwnPropSymbols$a(b)) {
11659
- if (__propIsEnum$a.call(b, prop))
11660
- __defNormalProp$a(a, prop, b[prop]);
11701
+ if (__hasOwnProp$b.call(b, prop))
11702
+ __defNormalProp$b(a, prop, b[prop]);
11703
+ if (__getOwnPropSymbols$b)
11704
+ for (var prop of __getOwnPropSymbols$b(b)) {
11705
+ if (__propIsEnum$b.call(b, prop))
11706
+ __defNormalProp$b(a, prop, b[prop]);
11661
11707
  }
11662
11708
  return a;
11663
11709
  };
@@ -11667,7 +11713,7 @@
11667
11713
  if (!methods.card) {
11668
11714
  throw new PaymentMethodDisabledError("Credit cards");
11669
11715
  }
11670
- const method = __spreadProps$5(__spreadValues$a({}, methods.bancontact), {
11716
+ const method = __spreadProps$5(__spreadValues$b({}, methods.bancontact), {
11671
11717
  publishable_key: methods.card.publishable_key
11672
11718
  });
11673
11719
  super(request, options, params, method);
@@ -11690,6 +11736,7 @@
11690
11736
  StripeBancontactPayment.stripe = stripe;
11691
11737
  }
11692
11738
  async tokenize() {
11739
+ await this.loadScripts(this.scripts);
11693
11740
  const cart = await this.getCart();
11694
11741
  const { source, error: sourceError } = await createBancontactSource(
11695
11742
  this.stripe,
@@ -11707,21 +11754,21 @@
11707
11754
  }
11708
11755
  }
11709
11756
 
11710
- var __defProp$9 = Object.defineProperty;
11757
+ var __defProp$a = Object.defineProperty;
11711
11758
  var __defProps$4 = Object.defineProperties;
11712
11759
  var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
11713
- var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
11714
- var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
11715
- var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
11716
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11717
- var __spreadValues$9 = (a, b) => {
11760
+ var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
11761
+ var __hasOwnProp$a = Object.prototype.hasOwnProperty;
11762
+ var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
11763
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11764
+ var __spreadValues$a = (a, b) => {
11718
11765
  for (var prop in b || (b = {}))
11719
- if (__hasOwnProp$9.call(b, prop))
11720
- __defNormalProp$9(a, prop, b[prop]);
11721
- if (__getOwnPropSymbols$9)
11722
- for (var prop of __getOwnPropSymbols$9(b)) {
11723
- if (__propIsEnum$9.call(b, prop))
11724
- __defNormalProp$9(a, prop, b[prop]);
11766
+ if (__hasOwnProp$a.call(b, prop))
11767
+ __defNormalProp$a(a, prop, b[prop]);
11768
+ if (__getOwnPropSymbols$a)
11769
+ for (var prop of __getOwnPropSymbols$a(b)) {
11770
+ if (__propIsEnum$a.call(b, prop))
11771
+ __defNormalProp$a(a, prop, b[prop]);
11725
11772
  }
11726
11773
  return a;
11727
11774
  };
@@ -11731,7 +11778,7 @@
11731
11778
  if (!methods.card) {
11732
11779
  throw new PaymentMethodDisabledError("Credit cards");
11733
11780
  }
11734
- const method = __spreadProps$4(__spreadValues$9({}, methods.klarna), {
11781
+ const method = __spreadProps$4(__spreadValues$a({}, methods.klarna), {
11735
11782
  publishable_key: methods.card.publishable_key
11736
11783
  });
11737
11784
  super(request, options, params, method);
@@ -11759,6 +11806,7 @@
11759
11806
  gateway: "stripe",
11760
11807
  intent: getKlarnaIntentDetails(cart)
11761
11808
  });
11809
+ await this.loadScripts(this.scripts);
11762
11810
  const { error } = await this.stripe.confirmKlarnaPayment(
11763
11811
  intent.client_secret,
11764
11812
  getKlarnaConfirmationDetails(cart)
@@ -11795,21 +11843,21 @@
11795
11843
  }
11796
11844
  }
11797
11845
 
11798
- var __defProp$8 = Object.defineProperty;
11846
+ var __defProp$9 = Object.defineProperty;
11799
11847
  var __defProps$3 = Object.defineProperties;
11800
11848
  var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
11801
- var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
11802
- var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
11803
- var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
11804
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11805
- var __spreadValues$8 = (a, b) => {
11849
+ var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
11850
+ var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
11851
+ var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
11852
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11853
+ var __spreadValues$9 = (a, b) => {
11806
11854
  for (var prop in b || (b = {}))
11807
- if (__hasOwnProp$8.call(b, prop))
11808
- __defNormalProp$8(a, prop, b[prop]);
11809
- if (__getOwnPropSymbols$8)
11810
- for (var prop of __getOwnPropSymbols$8(b)) {
11811
- if (__propIsEnum$8.call(b, prop))
11812
- __defNormalProp$8(a, prop, b[prop]);
11855
+ if (__hasOwnProp$9.call(b, prop))
11856
+ __defNormalProp$9(a, prop, b[prop]);
11857
+ if (__getOwnPropSymbols$9)
11858
+ for (var prop of __getOwnPropSymbols$9(b)) {
11859
+ if (__propIsEnum$9.call(b, prop))
11860
+ __defNormalProp$9(a, prop, b[prop]);
11813
11861
  }
11814
11862
  return a;
11815
11863
  };
@@ -11831,7 +11879,7 @@
11831
11879
  if (!methods.card) {
11832
11880
  throw new PaymentMethodDisabledError("Credit cards");
11833
11881
  }
11834
- const method = __spreadProps$3(__spreadValues$8({}, methods.google), {
11882
+ const method = __spreadProps$3(__spreadValues$9({}, methods.google), {
11835
11883
  publishable_key: methods.card.publishable_key
11836
11884
  });
11837
11885
  super(request, options, params, method);
@@ -11894,9 +11942,16 @@
11894
11942
  return [this.cardPaymentMethod];
11895
11943
  }
11896
11944
  async createElements() {
11945
+ const {
11946
+ elementId = "googlepay-button",
11947
+ locale = "en",
11948
+ style: { color = "black", type = "buy", sizeMode = "fill" } = {}
11949
+ } = this.params;
11897
11950
  if (!this.method.merchant_id) {
11898
11951
  throw new Error("Google merchant ID is not defined");
11899
11952
  }
11953
+ this.setElementContainer(elementId);
11954
+ await this.loadScripts(this.scripts);
11900
11955
  const isReadyToPay = await this.googleClient.isReadyToPay({
11901
11956
  apiVersion: API_VERSION$1,
11902
11957
  apiVersionMinor: API_MINOR_VERSION$1,
@@ -11910,7 +11965,21 @@
11910
11965
  }
11911
11966
  const cart = await this.getCart();
11912
11967
  const paymentRequestData = this._createPaymentRequestData(cart);
11913
- this._renderButton(paymentRequestData);
11968
+ this.element = this.googleClient.createButton({
11969
+ buttonColor: color,
11970
+ buttonType: type,
11971
+ buttonSizeMode: sizeMode,
11972
+ buttonLocale: locale,
11973
+ onClick: this._onClick.bind(this, paymentRequestData)
11974
+ });
11975
+ }
11976
+ mountElements() {
11977
+ const { classes = {} } = this.params;
11978
+ const container = this.elementContainer;
11979
+ container.appendChild(this.element);
11980
+ if (classes.base) {
11981
+ container.classList.add(classes.base);
11982
+ }
11914
11983
  }
11915
11984
  _createPaymentRequestData(cart) {
11916
11985
  const {
@@ -11939,29 +12008,6 @@
11939
12008
  }
11940
12009
  };
11941
12010
  }
11942
- _renderButton(paymentRequestData) {
11943
- const {
11944
- elementId = "googlepay-button",
11945
- locale = "en",
11946
- style: { color = "black", type = "buy", sizeMode = "fill" } = {},
11947
- classes = {}
11948
- } = this.params;
11949
- const container = document.getElementById(elementId);
11950
- if (!container) {
11951
- throw new DomElementNotFoundError(elementId);
11952
- }
11953
- if (classes.base) {
11954
- container.classList.add(classes.base);
11955
- }
11956
- const button = this.googleClient.createButton({
11957
- buttonColor: color,
11958
- buttonType: type,
11959
- buttonSizeMode: sizeMode,
11960
- buttonLocale: locale,
11961
- onClick: this._onClick.bind(this, paymentRequestData)
11962
- });
11963
- container.appendChild(button);
11964
- }
11965
12011
  async _onClick(paymentRequestData) {
11966
12012
  try {
11967
12013
  const paymentData = await this.googleClient.loadPaymentData(
@@ -11983,11 +12029,11 @@
11983
12029
  } = paymentMethodData;
11984
12030
  const token = JSON.parse(tokenizationData.token);
11985
12031
  const { card } = token;
11986
- await this.updateCart(__spreadValues$8({
12032
+ await this.updateCart(__spreadValues$9({
11987
12033
  account: {
11988
12034
  email
11989
12035
  },
11990
- billing: __spreadValues$8({
12036
+ billing: __spreadValues$9({
11991
12037
  method: "card",
11992
12038
  card: {
11993
12039
  token: token.id,
@@ -12017,21 +12063,21 @@
12017
12063
  }
12018
12064
  }
12019
12065
 
12020
- var __defProp$7 = Object.defineProperty;
12066
+ var __defProp$8 = Object.defineProperty;
12021
12067
  var __defProps$2 = Object.defineProperties;
12022
12068
  var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
12023
- var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
12024
- var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
12025
- var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
12026
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12027
- var __spreadValues$7 = (a, b) => {
12069
+ var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
12070
+ var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
12071
+ var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
12072
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12073
+ var __spreadValues$8 = (a, b) => {
12028
12074
  for (var prop in b || (b = {}))
12029
- if (__hasOwnProp$7.call(b, prop))
12030
- __defNormalProp$7(a, prop, b[prop]);
12031
- if (__getOwnPropSymbols$7)
12032
- for (var prop of __getOwnPropSymbols$7(b)) {
12033
- if (__propIsEnum$7.call(b, prop))
12034
- __defNormalProp$7(a, prop, b[prop]);
12075
+ if (__hasOwnProp$8.call(b, prop))
12076
+ __defNormalProp$8(a, prop, b[prop]);
12077
+ if (__getOwnPropSymbols$8)
12078
+ for (var prop of __getOwnPropSymbols$8(b)) {
12079
+ if (__propIsEnum$8.call(b, prop))
12080
+ __defNormalProp$8(a, prop, b[prop]);
12035
12081
  }
12036
12082
  return a;
12037
12083
  };
@@ -12041,7 +12087,7 @@
12041
12087
  if (!methods.card) {
12042
12088
  throw new PaymentMethodDisabledError("Credit cards");
12043
12089
  }
12044
- const method = __spreadProps$2(__spreadValues$7({}, methods.apple), {
12090
+ const method = __spreadProps$2(__spreadValues$8({}, methods.apple), {
12045
12091
  publishable_key: methods.card.publishable_key
12046
12092
  });
12047
12093
  super(request, options, params, method);
@@ -12064,6 +12110,13 @@
12064
12110
  StripeApplePayment.stripe = stripe;
12065
12111
  }
12066
12112
  async createElements() {
12113
+ const {
12114
+ elementId = "applepay-button",
12115
+ style: { type = "default", theme = "dark", height = "40px" } = {},
12116
+ classes = {}
12117
+ } = this.params;
12118
+ this.setElementContainer(elementId);
12119
+ await this.loadScripts(this.scripts);
12067
12120
  await this._authorizeDomain();
12068
12121
  const cart = await this.getCart();
12069
12122
  const paymentRequest = this._createPaymentRequest(cart);
@@ -12073,7 +12126,20 @@
12073
12126
  "This device is not capable of making Apple Pay payments"
12074
12127
  );
12075
12128
  }
12076
- this._renderButton(paymentRequest);
12129
+ this.element = this.stripe.elements().create("paymentRequestButton", {
12130
+ paymentRequest,
12131
+ style: {
12132
+ paymentRequestButton: {
12133
+ type,
12134
+ theme,
12135
+ height
12136
+ }
12137
+ },
12138
+ classes
12139
+ });
12140
+ }
12141
+ mountElements() {
12142
+ this.element.mount(`#${this.elementContainer.id}`);
12077
12143
  }
12078
12144
  async _authorizeDomain() {
12079
12145
  const domain = window.location.hostname;
@@ -12089,7 +12155,7 @@
12089
12155
  }
12090
12156
  _createPaymentRequest(cart) {
12091
12157
  const { require: { name, email, shipping, phone } = {} } = this.params;
12092
- const paymentRequest = this.stripe.paymentRequest(__spreadValues$7({
12158
+ const paymentRequest = this.stripe.paymentRequest(__spreadValues$8({
12093
12159
  requestPayerName: Boolean(name),
12094
12160
  requestPayerEmail: Boolean(email),
12095
12161
  requestPayerPhone: Boolean(phone),
@@ -12107,29 +12173,6 @@
12107
12173
  paymentRequest.on("paymentmethod", this._onPaymentMethod.bind(this));
12108
12174
  return paymentRequest;
12109
12175
  }
12110
- _renderButton(paymentRequest) {
12111
- const {
12112
- elementId = "applepay-button",
12113
- style: { type = "default", theme = "dark", height = "40px" } = {},
12114
- classes = {}
12115
- } = this.params;
12116
- const container = document.getElementById(elementId);
12117
- if (!container) {
12118
- throw new DomElementNotFoundError(elementId);
12119
- }
12120
- const button = this.stripe.elements().create("paymentRequestButton", {
12121
- paymentRequest,
12122
- style: {
12123
- paymentRequestButton: {
12124
- type,
12125
- theme,
12126
- height
12127
- }
12128
- },
12129
- classes
12130
- });
12131
- button.mount(`#${elementId}`);
12132
- }
12133
12176
  _getPaymentRequestData(cart) {
12134
12177
  const {
12135
12178
  currency,
@@ -12187,11 +12230,11 @@
12187
12230
  const { shippingAddress, updateWith } = event;
12188
12231
  const shipping = this._mapShippingAddress(shippingAddress);
12189
12232
  const cart = await this.updateCart({
12190
- shipping: __spreadProps$2(__spreadValues$7({}, shipping), { service: null }),
12233
+ shipping: __spreadProps$2(__spreadValues$8({}, shipping), { service: null }),
12191
12234
  shipment_rating: null
12192
12235
  });
12193
12236
  if (cart) {
12194
- updateWith(__spreadValues$7({ status: "success" }, this._getPaymentRequestData(cart)));
12237
+ updateWith(__spreadValues$8({ status: "success" }, this._getPaymentRequestData(cart)));
12195
12238
  } else {
12196
12239
  updateWith({ status: "invalid_shipping_address" });
12197
12240
  }
@@ -12202,7 +12245,7 @@
12202
12245
  shipping: { service: shippingOption.id }
12203
12246
  });
12204
12247
  if (cart) {
12205
- updateWith(__spreadValues$7({ status: "success" }, this._getPaymentRequestData(cart)));
12248
+ updateWith(__spreadValues$8({ status: "success" }, this._getPaymentRequestData(cart)));
12206
12249
  } else {
12207
12250
  updateWith({ status: "fail" });
12208
12251
  }
@@ -12216,16 +12259,16 @@
12216
12259
  complete
12217
12260
  } = event;
12218
12261
  const { require: { shipping: requireShipping } = {} } = this.params;
12219
- await this.updateCart(__spreadProps$2(__spreadValues$7({
12262
+ await this.updateCart(__spreadProps$2(__spreadValues$8({
12220
12263
  account: {
12221
12264
  email: payerEmail
12222
12265
  }
12223
12266
  }, requireShipping && {
12224
- shipping: __spreadProps$2(__spreadValues$7({}, this._mapShippingAddress(shippingAddress)), {
12267
+ shipping: __spreadProps$2(__spreadValues$8({}, this._mapShippingAddress(shippingAddress)), {
12225
12268
  service: shippingOption.id
12226
12269
  })
12227
12270
  }), {
12228
- billing: __spreadProps$2(__spreadValues$7({}, this._mapBillingAddress(billing_details)), {
12271
+ billing: __spreadProps$2(__spreadValues$8({}, this._mapBillingAddress(billing_details)), {
12229
12272
  method: "card",
12230
12273
  card: {
12231
12274
  gateway: "stripe",
@@ -12269,19 +12312,19 @@
12269
12312
  }
12270
12313
  }
12271
12314
 
12272
- var __defProp$6 = Object.defineProperty;
12273
- var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
12274
- var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
12275
- var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
12276
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12277
- var __spreadValues$6 = (a, b) => {
12315
+ var __defProp$7 = Object.defineProperty;
12316
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
12317
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
12318
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
12319
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12320
+ var __spreadValues$7 = (a, b) => {
12278
12321
  for (var prop in b || (b = {}))
12279
- if (__hasOwnProp$6.call(b, prop))
12280
- __defNormalProp$6(a, prop, b[prop]);
12281
- if (__getOwnPropSymbols$6)
12282
- for (var prop of __getOwnPropSymbols$6(b)) {
12283
- if (__propIsEnum$6.call(b, prop))
12284
- __defNormalProp$6(a, prop, b[prop]);
12322
+ if (__hasOwnProp$7.call(b, prop))
12323
+ __defNormalProp$7(a, prop, b[prop]);
12324
+ if (__getOwnPropSymbols$7)
12325
+ for (var prop of __getOwnPropSymbols$7(b)) {
12326
+ if (__propIsEnum$7.call(b, prop))
12327
+ __defNormalProp$7(a, prop, b[prop]);
12285
12328
  }
12286
12329
  return a;
12287
12330
  };
@@ -12319,7 +12362,6 @@
12319
12362
  return this.braintree.paypalCheckout;
12320
12363
  }
12321
12364
  async createElements() {
12322
- const cart = await this.getCart();
12323
12365
  const {
12324
12366
  elementId = "paypal-button",
12325
12367
  locale = "en_US",
@@ -12330,29 +12372,24 @@
12330
12372
  shape = "rect",
12331
12373
  label = "paypal",
12332
12374
  tagline = false
12333
- } = {},
12334
- classes = {}
12375
+ } = {}
12335
12376
  } = this.params;
12336
- const container = document.getElementById(elementId);
12337
- if (!container) {
12338
- throw new DomElementNotFoundError(elementId);
12339
- }
12377
+ this.setElementContainer(elementId);
12340
12378
  const authorization = await this.authorizeGateway({
12341
12379
  gateway: "braintree"
12342
12380
  });
12343
12381
  if (authorization.error) {
12344
12382
  throw new Error(authorization.error.message);
12345
12383
  }
12384
+ await this.loadScripts(this.scripts);
12346
12385
  const braintreeClient = await this.braintree.client.create({
12347
12386
  authorization
12348
12387
  });
12349
12388
  const paypalCheckout = await this.braintreePaypalCheckout.create({
12350
12389
  client: braintreeClient
12351
12390
  });
12352
- if (classes.base) {
12353
- container.classList.add(classes.base);
12354
- }
12355
- const button = this.paypal.Buttons({
12391
+ const cart = await this.getCart();
12392
+ this.element = this.paypal.Buttons({
12356
12393
  locale,
12357
12394
  style: {
12358
12395
  layout,
@@ -12372,7 +12409,14 @@
12372
12409
  onCancel: this.onCancel.bind(this),
12373
12410
  onError: this.onError.bind(this)
12374
12411
  });
12375
- button.render(`#${elementId}`);
12412
+ }
12413
+ mountElements() {
12414
+ const { classes = {} } = this.params;
12415
+ const container = this.elementContainer;
12416
+ this.element.render(`#${container.id}`);
12417
+ if (classes.base) {
12418
+ container.classList.add(classes.base);
12419
+ }
12376
12420
  }
12377
12421
  _createBillingAgreement(paypalCheckout, cart) {
12378
12422
  const { require: { shipping: requireShipping = true } = {} } = this.params;
@@ -12388,7 +12432,7 @@
12388
12432
  const { require: { shipping: requireShipping = true } = {} } = this.params;
12389
12433
  const { details, nonce } = await paypalCheckout.tokenizePayment(data);
12390
12434
  const { email, countryCode, firstName, lastName } = details;
12391
- await this.updateCart(__spreadValues$6({
12435
+ await this.updateCart(__spreadValues$7({
12392
12436
  account: {
12393
12437
  email
12394
12438
  },
@@ -12403,7 +12447,7 @@
12403
12447
  }
12404
12448
  }
12405
12449
  }, requireShipping && {
12406
- shipping: __spreadValues$6({
12450
+ shipping: __spreadValues$7({
12407
12451
  name: details.shippingAddress.recipientName
12408
12452
  }, this._mapAddress(details.shippingAddress))
12409
12453
  }));
@@ -12421,19 +12465,19 @@
12421
12465
  }
12422
12466
  }
12423
12467
 
12424
- var __defProp$5 = Object.defineProperty;
12425
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
12426
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
12427
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
12428
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12429
- var __spreadValues$5 = (a, b) => {
12468
+ var __defProp$6 = Object.defineProperty;
12469
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
12470
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
12471
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
12472
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12473
+ var __spreadValues$6 = (a, b) => {
12430
12474
  for (var prop in b || (b = {}))
12431
- if (__hasOwnProp$5.call(b, prop))
12432
- __defNormalProp$5(a, prop, b[prop]);
12433
- if (__getOwnPropSymbols$5)
12434
- for (var prop of __getOwnPropSymbols$5(b)) {
12435
- if (__propIsEnum$5.call(b, prop))
12436
- __defNormalProp$5(a, prop, b[prop]);
12475
+ if (__hasOwnProp$6.call(b, prop))
12476
+ __defNormalProp$6(a, prop, b[prop]);
12477
+ if (__getOwnPropSymbols$6)
12478
+ for (var prop of __getOwnPropSymbols$6(b)) {
12479
+ if (__propIsEnum$6.call(b, prop))
12480
+ __defNormalProp$6(a, prop, b[prop]);
12437
12481
  }
12438
12482
  return a;
12439
12483
  };
@@ -12504,9 +12548,16 @@
12504
12548
  return [this.cardPaymentMethod];
12505
12549
  }
12506
12550
  async createElements() {
12551
+ const {
12552
+ elementId = "googlepay-button",
12553
+ locale = "en",
12554
+ style: { color = "black", type = "buy", sizeMode = "fill" } = {}
12555
+ } = this.params;
12507
12556
  if (!this.method.merchant_id) {
12508
12557
  throw new Error("Google merchant ID is not defined");
12509
12558
  }
12559
+ this.setElementContainer(elementId);
12560
+ await this.loadScripts(this.scripts);
12510
12561
  const isReadyToPay = await this.googleClient.isReadyToPay({
12511
12562
  apiVersion: API_VERSION,
12512
12563
  apiVersionMinor: API_MINOR_VERSION,
@@ -12527,7 +12578,21 @@
12527
12578
  const cart = await this.getCart();
12528
12579
  const paymentRequestData = this._createPaymentRequestData(cart);
12529
12580
  const paymentDataRequest = googlePayment.createPaymentDataRequest(paymentRequestData);
12530
- this._renderButton(googlePayment, paymentDataRequest);
12581
+ this.element = this.googleClient.createButton({
12582
+ buttonColor: color,
12583
+ buttonType: type,
12584
+ buttonSizeMode: sizeMode,
12585
+ buttonLocale: locale,
12586
+ onClick: this._onClick.bind(this, googlePayment, paymentDataRequest)
12587
+ });
12588
+ }
12589
+ mountElements() {
12590
+ const { classes = {} } = this.params;
12591
+ const container = this.elementContainer;
12592
+ container.appendChild(this.element);
12593
+ if (classes.base) {
12594
+ container.classList.add(classes.base);
12595
+ }
12531
12596
  }
12532
12597
  async _createBraintreeClient() {
12533
12598
  const authorization = await this.authorizeGateway({
@@ -12567,29 +12632,6 @@
12567
12632
  }
12568
12633
  };
12569
12634
  }
12570
- _renderButton(googlePayment, paymentDataRequest) {
12571
- const {
12572
- elementId = "googlepay-button",
12573
- locale = "en",
12574
- style: { color = "black", type = "buy", sizeMode = "fill" } = {},
12575
- classes = {}
12576
- } = this.params;
12577
- const container = document.getElementById(elementId);
12578
- if (!container) {
12579
- throw new DomElementNotFoundError(elementId);
12580
- }
12581
- if (classes.base) {
12582
- container.classList.add(classes.base);
12583
- }
12584
- const button = this.googleClient.createButton({
12585
- buttonColor: color,
12586
- buttonType: type,
12587
- buttonSizeMode: sizeMode,
12588
- buttonLocale: locale,
12589
- onClick: this._onClick.bind(this, googlePayment, paymentDataRequest)
12590
- });
12591
- container.appendChild(button);
12592
- }
12593
12635
  async _onClick(googlePayment, paymentDataRequest) {
12594
12636
  try {
12595
12637
  const paymentData = await this.googleClient.loadPaymentData(
@@ -12609,11 +12651,11 @@
12609
12651
  const {
12610
12652
  info: { billingAddress }
12611
12653
  } = paymentMethodData;
12612
- await this.updateCart(__spreadValues$5({
12654
+ await this.updateCart(__spreadValues$6({
12613
12655
  account: {
12614
12656
  email
12615
12657
  },
12616
- billing: __spreadValues$5({
12658
+ billing: __spreadValues$6({
12617
12659
  method: "google",
12618
12660
  google: {
12619
12661
  nonce,
@@ -12636,22 +12678,22 @@
12636
12678
  country: address.countryCode,
12637
12679
  phone: address.phoneNumber
12638
12680
  };
12639
- }
12640
- }
12641
-
12642
- var __defProp$4 = Object.defineProperty;
12643
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
12644
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
12645
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
12646
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12647
- var __spreadValues$4 = (a, b) => {
12681
+ }
12682
+ }
12683
+
12684
+ var __defProp$5 = Object.defineProperty;
12685
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
12686
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
12687
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
12688
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12689
+ var __spreadValues$5 = (a, b) => {
12648
12690
  for (var prop in b || (b = {}))
12649
- if (__hasOwnProp$4.call(b, prop))
12650
- __defNormalProp$4(a, prop, b[prop]);
12651
- if (__getOwnPropSymbols$4)
12652
- for (var prop of __getOwnPropSymbols$4(b)) {
12653
- if (__propIsEnum$4.call(b, prop))
12654
- __defNormalProp$4(a, prop, b[prop]);
12691
+ if (__hasOwnProp$5.call(b, prop))
12692
+ __defNormalProp$5(a, prop, b[prop]);
12693
+ if (__getOwnPropSymbols$5)
12694
+ for (var prop of __getOwnPropSymbols$5(b)) {
12695
+ if (__propIsEnum$5.call(b, prop))
12696
+ __defNormalProp$5(a, prop, b[prop]);
12655
12697
  }
12656
12698
  return a;
12657
12699
  };
@@ -12684,6 +12726,9 @@
12684
12726
  return window.ApplePaySession;
12685
12727
  }
12686
12728
  async createElements() {
12729
+ const { elementId = "applepay-button" } = this.params;
12730
+ this.setElementContainer(elementId);
12731
+ await this.loadScripts(this.scripts);
12687
12732
  if (!this.ApplePaySession.canMakePayments()) {
12688
12733
  throw new Error(
12689
12734
  "This device is not capable of making Apple Pay payments"
@@ -12695,21 +12740,18 @@
12695
12740
  client: braintreeClient
12696
12741
  });
12697
12742
  const paymentRequest = await this._createPaymentRequest(cart, applePayment);
12698
- this._renderButton(applePayment, paymentRequest);
12743
+ this.element = this._createButton(applePayment, paymentRequest);
12699
12744
  }
12700
- _renderButton(applePayment, paymentRequest) {
12701
- const {
12702
- elementId = "applepay-button",
12703
- style: { type = "plain", theme = "black", height = "40px" } = {},
12704
- classes = {}
12705
- } = this.params;
12706
- const container = document.getElementById(elementId);
12707
- if (!container) {
12708
- throw new DomElementNotFoundError(elementId);
12709
- }
12745
+ mountElements() {
12746
+ const { classes = {} } = this.params;
12747
+ const container = this.elementContainer;
12748
+ container.appendChild(this.element);
12710
12749
  if (classes.base) {
12711
12750
  container.classList.add(classes.base);
12712
12751
  }
12752
+ }
12753
+ _createButton(applePayment, paymentRequest) {
12754
+ const { style: { type = "plain", theme = "black", height = "40px" } = {} } = this.params;
12713
12755
  const button = document.createElement("div");
12714
12756
  button.style.appearance = "-apple-pay-button";
12715
12757
  button.style["-apple-pay-button-type"] = type;
@@ -12719,7 +12761,7 @@
12719
12761
  "click",
12720
12762
  this._createPaymentSession.bind(this, applePayment, paymentRequest)
12721
12763
  );
12722
- container.appendChild(button);
12764
+ return button;
12723
12765
  }
12724
12766
  async _createBraintreeClient() {
12725
12767
  const authorization = await this.authorizeGateway({
@@ -12787,11 +12829,11 @@
12787
12829
  if (!payload) {
12788
12830
  return session.completePayment(this.ApplePaySession.STATUS_FAILURE);
12789
12831
  }
12790
- await this.updateCart(__spreadValues$4({
12832
+ await this.updateCart(__spreadValues$5({
12791
12833
  account: {
12792
12834
  email: shippingContact.emailAddress
12793
12835
  },
12794
- billing: __spreadValues$4({
12836
+ billing: __spreadValues$5({
12795
12837
  method: "apple",
12796
12838
  apple: {
12797
12839
  nonce: payload.nonce,
@@ -12958,21 +13000,21 @@
12958
13000
  }
12959
13001
  }
12960
13002
 
12961
- var __defProp$3 = Object.defineProperty;
13003
+ var __defProp$4 = Object.defineProperty;
12962
13004
  var __defProps$1 = Object.defineProperties;
12963
13005
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
12964
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
12965
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
12966
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
12967
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12968
- var __spreadValues$3 = (a, b) => {
13006
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
13007
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
13008
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
13009
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13010
+ var __spreadValues$4 = (a, b) => {
12969
13011
  for (var prop in b || (b = {}))
12970
- if (__hasOwnProp$3.call(b, prop))
12971
- __defNormalProp$3(a, prop, b[prop]);
12972
- if (__getOwnPropSymbols$3)
12973
- for (var prop of __getOwnPropSymbols$3(b)) {
12974
- if (__propIsEnum$3.call(b, prop))
12975
- __defNormalProp$3(a, prop, b[prop]);
13012
+ if (__hasOwnProp$4.call(b, prop))
13013
+ __defNormalProp$4(a, prop, b[prop]);
13014
+ if (__getOwnPropSymbols$4)
13015
+ for (var prop of __getOwnPropSymbols$4(b)) {
13016
+ if (__propIsEnum$4.call(b, prop))
13017
+ __defNormalProp$4(a, prop, b[prop]);
12976
13018
  }
12977
13019
  return a;
12978
13020
  };
@@ -12999,7 +13041,7 @@
12999
13041
  },
13000
13042
  {}
13001
13043
  );
13002
- const mapAddressFields = (cart, addressField) => __spreadProps$1(__spreadValues$3({}, mapFields(addressFieldsMap, cart[addressField])), {
13044
+ const mapAddressFields = (cart, addressField) => __spreadProps$1(__spreadValues$4({}, mapFields(addressFieldsMap, cart[addressField])), {
13003
13045
  email: get(cart, "account.email")
13004
13046
  });
13005
13047
  function getOrderLines(cart) {
@@ -13098,19 +13140,19 @@
13098
13140
  }
13099
13141
  }
13100
13142
 
13101
- var __defProp$2 = Object.defineProperty;
13102
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
13103
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
13104
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
13105
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13106
- var __spreadValues$2 = (a, b) => {
13143
+ var __defProp$3 = Object.defineProperty;
13144
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
13145
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
13146
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
13147
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13148
+ var __spreadValues$3 = (a, b) => {
13107
13149
  for (var prop in b || (b = {}))
13108
- if (__hasOwnProp$2.call(b, prop))
13109
- __defNormalProp$2(a, prop, b[prop]);
13110
- if (__getOwnPropSymbols$2)
13111
- for (var prop of __getOwnPropSymbols$2(b)) {
13112
- if (__propIsEnum$2.call(b, prop))
13113
- __defNormalProp$2(a, prop, b[prop]);
13150
+ if (__hasOwnProp$3.call(b, prop))
13151
+ __defNormalProp$3(a, prop, b[prop]);
13152
+ if (__getOwnPropSymbols$3)
13153
+ for (var prop of __getOwnPropSymbols$3(b)) {
13154
+ if (__propIsEnum$3.call(b, prop))
13155
+ __defNormalProp$3(a, prop, b[prop]);
13114
13156
  }
13115
13157
  return a;
13116
13158
  };
@@ -13145,18 +13187,6 @@
13145
13187
  return `${window.location.origin + window.location.pathname}?gateway=paypal`;
13146
13188
  }
13147
13189
  async createElements() {
13148
- const cart = await this.getCart();
13149
- const hasSubscriptionProduct = Boolean(cart.subscription_delivery);
13150
- if (hasSubscriptionProduct && !this.method.ppcp) {
13151
- throw new Error(
13152
- "Subscriptions are only supported by PayPal Commerce Platform. See Payment settings in the Swell dashboard to enable PayPal Commerce Platform"
13153
- );
13154
- }
13155
- if (!(cart.capture_total > 0)) {
13156
- throw new Error(
13157
- "Invalid PayPal button amount. Value should be greater than zero."
13158
- );
13159
- }
13160
13190
  const {
13161
13191
  elementId = "paypal-button",
13162
13192
  locale = "en_US",
@@ -13167,14 +13197,13 @@
13167
13197
  shape = "rect",
13168
13198
  label = "paypal",
13169
13199
  tagline = false
13170
- } = {},
13171
- classes = {}
13200
+ } = {}
13172
13201
  } = this.params;
13173
- const container = document.getElementById(elementId);
13174
- if (!container) {
13175
- throw new DomElementNotFoundError(elementId);
13176
- }
13177
- const button = this.paypal.Buttons({
13202
+ this.setElementContainer(elementId);
13203
+ const cart = await this.getCart();
13204
+ this._validateCart(cart);
13205
+ await this.loadScripts(this.scripts);
13206
+ this.element = this.paypal.Buttons({
13178
13207
  locale,
13179
13208
  style: {
13180
13209
  layout,
@@ -13189,11 +13218,28 @@
13189
13218
  onApprove: this._onApprove.bind(this),
13190
13219
  onError: this.onError.bind(this)
13191
13220
  });
13192
- button.render(`#${elementId}`);
13221
+ }
13222
+ mountElements() {
13223
+ const { classes = {} } = this.params;
13224
+ const container = this.elementContainer;
13225
+ this.element.render(`#${container.id}`);
13193
13226
  if (classes.base) {
13194
13227
  container.classList.add(classes.base);
13195
13228
  }
13196
13229
  }
13230
+ _validateCart(cart) {
13231
+ const hasSubscriptionProduct = Boolean(cart.subscription_delivery);
13232
+ if (hasSubscriptionProduct && !this.method.ppcp) {
13233
+ throw new Error(
13234
+ "Subscriptions are only supported by PayPal Commerce Platform. See Payment settings in the Swell dashboard to enable PayPal Commerce Platform"
13235
+ );
13236
+ }
13237
+ if (!(cart.capture_total > 0)) {
13238
+ throw new Error(
13239
+ "Invalid PayPal button amount. Value should be greater than zero."
13240
+ );
13241
+ }
13242
+ }
13197
13243
  async _onCreateOrder(cart, data, actions) {
13198
13244
  const { require: { shipping: requireShipping = true } = {} } = this.params;
13199
13245
  const { capture_total, currency, subscription_delivery } = cart;
@@ -13302,11 +13348,11 @@
13302
13348
  const billing = payer.address;
13303
13349
  const shipping = get(order, "purchase_units[0].shipping");
13304
13350
  const name = `${payer.name.given_name} ${payer.name.surname}`;
13305
- await this.updateCart(__spreadValues$2({
13351
+ await this.updateCart(__spreadValues$3({
13306
13352
  account: {
13307
13353
  email: payer.email_address
13308
13354
  },
13309
- billing: __spreadValues$2({
13355
+ billing: __spreadValues$3({
13310
13356
  method: "paypal",
13311
13357
  paypal: {
13312
13358
  order_id: orderId
@@ -13314,7 +13360,7 @@
13314
13360
  name
13315
13361
  }, this._mapAddress(billing))
13316
13362
  }, requireShipping && {
13317
- shipping: __spreadValues$2({
13363
+ shipping: __spreadValues$3({
13318
13364
  first_name: payer.name.given_name,
13319
13365
  last_name: payer.name.surname,
13320
13366
  name: shipping.name.full_name
@@ -13334,21 +13380,21 @@
13334
13380
  }
13335
13381
  }
13336
13382
 
13337
- var __defProp$1 = Object.defineProperty;
13383
+ var __defProp$2 = Object.defineProperty;
13338
13384
  var __defProps = Object.defineProperties;
13339
13385
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
13340
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
13341
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
13342
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
13343
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13344
- var __spreadValues$1 = (a, b) => {
13386
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
13387
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
13388
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
13389
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13390
+ var __spreadValues$2 = (a, b) => {
13345
13391
  for (var prop in b || (b = {}))
13346
- if (__hasOwnProp$1.call(b, prop))
13347
- __defNormalProp$1(a, prop, b[prop]);
13348
- if (__getOwnPropSymbols$1)
13349
- for (var prop of __getOwnPropSymbols$1(b)) {
13350
- if (__propIsEnum$1.call(b, prop))
13351
- __defNormalProp$1(a, prop, b[prop]);
13392
+ if (__hasOwnProp$2.call(b, prop))
13393
+ __defNormalProp$2(a, prop, b[prop]);
13394
+ if (__getOwnPropSymbols$2)
13395
+ for (var prop of __getOwnPropSymbols$2(b)) {
13396
+ if (__propIsEnum$2.call(b, prop))
13397
+ __defNormalProp$2(a, prop, b[prop]);
13352
13398
  }
13353
13399
  return a;
13354
13400
  };
@@ -13384,28 +13430,39 @@
13384
13430
  return `${window.location.origin + window.location.pathname}?gateway=amazon`;
13385
13431
  }
13386
13432
  async createElements() {
13433
+ const {
13434
+ elementId = "amazonpay-button",
13435
+ locale = "en_US",
13436
+ placement = "Checkout",
13437
+ style: { color = "Gold" } = {},
13438
+ require: { shipping: requireShipping } = {}
13439
+ } = this.params;
13440
+ this.setElementContainer(elementId);
13387
13441
  const cart = await this.getCart();
13388
- const returnUrl = this.returnUrl;
13389
- const isSubscription = Boolean(cart.subscription_delivery);
13390
- const session = await this.authorizeGateway({
13391
- gateway: "amazon",
13392
- params: __spreadProps(__spreadValues$1({
13393
- chargePermissionType: isSubscription ? "Recurring" : "OneTime"
13394
- }, isSubscription ? {
13395
- recurringMetadata: {
13396
- frequency: {
13397
- unit: "Variable",
13398
- value: "0"
13399
- }
13400
- }
13401
- } : {}), {
13402
- webCheckoutDetails: {
13403
- checkoutReviewReturnUrl: `${returnUrl}&redirect_status=succeeded`,
13404
- checkoutCancelUrl: `${returnUrl}&redirect_status=canceled`
13405
- }
13406
- })
13407
- });
13408
- this._renderButton(cart, session);
13442
+ const session = await this._createSession(cart);
13443
+ await this.loadScripts(this.scripts);
13444
+ this.element = {
13445
+ ledgerCurrency: cart.currency,
13446
+ checkoutLanguage: locale,
13447
+ productType: Boolean(requireShipping) ? "PayAndShip" : "PayOnly",
13448
+ buttonColor: color,
13449
+ placement,
13450
+ merchantId: this.merchantId,
13451
+ publicKeyId: this.publicKeyId,
13452
+ createCheckoutSessionConfig: {
13453
+ payloadJSON: session.payload,
13454
+ signature: session.signature
13455
+ }
13456
+ };
13457
+ }
13458
+ mountElements() {
13459
+ const { classes = {} } = this.params;
13460
+ const container = this.elementContainer;
13461
+ const amazon = this.amazon;
13462
+ amazon.Pay.renderButton(`#${container.id}`, this.element);
13463
+ if (classes.base) {
13464
+ container.classList.add(classes.base);
13465
+ }
13409
13466
  }
13410
13467
  async tokenize() {
13411
13468
  const cart = await this.getCart();
@@ -13449,39 +13506,27 @@
13449
13506
  throw new Error(`Unknown redirect status: ${redirect_status}`);
13450
13507
  }
13451
13508
  }
13452
- _renderButton(cart, session) {
13453
- const amazon = this.amazon;
13454
- const merchantId = this.merchantId;
13455
- const publicKeyId = this.publicKeyId;
13456
- const { payload: payloadJSON, signature } = session;
13457
- const {
13458
- elementId = "amazonpay-button",
13459
- locale = "en_US",
13460
- placement = "Checkout",
13461
- style: { color = "Gold" } = {},
13462
- require: { shipping: requireShipping } = {},
13463
- classes = {}
13464
- } = this.params;
13465
- const container = document.getElementById(elementId);
13466
- if (!container) {
13467
- throw new DomElementNotFoundError(elementId);
13468
- }
13469
- amazon.Pay.renderButton(`#${elementId}`, {
13470
- ledgerCurrency: cart.currency,
13471
- checkoutLanguage: locale,
13472
- productType: Boolean(requireShipping) ? "PayAndShip" : "PayOnly",
13473
- buttonColor: color,
13474
- placement,
13475
- merchantId,
13476
- publicKeyId,
13477
- createCheckoutSessionConfig: {
13478
- payloadJSON,
13479
- signature
13480
- }
13509
+ _createSession(cart) {
13510
+ const returnUrl = this.returnUrl;
13511
+ const isSubscription = Boolean(cart.subscription_delivery);
13512
+ return this.authorizeGateway({
13513
+ gateway: "amazon",
13514
+ params: __spreadProps(__spreadValues$2({
13515
+ chargePermissionType: isSubscription ? "Recurring" : "OneTime"
13516
+ }, isSubscription ? {
13517
+ recurringMetadata: {
13518
+ frequency: {
13519
+ unit: "Variable",
13520
+ value: "0"
13521
+ }
13522
+ }
13523
+ } : {}), {
13524
+ webCheckoutDetails: {
13525
+ checkoutReviewReturnUrl: `${returnUrl}&redirect_status=succeeded`,
13526
+ checkoutCancelUrl: `${returnUrl}&redirect_status=canceled`
13527
+ }
13528
+ })
13481
13529
  });
13482
- if (classes.base) {
13483
- container.classList.add(classes.base);
13484
- }
13485
13530
  }
13486
13531
  async _handleSuccessfulRedirect(queryParams) {
13487
13532
  const { confirm, amazonCheckoutSessionId } = queryParams;
@@ -13499,6 +13544,67 @@
13499
13544
  }
13500
13545
  }
13501
13546
 
13547
+ var __defProp$1 = Object.defineProperty;
13548
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
13549
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
13550
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
13551
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13552
+ var __spreadValues$1 = (a, b) => {
13553
+ for (var prop in b || (b = {}))
13554
+ if (__hasOwnProp$1.call(b, prop))
13555
+ __defNormalProp$1(a, prop, b[prop]);
13556
+ if (__getOwnPropSymbols$1)
13557
+ for (var prop of __getOwnPropSymbols$1(b)) {
13558
+ if (__propIsEnum$1.call(b, prop))
13559
+ __defNormalProp$1(a, prop, b[prop]);
13560
+ }
13561
+ return a;
13562
+ };
13563
+ function adjustConfig(params) {
13564
+ if (!params.config) {
13565
+ return;
13566
+ }
13567
+ if (params.card) {
13568
+ console.warn('Please move the "config" field to the "card.config"');
13569
+ params.card.config = params.config;
13570
+ }
13571
+ if (params.ideal) {
13572
+ console.warn('Please move the "config" field to the "ideal.config"');
13573
+ params.ideal.config = params.config;
13574
+ }
13575
+ delete params.config;
13576
+ }
13577
+ function adjustElementId(methodParams) {
13578
+ if (methodParams.cardNumber) {
13579
+ adjustElementId(methodParams.cardNumber);
13580
+ }
13581
+ if (methodParams.cardExpiry) {
13582
+ adjustElementId(methodParams.cardExpiry);
13583
+ }
13584
+ if (methodParams.cardCvc) {
13585
+ adjustElementId(methodParams.cardCvc);
13586
+ }
13587
+ if (!methodParams.elementId) {
13588
+ return;
13589
+ }
13590
+ if (methodParams.elementId.startsWith("#")) {
13591
+ console.warn(
13592
+ `Please remove the "#" sign from the "${methodParams.elementId}" element ID`
13593
+ );
13594
+ methodParams.elementId = methodParams.elementId.substring(1);
13595
+ }
13596
+ }
13597
+ function adjustParams(_params) {
13598
+ const params = __spreadValues$1({}, _params);
13599
+ adjustConfig(params);
13600
+ return params;
13601
+ }
13602
+ function adjustMethodParams(_methodParams) {
13603
+ const methodParams = __spreadValues$1({}, _methodParams);
13604
+ adjustElementId(methodParams);
13605
+ return methodParams;
13606
+ }
13607
+
13502
13608
  class PaymentController {
13503
13609
  constructor(request, options) {
13504
13610
  this.request = request;
@@ -13519,14 +13625,18 @@
13519
13625
  if (!params) {
13520
13626
  throw new Error("Payment element parameters are not provided");
13521
13627
  }
13522
- this._performPaymentAction("createElements");
13628
+ const paymentInstances = await this._createPaymentInstances();
13629
+ await this._performPaymentAction(paymentInstances, "createElements").then(
13630
+ (paymentInstances2) => this._performPaymentAction(paymentInstances2, "mountElements")
13631
+ );
13523
13632
  }
13524
13633
  async tokenize(params = this.params) {
13525
13634
  this.params = params;
13526
13635
  if (!this.params) {
13527
13636
  throw new Error("Tokenization parameters are not provided");
13528
13637
  }
13529
- this._performPaymentAction("tokenize");
13638
+ const paymentInstances = await this._createPaymentInstances();
13639
+ await this._performPaymentAction(paymentInstances, "tokenize");
13530
13640
  }
13531
13641
  async handleRedirect(params = this.params) {
13532
13642
  const queryParams = getLocationParams(window.location);
@@ -13538,7 +13648,12 @@
13538
13648
  throw new Error("Redirect parameters are not provided");
13539
13649
  }
13540
13650
  removeUrlParams();
13541
- this._performPaymentAction("handleRedirect", queryParams);
13651
+ const paymentInstances = await this._createPaymentInstances();
13652
+ await this._performPaymentAction(
13653
+ paymentInstances,
13654
+ "handleRedirect",
13655
+ queryParams
13656
+ );
13542
13657
  }
13543
13658
  async authenticate(id) {
13544
13659
  try {
@@ -13577,23 +13692,6 @@
13577
13692
  async authorizeGateway(data) {
13578
13693
  return this._vaultRequest("post", "/authorization", data);
13579
13694
  }
13580
- _normalizeParams() {
13581
- if (!this.params) {
13582
- return;
13583
- }
13584
- if (this.params.config) {
13585
- console.warn(
13586
- 'Please move the "config" field to the payment method parameters ("card.config" or/and "ideal.config").'
13587
- );
13588
- if (this.params.card) {
13589
- this.params.card.config = this.params.config;
13590
- }
13591
- if (this.params.ideal) {
13592
- this.params.ideal.config = this.params.config;
13593
- }
13594
- delete this.params.config;
13595
- }
13596
- }
13597
13695
  async _getPaymentMethods() {
13598
13696
  const paymentMethods = await methods$2(
13599
13697
  this.request,
@@ -13619,35 +13717,55 @@
13619
13717
  }
13620
13718
  return response;
13621
13719
  }
13622
- async _performPaymentAction(action, ...args) {
13720
+ async _createPaymentInstances() {
13623
13721
  const paymentMethods = await this._getPaymentMethods();
13624
- this._normalizeParams();
13625
- Object.entries(this.params).forEach(([method, params]) => {
13722
+ const params = adjustParams(this.params);
13723
+ return Object.entries(params).reduce((acc, [method, params2]) => {
13626
13724
  const methodSettings = paymentMethods[method];
13627
13725
  if (!methodSettings) {
13628
- return console.error(new PaymentMethodDisabledError(method));
13726
+ console.error(new PaymentMethodDisabledError(method));
13727
+ return acc;
13629
13728
  }
13630
13729
  const PaymentClass = this._getPaymentClass(
13631
13730
  method,
13632
13731
  methodSettings.gateway
13633
13732
  );
13634
13733
  if (!PaymentClass) {
13635
- return console.error(
13734
+ console.error(
13636
13735
  new UnsupportedPaymentMethodError(method, methodSettings.gateway)
13637
13736
  );
13737
+ return acc;
13638
13738
  }
13739
+ const methodParams = adjustMethodParams(params2);
13639
13740
  try {
13640
- const payment = new PaymentClass(
13741
+ const paymentInstance = new PaymentClass(
13641
13742
  this.request,
13642
13743
  this.options,
13643
- params,
13744
+ methodParams,
13644
13745
  paymentMethods
13645
13746
  );
13646
- payment.loadScripts(payment.scripts).then(payment[action].bind(payment, ...args)).catch(payment.onError.bind(payment));
13747
+ acc.push(paymentInstance);
13647
13748
  } catch (error) {
13648
- return console.error(error.message);
13749
+ console.error(error);
13649
13750
  }
13650
- });
13751
+ return acc;
13752
+ }, []);
13753
+ }
13754
+ async _performPaymentAction(paymentInstances, action, ...args) {
13755
+ const nextPaymentInstances = [];
13756
+ for (const paymentInstance of paymentInstances) {
13757
+ try {
13758
+ const paymentAction = paymentInstance[action];
13759
+ if (paymentAction) {
13760
+ await paymentAction.call(paymentInstance, ...args);
13761
+ nextPaymentInstances.push(paymentInstance);
13762
+ }
13763
+ } catch (error) {
13764
+ const onPaymentError = paymentInstance.onError.bind(paymentInstance);
13765
+ onPaymentError(error);
13766
+ }
13767
+ }
13768
+ return nextPaymentInstances;
13651
13769
  }
13652
13770
  _getPaymentClass(method, gateway) {
13653
13771
  switch (method) {
@@ -13949,7 +14067,7 @@
13949
14067
  previewContent: null
13950
14068
  };
13951
14069
  const api = {
13952
- version: "3.22.0",
14070
+ version: "3.22.2",
13953
14071
  options,
13954
14072
  request,
13955
14073
  init(store, key, opt = {}) {