@merchi/cart 1.4.84 → 1.4.86
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/esm/CartProvider.js +80 -49
- package/esm/CartProvider.load.test.js +418 -71
- package/esm/forms/FormShipmentAddressAndNotes.js +51 -20
- package/esm/panels/PanelPaymentSuccess.js +22 -15
- package/esm/panels/PanelPaymentSuccess.test.js +68 -0
- package/esm/utilities/checkoutCartClient.js +32 -0
- package/esm/utilities/test_checkout.js +2 -18
- package/lib/CartProvider.js +80 -49
- package/lib/forms/FormShipmentAddressAndNotes.js +51 -20
- package/lib/panels/PanelPaymentSuccess.js +22 -14
- package/lib/utilities/checkoutCartClient.d.ts +5 -0
- package/lib/utilities/checkoutCartClient.js +38 -0
- package/lib/utilities/test_checkout.d.ts +1 -4
- package/lib/utilities/test_checkout.js +25 -20
- package/package.json +2 -2
- package/src/CartProvider.load.test.tsx +110 -7
- package/src/CartProvider.tsx +34 -23
- package/src/forms/FormShipmentAddressAndNotes.tsx +21 -6
- package/src/panels/PanelPaymentSuccess.test.tsx +36 -0
- package/src/panels/PanelPaymentSuccess.tsx +20 -12
- package/src/utilities/checkoutCartClient.ts +16 -0
- package/src/utilities/test_checkout.ts +2 -19
|
@@ -19,12 +19,11 @@ import InputsAddress from "./InputsAddress";
|
|
|
19
19
|
import { CheckoutContainer, InnerContainer } from "../components/containers";
|
|
20
20
|
import { Title } from "../components";
|
|
21
21
|
import { checkoutShipmentHydrationAction, shipmentFormId } from "../utilities/shipment";
|
|
22
|
+
import { getCheckoutCartClient } from "../utilities/checkoutCartClient";
|
|
22
23
|
import { faMapMarkerAlt } from "@fortawesome/free-solid-svg-icons";
|
|
23
24
|
import { useCartContext } from "../CartProvider";
|
|
24
25
|
import { useEffect, useRef, useState } from "react";
|
|
25
|
-
import { getCartCookieToken } from "../utilities/cookie";
|
|
26
26
|
import { makeAddress, sanitizeAddressFields } from "../utilities/address";
|
|
27
|
-
import { makeCart } from "../utilities/cart";
|
|
28
27
|
import { cartEmbed } from "../utilities/helpers";
|
|
29
28
|
import { tabIdCheckout } from "../utilities/tabs";
|
|
30
29
|
import { addressHasContent, getSavedCheckoutAddress, saveCheckoutAddress } from "../utilities/local_storage";
|
|
@@ -133,6 +132,13 @@ export function ActiveFormShipmentAddressAndNotes() {
|
|
|
133
132
|
addressFieldsOpen = _useState2[0],
|
|
134
133
|
setAddressFieldsOpen = _useState2[1];
|
|
135
134
|
var hydratedShipmentOptionsRef = useRef(false);
|
|
135
|
+
var currentCartId = useRef(cart === null || cart === void 0 ? void 0 : cart.id);
|
|
136
|
+
useEffect(function () {
|
|
137
|
+
currentCartId.current = cart === null || cart === void 0 ? void 0 : cart.id;
|
|
138
|
+
return function () {
|
|
139
|
+
currentCartId.current = undefined;
|
|
140
|
+
};
|
|
141
|
+
}, [cart === null || cart === void 0 ? void 0 : cart.id]);
|
|
136
142
|
useEffect(function () {
|
|
137
143
|
if (hydratedShipmentOptionsRef.current || !(cart !== null && cart !== void 0 && cart.id)) return;
|
|
138
144
|
var draft = getSavedCheckoutAddress(domainId);
|
|
@@ -156,49 +162,74 @@ export function ActiveFormShipmentAddressAndNotes() {
|
|
|
156
162
|
}
|
|
157
163
|
function _saveCartShipmentAddressAndGoToNextTab() {
|
|
158
164
|
_saveCartShipmentAddressAndGoToNextTab = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(values) {
|
|
159
|
-
var
|
|
165
|
+
var _cart$invoice;
|
|
166
|
+
var cartId, address, receiverNotes, shipmentApi, addressFields, _receiverAddress, cartEnt, savedCart, cartJson, _t;
|
|
160
167
|
return _regenerator().w(function (_context2) {
|
|
161
168
|
while (1) switch (_context2.p = _context2.n) {
|
|
162
169
|
case 0:
|
|
170
|
+
cartId = cart === null || cart === void 0 ? void 0 : cart.id;
|
|
171
|
+
if (!(!cartId || ((_cart$invoice = cart.invoice) === null || _cart$invoice === void 0 ? void 0 : _cart$invoice.unpaid) === false)) {
|
|
172
|
+
_context2.n = 1;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
return _context2.a(2);
|
|
176
|
+
case 1:
|
|
163
177
|
address = values.receiverAddress, receiverNotes = values.receiverNotes;
|
|
164
178
|
setLoadingTotals(true);
|
|
165
|
-
_context2.p =
|
|
166
|
-
_context2.n =
|
|
167
|
-
return
|
|
168
|
-
case
|
|
169
|
-
|
|
179
|
+
_context2.p = 2;
|
|
180
|
+
_context2.n = 3;
|
|
181
|
+
return getCheckoutCartClient(cart, domainId);
|
|
182
|
+
case 3:
|
|
183
|
+
shipmentApi = _context2.v;
|
|
184
|
+
if (shipmentApi) {
|
|
185
|
+
_context2.n = 4;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
alertError("Unable to verify this cart. Reload checkout and try again.");
|
|
189
|
+
return _context2.a(2);
|
|
190
|
+
case 4:
|
|
170
191
|
// Never PATCH an existing Address via cart token — create a fresh embed.
|
|
171
192
|
addressFields = sanitizeAddressFields(address);
|
|
172
193
|
_receiverAddress = makeAddress(addressFields, true);
|
|
173
|
-
cartEnt =
|
|
194
|
+
cartEnt = new shipmentApi.Cart().fromJson(cart);
|
|
174
195
|
cartEnt.receiverAddress = _receiverAddress;
|
|
175
196
|
cartEnt.receiverNotes = receiverNotes;
|
|
176
|
-
_context2.n =
|
|
197
|
+
_context2.n = 5;
|
|
177
198
|
return cartEnt.save({
|
|
178
199
|
embed: cartEmbed
|
|
179
200
|
});
|
|
180
|
-
case
|
|
201
|
+
case 5:
|
|
202
|
+
savedCart = _context2.v;
|
|
203
|
+
if (!(currentCartId.current !== cartId)) {
|
|
204
|
+
_context2.n = 6;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
return _context2.a(2);
|
|
208
|
+
case 6:
|
|
181
209
|
saveCheckoutAddress(domainId, addressFields, receiverNotes);
|
|
182
|
-
|
|
210
|
+
cartJson = savedCart.toJson();
|
|
211
|
+
setCart(function (current) {
|
|
212
|
+
return (current === null || current === void 0 ? void 0 : current.id) === cartId ? cartJson : current;
|
|
213
|
+
});
|
|
183
214
|
setActiveTabAndEditDisabled({
|
|
184
215
|
tabId: tabIdCheckout,
|
|
185
216
|
tabIndexToSet: 2,
|
|
186
217
|
disabled: false
|
|
187
218
|
});
|
|
188
|
-
_context2.n =
|
|
219
|
+
_context2.n = 8;
|
|
189
220
|
break;
|
|
190
|
-
case
|
|
191
|
-
_context2.p =
|
|
221
|
+
case 7:
|
|
222
|
+
_context2.p = 7;
|
|
192
223
|
_t = _context2.v;
|
|
193
224
|
alertError(_t.errorMessage || _t.message || "Unable to set shipment address.");
|
|
194
|
-
case
|
|
195
|
-
_context2.p =
|
|
225
|
+
case 8:
|
|
226
|
+
_context2.p = 8;
|
|
196
227
|
setLoadingTotals(false);
|
|
197
|
-
return _context2.f(
|
|
198
|
-
case
|
|
228
|
+
return _context2.f(8);
|
|
229
|
+
case 9:
|
|
199
230
|
return _context2.a(2);
|
|
200
231
|
}
|
|
201
|
-
}, _callee2, null, [[
|
|
232
|
+
}, _callee2, null, [[2, 7, 8, 9]]);
|
|
202
233
|
}));
|
|
203
234
|
return _saveCartShipmentAddressAndGoToNextTab.apply(this, arguments);
|
|
204
235
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import TestOrderNotice from '@merchi/invoice/lib/TestOrderNotice';
|
|
1
2
|
import { CheckoutContainer, InnerContainer } from '../components/containers';
|
|
2
3
|
import { tabIdPaymentSuccess } from '../utilities/tabs';
|
|
3
4
|
import { companyPrimaryAddress } from '../utilities/company';
|
|
@@ -6,9 +7,10 @@ import { faCheckCircle } from '@fortawesome/free-solid-svg-icons';
|
|
|
6
7
|
import { Button, ButtonInvoiceDownload } from '../buttons';
|
|
7
8
|
import { CartBody, CartTabPanel } from '../components';
|
|
8
9
|
import { useCartContext } from '../CartProvider';
|
|
9
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
10
11
|
function PanelPaymentSuccess() {
|
|
11
12
|
var _useCartContext = useCartContext(),
|
|
13
|
+
cart = _useCartContext.cart,
|
|
12
14
|
classNameBtnPrimary = _useCartContext.classNameBtnPrimary,
|
|
13
15
|
customSuccessMessage = _useCartContext.customSuccessMessage,
|
|
14
16
|
fetchingCart = _useCartContext.fetchingCart,
|
|
@@ -24,20 +26,25 @@ function PanelPaymentSuccess() {
|
|
|
24
26
|
children: /*#__PURE__*/_jsxs(CartBody, {
|
|
25
27
|
children: [/*#__PURE__*/_jsx(CheckoutContainer, {
|
|
26
28
|
children: /*#__PURE__*/_jsxs(InnerContainer, {
|
|
27
|
-
children: [/*#__PURE__*/_jsx(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
children: [invoiceJson.isTest || cart !== null && cart !== void 0 && cart.isTest ? /*#__PURE__*/_jsx(TestOrderNotice, {
|
|
30
|
+
title: "Test order #".concat(id),
|
|
31
|
+
paymentReceived: unpaid === false
|
|
32
|
+
}) : /*#__PURE__*/_jsxs(_Fragment, {
|
|
33
|
+
children: [/*#__PURE__*/_jsx("h2", {
|
|
34
|
+
children: /*#__PURE__*/_jsx(FontAwesomeIcon, {
|
|
35
|
+
icon: faCheckCircle
|
|
36
|
+
})
|
|
37
|
+
}), /*#__PURE__*/_jsxs("h3", {
|
|
38
|
+
children: ["Order #", id]
|
|
39
|
+
}), /*#__PURE__*/_jsx("h4", {
|
|
40
|
+
children: "Payment Received!"
|
|
41
|
+
}), customSuccessMessage ? /*#__PURE__*/_jsx("p", {
|
|
42
|
+
className: "merchi-cart-success-message ",
|
|
43
|
+
children: customSuccessMessage
|
|
44
|
+
}) : /*#__PURE__*/_jsxs("p", {
|
|
45
|
+
className: "merchi-cart-success-message ",
|
|
46
|
+
children: ["Your order #", id, " is being processed and you should receive an email from us shortly. If you haven't heard from us within 24 hours please feel free to contact us", email ? " at ".concat(email.emailAddress, ".") : '.']
|
|
47
|
+
})]
|
|
41
48
|
}), !unpaid && /*#__PURE__*/_jsx("p", {
|
|
42
49
|
children: /*#__PURE__*/_jsx(ButtonInvoiceDownload, {})
|
|
43
50
|
}), /*#__PURE__*/_jsx("p", {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { renderToStaticMarkup } from 'react-dom/server.node';
|
|
3
|
+
import { useCartContext } from '../CartProvider';
|
|
4
|
+
import PanelPaymentSuccess from './PanelPaymentSuccess';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
jest.mock('../CartProvider', function () {
|
|
7
|
+
return {
|
|
8
|
+
useCartContext: jest.fn()
|
|
9
|
+
};
|
|
10
|
+
});
|
|
11
|
+
jest.mock('../components/containers', function () {
|
|
12
|
+
return {
|
|
13
|
+
CheckoutContainer: function CheckoutContainer(_ref) {
|
|
14
|
+
var children = _ref.children;
|
|
15
|
+
return children;
|
|
16
|
+
},
|
|
17
|
+
InnerContainer: function InnerContainer(_ref2) {
|
|
18
|
+
var children = _ref2.children;
|
|
19
|
+
return children;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
jest.mock('../components', function () {
|
|
24
|
+
return {
|
|
25
|
+
CartBody: function CartBody(_ref3) {
|
|
26
|
+
var children = _ref3.children;
|
|
27
|
+
return children;
|
|
28
|
+
},
|
|
29
|
+
CartTabPanel: function CartTabPanel(_ref4) {
|
|
30
|
+
var children = _ref4.children;
|
|
31
|
+
return children;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
jest.mock('../buttons', function () {
|
|
36
|
+
return {
|
|
37
|
+
Button: function Button(_ref5) {
|
|
38
|
+
var children = _ref5.children;
|
|
39
|
+
return /*#__PURE__*/_jsx("button", {
|
|
40
|
+
children: children
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
ButtonInvoiceDownload: function ButtonInvoiceDownload() {
|
|
44
|
+
return /*#__PURE__*/_jsx("button", {
|
|
45
|
+
children: "Download receipt"
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
it.each([[true, false, true], [undefined, true, true], [false, false, false]])('labels the confirmation for invoice %s and cart %s', function (invoiceTest, cartTest, expectedTest) {
|
|
51
|
+
useCartContext.mockReturnValue({
|
|
52
|
+
cart: {
|
|
53
|
+
isTest: cartTest
|
|
54
|
+
},
|
|
55
|
+
invoiceJson: {
|
|
56
|
+
id: 42,
|
|
57
|
+
isTest: invoiceTest,
|
|
58
|
+
unpaid: false
|
|
59
|
+
},
|
|
60
|
+
customSuccessMessage: 'Our team is preparing your goods.'
|
|
61
|
+
});
|
|
62
|
+
var page = renderToStaticMarkup(/*#__PURE__*/_jsx(PanelPaymentSuccess, {}));
|
|
63
|
+
expect(page.includes('Test order #42')).toBe(expectedTest);
|
|
64
|
+
expect(page.includes('Simulated payment received.')).toBe(expectedTest);
|
|
65
|
+
expect(page.includes('Payment Received!')).toBe(!expectedTest);
|
|
66
|
+
expect(page.includes('Our team is preparing your goods.')).toBe(!expectedTest);
|
|
67
|
+
expect(page).toContain('Download receipt');
|
|
68
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
2
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
3
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
4
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
5
|
+
import { Merchi } from '@merchi/sdk';
|
|
6
|
+
import { getCartCookie } from './cookie';
|
|
7
|
+
export function getCheckoutCartClient(_x, _x2, _x3) {
|
|
8
|
+
return _getCheckoutCartClient.apply(this, arguments);
|
|
9
|
+
}
|
|
10
|
+
function _getCheckoutCartClient() {
|
|
11
|
+
_getCheckoutCartClient = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(cart, domainId, apiUrl) {
|
|
12
|
+
var token, cookie;
|
|
13
|
+
return _regenerator().w(function (_context) {
|
|
14
|
+
while (1) switch (_context.n) {
|
|
15
|
+
case 0:
|
|
16
|
+
token = cart.token; // Another tab can replace the cookie while checkout still shows its own cart.
|
|
17
|
+
if (!(!token && domainId)) {
|
|
18
|
+
_context.n = 2;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
_context.n = 1;
|
|
22
|
+
return getCartCookie(domainId, cart.isTest === true);
|
|
23
|
+
case 1:
|
|
24
|
+
cookie = _context.v;
|
|
25
|
+
if ((cookie === null || cookie === void 0 ? void 0 : cookie[0]) === String(cart.id)) token = cookie[1];
|
|
26
|
+
case 2:
|
|
27
|
+
return _context.a(2, token ? new Merchi(undefined, undefined, undefined, token, apiUrl) : undefined);
|
|
28
|
+
}
|
|
29
|
+
}, _callee);
|
|
30
|
+
}));
|
|
31
|
+
return _getCheckoutCartClient.apply(this, arguments);
|
|
32
|
+
}
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export var TEST_CARD_NUMBER = '4242 4242 4242 4242';
|
|
4
|
-
export function readTestCheckoutFlag() {
|
|
5
|
-
if (typeof window === 'undefined') {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
try {
|
|
9
|
-
var params = new URLSearchParams(window.location.search);
|
|
10
|
-
if (params.get(TEST_CHECKOUT_QUERY) === '1') {
|
|
11
|
-
window.localStorage.setItem(TEST_CHECKOUT_STORAGE_KEY, '1');
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
return window.localStorage.getItem(TEST_CHECKOUT_STORAGE_KEY) === '1';
|
|
15
|
-
} catch (_unused) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
import { readTestCheckoutFlag } from '@merchi/invoice/lib/testCheckout';
|
|
2
|
+
export { readTestCheckoutFlag, TEST_CARD_NUMBER, TEST_CHECKOUT_QUERY, TEST_CHECKOUT_STORAGE_KEY } from '@merchi/invoice/lib/testCheckout';
|
|
19
3
|
export function persistTestCheckoutFlag() {
|
|
20
4
|
return readTestCheckoutFlag();
|
|
21
5
|
}
|
package/lib/CartProvider.js
CHANGED
|
@@ -22,6 +22,7 @@ var _test_checkout = require("./utilities/test_checkout");
|
|
|
22
22
|
var _reportFailure = require("./utilities/reportFailure");
|
|
23
23
|
var _automatedClient = require("./utilities/automatedClient");
|
|
24
24
|
var _cartLoadFailure = require("./utilities/cartLoadFailure");
|
|
25
|
+
var _checkoutCartClient = require("./utilities/checkoutCartClient");
|
|
25
26
|
var _job_source = require("./utilities/job_source");
|
|
26
27
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
27
28
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t10 in e) "default" !== _t10 && {}.hasOwnProperty.call(e, _t10) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t10)) && (i.get || i.set) ? o(f, _t10, i) : f[_t10] = e[_t10]); return f; })(e, t); }
|
|
@@ -843,55 +844,68 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
843
844
|
}
|
|
844
845
|
function _updateCartShipmentAddress() {
|
|
845
846
|
_updateCartShipmentAddress = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(address) {
|
|
846
|
-
var
|
|
847
|
+
var _cart$invoice;
|
|
848
|
+
var cartId, shipmentApi, addressFields, cartEnt, savedCart, cartJson, cartWithShipmentGroups, _t7;
|
|
847
849
|
return _regenerator().w(function (_context9) {
|
|
848
850
|
while (1) switch (_context9.p = _context9.n) {
|
|
849
851
|
case 0:
|
|
850
|
-
|
|
851
|
-
|
|
852
|
+
cartId = cart === null || cart === void 0 ? void 0 : cart.id;
|
|
853
|
+
if (!(!cartId || ((_cart$invoice = cart.invoice) === null || _cart$invoice === void 0 ? void 0 : _cart$invoice.unpaid) === false)) {
|
|
854
|
+
_context9.n = 1;
|
|
855
|
+
break;
|
|
856
|
+
}
|
|
857
|
+
return _context9.a(2);
|
|
852
858
|
case 1:
|
|
853
|
-
token = _context9.v;
|
|
854
|
-
addressFields = (0, _address.sanitizeAddressFields)(address);
|
|
855
|
-
receiverAddress = (0, _address.makeAddress)(addressFields, true);
|
|
856
|
-
cartEnt = (0, _cart3.makeCart)(cart, false, token);
|
|
857
859
|
setFetchingShipmentGroups(true);
|
|
858
860
|
_context9.p = 2;
|
|
859
|
-
cartEnt.receiverAddress = receiverAddress;
|
|
860
861
|
_context9.n = 3;
|
|
862
|
+
return (0, _checkoutCartClient.getCheckoutCartClient)(cart, domainId, merchi.backendUri);
|
|
863
|
+
case 3:
|
|
864
|
+
shipmentApi = _context9.v;
|
|
865
|
+
if (shipmentApi) {
|
|
866
|
+
_context9.n = 4;
|
|
867
|
+
break;
|
|
868
|
+
}
|
|
869
|
+
alertError('Unable to verify this cart. Reload checkout and try again.');
|
|
870
|
+
return _context9.a(2);
|
|
871
|
+
case 4:
|
|
872
|
+
addressFields = (0, _address.sanitizeAddressFields)(address);
|
|
873
|
+
cartEnt = new shipmentApi.Cart().fromJson(cart);
|
|
874
|
+
cartEnt.receiverAddress = (0, _address.makeAddress)(addressFields, true);
|
|
875
|
+
_context9.n = 5;
|
|
861
876
|
return cartEnt.save({
|
|
862
877
|
embed: _helpers.cartEmbed
|
|
863
878
|
});
|
|
864
|
-
case
|
|
865
|
-
|
|
866
|
-
cartJson =
|
|
879
|
+
case 5:
|
|
880
|
+
savedCart = _context9.v;
|
|
881
|
+
cartJson = savedCart.toJson();
|
|
867
882
|
(0, _local_storage.saveCheckoutAddress)(domainId, addressFields);
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
return merchi.authenticatedFetch("/generate-cart-shipment-quotes/".concat(cart.id, "/"), {
|
|
872
|
-
method: 'GET',
|
|
873
|
-
query: query
|
|
883
|
+
_context9.n = 6;
|
|
884
|
+
return shipmentApi.authenticatedFetch("/generate-cart-shipment-quotes/".concat(cartId, "/"), {
|
|
885
|
+
method: 'GET'
|
|
874
886
|
});
|
|
875
|
-
case
|
|
887
|
+
case 6:
|
|
876
888
|
cartWithShipmentGroups = _context9.v;
|
|
877
|
-
setCart(
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
889
|
+
setCart(function (current) {
|
|
890
|
+
return (current === null || current === void 0 ? void 0 : current.id) === cartId ? _objectSpread(_objectSpread({}, cartJson), {}, {
|
|
891
|
+
shipmentGroups: cartWithShipmentGroups.shipmentGroups || []
|
|
892
|
+
}) : current;
|
|
893
|
+
});
|
|
894
|
+
_context9.n = 8;
|
|
881
895
|
break;
|
|
882
|
-
case
|
|
883
|
-
_context9.p =
|
|
896
|
+
case 7:
|
|
897
|
+
_context9.p = 7;
|
|
884
898
|
_t7 = _context9.v;
|
|
885
899
|
(0, _reportFailure.reportCartFailure)(_t7, _reportFailure.CART_FAILURE_SOURCES.update);
|
|
886
900
|
alertError(_t7.errorMessage || _t7.message || 'Unable to set address');
|
|
887
|
-
case
|
|
888
|
-
_context9.p =
|
|
901
|
+
case 8:
|
|
902
|
+
_context9.p = 8;
|
|
889
903
|
setFetchingShipmentGroups(false);
|
|
890
|
-
return _context9.f(
|
|
891
|
-
case
|
|
904
|
+
return _context9.f(8);
|
|
905
|
+
case 9:
|
|
892
906
|
return _context9.a(2);
|
|
893
907
|
}
|
|
894
|
-
}, _callee9, null, [[2,
|
|
908
|
+
}, _callee9, null, [[2, 7, 8, 9]]);
|
|
895
909
|
}));
|
|
896
910
|
return _updateCartShipmentAddress.apply(this, arguments);
|
|
897
911
|
}
|
|
@@ -900,39 +914,56 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
900
914
|
}
|
|
901
915
|
function _getCartShipmentOptions() {
|
|
902
916
|
_getCartShipmentOptions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
|
|
903
|
-
var
|
|
917
|
+
var cartId, shipmentApi, cartWithGroups, _t8;
|
|
904
918
|
return _regenerator().w(function (_context0) {
|
|
905
919
|
while (1) switch (_context0.p = _context0.n) {
|
|
906
920
|
case 0:
|
|
921
|
+
cartId = cart === null || cart === void 0 ? void 0 : cart.id;
|
|
922
|
+
if (cartId) {
|
|
923
|
+
_context0.n = 1;
|
|
924
|
+
break;
|
|
925
|
+
}
|
|
926
|
+
return _context0.a(2);
|
|
927
|
+
case 1:
|
|
907
928
|
setFetchingShipmentGroups(true);
|
|
908
|
-
_context0.p =
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
929
|
+
_context0.p = 2;
|
|
930
|
+
_context0.n = 3;
|
|
931
|
+
return (0, _checkoutCartClient.getCheckoutCartClient)(cart, domainId, merchi.backendUri);
|
|
932
|
+
case 3:
|
|
933
|
+
shipmentApi = _context0.v;
|
|
934
|
+
if (shipmentApi) {
|
|
935
|
+
_context0.n = 4;
|
|
936
|
+
break;
|
|
937
|
+
}
|
|
938
|
+
alertError('Unable to verify this cart. Reload checkout and try again.');
|
|
939
|
+
return _context0.a(2);
|
|
940
|
+
case 4:
|
|
941
|
+
_context0.n = 5;
|
|
942
|
+
return shipmentApi.authenticatedFetch("/generate-cart-shipment-quotes/".concat(cartId, "/"), {
|
|
943
|
+
method: 'GET'
|
|
915
944
|
});
|
|
916
|
-
case
|
|
945
|
+
case 5:
|
|
917
946
|
cartWithGroups = _context0.v;
|
|
918
|
-
setCart(
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
947
|
+
setCart(function (current) {
|
|
948
|
+
return (current === null || current === void 0 ? void 0 : current.id) === cartId ? _objectSpread(_objectSpread({}, current), {}, {
|
|
949
|
+
shipmentGroups: cartWithGroups.shipmentGroups || []
|
|
950
|
+
}) : current;
|
|
951
|
+
});
|
|
952
|
+
_context0.n = 7;
|
|
922
953
|
break;
|
|
923
|
-
case
|
|
924
|
-
_context0.p =
|
|
954
|
+
case 6:
|
|
955
|
+
_context0.p = 6;
|
|
925
956
|
_t8 = _context0.v;
|
|
926
957
|
(0, _reportFailure.reportCartFailure)(_t8, _reportFailure.CART_FAILURE_SOURCES.shipping);
|
|
927
958
|
alertError(_t8.errorMessage || _t8.message || 'Unable to fetch shipment options');
|
|
928
|
-
case
|
|
929
|
-
_context0.p =
|
|
959
|
+
case 7:
|
|
960
|
+
_context0.p = 7;
|
|
930
961
|
setFetchingShipmentGroups(false);
|
|
931
|
-
return _context0.f(
|
|
932
|
-
case
|
|
962
|
+
return _context0.f(7);
|
|
963
|
+
case 8:
|
|
933
964
|
return _context0.a(2);
|
|
934
965
|
}
|
|
935
|
-
}, _callee0, null, [[
|
|
966
|
+
}, _callee0, null, [[2, 6, 7, 8]]);
|
|
936
967
|
}));
|
|
937
968
|
return _getCartShipmentOptions.apply(this, arguments);
|
|
938
969
|
}
|
|
@@ -10,12 +10,11 @@ var _InputsAddress = _interopRequireDefault(require("./InputsAddress"));
|
|
|
10
10
|
var _containers = require("../components/containers");
|
|
11
11
|
var _components = require("../components");
|
|
12
12
|
var _shipment = require("../utilities/shipment");
|
|
13
|
+
var _checkoutCartClient = require("../utilities/checkoutCartClient");
|
|
13
14
|
var _freeSolidSvgIcons = require("@fortawesome/free-solid-svg-icons");
|
|
14
15
|
var _CartProvider = require("../CartProvider");
|
|
15
16
|
var _react = require("react");
|
|
16
|
-
var _cookie = require("../utilities/cookie");
|
|
17
17
|
var _address = require("../utilities/address");
|
|
18
|
-
var _cart = require("../utilities/cart");
|
|
19
18
|
var _helpers = require("../utilities/helpers");
|
|
20
19
|
var _tabs = require("../utilities/tabs");
|
|
21
20
|
var _local_storage = require("../utilities/local_storage");
|
|
@@ -141,6 +140,13 @@ function ActiveFormShipmentAddressAndNotes() {
|
|
|
141
140
|
addressFieldsOpen = _useState2[0],
|
|
142
141
|
setAddressFieldsOpen = _useState2[1];
|
|
143
142
|
var hydratedShipmentOptionsRef = (0, _react.useRef)(false);
|
|
143
|
+
var currentCartId = (0, _react.useRef)(cart === null || cart === void 0 ? void 0 : cart.id);
|
|
144
|
+
(0, _react.useEffect)(function () {
|
|
145
|
+
currentCartId.current = cart === null || cart === void 0 ? void 0 : cart.id;
|
|
146
|
+
return function () {
|
|
147
|
+
currentCartId.current = undefined;
|
|
148
|
+
};
|
|
149
|
+
}, [cart === null || cart === void 0 ? void 0 : cart.id]);
|
|
144
150
|
(0, _react.useEffect)(function () {
|
|
145
151
|
if (hydratedShipmentOptionsRef.current || !(cart !== null && cart !== void 0 && cart.id)) return;
|
|
146
152
|
var draft = (0, _local_storage.getSavedCheckoutAddress)(domainId);
|
|
@@ -164,49 +170,74 @@ function ActiveFormShipmentAddressAndNotes() {
|
|
|
164
170
|
}
|
|
165
171
|
function _saveCartShipmentAddressAndGoToNextTab() {
|
|
166
172
|
_saveCartShipmentAddressAndGoToNextTab = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(values) {
|
|
167
|
-
var
|
|
173
|
+
var _cart$invoice;
|
|
174
|
+
var cartId, address, receiverNotes, shipmentApi, addressFields, _receiverAddress, cartEnt, savedCart, cartJson, _t;
|
|
168
175
|
return _regenerator().w(function (_context2) {
|
|
169
176
|
while (1) switch (_context2.p = _context2.n) {
|
|
170
177
|
case 0:
|
|
178
|
+
cartId = cart === null || cart === void 0 ? void 0 : cart.id;
|
|
179
|
+
if (!(!cartId || ((_cart$invoice = cart.invoice) === null || _cart$invoice === void 0 ? void 0 : _cart$invoice.unpaid) === false)) {
|
|
180
|
+
_context2.n = 1;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
return _context2.a(2);
|
|
184
|
+
case 1:
|
|
171
185
|
address = values.receiverAddress, receiverNotes = values.receiverNotes;
|
|
172
186
|
setLoadingTotals(true);
|
|
173
|
-
_context2.p =
|
|
174
|
-
_context2.n =
|
|
175
|
-
return (0,
|
|
176
|
-
case
|
|
177
|
-
|
|
187
|
+
_context2.p = 2;
|
|
188
|
+
_context2.n = 3;
|
|
189
|
+
return (0, _checkoutCartClient.getCheckoutCartClient)(cart, domainId);
|
|
190
|
+
case 3:
|
|
191
|
+
shipmentApi = _context2.v;
|
|
192
|
+
if (shipmentApi) {
|
|
193
|
+
_context2.n = 4;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
alertError("Unable to verify this cart. Reload checkout and try again.");
|
|
197
|
+
return _context2.a(2);
|
|
198
|
+
case 4:
|
|
178
199
|
// Never PATCH an existing Address via cart token — create a fresh embed.
|
|
179
200
|
addressFields = (0, _address.sanitizeAddressFields)(address);
|
|
180
201
|
_receiverAddress = (0, _address.makeAddress)(addressFields, true);
|
|
181
|
-
cartEnt =
|
|
202
|
+
cartEnt = new shipmentApi.Cart().fromJson(cart);
|
|
182
203
|
cartEnt.receiverAddress = _receiverAddress;
|
|
183
204
|
cartEnt.receiverNotes = receiverNotes;
|
|
184
|
-
_context2.n =
|
|
205
|
+
_context2.n = 5;
|
|
185
206
|
return cartEnt.save({
|
|
186
207
|
embed: _helpers.cartEmbed
|
|
187
208
|
});
|
|
188
|
-
case
|
|
209
|
+
case 5:
|
|
210
|
+
savedCart = _context2.v;
|
|
211
|
+
if (!(currentCartId.current !== cartId)) {
|
|
212
|
+
_context2.n = 6;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
return _context2.a(2);
|
|
216
|
+
case 6:
|
|
189
217
|
(0, _local_storage.saveCheckoutAddress)(domainId, addressFields, receiverNotes);
|
|
190
|
-
|
|
218
|
+
cartJson = savedCart.toJson();
|
|
219
|
+
setCart(function (current) {
|
|
220
|
+
return (current === null || current === void 0 ? void 0 : current.id) === cartId ? cartJson : current;
|
|
221
|
+
});
|
|
191
222
|
setActiveTabAndEditDisabled({
|
|
192
223
|
tabId: _tabs.tabIdCheckout,
|
|
193
224
|
tabIndexToSet: 2,
|
|
194
225
|
disabled: false
|
|
195
226
|
});
|
|
196
|
-
_context2.n =
|
|
227
|
+
_context2.n = 8;
|
|
197
228
|
break;
|
|
198
|
-
case
|
|
199
|
-
_context2.p =
|
|
229
|
+
case 7:
|
|
230
|
+
_context2.p = 7;
|
|
200
231
|
_t = _context2.v;
|
|
201
232
|
alertError(_t.errorMessage || _t.message || "Unable to set shipment address.");
|
|
202
|
-
case
|
|
203
|
-
_context2.p =
|
|
233
|
+
case 8:
|
|
234
|
+
_context2.p = 8;
|
|
204
235
|
setLoadingTotals(false);
|
|
205
|
-
return _context2.f(
|
|
206
|
-
case
|
|
236
|
+
return _context2.f(8);
|
|
237
|
+
case 9:
|
|
207
238
|
return _context2.a(2);
|
|
208
239
|
}
|
|
209
|
-
}, _callee2, null, [[
|
|
240
|
+
}, _callee2, null, [[2, 7, 8, 9]]);
|
|
210
241
|
}));
|
|
211
242
|
return _saveCartShipmentAddressAndGoToNextTab.apply(this, arguments);
|
|
212
243
|
}
|