swell-js 5.6.0 → 5.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.mjs CHANGED
@@ -446,7 +446,7 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
446
446
  const api = {};
447
447
 
448
448
  Object.assign(api, {
449
- version: '5.6.0',
449
+ version: '5.6.1',
450
450
  options,
451
451
  request,
452
452
 
package/dist/payment.mjs CHANGED
@@ -2156,12 +2156,25 @@ async function onPaymentDataChanged(intermediatePaymentData) {
2156
2156
  );
2157
2157
  }
2158
2158
 
2159
- // Auto-apply shipping if only one service is available
2160
- if (cart.shipment_rating.services.length === 1) {
2161
- const [singleService] = cart.shipment_rating.services;
2159
+ let shippingService;
2162
2160
 
2161
+ if (intermediatePaymentData.shippingOptionData?.id) {
2162
+ const defaultServiceId =
2163
+ intermediatePaymentData.shippingOptionData?.id;
2164
+
2165
+ shippingService = cart.shipment_rating.services.find(
2166
+ (service) => service.id === defaultServiceId,
2167
+ );
2168
+ }
2169
+
2170
+ if (shippingService === undefined) {
2171
+ // Auto-apply first shipping service in the list
2172
+ shippingService = cart.shipment_rating.services[0];
2173
+ }
2174
+
2175
+ if (cart.shipping?.service !== shippingService.id) {
2163
2176
  cart = await this.updateCart({
2164
- shipping: { service: singleService.id },
2177
+ shipping: { service: shippingService.id },
2165
2178
  });
2166
2179
  }
2167
2180
 
package/dist/swell.cjs CHANGED
@@ -8774,12 +8774,25 @@ async function onPaymentDataChanged(intermediatePaymentData) {
8774
8774
  );
8775
8775
  }
8776
8776
 
8777
- // Auto-apply shipping if only one service is available
8778
- if (cart.shipment_rating.services.length === 1) {
8779
- const [singleService] = cart.shipment_rating.services;
8777
+ let shippingService;
8780
8778
 
8779
+ if (intermediatePaymentData.shippingOptionData?.id) {
8780
+ const defaultServiceId =
8781
+ intermediatePaymentData.shippingOptionData?.id;
8782
+
8783
+ shippingService = cart.shipment_rating.services.find(
8784
+ (service) => service.id === defaultServiceId,
8785
+ );
8786
+ }
8787
+
8788
+ if (shippingService === undefined) {
8789
+ // Auto-apply first shipping service in the list
8790
+ shippingService = cart.shipment_rating.services[0];
8791
+ }
8792
+
8793
+ if (cart.shipping?.service !== shippingService.id) {
8781
8794
  cart = await this.updateCart({
8782
- shipping: { service: singleService.id },
8795
+ shipping: { service: shippingService.id },
8783
8796
  });
8784
8797
  }
8785
8798
 
@@ -12931,7 +12944,7 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
12931
12944
  const api = {};
12932
12945
 
12933
12946
  Object.assign(api, {
12934
- version: '5.6.0',
12947
+ version: '5.6.1',
12935
12948
  options,
12936
12949
  request,
12937
12950