swell-js 5.8.0 → 5.8.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 +2 -2
- package/dist/attributes.mjs +1 -1
- package/dist/cache.mjs +1 -1
- package/dist/card.mjs +1 -1
- package/dist/cart.mjs +1 -1
- package/dist/categories.mjs +1 -1
- package/dist/content.mjs +1 -1
- package/dist/cookie.mjs +1 -1
- package/dist/{index.a227b03d.mjs → index.a8d5c125.mjs} +1 -1
- package/dist/index.mjs +1 -1
- package/dist/payment.mjs +21 -103
- package/dist/products.mjs +1 -1
- package/dist/settings.mjs +1 -1
- package/dist/subscriptions.mjs +1 -1
- package/dist/swell.cjs +20 -102
- package/dist/swell.cjs.map +1 -1
- package/dist/swell.umd.min.js +20 -102
- package/dist/swell.umd.min.js.map +1 -1
- package/dist/utils/index.mjs +1 -1
- package/package.json +1 -1
package/dist/swell.umd.min.js
CHANGED
|
@@ -12655,7 +12655,7 @@
|
|
|
12655
12655
|
THB: 10,
|
|
12656
12656
|
};
|
|
12657
12657
|
|
|
12658
|
-
const addressFieldsMap
|
|
12658
|
+
const addressFieldsMap = {
|
|
12659
12659
|
city: 'city',
|
|
12660
12660
|
country: 'country',
|
|
12661
12661
|
line1: 'address1',
|
|
@@ -12693,7 +12693,7 @@
|
|
|
12693
12693
|
details.email = cart.account.email;
|
|
12694
12694
|
}
|
|
12695
12695
|
|
|
12696
|
-
const address = mapValues(addressFieldsMap
|
|
12696
|
+
const address = mapValues(addressFieldsMap, cart.billing);
|
|
12697
12697
|
if (!isEmpty(address)) {
|
|
12698
12698
|
details.address = address;
|
|
12699
12699
|
}
|
|
@@ -16830,105 +16830,6 @@
|
|
|
16830
16830
|
}
|
|
16831
16831
|
}
|
|
16832
16832
|
|
|
16833
|
-
const addressFieldsMap = {
|
|
16834
|
-
given_name: 'first_name',
|
|
16835
|
-
family_name: 'last_name',
|
|
16836
|
-
city: 'city',
|
|
16837
|
-
country: 'country',
|
|
16838
|
-
phone: 'phone',
|
|
16839
|
-
postal_code: 'zip',
|
|
16840
|
-
street_address: 'address1',
|
|
16841
|
-
street_address2: 'address2',
|
|
16842
|
-
region: 'state',
|
|
16843
|
-
};
|
|
16844
|
-
|
|
16845
|
-
const mapFields = (fieldsMap, data) =>
|
|
16846
|
-
reduce(
|
|
16847
|
-
fieldsMap,
|
|
16848
|
-
(acc, srcKey, destKey) => {
|
|
16849
|
-
const value = data[srcKey];
|
|
16850
|
-
if (value) {
|
|
16851
|
-
acc[destKey] = value;
|
|
16852
|
-
}
|
|
16853
|
-
return acc;
|
|
16854
|
-
},
|
|
16855
|
-
{},
|
|
16856
|
-
);
|
|
16857
|
-
|
|
16858
|
-
const mapAddressFields = (cart, addressField) => ({
|
|
16859
|
-
...mapFields(addressFieldsMap, cart[addressField]),
|
|
16860
|
-
email: get(cart, 'account.email'),
|
|
16861
|
-
});
|
|
16862
|
-
|
|
16863
|
-
function getOrderLines(cart) {
|
|
16864
|
-
const items = map(cart.items, (item) => ({
|
|
16865
|
-
type: 'physical',
|
|
16866
|
-
name: get(item, 'product.name'),
|
|
16867
|
-
reference: get(item, 'product.sku') || get(item, 'product.slug'),
|
|
16868
|
-
quantity: item.quantity,
|
|
16869
|
-
unit_price: Math.round(toNumber(item.price - item.discount_each) * 100),
|
|
16870
|
-
total_amount: Math.round(
|
|
16871
|
-
toNumber(item.price_total - item.discount_total) * 100,
|
|
16872
|
-
),
|
|
16873
|
-
tax_rate: 0,
|
|
16874
|
-
total_tax_amount: 0,
|
|
16875
|
-
}));
|
|
16876
|
-
|
|
16877
|
-
const tax = get(cart, 'tax_included_total');
|
|
16878
|
-
const taxAmount = toNumber(tax) * 100;
|
|
16879
|
-
if (tax) {
|
|
16880
|
-
items.push({
|
|
16881
|
-
type: 'sales_tax',
|
|
16882
|
-
name: 'Taxes',
|
|
16883
|
-
quantity: 1,
|
|
16884
|
-
unit_price: taxAmount,
|
|
16885
|
-
total_amount: taxAmount,
|
|
16886
|
-
tax_rate: 0,
|
|
16887
|
-
total_tax_amount: 0,
|
|
16888
|
-
});
|
|
16889
|
-
}
|
|
16890
|
-
|
|
16891
|
-
const shipping = get(cart, 'shipping', {});
|
|
16892
|
-
const shippingTotal = get(cart, 'shipment_total', {});
|
|
16893
|
-
const shippingAmount = toNumber(shippingTotal) * 100;
|
|
16894
|
-
if (shipping.price) {
|
|
16895
|
-
items.push({
|
|
16896
|
-
type: 'shipping_fee',
|
|
16897
|
-
name: shipping.service_name,
|
|
16898
|
-
quantity: 1,
|
|
16899
|
-
unit_price: shippingAmount,
|
|
16900
|
-
total_amount: shippingAmount,
|
|
16901
|
-
tax_rate: 0,
|
|
16902
|
-
total_tax_amount: 0,
|
|
16903
|
-
});
|
|
16904
|
-
}
|
|
16905
|
-
|
|
16906
|
-
return items;
|
|
16907
|
-
}
|
|
16908
|
-
|
|
16909
|
-
function getKlarnaSessionData(cart) {
|
|
16910
|
-
const returnUrl = `${window.location.origin}${window.location.pathname}?gateway=klarna_direct&sid={{session_id}}`;
|
|
16911
|
-
const successUrl = `${returnUrl}&authorization_token={{authorization_token}}`;
|
|
16912
|
-
|
|
16913
|
-
return {
|
|
16914
|
-
locale: cart.display_locale || get(cart, 'settings.locale') || 'en-US',
|
|
16915
|
-
purchase_country:
|
|
16916
|
-
get(cart, 'billing.country') || get(cart, 'shipping.country'),
|
|
16917
|
-
purchase_currency: cart.currency,
|
|
16918
|
-
billing_address: mapAddressFields(cart, 'billing'),
|
|
16919
|
-
shipping_address: mapAddressFields(cart, 'shipping'),
|
|
16920
|
-
order_amount: Math.round(get(cart, 'capture_total', 0) * 100),
|
|
16921
|
-
order_lines: JSON.stringify(getOrderLines(cart)),
|
|
16922
|
-
merchant_urls: {
|
|
16923
|
-
success: successUrl,
|
|
16924
|
-
back: returnUrl,
|
|
16925
|
-
cancel: returnUrl,
|
|
16926
|
-
error: returnUrl,
|
|
16927
|
-
failure: returnUrl,
|
|
16928
|
-
},
|
|
16929
|
-
};
|
|
16930
|
-
}
|
|
16931
|
-
|
|
16932
16833
|
class KlarnaDirectPayment extends Payment {
|
|
16933
16834
|
constructor(api, options, params, methods) {
|
|
16934
16835
|
super(api, options, params, methods.klarna);
|
|
@@ -16937,6 +16838,7 @@
|
|
|
16937
16838
|
async tokenize() {
|
|
16938
16839
|
const cart = await this.getCart();
|
|
16939
16840
|
const sessionData = getKlarnaSessionData(cart);
|
|
16841
|
+
|
|
16940
16842
|
const session = await this.createIntent({
|
|
16941
16843
|
gateway: 'klarna',
|
|
16942
16844
|
intent: sessionData,
|
|
@@ -16969,6 +16871,22 @@
|
|
|
16969
16871
|
}
|
|
16970
16872
|
}
|
|
16971
16873
|
|
|
16874
|
+
function getKlarnaSessionData(cart) {
|
|
16875
|
+
const returnUrl = `${window.location.origin}${window.location.pathname}?gateway=klarna_direct&sid={{session_id}}`;
|
|
16876
|
+
const successUrl = `${returnUrl}&authorization_token={{authorization_token}}`;
|
|
16877
|
+
|
|
16878
|
+
return {
|
|
16879
|
+
cart_id: cart.id,
|
|
16880
|
+
merchant_urls: {
|
|
16881
|
+
success: successUrl,
|
|
16882
|
+
back: returnUrl,
|
|
16883
|
+
cancel: returnUrl,
|
|
16884
|
+
error: returnUrl,
|
|
16885
|
+
failure: returnUrl,
|
|
16886
|
+
},
|
|
16887
|
+
};
|
|
16888
|
+
}
|
|
16889
|
+
|
|
16972
16890
|
class PaypalDirectPayment extends Payment {
|
|
16973
16891
|
constructor(api, options, params, methods) {
|
|
16974
16892
|
super(api, options, params, methods.paypal);
|
|
@@ -18558,7 +18476,7 @@
|
|
|
18558
18476
|
const api = {};
|
|
18559
18477
|
|
|
18560
18478
|
Object.assign(api, {
|
|
18561
|
-
version: '5.8.
|
|
18479
|
+
version: '5.8.1',
|
|
18562
18480
|
options,
|
|
18563
18481
|
request,
|
|
18564
18482
|
|