swell-js 3.17.9 → 3.17.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,7 +9,7 @@ Universal JavaScript client for Swell's Frontend API, providing client-safe acce
9
9
  - Resolve linked content to dynamically generate page URLs
10
10
  - Format prices in the store's currency
11
11
 
12
- > This SDK implements a subset of operations available in Swell's [Backend API](https://swell.store/docs/api) and is authorized with a public key + session token, making it safe to use in any context. You should only use the Backend API server-side, and keep your secret keys stored as environment variables.
12
+ > This SDK implements a subset of operations available in Swell's [Backend API](https://developers.swell.is/backend-api/) and is authorized with a public key + session token, making it safe to use in any context. You should only use the Backend API server-side, and keep your secret keys stored as environment variables.
13
13
 
14
14
  **About Swell**
15
15
 
@@ -17,4 +17,4 @@ Universal JavaScript client for Swell's Frontend API, providing client-safe acce
17
17
 
18
18
  ## Documentation
19
19
 
20
- 📖 [**View Swell.js Documentation**](https://swell.store/docs/js/)
20
+ 📖 [**View Swell.js Documentation**](https://developers.swell.is/frontend-api/)
@@ -10,7 +10,7 @@ import { m as methods$4 } from './attributes-db35134e.js';
10
10
  import { m as methods$5 } from './subscriptions-0e44e99f.js';
11
11
  import { m as methods$6 } from './content-eb42ecce.js';
12
12
  import { m as methods$7 } from './settings-b1a4a4af.js';
13
- import { m as methods$8 } from './payment-fd4a2cbe.js';
13
+ import { m as methods$8 } from './payment-dc6ea1a4.js';
14
14
  import { m as methods$9 } from './locale-bd31bf45.js';
15
15
  import { m as methods$a } from './currency-0ff55be3.js';
16
16
  import 'isomorphic-unfetch';
package/dist/api.js CHANGED
@@ -1,4 +1,4 @@
1
- export { a as default } from './api-c9fbb688.js';
1
+ export { a as default } from './api-f8f85e5f.js';
2
2
  import './card-2f5f9866.js';
3
3
  import './index-bce8d606.js';
4
4
  import 'qs';
@@ -24,7 +24,7 @@ import './categories-e52bebe3.js';
24
24
  import './subscriptions-0e44e99f.js';
25
25
  import './content-eb42ecce.js';
26
26
  import './settings-b1a4a4af.js';
27
- import './payment-fd4a2cbe.js';
27
+ import './payment-dc6ea1a4.js';
28
28
  import 'lodash/toLower';
29
29
  import 'lodash/reduce';
30
30
  import 'lodash/isEmpty';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { q as utils } from './index-bce8d606.js';
2
- export { a as default } from './api-c9fbb688.js';
2
+ export { a as default } from './api-f8f85e5f.js';
3
3
  import 'qs';
4
4
  import 'lodash/set';
5
5
  import 'lodash/get';
@@ -24,7 +24,7 @@ import './categories-e52bebe3.js';
24
24
  import './subscriptions-0e44e99f.js';
25
25
  import './content-eb42ecce.js';
26
26
  import './settings-b1a4a4af.js';
27
- import './payment-fd4a2cbe.js';
27
+ import './payment-dc6ea1a4.js';
28
28
  import 'lodash/toLower';
29
29
  import 'lodash/reduce';
30
30
  import 'lodash/isEmpty';
@@ -22,38 +22,32 @@ const billingFieldsMap = {
22
22
  phone: 'phone',
23
23
  };
24
24
 
25
- function getBillingDetails(data) {
26
- const { account = {}, billing, shipping } = data;
27
- const accountShipping = get(account, 'shipping', {});
28
- const accountBilling = get(account, 'billing', {});
25
+ function mapValues(fieldsMap, data) {
26
+ const result = {};
27
+ for (const [destinationKey, sourceKey] of Object.entries(fieldsMap)) {
28
+ const value = data[sourceKey];
29
+ if (value) {
30
+ result[destinationKey] = value;
31
+ }
32
+ }
33
+ return result;
34
+ }
29
35
 
30
- const billingData = {
31
- ...accountShipping,
32
- ...accountBilling,
33
- ...shipping,
34
- ...billing,
36
+ function getBillingDetails(cart) {
37
+ const details = {
38
+ ...mapValues(billingFieldsMap, cart.billing),
35
39
  };
36
- const fillValues = (fieldsMap) =>
37
- reduce(
38
- fieldsMap,
39
- (acc, value, key) => {
40
- const billingValue = billingData[value];
41
- if (billingValue) {
42
- acc[key] = billingValue;
43
- }
44
- return acc;
45
- },
46
- {},
47
- );
48
40
 
49
- const billingDetails = fillValues(billingFieldsMap);
50
- if (!isEmpty(billingDetails)) {
51
- const address = fillValues(addressFieldsMap$1);
52
- return {
53
- ...billingDetails,
54
- ...(!isEmpty(address) ? { address } : {}),
55
- };
41
+ if (cart.account && cart.account.email) {
42
+ details.email = cart.account.email;
56
43
  }
44
+
45
+ const address = mapValues(addressFieldsMap$1, cart.billing);
46
+ if (!isEmpty(address)) {
47
+ details.address = address;
48
+ }
49
+
50
+ return details;
57
51
  }
58
52
 
59
53
  function getKlarnaItems(cart) {
@@ -186,29 +180,42 @@ function setBancontactOwner(source, data) {
186
180
  };
187
181
  }
188
182
 
189
- async function createPaymentMethod(stripe, cardElement, cart) {
183
+ async function createPaymentMethod(stripe, cardElement, authorize, cart) {
190
184
  const billingDetails = getBillingDetails(cart);
191
- const { error, paymentMethod } = await stripe.createPaymentMethod({
192
- type: 'card',
193
- card: cardElement,
194
- ...(billingDetails ? { billing_details: billingDetails } : {}),
185
+ const { paymentMethod, error: paymentMethodError } =
186
+ await stripe.createPaymentMethod({
187
+ type: 'card',
188
+ card: cardElement,
189
+ ...(!isEmpty(billingDetails) ? { billing_details: billingDetails } : {}),
190
+ });
191
+
192
+ if (paymentMethodError) {
193
+ return { error: paymentMethodError };
194
+ }
195
+
196
+ const customer = cart.account && cart.account.stripe_customer;
197
+ const authorization = await authorize({
198
+ gateway: 'stripe',
199
+ params: {
200
+ usage: 'off_session',
201
+ payment_method: paymentMethod.id,
202
+ ...(customer ? { customer } : {}),
203
+ },
195
204
  });
196
- return error
197
- ? { error }
198
- : {
199
- token: paymentMethod.id,
200
- last4: paymentMethod.card.last4,
201
- exp_month: paymentMethod.card.exp_month,
202
- exp_year: paymentMethod.card.exp_year,
203
- brand: paymentMethod.card.brand,
204
- address_check: paymentMethod.card.checks.address_line1_check,
205
- cvc_check: paymentMethod.card.checks.cvc_check,
206
- zip_check: paymentMethod.card.checks.address_zip_check,
207
- };
205
+
206
+ if (!authorization) {
207
+ return;
208
+ }
209
+
210
+ const { error: setupIntentError } = await stripe.confirmCardSetup(
211
+ authorization.client_secret,
212
+ );
213
+
214
+ return setupIntentError ? { error: setupIntentError } : authorization.card;
208
215
  }
209
216
 
210
- async function createIDealPaymentMethod(stripe, element, billing = {}) {
211
- const billingDetails = getBillingDetails(billing);
217
+ async function createIDealPaymentMethod(stripe, element, cart) {
218
+ const billingDetails = getBillingDetails(cart);
212
219
  return await stripe.createPaymentMethod({
213
220
  type: 'ideal',
214
221
  ideal: element,
@@ -905,10 +912,13 @@ async function paymentTokenize(request, params, payMethods, cart) {
905
912
  const paymentMethod = await createPaymentMethod(
906
913
  stripe,
907
914
  CARD_ELEMENTS.stripe,
915
+ methods(request).authorizeGateway,
908
916
  cart,
909
- );
917
+ ).catch(onError);
910
918
 
911
- if (paymentMethod.error) {
919
+ if (!paymentMethod) {
920
+ return;
921
+ } else if (paymentMethod.error) {
912
922
  return onError(paymentMethod.error);
913
923
  } else if (capture_total < 1) {
914
924
  // should save payment method data when payment amount is less than 1
@@ -939,7 +949,8 @@ async function paymentTokenize(request, params, payMethods, cart) {
939
949
  amount,
940
950
  currency,
941
951
  capture_method: 'manual',
942
- setup_future_usage: 'off_session',
952
+ off_session: true,
953
+ confirm: true,
943
954
  ...(stripeCustomer ? { customer: stripeCustomer } : {}),
944
955
  },
945
956
  })
@@ -1004,7 +1015,7 @@ async function paymentTokenize(request, params, payMethods, cart) {
1004
1015
  const { error, paymentMethod } = await createIDealPaymentMethod(
1005
1016
  API.stripe,
1006
1017
  CARD_ELEMENTS.stripe,
1007
- cart.billing,
1018
+ cart,
1008
1019
  );
1009
1020
 
1010
1021
  if (error) {
package/dist/payment.js CHANGED
@@ -1,4 +1,4 @@
1
- export { m as default, s as shouldUsePayPalEmail } from './payment-fd4a2cbe.js';
1
+ export { m as default, s as shouldUsePayPalEmail } from './payment-dc6ea1a4.js';
2
2
  import 'lodash/get';
3
3
  import 'lodash/toLower';
4
4
  import './cart-21650912.js';