swell-js 4.2.6 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/api.mjs +15 -6
  2. package/dist/attributes.mjs +1 -1
  3. package/dist/cache.mjs +1 -1
  4. package/dist/card.mjs +1 -1
  5. package/dist/cart.mjs +1 -1
  6. package/dist/categories.mjs +1 -1
  7. package/dist/content.mjs +1 -1
  8. package/dist/cookie.mjs +1 -1
  9. package/dist/{index.a911a674.mjs → index.3c15c4d3.mjs} +1 -1
  10. package/dist/index.mjs +1 -1
  11. package/dist/payment.mjs +279 -14
  12. package/dist/products.mjs +1 -1
  13. package/dist/settings.mjs +1 -1
  14. package/dist/subscriptions.mjs +1 -1
  15. package/dist/swell.cjs +292 -18
  16. package/dist/swell.cjs.map +1 -1
  17. package/dist/swell.umd.min.js +292 -18
  18. package/dist/swell.umd.min.js.map +1 -1
  19. package/dist/utils/index.mjs +1 -1
  20. package/package.json +4 -2
  21. package/types/account/camel.ts +26 -0
  22. package/types/account/index.ts +26 -0
  23. package/types/account/{snake.d.ts → snake.ts} +8 -10
  24. package/types/attribute/camel.ts +15 -0
  25. package/types/attribute/index.ts +8 -0
  26. package/types/attribute/{snake.d.ts → snake.ts} +3 -4
  27. package/types/billing/camel.ts +39 -0
  28. package/types/billing/index.ts +21 -0
  29. package/types/billing/{snake.d.ts → snake.ts} +9 -18
  30. package/types/card/camel.ts +28 -0
  31. package/types/card/index.ts +26 -0
  32. package/types/card/{snake.d.ts → snake.ts} +6 -6
  33. package/types/cart/camel.ts +95 -0
  34. package/types/cart/index.ts +45 -0
  35. package/types/cart/{snake.d.ts → snake.ts} +20 -31
  36. package/types/category/camel.ts +21 -0
  37. package/types/category/index.ts +8 -0
  38. package/types/category/{snake.d.ts → snake.ts} +3 -5
  39. package/types/content/camel.ts +6 -0
  40. package/types/content/index.ts +8 -0
  41. package/types/content/{snake.d.ts → snake.ts} +3 -5
  42. package/types/coupon/camel.ts +15 -0
  43. package/types/coupon/index.ts +2 -0
  44. package/types/coupon/{snake.d.ts → snake.ts} +3 -3
  45. package/types/currency/camel.ts +14 -0
  46. package/types/currency/index.ts +34 -0
  47. package/types/currency/{snake.d.ts → snake.ts} +3 -3
  48. package/types/discount/camel.ts +32 -0
  49. package/types/discount/index.ts +7 -0
  50. package/types/discount/{snake.d.ts → snake.ts} +7 -9
  51. package/types/giftcard/camel.ts +30 -0
  52. package/types/giftcard/index.ts +2 -0
  53. package/types/giftcard/{snake.d.ts → snake.ts} +7 -9
  54. package/types/index.d.ts +407 -405
  55. package/types/invoice/camel.ts +37 -0
  56. package/types/invoice/index.ts +8 -0
  57. package/types/invoice/{snake.d.ts → snake.ts} +11 -11
  58. package/types/order/camel.ts +79 -0
  59. package/types/order/index.ts +32 -0
  60. package/types/order/{snake.d.ts → snake.ts} +18 -26
  61. package/types/payment/camel.ts +58 -0
  62. package/types/payment/index.ts +79 -0
  63. package/types/payment/{snake.d.ts → snake.ts} +16 -21
  64. package/types/product/camel.ts +86 -0
  65. package/types/product/index.ts +72 -0
  66. package/types/product/{snake.d.ts → snake.ts} +12 -23
  67. package/types/promotion/camel.ts +28 -0
  68. package/types/promotion/index.ts +2 -0
  69. package/types/promotion/{snake.d.ts → snake.ts} +6 -8
  70. package/types/purchase_link/camel.ts +21 -0
  71. package/types/purchase_link/index.ts +2 -0
  72. package/types/purchase_link/{snake.d.ts → snake.ts} +6 -6
  73. package/types/refund/camel.ts +19 -0
  74. package/types/refund/index.ts +2 -0
  75. package/types/refund/{snake.d.ts → snake.ts} +5 -5
  76. package/types/shipment_rating/camel.ts +15 -0
  77. package/types/shipment_rating/index.ts +2 -0
  78. package/types/shipment_rating/{snake.d.ts → snake.ts} +2 -4
  79. package/types/subscription/camel.ts +61 -0
  80. package/types/subscription/index.ts +28 -0
  81. package/types/subscription/{snake.d.ts → snake.ts} +14 -20
  82. package/types/utils.ts +10 -0
  83. package/types/account/camel.d.ts +0 -8
  84. package/types/account/index.d.ts +0 -9
  85. package/types/attribute/camel.d.ts +0 -4
  86. package/types/attribute/index.d.ts +0 -4
  87. package/types/billing/camel.d.ts +0 -25
  88. package/types/billing/index.d.ts +0 -38
  89. package/types/card/camel.d.ts +0 -9
  90. package/types/card/index.d.ts +0 -9
  91. package/types/cart/camel.d.ts +0 -32
  92. package/types/cart/index.d.ts +0 -46
  93. package/types/category/camel.d.ts +0 -4
  94. package/types/category/index.d.ts +0 -4
  95. package/types/content/camel.d.ts +0 -5
  96. package/types/content/index.d.ts +0 -8
  97. package/types/coupon/camel.d.ts +0 -4
  98. package/types/coupon/index.d.ts +0 -4
  99. package/types/currency/camel.d.ts +0 -15
  100. package/types/currency/index.d.ts +0 -21
  101. package/types/discount/camel.d.ts +0 -15
  102. package/types/discount/index.d.ts +0 -18
  103. package/types/giftcard/camel.d.ts +0 -6
  104. package/types/giftcard/index.d.ts +0 -5
  105. package/types/invoice/camel.d.ts +0 -4
  106. package/types/invoice/index.d.ts +0 -4
  107. package/types/order/camel.d.ts +0 -15
  108. package/types/order/index.d.ts +0 -20
  109. package/types/payment/camel.d.ts +0 -35
  110. package/types/payment/index.d.ts +0 -51
  111. package/types/product/camel.d.ts +0 -24
  112. package/types/product/index.d.ts +0 -49
  113. package/types/promotion/camel.d.ts +0 -7
  114. package/types/promotion/index.d.ts +0 -8
  115. package/types/purchase_link/camel.d.ts +0 -4
  116. package/types/purchase_link/index.d.ts +0 -4
  117. package/types/refund/camel.d.ts +0 -4
  118. package/types/refund/index.d.ts +0 -4
  119. package/types/shipment_rating/camel.d.ts +0 -7
  120. package/types/shipment_rating/index.d.ts +0 -10
  121. package/types/subscription/camel.d.ts +0 -15
  122. package/types/subscription/index.d.ts +0 -21
  123. /package/types/locale/{index.d.ts → index.ts} +0 -0
  124. /package/types/settings/{index.d.ts → index.ts} +0 -0
package/dist/api.mjs CHANGED
@@ -7,7 +7,7 @@ import methods$5 from './products.mjs';
7
7
  import methods$6 from './categories.mjs';
8
8
  import methods$7 from './attributes.mjs';
9
9
  import methods$8 from './subscriptions.mjs';
10
- import { d as defaultMethods, y as trimEnd, z as setOptions, A as utils, B as trimStart, C as trimBoth, t as toSnake, D as stringifyQuery, E as base64Encode, i as isServer, a as toCamel } from './index.a911a674.mjs';
10
+ import { d as defaultMethods, z as trimEnd, A as setOptions, B as utils, C as trimStart, D as trimBoth, t as toSnake, E as stringifyQuery, q as base64Encode, i as isServer, a as toCamel } from './index.3c15c4d3.mjs';
11
11
  import methods$9 from './content.mjs';
12
12
  import methods$a from './settings.mjs';
13
13
  import PaymentController from './payment.mjs';
@@ -126,12 +126,21 @@ function methods(api, _opt) {
126
126
  };
127
127
  }
128
128
 
129
+ /** @typedef {import('../types').InitOptions} InitOptions */
130
+
131
+ /**
132
+ * @template {'snake' | 'camel'} C
133
+ * @typedef {import('../types').SwellClient<C>} SwellClient<C>
134
+ */
135
+
129
136
  /**
130
137
  * Swell API client
131
- * @param {string} initStore - Store name
132
- * @param {string} initKey - API key
133
- * @param {InitOptions} initOptions - Options
134
- * @returns {SwellClient} API client
138
+ *
139
+ * @template {'snake' | 'camel'} C
140
+ * @param {string} [initStore] - Store name
141
+ * @param {string} [initKey] - API key
142
+ * @param {InitOptions} [initOptions] - Options
143
+ * @returns {SwellClient<C>} API client
135
144
  */
136
145
  function swell(initStore = undefined, initKey, initOptions = {}) {
137
146
  const options = {
@@ -145,7 +154,7 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
145
154
  const api = {};
146
155
 
147
156
  Object.assign(api, {
148
- version: '4.2.6',
157
+ version: '5.1.0',
149
158
  options,
150
159
  request,
151
160
 
@@ -1,4 +1,4 @@
1
- import { d as defaultMethods } from './index.a911a674.mjs';
1
+ import { d as defaultMethods } from './index.3c15c4d3.mjs';
2
2
  import cacheApi from './cache.mjs';
3
3
  import 'qs';
4
4
  import './find.18f1ac6d.mjs';
package/dist/cache.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { s as set, m as merge, a as toCamel, h as toCamelPath, j as getOptions } from './index.a911a674.mjs';
1
+ import { s as set, m as merge, a as toCamel, h as toCamelPath, j as getOptions } from './index.3c15c4d3.mjs';
2
2
  import { g as get } from './find.18f1ac6d.mjs';
3
3
  import 'qs';
4
4
  import './round.577a8441.mjs';
package/dist/card.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as toSnake, v as vaultRequest } from './index.a911a674.mjs';
1
+ import { t as toSnake, v as vaultRequest } from './index.3c15c4d3.mjs';
2
2
  import 'qs';
3
3
  import './find.18f1ac6d.mjs';
4
4
  import './round.577a8441.mjs';
package/dist/cart.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import 'qs';
2
- import { c as cloneDeep } from './index.a911a674.mjs';
2
+ import { c as cloneDeep } from './index.3c15c4d3.mjs';
3
3
  import 'deepmerge';
4
4
  import 'fast-case';
5
5
  import { cleanProductOptions } from './products.mjs';
@@ -1,4 +1,4 @@
1
- import { d as defaultMethods } from './index.a911a674.mjs';
1
+ import { d as defaultMethods } from './index.3c15c4d3.mjs';
2
2
  import cacheApi from './cache.mjs';
3
3
  import 'qs';
4
4
  import './find.18f1ac6d.mjs';
package/dist/content.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import cacheApi from './cache.mjs';
2
- import './index.a911a674.mjs';
2
+ import './index.3c15c4d3.mjs';
3
3
  import 'qs';
4
4
  import './find.18f1ac6d.mjs';
5
5
  import './round.577a8441.mjs';
package/dist/cookie.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as isServer } from './index.a911a674.mjs';
1
+ import { i as isServer } from './index.3c15c4d3.mjs';
2
2
  import 'qs';
3
3
  import './find.18f1ac6d.mjs';
4
4
  import './round.577a8441.mjs';
@@ -1804,4 +1804,4 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1804
1804
  vaultRequest
1805
1805
  }, Symbol.toStringTag, { value: 'Module' }));
1806
1806
 
1807
- export { utils as A, trimStart as B, trimBoth as C, stringifyQuery as D, base64Encode as E, toLower as F, toCamel as a, isObject as b, cloneDeep as c, defaultMethods as d, camelCase as e, snakeCase as f, isEqual as g, toCamelPath as h, isServer as i, getOptions as j, isFunction as k, loadScript as l, merge as m, isEmpty as n, isLiveMode as o, pick$1 as p, map as q, reduce as r, set as s, toSnake as t, uniq as u, vaultRequest as v, getLocationParams as w, removeUrlParams as x, trimEnd as y, setOptions as z };
1807
+ export { setOptions as A, utils as B, trimStart as C, trimBoth as D, stringifyQuery as E, toLower as F, toCamel as a, isObject as b, cloneDeep as c, defaultMethods as d, camelCase as e, snakeCase as f, isEqual as g, toCamelPath as h, isServer as i, getOptions as j, isFunction as k, loadScript as l, merge as m, isEmpty as n, isLiveMode as o, pick$1 as p, base64Encode as q, reduce as r, set as s, toSnake as t, uniq as u, vaultRequest as v, map as w, getLocationParams as x, removeUrlParams as y, trimEnd as z };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  export { default } from './api.mjs';
2
2
  import './card.mjs';
3
- import './index.a911a674.mjs';
3
+ import './index.3c15c4d3.mjs';
4
4
  import 'qs';
5
5
  import './find.18f1ac6d.mjs';
6
6
  import './round.577a8441.mjs';
package/dist/payment.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import methods from './cart.mjs';
2
2
  import methods$1 from './settings.mjs';
3
- import { b as isObject, k as isFunction, l as loadScript, c as cloneDeep, t as toSnake, v as vaultRequest, p as pick, n as isEmpty, o as isLiveMode, q as map, r as reduce, w as getLocationParams, x as removeUrlParams, a as toCamel } from './index.a911a674.mjs';
3
+ import { b as isObject, k as isFunction, l as loadScript, c as cloneDeep, t as toSnake, v as vaultRequest, p as pick, n as isEmpty, o as isLiveMode, q as base64Encode, w as map, r as reduce, x as getLocationParams, y as removeUrlParams, a as toCamel } from './index.3c15c4d3.mjs';
4
4
  import { g as get, t as toNumber } from './find.18f1ac6d.mjs';
5
5
  import 'qs';
6
6
  import 'deepmerge';
@@ -1960,10 +1960,12 @@ class BraintreePaypalPayment extends Payment {
1960
1960
  }
1961
1961
  }
1962
1962
 
1963
- const API_VERSION = 2;
1964
- const API_MINOR_VERSION = 0;
1965
- const ALLOWED_CARD_AUTH_METHODS = ['PAN_ONLY', 'CRYPTOGRAM_3DS'];
1966
- const ALLOWED_CARD_NETWORKS = [
1963
+ const API_VERSION$1 = 2;
1964
+ const API_MINOR_VERSION$1 = 0;
1965
+
1966
+ const ALLOWED_CARD_AUTH_METHODS$1 = ['PAN_ONLY', 'CRYPTOGRAM_3DS'];
1967
+
1968
+ const ALLOWED_CARD_NETWORKS$1 = [
1967
1969
  'AMEX',
1968
1970
  'DISCOVER',
1969
1971
  'INTERAC',
@@ -2001,6 +2003,7 @@ class BraintreeGooglePayment extends Payment {
2001
2003
  return window.google;
2002
2004
  }
2003
2005
 
2006
+ /** @returns {google.payments.api.PaymentsClient} */
2004
2007
  get googleClient() {
2005
2008
  if (!BraintreeGooglePayment.googleClient) {
2006
2009
  if (this.google) {
@@ -2021,12 +2024,13 @@ class BraintreeGooglePayment extends Payment {
2021
2024
  BraintreeGooglePayment.googleClient = googleClient;
2022
2025
  }
2023
2026
 
2027
+ /** @returns {google.payments.api.PaymentMethodSpecification} */
2024
2028
  get cardPaymentMethod() {
2025
2029
  return {
2026
2030
  type: 'CARD',
2027
2031
  parameters: {
2028
- allowedAuthMethods: ALLOWED_CARD_AUTH_METHODS,
2029
- allowedCardNetworks: ALLOWED_CARD_NETWORKS,
2032
+ allowedAuthMethods: ALLOWED_CARD_AUTH_METHODS$1,
2033
+ allowedCardNetworks: ALLOWED_CARD_NETWORKS$1,
2030
2034
  billingAddressRequired: true,
2031
2035
  billingAddressParameters: {
2032
2036
  format: 'FULL',
@@ -2036,6 +2040,7 @@ class BraintreeGooglePayment extends Payment {
2036
2040
  };
2037
2041
  }
2038
2042
 
2043
+ /** @returns {google.payments.api.PaymentMethodSpecification[]} */
2039
2044
  get allowedPaymentMethods() {
2040
2045
  return [this.cardPaymentMethod];
2041
2046
  }
@@ -2044,7 +2049,7 @@ class BraintreeGooglePayment extends Payment {
2044
2049
  const {
2045
2050
  elementId = 'googlepay-button',
2046
2051
  locale = 'en',
2047
- style: { color = 'black', type = 'buy', sizeMode = 'fill' } = {},
2052
+ style: { color = 'black', type = 'plain', sizeMode = 'fill' } = {},
2048
2053
  } = this.params;
2049
2054
 
2050
2055
  if (!this.method.merchant_id) {
@@ -2055,8 +2060,8 @@ class BraintreeGooglePayment extends Payment {
2055
2060
  await this.loadScripts(this.scripts);
2056
2061
 
2057
2062
  const isReadyToPay = await this.googleClient.isReadyToPay({
2058
- apiVersion: API_VERSION,
2059
- apiVersionMinor: API_MINOR_VERSION,
2063
+ apiVersion: API_VERSION$1,
2064
+ apiVersionMinor: API_MINOR_VERSION$1,
2060
2065
  allowedPaymentMethods: this.allowedPaymentMethods,
2061
2066
  existingPaymentMethodRequired: true,
2062
2067
  });
@@ -2071,7 +2076,7 @@ class BraintreeGooglePayment extends Payment {
2071
2076
  const googlePayment = await this.braintree.googlePayment.create({
2072
2077
  client: braintreeClient,
2073
2078
  googleMerchantId: this.method.merchant_id,
2074
- googlePayVersion: API_VERSION,
2079
+ googlePayVersion: API_VERSION$1,
2075
2080
  });
2076
2081
  const paymentRequestData = this._createPaymentRequestData(cart);
2077
2082
  const paymentDataRequest =
@@ -2084,6 +2089,12 @@ class BraintreeGooglePayment extends Payment {
2084
2089
  buttonLocale: locale,
2085
2090
  onClick: this._onClick.bind(this, googlePayment, paymentDataRequest),
2086
2091
  });
2092
+
2093
+ const button = this.element.querySelector('#gpay-button-online-api-id');
2094
+
2095
+ if (button) {
2096
+ button.style['min-width'] = 'auto';
2097
+ }
2087
2098
  }
2088
2099
 
2089
2100
  mountElements() {
@@ -2111,18 +2122,20 @@ class BraintreeGooglePayment extends Payment {
2111
2122
  });
2112
2123
  }
2113
2124
 
2125
+ /** @returns {google.payments.api.PaymentDataRequest} */
2114
2126
  _createPaymentRequestData(cart) {
2115
2127
  const {
2116
- settings: { name },
2128
+ settings: { name, country },
2117
2129
  capture_total,
2118
2130
  currency,
2119
2131
  } = cart;
2120
2132
  const { require: { email, shipping, phone } = {} } = this.params;
2121
2133
 
2122
2134
  return {
2123
- apiVersion: API_VERSION,
2124
- apiVersionMinor: API_MINOR_VERSION,
2135
+ apiVersion: API_VERSION$1,
2136
+ apiVersionMinor: API_MINOR_VERSION$1,
2125
2137
  transactionInfo: {
2138
+ countryCode: country,
2126
2139
  currencyCode: currency,
2127
2140
  totalPrice: capture_total.toString(),
2128
2141
  totalPriceStatus: 'ESTIMATED',
@@ -2140,6 +2153,10 @@ class BraintreeGooglePayment extends Payment {
2140
2153
  };
2141
2154
  }
2142
2155
 
2156
+ /**
2157
+ * @param {object} googlePayment
2158
+ * @param {google.payments.api.PaymentDataRequest} paymentDataRequest
2159
+ */
2143
2160
  async _onClick(googlePayment, paymentDataRequest) {
2144
2161
  try {
2145
2162
  const paymentData =
@@ -2153,6 +2170,10 @@ class BraintreeGooglePayment extends Payment {
2153
2170
  }
2154
2171
  }
2155
2172
 
2173
+ /**
2174
+ * @param {object} googlePayment
2175
+ * @param {google.payments.api.PaymentData} paymentData
2176
+ */
2156
2177
  async _submitPayment(googlePayment, paymentData) {
2157
2178
  const { require: { shipping: requireShipping } = {} } = this.params;
2158
2179
  const { nonce } = await googlePayment.parseResponse(paymentData);
@@ -2181,6 +2202,7 @@ class BraintreeGooglePayment extends Payment {
2181
2202
  this.onSuccess();
2182
2203
  }
2183
2204
 
2205
+ /** @param {google.payments.api.Address} address */
2184
2206
  _mapAddress(address) {
2185
2207
  return {
2186
2208
  name: address.name,
@@ -2404,6 +2426,247 @@ class BraintreeApplePayment extends Payment {
2404
2426
  }
2405
2427
  }
2406
2428
 
2429
+ const API_VERSION = 2;
2430
+ const API_MINOR_VERSION = 0;
2431
+
2432
+ const ALLOWED_CARD_AUTH_METHODS = ['PAN_ONLY', 'CRYPTOGRAM_3DS'];
2433
+
2434
+ const ALLOWED_CARD_NETWORKS = [
2435
+ 'AMEX',
2436
+ 'DISCOVER',
2437
+ 'INTERAC',
2438
+ 'JCB',
2439
+ 'MASTERCARD',
2440
+ 'VISA',
2441
+ ];
2442
+
2443
+ class AuthorizeNetGooglePayment extends Payment {
2444
+ constructor(api, options, params, methods) {
2445
+ if (!methods.card) {
2446
+ throw new PaymentMethodDisabledError('Credit cards');
2447
+ }
2448
+
2449
+ super(api, options, params, methods.google);
2450
+ }
2451
+
2452
+ get scripts() {
2453
+ return ['google-pay'];
2454
+ }
2455
+
2456
+ get google() {
2457
+ if (!window.google) {
2458
+ throw new LibraryNotLoadedError('Google');
2459
+ }
2460
+
2461
+ return window.google;
2462
+ }
2463
+
2464
+ /** @returns {google.payments.api.PaymentsClient} */
2465
+ get googleClient() {
2466
+ if (!AuthorizeNetGooglePayment.googleClient) {
2467
+ if (this.google) {
2468
+ AuthorizeNetGooglePayment.googleClient =
2469
+ new this.google.payments.api.PaymentsClient({
2470
+ environment: isLiveMode(this.method.mode) ? 'PRODUCTION' : 'TEST',
2471
+ });
2472
+ }
2473
+
2474
+ if (!AuthorizeNetGooglePayment.googleClient) {
2475
+ throw new LibraryNotLoadedError('Google client');
2476
+ }
2477
+ }
2478
+
2479
+ return AuthorizeNetGooglePayment.googleClient;
2480
+ }
2481
+
2482
+ /**
2483
+ * @param {boolean} [submit]
2484
+ * @returns {google.payments.api.PaymentMethodSpecification[]}
2485
+ */
2486
+ _getCardPaymentMethod(submit = false) {
2487
+ return {
2488
+ type: 'CARD',
2489
+ parameters: {
2490
+ allowedAuthMethods: ALLOWED_CARD_AUTH_METHODS,
2491
+ allowedCardNetworks: ALLOWED_CARD_NETWORKS,
2492
+ billingAddressRequired: true,
2493
+ billingAddressParameters: {
2494
+ format: 'FULL',
2495
+ phoneNumberRequired: true,
2496
+ },
2497
+ },
2498
+ ...(submit && {
2499
+ tokenizationSpecification: {
2500
+ type: 'PAYMENT_GATEWAY',
2501
+ parameters: {
2502
+ gateway: 'authorizenet',
2503
+ gatewayMerchantId: this.method.gateway_merchant_id,
2504
+ },
2505
+ },
2506
+ }),
2507
+ };
2508
+ }
2509
+
2510
+ /**
2511
+ * @param {boolean} [submit]
2512
+ * @returns {google.payments.api.PaymentMethodSpecification[]}
2513
+ */
2514
+ _getAllowedPaymentMethods(submit = false) {
2515
+ return [this._getCardPaymentMethod(submit)];
2516
+ }
2517
+
2518
+ /**
2519
+ * @param {import('../../../types').Cart} cart
2520
+ * @returns {google.payments.api.PaymentDataRequest}
2521
+ */
2522
+ _createPaymentRequestData(cart) {
2523
+ const {
2524
+ settings: { name, country },
2525
+ capture_total,
2526
+ currency,
2527
+ } = cart;
2528
+
2529
+ const { require: { email, shipping, phone } = {} } = this.params;
2530
+
2531
+ return {
2532
+ apiVersion: API_VERSION,
2533
+ apiVersionMinor: API_MINOR_VERSION,
2534
+ transactionInfo: {
2535
+ countryCode: country,
2536
+ currencyCode: currency,
2537
+ totalPrice: capture_total.toString(),
2538
+ totalPriceStatus: 'ESTIMATED',
2539
+ },
2540
+ allowedPaymentMethods: this._getAllowedPaymentMethods(true),
2541
+ emailRequired: Boolean(email),
2542
+ shippingAddressRequired: Boolean(shipping),
2543
+ shippingAddressParameters: {
2544
+ phoneNumberRequired: Boolean(phone),
2545
+ },
2546
+ merchantInfo: {
2547
+ merchantName: name,
2548
+ merchantId: this.method.merchant_id,
2549
+ },
2550
+ };
2551
+ }
2552
+
2553
+ /** @param {google.payments.api.Address} address */
2554
+ _mapAddress(address) {
2555
+ return {
2556
+ name: address.name,
2557
+ address1: address.address1,
2558
+ address2: address.address2,
2559
+ city: address.locality,
2560
+ state: address.administrativeArea,
2561
+ zip: address.postalCode,
2562
+ country: address.countryCode,
2563
+ phone: address.phoneNumber,
2564
+ };
2565
+ }
2566
+
2567
+ /** @param {google.payments.api.PaymentData} paymentData */
2568
+ async _submitPayment(paymentData) {
2569
+ const { require: { shipping: requireShipping } = {} } = this.params;
2570
+ const { email, shippingAddress, paymentMethodData } = paymentData;
2571
+ const {
2572
+ info: { billingAddress },
2573
+ tokenizationData: { token },
2574
+ } = paymentMethodData;
2575
+
2576
+ await this.updateCart({
2577
+ account: {
2578
+ email,
2579
+ },
2580
+ billing: {
2581
+ method: 'google',
2582
+ google: {
2583
+ gateway: 'authorizenet',
2584
+ token: base64Encode(token),
2585
+ },
2586
+ ...this._mapAddress(billingAddress),
2587
+ },
2588
+ ...(requireShipping && {
2589
+ shipping: this._mapAddress(shippingAddress),
2590
+ }),
2591
+ });
2592
+
2593
+ this.onSuccess();
2594
+ }
2595
+
2596
+ /**
2597
+ * @param {google.payments.api.PaymentDataRequest} paymentDataRequest
2598
+ */
2599
+ async _onClick(paymentDataRequest) {
2600
+ try {
2601
+ const paymentData =
2602
+ await this.googleClient.loadPaymentData(paymentDataRequest);
2603
+
2604
+ if (paymentData) {
2605
+ await this._submitPayment(paymentData);
2606
+ }
2607
+ } catch (error) {
2608
+ this.onError(error);
2609
+ }
2610
+ }
2611
+
2612
+ /** @param {import('../../../types').Cart} cart */
2613
+ async createElements(cart) {
2614
+ const {
2615
+ elementId = 'googlepay-button',
2616
+ locale = 'en',
2617
+ style: { color = 'black', type = 'plain', sizeMode = 'fill' } = {},
2618
+ } = this.params;
2619
+
2620
+ if (!this.method.merchant_id) {
2621
+ throw new Error('Google merchant ID is not defined');
2622
+ }
2623
+
2624
+ this.setElementContainer(elementId);
2625
+ await this.loadScripts(this.scripts);
2626
+
2627
+ const isReadyToPay = await this.googleClient.isReadyToPay({
2628
+ apiVersion: API_VERSION,
2629
+ apiVersionMinor: API_MINOR_VERSION,
2630
+ allowedPaymentMethods: this._getAllowedPaymentMethods(false),
2631
+ existingPaymentMethodRequired: true,
2632
+ });
2633
+
2634
+ if (!isReadyToPay.result) {
2635
+ throw new Error(
2636
+ 'This device is not capable of making Google Pay payments',
2637
+ );
2638
+ }
2639
+
2640
+ const paymentDataRequest = this._createPaymentRequestData(cart);
2641
+
2642
+ this.element = this.googleClient.createButton({
2643
+ buttonColor: color,
2644
+ buttonType: type,
2645
+ buttonSizeMode: sizeMode,
2646
+ buttonLocale: locale,
2647
+ allowedPaymentMethods: this._getAllowedPaymentMethods(false),
2648
+ onClick: this._onClick.bind(this, paymentDataRequest),
2649
+ });
2650
+
2651
+ const button = this.element.querySelector('#gpay-button-online-api-id');
2652
+
2653
+ if (button) {
2654
+ button.style['min-width'] = 'auto';
2655
+ }
2656
+ }
2657
+
2658
+ mountElements() {
2659
+ const { classes = {} } = this.params;
2660
+ const container = this.elementContainer;
2661
+
2662
+ container.appendChild(this.element);
2663
+
2664
+ if (classes.base) {
2665
+ container.classList.add(classes.base);
2666
+ }
2667
+ }
2668
+ }
2669
+
2407
2670
  class QuickpayCardPayment extends Payment {
2408
2671
  constructor(api, options, params, methods) {
2409
2672
  super(api, options, params, methods.card);
@@ -3543,6 +3806,8 @@ class PaymentController {
3543
3806
  return StripeGooglePayment;
3544
3807
  case 'braintree':
3545
3808
  return BraintreeGooglePayment;
3809
+ case 'authorizenet':
3810
+ return AuthorizeNetGooglePayment;
3546
3811
  default:
3547
3812
  return null;
3548
3813
  }
package/dist/products.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { d as defaultMethods, r as reduce, t as toSnake, a as toCamel, f as snakeCase, u as uniq, g as isEqual } from './index.a911a674.mjs';
1
+ import { d as defaultMethods, r as reduce, t as toSnake, a as toCamel, f as snakeCase, u as uniq, g as isEqual } from './index.3c15c4d3.mjs';
2
2
  import cacheApi from './cache.mjs';
3
3
  import methods$1 from './attributes.mjs';
4
4
  import { g as get, f as find } from './find.18f1ac6d.mjs';
package/dist/settings.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { s as set, a as toCamel, m as merge, c as cloneDeep, b as isObject, e as camelCase } from './index.a911a674.mjs';
1
+ import { s as set, a as toCamel, m as merge, c as cloneDeep, b as isObject, e as camelCase } from './index.3c15c4d3.mjs';
2
2
  import { g as get, f as find } from './find.18f1ac6d.mjs';
3
3
  import 'qs';
4
4
  import './round.577a8441.mjs';
@@ -1,5 +1,5 @@
1
1
  import { cleanProductOptions } from './products.mjs';
2
- import { d as defaultMethods } from './index.a911a674.mjs';
2
+ import { d as defaultMethods } from './index.3c15c4d3.mjs';
3
3
  import cacheApi from './cache.mjs';
4
4
  import './attributes.mjs';
5
5
  import './find.18f1ac6d.mjs';