merchi_cart 1.4.3 → 1.4.5
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 +96 -76
- package/esm/forms/InputsAddress.js +329 -74
- package/esm/stripe/LegacyStripeCardForm.js +11 -4
- package/esm/stripe/StripeCardForm.js +124 -15
- package/esm/stripe/actions.js +161 -57
- package/esm/stripe/actions.test.js +132 -0
- package/esm/styles/globals.css +37 -0
- package/esm/styles/globals.css.map +1 -1
- package/esm/utilities/address.js +101 -0
- package/esm/utilities/cookie.js +20 -17
- package/esm/utilities/index.js +1 -0
- package/esm/utilities/test_checkout.js +25 -0
- package/esm/utilities/test_checkout.test.js +31 -0
- package/lib/CartProvider.d.ts +3 -1
- package/lib/CartProvider.js +96 -76
- package/lib/forms/InputsAddress.d.ts +1 -1
- package/lib/forms/InputsAddress.js +329 -71
- package/lib/stripe/LegacyStripeCardForm.js +10 -3
- package/lib/stripe/StripeCardForm.js +122 -16
- package/lib/stripe/actions.d.ts +2 -0
- package/lib/stripe/actions.js +163 -57
- package/lib/stripe/actions.test.d.ts +1 -0
- package/lib/styles/globals.css +37 -0
- package/lib/styles/globals.css.map +1 -1
- package/lib/utilities/address.d.ts +10 -0
- package/lib/utilities/address.js +103 -1
- package/lib/utilities/cookie.d.ts +3 -3
- package/lib/utilities/cookie.js +20 -17
- package/lib/utilities/index.d.ts +1 -0
- package/lib/utilities/index.js +11 -0
- package/lib/utilities/test_checkout.d.ts +6 -0
- package/lib/utilities/test_checkout.js +34 -0
- package/lib/utilities/test_checkout.test.d.ts +1 -0
- package/package.json +6 -4
- package/src/CartProvider.tsx +30 -15
- package/src/forms/InputsAddress.tsx +305 -72
- package/src/stripe/LegacyStripeCardForm.tsx +9 -3
- package/src/stripe/StripeCardForm.tsx +92 -8
- package/src/stripe/actions.test.ts +50 -0
- package/src/stripe/actions.ts +41 -0
- package/src/styles/globals.scss +42 -0
- package/src/utilities/address.ts +99 -0
- package/src/utilities/cookie.ts +9 -6
- package/src/utilities/index.ts +1 -0
- package/src/utilities/test_checkout.test.ts +39 -0
- package/src/utilities/test_checkout.ts +27 -0
- package/esm/types/react-geosuggest/index.d.js +0 -0
- package/src/types/react-geosuggest/index.d.ts +0 -1
package/esm/CartProvider.js
CHANGED
|
@@ -31,6 +31,7 @@ import { makeJob } from './utilities/job';
|
|
|
31
31
|
import { makeProduct } from './utilities/product';
|
|
32
32
|
import { getSavedCheckoutCustomer, saveCheckoutAddress } from './utilities/local_storage';
|
|
33
33
|
import { makeUser } from './utilities/user';
|
|
34
|
+
import { persistTestCheckoutFlag, readTestCheckoutFlag } from './utilities/test_checkout';
|
|
34
35
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
35
36
|
var CartContext = /*#__PURE__*/createContext({
|
|
36
37
|
cart: {},
|
|
@@ -230,9 +231,9 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
230
231
|
_ref$classNameCartTog = _ref.classNameCartToggleIconButton,
|
|
231
232
|
classNameCartToggleIconButton = _ref$classNameCartTog === void 0 ? 'cart-icon-button-class' : _ref$classNameCartTog,
|
|
232
233
|
_ref$classNameCartGoo = _ref.classNameCartGoogleSuggestList,
|
|
233
|
-
classNameCartGoogleSuggestList = _ref$classNameCartGoo === void 0 ? '
|
|
234
|
+
classNameCartGoogleSuggestList = _ref$classNameCartGoo === void 0 ? 'merchi-cart-google-suggest-list' : _ref$classNameCartGoo,
|
|
234
235
|
_ref$classNameCartGoo2 = _ref.classNameCartGoogleSuggestListItem,
|
|
235
|
-
classNameCartGoogleSuggestListItem = _ref$classNameCartGoo2 === void 0 ? 'list-
|
|
236
|
+
classNameCartGoogleSuggestListItem = _ref$classNameCartGoo2 === void 0 ? 'merchi-cart-google-suggest-list-item' : _ref$classNameCartGoo2,
|
|
236
237
|
_ref$classNameCartHea = _ref.classNameCartHeader,
|
|
237
238
|
classNameCartHeader = _ref$classNameCartHea === void 0 ? 'merchi-cart-header' : _ref$classNameCartHea,
|
|
238
239
|
_ref$classNameCartIte = _ref.classNameCartItemFeatureImage,
|
|
@@ -317,6 +318,8 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
317
318
|
discountShowAppliedItems = _ref$discountShowAppl === void 0 ? true : _ref$discountShowAppl,
|
|
318
319
|
_ref$showDiscountCode = _ref.showDiscountCode,
|
|
319
320
|
showDiscountCode = _ref$showDiscountCode === void 0 ? true : _ref$showDiscountCode,
|
|
321
|
+
_ref$googlePlacesLoad = _ref.googlePlacesLoaded,
|
|
322
|
+
googlePlacesLoaded = _ref$googlePlacesLoad === void 0 ? false : _ref$googlePlacesLoad,
|
|
320
323
|
_ref$hideHead = _ref.hideHead,
|
|
321
324
|
hideHead = _ref$hideHead === void 0 ? false : _ref$hideHead,
|
|
322
325
|
_ref$includeTheme = _ref.includeTheme,
|
|
@@ -377,32 +380,20 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
377
380
|
});
|
|
378
381
|
setActiveTabIndex(tabId);
|
|
379
382
|
}
|
|
380
|
-
var _useState11 = useState(
|
|
383
|
+
var _useState11 = useState({}),
|
|
381
384
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if (typeof window !== 'undefined') {
|
|
386
|
-
if (!window.googleMapsScriptLoaded) {
|
|
387
|
-
window.googleMapsScriptLoaded = function () {
|
|
388
|
-
setGoogleMapsLoaded(true);
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
var _useState13 = useState({}),
|
|
393
|
-
_useState14 = _slicedToArray(_useState13, 2),
|
|
394
|
-
cartItem = _useState14[0],
|
|
395
|
-
setCartItem = _useState14[1];
|
|
396
|
-
var _useState15 = useState({
|
|
385
|
+
cartItem = _useState12[0],
|
|
386
|
+
setCartItem = _useState12[1];
|
|
387
|
+
var _useState13 = useState({
|
|
397
388
|
icon: faInfoCircle,
|
|
398
389
|
message: '',
|
|
399
390
|
show: false,
|
|
400
391
|
title: '',
|
|
401
392
|
type: 'info'
|
|
402
393
|
}),
|
|
403
|
-
|
|
404
|
-
alert =
|
|
405
|
-
setAlert =
|
|
394
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
395
|
+
alert = _useState14[0],
|
|
396
|
+
setAlert = _useState14[1];
|
|
406
397
|
function alertSuccess(message) {
|
|
407
398
|
setAlert({
|
|
408
399
|
icon: faCheckCircle,
|
|
@@ -424,14 +415,14 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
424
415
|
function closeClearCart() {
|
|
425
416
|
setActiveTabIndex(tabIdItems);
|
|
426
417
|
}
|
|
418
|
+
var _useState15 = useState(false),
|
|
419
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
420
|
+
fetchingCart = _useState16[0],
|
|
421
|
+
setFetchingCart = _useState16[1];
|
|
427
422
|
var _useState17 = useState(false),
|
|
428
423
|
_useState18 = _slicedToArray(_useState17, 2),
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
var _useState19 = useState(false),
|
|
432
|
-
_useState20 = _slicedToArray(_useState19, 2),
|
|
433
|
-
cartSettingsInvalid = _useState20[0],
|
|
434
|
-
setCartSettingsInvalid = _useState20[1];
|
|
424
|
+
cartSettingsInvalid = _useState18[0],
|
|
425
|
+
setCartSettingsInvalid = _useState18[1];
|
|
435
426
|
function attachSavedClientIfNeeded(_x) {
|
|
436
427
|
return _attachSavedClientIfNeeded.apply(this, arguments);
|
|
437
428
|
} // Create cart and save cart cookie
|
|
@@ -509,48 +500,66 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
509
500
|
}
|
|
510
501
|
function _createCartAndCookie() {
|
|
511
502
|
_createCartAndCookie = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(callback) {
|
|
512
|
-
var _cart, _cartJson;
|
|
503
|
+
var isTest, _cart, created, _cartJson;
|
|
513
504
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
514
505
|
while (1) switch (_context2.prev = _context2.next) {
|
|
515
506
|
case 0:
|
|
516
507
|
setFetchingCart(true);
|
|
517
508
|
_context2.prev = 1;
|
|
509
|
+
isTest = readTestCheckoutFlag();
|
|
518
510
|
_cart = makeCart({
|
|
519
511
|
domain: {
|
|
520
512
|
id: domainId
|
|
521
|
-
}
|
|
513
|
+
},
|
|
514
|
+
isTest: isTest
|
|
522
515
|
}, true);
|
|
523
|
-
|
|
516
|
+
if (!isTest) {
|
|
517
|
+
_context2.next = 11;
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
_context2.next = 7;
|
|
521
|
+
return merchi.authenticatedFetch('/carts/', {
|
|
522
|
+
method: 'POST',
|
|
523
|
+
body: _cart.toFormData(),
|
|
524
|
+
query: [['embed', JSON.stringify(cartEmbed)], ['skip_rights', 'y'], ['is_test', 'true']]
|
|
525
|
+
});
|
|
526
|
+
case 7:
|
|
527
|
+
created = _context2.sent;
|
|
528
|
+
_cart.fromJson(created.cart);
|
|
529
|
+
_context2.next = 13;
|
|
530
|
+
break;
|
|
531
|
+
case 11:
|
|
532
|
+
_context2.next = 13;
|
|
524
533
|
return _cart.create({
|
|
525
534
|
embed: cartEmbed
|
|
526
535
|
});
|
|
527
|
-
case
|
|
528
|
-
_context2.next =
|
|
536
|
+
case 13:
|
|
537
|
+
_context2.next = 15;
|
|
529
538
|
return _cart.toJson();
|
|
530
|
-
case
|
|
539
|
+
case 15:
|
|
531
540
|
_cartJson = _context2.sent;
|
|
532
|
-
if (domainId) setCartCookie(Number(domainId), _cartJson, undefined);
|
|
533
|
-
_context2.next =
|
|
541
|
+
if (domainId) setCartCookie(Number(domainId), _cartJson, undefined, isTest);
|
|
542
|
+
_context2.next = 19;
|
|
534
543
|
return attachSavedClientIfNeeded(_cartJson);
|
|
535
|
-
case
|
|
544
|
+
case 19:
|
|
536
545
|
_cartJson = _context2.sent;
|
|
537
546
|
setCart(_objectSpread({}, _cartJson));
|
|
538
547
|
if (callback) callback();
|
|
539
|
-
_context2.next =
|
|
548
|
+
_context2.next = 27;
|
|
540
549
|
break;
|
|
541
|
-
case
|
|
542
|
-
_context2.prev =
|
|
550
|
+
case 24:
|
|
551
|
+
_context2.prev = 24;
|
|
543
552
|
_context2.t0 = _context2["catch"](1);
|
|
544
553
|
alertError(_context2.t0.errorMessage || _context2.t0.message || 'Unable to fetch cart.');
|
|
545
|
-
case
|
|
546
|
-
_context2.prev =
|
|
554
|
+
case 27:
|
|
555
|
+
_context2.prev = 27;
|
|
547
556
|
setFetchingCart(false);
|
|
548
|
-
return _context2.finish(
|
|
549
|
-
case
|
|
557
|
+
return _context2.finish(27);
|
|
558
|
+
case 30:
|
|
550
559
|
case "end":
|
|
551
560
|
return _context2.stop();
|
|
552
561
|
}
|
|
553
|
-
}, _callee2, null, [[1,
|
|
562
|
+
}, _callee2, null, [[1, 24, 27, 30]]);
|
|
554
563
|
}));
|
|
555
564
|
return _createCartAndCookie.apply(this, arguments);
|
|
556
565
|
}
|
|
@@ -559,7 +568,7 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
559
568
|
}
|
|
560
569
|
function _getCart() {
|
|
561
570
|
_getCart = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(cartIdAndToken) {
|
|
562
|
-
var id, _cart2, _cartJson2;
|
|
571
|
+
var id, _cart2, _cartJson2, isTest;
|
|
563
572
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
564
573
|
while (1) switch (_context3.prev = _context3.next) {
|
|
565
574
|
case 0:
|
|
@@ -577,37 +586,47 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
577
586
|
return _cart2.toJson();
|
|
578
587
|
case 9:
|
|
579
588
|
_cartJson2 = _context3.sent;
|
|
580
|
-
|
|
581
|
-
|
|
589
|
+
isTest = readTestCheckoutFlag();
|
|
590
|
+
if (!(Boolean(_cartJson2.isTest) !== isTest)) {
|
|
591
|
+
_context3.next = 15;
|
|
582
592
|
break;
|
|
583
593
|
}
|
|
584
|
-
_context3.next =
|
|
594
|
+
_context3.next = 14;
|
|
595
|
+
return createCartAndCookie();
|
|
596
|
+
case 14:
|
|
597
|
+
return _context3.abrupt("return");
|
|
598
|
+
case 15:
|
|
599
|
+
if (!(stripeIsValidAndActive(_cartJson2) || isTest)) {
|
|
600
|
+
_context3.next = 22;
|
|
601
|
+
break;
|
|
602
|
+
}
|
|
603
|
+
_context3.next = 18;
|
|
585
604
|
return attachSavedClientIfNeeded(_cartJson2);
|
|
586
|
-
case
|
|
605
|
+
case 18:
|
|
587
606
|
_cartJson2 = _context3.sent;
|
|
588
607
|
setCart(_objectSpread({}, _cartJson2));
|
|
589
|
-
_context3.next =
|
|
608
|
+
_context3.next = 24;
|
|
590
609
|
break;
|
|
591
|
-
case
|
|
610
|
+
case 22:
|
|
592
611
|
console.error("MErhci cart error: Stripe payment " + "options have not been correctly set up. " + "Check the company profile payment options tab " + "to set and edit stripe payment options.");
|
|
593
612
|
setCartSettingsInvalid(true);
|
|
594
|
-
case
|
|
595
|
-
_context3.next =
|
|
613
|
+
case 24:
|
|
614
|
+
_context3.next = 30;
|
|
596
615
|
break;
|
|
597
|
-
case
|
|
598
|
-
_context3.prev =
|
|
616
|
+
case 26:
|
|
617
|
+
_context3.prev = 26;
|
|
599
618
|
_context3.t0 = _context3["catch"](3);
|
|
600
|
-
_context3.next =
|
|
619
|
+
_context3.next = 30;
|
|
601
620
|
return createCartAndCookie();
|
|
602
|
-
case
|
|
603
|
-
_context3.prev =
|
|
621
|
+
case 30:
|
|
622
|
+
_context3.prev = 30;
|
|
604
623
|
setFetchingCart(false);
|
|
605
|
-
return _context3.finish(
|
|
606
|
-
case
|
|
624
|
+
return _context3.finish(30);
|
|
625
|
+
case 33:
|
|
607
626
|
case "end":
|
|
608
627
|
return _context3.stop();
|
|
609
628
|
}
|
|
610
|
-
}, _callee3, null, [[3,
|
|
629
|
+
}, _callee3, null, [[3, 26, 30, 33]]);
|
|
611
630
|
}));
|
|
612
631
|
return _getCart.apply(this, arguments);
|
|
613
632
|
}
|
|
@@ -658,10 +677,10 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
658
677
|
}));
|
|
659
678
|
return _clearCart.apply(this, arguments);
|
|
660
679
|
}
|
|
661
|
-
var
|
|
662
|
-
|
|
663
|
-
fetchingShipmentGroups =
|
|
664
|
-
setFetchingShipmentGroups =
|
|
680
|
+
var _useState19 = useState(false),
|
|
681
|
+
_useState20 = _slicedToArray(_useState19, 2),
|
|
682
|
+
fetchingShipmentGroups = _useState20[0],
|
|
683
|
+
setFetchingShipmentGroups = _useState20[1];
|
|
665
684
|
function updateCartShipmentAddress(_x5) {
|
|
666
685
|
return _updateCartShipmentAddress.apply(this, arguments);
|
|
667
686
|
}
|
|
@@ -804,10 +823,10 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
804
823
|
}));
|
|
805
824
|
return _isMerchiCartFetching.apply(this, arguments);
|
|
806
825
|
}
|
|
807
|
-
var
|
|
808
|
-
|
|
809
|
-
loading =
|
|
810
|
-
setLoading =
|
|
826
|
+
var _useState21 = useState(false),
|
|
827
|
+
_useState22 = _slicedToArray(_useState21, 2),
|
|
828
|
+
loading = _useState22[0],
|
|
829
|
+
setLoading = _useState22[1];
|
|
811
830
|
|
|
812
831
|
// Fetch the associated cart theme via the cart domain.
|
|
813
832
|
function actionFetchTheme() {
|
|
@@ -890,14 +909,14 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
890
909
|
}));
|
|
891
910
|
return _refetchCart.apply(this, arguments);
|
|
892
911
|
}
|
|
893
|
-
var
|
|
912
|
+
var _useState23 = useState({}),
|
|
913
|
+
_useState24 = _slicedToArray(_useState23, 2),
|
|
914
|
+
invoiceJson = _useState24[0],
|
|
915
|
+
setInvoiceJson = _useState24[1];
|
|
916
|
+
var _useState25 = useState(false),
|
|
894
917
|
_useState26 = _slicedToArray(_useState25, 2),
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
var _useState27 = useState(false),
|
|
898
|
-
_useState28 = _slicedToArray(_useState27, 2),
|
|
899
|
-
loadingTotals = _useState28[0],
|
|
900
|
-
setLoadingTotals = _useState28[1];
|
|
918
|
+
loadingTotals = _useState26[0],
|
|
919
|
+
setLoadingTotals = _useState26[1];
|
|
901
920
|
function addCartItem(_x6, _x7, _x8) {
|
|
902
921
|
return _addCartItem.apply(this, arguments);
|
|
903
922
|
}
|
|
@@ -984,6 +1003,7 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
984
1003
|
window.createCartAndCookie = createCartAndCookie;
|
|
985
1004
|
}
|
|
986
1005
|
useEffect(function () {
|
|
1006
|
+
persistTestCheckoutFlag();
|
|
987
1007
|
if (domainId) actionGetMerchiCart();
|
|
988
1008
|
if (domainId && includeTheme) actionFetchTheme();
|
|
989
1009
|
}, [domainId]);
|