swell-js 3.17.2 → 3.17.3

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/LICENSE CHANGED
@@ -1,4 +1,6 @@
1
- Copyright 2019 Schema Technologies, LLC
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Swell Commerce Corp.
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
6
 
@@ -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-4fd3868e.js';
13
+ import { m as methods$8 } from './payment-fd4a2cbe.js';
14
14
  import { m as methods$9 } from './locale-9de8dba1.js';
15
15
  import { m as methods$a } from './currency-209bb202.js';
16
16
 
package/dist/api.js CHANGED
@@ -1,4 +1,4 @@
1
- export { a as default } from './api-31197cfd.js';
1
+ export { a as default } from './api-d1c4929d.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-4fd3868e.js';
27
+ import './payment-fd4a2cbe.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-31197cfd.js';
2
+ export { a as default } from './api-d1c4929d.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-4fd3868e.js';
27
+ import './payment-fd4a2cbe.js';
28
28
  import 'lodash/toLower';
29
29
  import 'lodash/reduce';
30
30
  import 'lodash/isEmpty';
@@ -699,10 +699,30 @@ async function stripeElements(request, payMethods, params) {
699
699
  }
700
700
  }
701
701
 
702
+ /**
703
+ * Update cart email with paypal's when no email is present
704
+ */
705
+ async function shouldUsePayPalEmail(guest, request, options) {
706
+ // Only check if the email should be updated when the user is not logged in (guest user)
707
+ if (!guest) return false;
708
+
709
+ // Refetch to avoid stale data from the cart
710
+ const updatedCart = await methods$1(request, options).get();
711
+ const currentEmail = get(updatedCart, 'account.email');
712
+
713
+ // If no email is present, use paypal's email
714
+ if (!currentEmail) {
715
+ return true;
716
+ } else {
717
+ return false;
718
+ }
719
+ }
720
+
702
721
  async function payPalButton(request, cart, payMethods, params) {
703
722
  const paypal = window.paypal;
704
723
  const { paypal: { locale, style, elementId } = {} } = params;
705
- const { capture_total, currency, account_logged_in } = cart;
724
+ const { capture_total, currency, guest } = cart;
725
+
706
726
  const onError = (error) => {
707
727
  const errorHandler = get(params, 'paypal.onError');
708
728
  if (isFunction(errorHandler)) {
@@ -748,13 +768,19 @@ async function payPalButton(request, cart, payMethods, params) {
748
768
  onApprove: (data, actions) =>
749
769
  actions.order
750
770
  .get()
751
- .then((order) => {
771
+ .then(async (order) => {
752
772
  const orderId = order.id;
753
773
  const payer = order.payer;
754
774
  const shipping = get(order, 'purchase_units[0].shipping');
755
775
 
776
+ const usePayPalEmail = await shouldUsePayPalEmail(
777
+ guest,
778
+ request,
779
+ options,
780
+ );
781
+
756
782
  return methods$1(request).update({
757
- ...(!account_logged_in && {
783
+ ...(usePayPalEmail && {
758
784
  account: {
759
785
  email: payer.email_address,
760
786
  },
@@ -1299,4 +1325,4 @@ async function authenticateStripeCard(request, payment, payMethods) {
1299
1325
  : { status: actionResult.status };
1300
1326
  }
1301
1327
 
1302
- export { methods as m };
1328
+ export { methods as m, shouldUsePayPalEmail as s };
package/dist/payment.js CHANGED
@@ -1,4 +1,4 @@
1
- export { m as default } from './payment-4fd3868e.js';
1
+ export { m as default, s as shouldUsePayPalEmail } from './payment-fd4a2cbe.js';
2
2
  import 'lodash/get';
3
3
  import 'lodash/toLower';
4
4
  import './cart-21650912.js';