@merchi/cart 1.4.4 → 1.4.6

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.
Files changed (49) hide show
  1. package/esm/CartProvider.js +58 -20
  2. package/esm/forms/FormShipmentAddressAndNotes.js +24 -3
  3. package/esm/stripe/LegacyStripeCardForm.js +11 -4
  4. package/esm/stripe/StripeCardForm.js +122 -16
  5. package/esm/stripe/actions.js +155 -57
  6. package/esm/stripe/actions.test.js +120 -0
  7. package/esm/utilities/cookie.js +15 -12
  8. package/esm/utilities/index.js +2 -0
  9. package/esm/utilities/job_source.js +139 -0
  10. package/esm/utilities/job_source.test.js +75 -0
  11. package/esm/utilities/shipment.js +22 -0
  12. package/esm/utilities/shipment.test.js +60 -0
  13. package/esm/utilities/test_checkout.js +25 -0
  14. package/esm/utilities/test_checkout.test.js +31 -0
  15. package/lib/CartProvider.js +58 -20
  16. package/lib/forms/FormShipmentAddressAndNotes.js +22 -1
  17. package/lib/stripe/LegacyStripeCardForm.js +10 -3
  18. package/lib/stripe/StripeCardForm.js +123 -17
  19. package/lib/stripe/actions.d.ts +2 -0
  20. package/lib/stripe/actions.js +157 -57
  21. package/lib/stripe/actions.test.d.ts +1 -0
  22. package/lib/utilities/cookie.d.ts +3 -3
  23. package/lib/utilities/cookie.js +15 -12
  24. package/lib/utilities/index.d.ts +2 -0
  25. package/lib/utilities/index.js +22 -0
  26. package/lib/utilities/job_source.d.ts +23 -0
  27. package/lib/utilities/job_source.js +152 -0
  28. package/lib/utilities/job_source.test.d.ts +1 -0
  29. package/lib/utilities/shipment.d.ts +15 -0
  30. package/lib/utilities/shipment.js +24 -0
  31. package/lib/utilities/shipment.test.d.ts +1 -0
  32. package/lib/utilities/test_checkout.d.ts +6 -0
  33. package/lib/utilities/test_checkout.js +34 -0
  34. package/lib/utilities/test_checkout.test.d.ts +1 -0
  35. package/package.json +8 -5
  36. package/src/CartProvider.tsx +42 -4
  37. package/src/forms/FormShipmentAddressAndNotes.tsx +34 -2
  38. package/src/stripe/LegacyStripeCardForm.tsx +9 -3
  39. package/src/stripe/StripeCardForm.tsx +92 -8
  40. package/src/stripe/actions.test.ts +50 -0
  41. package/src/stripe/actions.ts +41 -0
  42. package/src/utilities/cookie.ts +9 -6
  43. package/src/utilities/index.ts +2 -0
  44. package/src/utilities/job_source.test.ts +86 -0
  45. package/src/utilities/job_source.ts +165 -0
  46. package/src/utilities/shipment.test.ts +68 -0
  47. package/src/utilities/shipment.ts +34 -0
  48. package/src/utilities/test_checkout.test.ts +39 -0
  49. package/src/utilities/test_checkout.ts +27 -0
@@ -32,6 +32,8 @@ import { makeJob } from './utilities/job';
32
32
  import { makeProduct } from './utilities/product';
33
33
  import { getSavedCheckoutCustomer, saveCheckoutAddress } from './utilities/local_storage';
34
34
  import { makeUser } from './utilities/user';
35
+ import { persistTestCheckoutFlag, readTestCheckoutFlag } from './utilities/test_checkout';
36
+ import { appendJobSourceToFormData, captureAndReadJobSource, cartNeedsSourceUpdate, jobSourceFieldsForApi } from './utilities/job_source';
35
37
  import { jsx as _jsx } from "react/jsx-runtime";
36
38
  var CartContext = /*#__PURE__*/createContext({
37
39
  cart: {},
@@ -497,27 +499,36 @@ var CartProvider = function CartProvider(_ref) {
497
499
  }
498
500
  function _createCartAndCookie() {
499
501
  _createCartAndCookie = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(callback) {
500
- var _cart, cartJson, _t3;
502
+ var isTest, jobSource, _cart, query, created, cartJson, _t3;
501
503
  return _regenerator().w(function (_context2) {
502
504
  while (1) switch (_context2.p = _context2.n) {
503
505
  case 0:
504
506
  setFetchingCart(true);
505
507
  _context2.p = 1;
508
+ isTest = readTestCheckoutFlag();
509
+ jobSource = jobSourceFieldsForApi(captureAndReadJobSource());
506
510
  _cart = makeCart({
507
511
  domain: {
508
512
  id: domainId
509
- }
513
+ },
514
+ isTest: isTest
510
515
  }, true);
516
+ query = [['embed', JSON.stringify(cartEmbed)], ['skip_rights', 'y']];
517
+ if (isTest) query.push(['is_test', 'true']);
511
518
  _context2.n = 2;
512
- return _cart.create({
513
- embed: cartEmbed
519
+ return merchi.authenticatedFetch('/carts/', {
520
+ method: 'POST',
521
+ body: appendJobSourceToFormData(_cart.toFormData(), jobSource),
522
+ query: query
514
523
  });
515
524
  case 2:
525
+ created = _context2.v;
526
+ _cart.fromJson(created.cart);
516
527
  _context2.n = 3;
517
528
  return _cart.toJson();
518
529
  case 3:
519
530
  cartJson = _context2.v;
520
- if (domainId) setCartCookie(Number(domainId), cartJson, undefined);
531
+ if (domainId) setCartCookie(Number(domainId), cartJson, undefined, isTest);
521
532
  _context2.n = 4;
522
533
  return attachSavedClientIfNeeded(cartJson);
523
534
  case 4:
@@ -546,7 +557,7 @@ var CartProvider = function CartProvider(_ref) {
546
557
  }
547
558
  function _getCart() {
548
559
  _getCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(cartIdAndToken) {
549
- var id, _cart2, cartJson, _t4;
560
+ var id, _cart2, cartJson, isTest, jobSource, saved, _t4;
550
561
  return _regenerator().w(function (_context3) {
551
562
  while (1) switch (_context3.p = _context3.n) {
552
563
  case 0:
@@ -564,36 +575,62 @@ var CartProvider = function CartProvider(_ref) {
564
575
  return _cart2.toJson();
565
576
  case 3:
566
577
  cartJson = _context3.v;
567
- if (!stripeIsValidAndActive(cartJson)) {
578
+ isTest = readTestCheckoutFlag();
579
+ if (!(Boolean(cartJson.isTest) !== isTest)) {
568
580
  _context3.n = 5;
569
581
  break;
570
582
  }
571
583
  _context3.n = 4;
572
- return attachSavedClientIfNeeded(cartJson);
584
+ return createCartAndCookie();
573
585
  case 4:
586
+ return _context3.a(2);
587
+ case 5:
588
+ jobSource = jobSourceFieldsForApi(captureAndReadJobSource());
589
+ if (!cartNeedsSourceUpdate(cartJson, jobSource)) {
590
+ _context3.n = 7;
591
+ break;
592
+ }
593
+ _context3.n = 6;
594
+ return merchi.authenticatedFetch("/carts/".concat(_cart2.id, "/"), {
595
+ method: 'PATCH',
596
+ body: appendJobSourceToFormData(_cart2.toFormData(), jobSource),
597
+ query: [['embed', JSON.stringify(cartEmbed)], ['skip_rights', 'y']]
598
+ });
599
+ case 6:
600
+ saved = _context3.v;
601
+ _cart2.fromJson(saved.cart);
602
+ cartJson = _cart2.toJson();
603
+ case 7:
604
+ if (!(stripeIsValidAndActive(cartJson) || isTest)) {
605
+ _context3.n = 9;
606
+ break;
607
+ }
608
+ _context3.n = 8;
609
+ return attachSavedClientIfNeeded(cartJson);
610
+ case 8:
574
611
  cartJson = _context3.v;
575
612
  setCart(_objectSpread({}, cartJson));
576
- _context3.n = 6;
613
+ _context3.n = 10;
577
614
  break;
578
- case 5:
615
+ case 9:
579
616
  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.");
580
617
  setCartSettingsInvalid(true);
581
- case 6:
582
- _context3.n = 8;
618
+ case 10:
619
+ _context3.n = 12;
583
620
  break;
584
- case 7:
585
- _context3.p = 7;
621
+ case 11:
622
+ _context3.p = 11;
586
623
  _t4 = _context3.v;
587
- _context3.n = 8;
624
+ _context3.n = 12;
588
625
  return createCartAndCookie();
589
- case 8:
590
- _context3.p = 8;
626
+ case 12:
627
+ _context3.p = 12;
591
628
  setFetchingCart(false);
592
- return _context3.f(8);
593
- case 9:
629
+ return _context3.f(12);
630
+ case 13:
594
631
  return _context3.a(2);
595
632
  }
596
- }, _callee3, null, [[1, 7, 8, 9]]);
633
+ }, _callee3, null, [[1, 11, 12, 13]]);
597
634
  }));
598
635
  return _getCart.apply(this, arguments);
599
636
  }
@@ -956,6 +993,7 @@ var CartProvider = function CartProvider(_ref) {
956
993
  window.createCartAndCookie = createCartAndCookie;
957
994
  }
958
995
  useEffect(function () {
996
+ persistTestCheckoutFlag();
959
997
  if (domainId) actionGetMerchiCart();
960
998
  if (domainId && includeTheme) actionFetchTheme();
961
999
  }, [domainId]);
@@ -18,10 +18,10 @@ import { useForm } from "react-hook-form";
18
18
  import InputsAddress from "./InputsAddress";
19
19
  import { CheckoutContainer, InnerContainer } from "../components/containers";
20
20
  import { Title } from "../components";
21
- import { shipmentFormId } from "../utilities/shipment";
21
+ import { checkoutShipmentHydrationAction, shipmentFormId } from "../utilities/shipment";
22
22
  import { faMapMarkerAlt } from "@fortawesome/free-solid-svg-icons";
23
23
  import { useCartContext } from "../CartProvider";
24
- import { useState } from "react";
24
+ import { useEffect, useRef, useState } from "react";
25
25
  import { getCartCookieToken } from "../utilities/cookie";
26
26
  import { makeAddress, sanitizeAddressFields } from "../utilities/address";
27
27
  import { makeCart } from "../utilities/cart";
@@ -121,7 +121,9 @@ export function ActiveFormShipmentAddressAndNotes() {
121
121
  cart = _useCartContext2.cart,
122
122
  setCart = _useCartContext2.setCart,
123
123
  setLoadingTotals = _useCartContext2.setLoadingTotals,
124
- setActiveTabAndEditDisabled = _useCartContext2.setActiveTabAndEditDisabled;
124
+ setActiveTabAndEditDisabled = _useCartContext2.setActiveTabAndEditDisabled,
125
+ updateCartShipmentAddress = _useCartContext2.updateCartShipmentAddress,
126
+ getCartShipmentOptions = _useCartContext2.getCartShipmentOptions;
125
127
  var saved = getSavedCheckoutAddress(domainId);
126
128
  var cartAddress = cart === null || cart === void 0 ? void 0 : cart.receiverAddress;
127
129
  var receiverAddress = addressHasContent(cartAddress) ? cartAddress : saved.address || {};
@@ -130,6 +132,25 @@ export function ActiveFormShipmentAddressAndNotes() {
130
132
  _useState2 = _slicedToArray(_useState, 2),
131
133
  addressFieldsOpen = _useState2[0],
132
134
  setAddressFieldsOpen = _useState2[1];
135
+ var hydratedShipmentOptionsRef = useRef(false);
136
+ useEffect(function () {
137
+ if (hydratedShipmentOptionsRef.current || !(cart !== null && cart !== void 0 && cart.id)) return;
138
+ var draft = getSavedCheckoutAddress(domainId);
139
+ var action = checkoutShipmentHydrationAction({
140
+ cartAddress: cart === null || cart === void 0 ? void 0 : cart.receiverAddress,
141
+ savedAddress: draft.address,
142
+ shipmentGroups: cart === null || cart === void 0 ? void 0 : cart.shipmentGroups
143
+ });
144
+ if (!action) return;
145
+ hydratedShipmentOptionsRef.current = true;
146
+ if (action === "apply-saved-address" && draft.address) {
147
+ updateCartShipmentAddress(draft.address);
148
+ return;
149
+ }
150
+ if (action === "refresh-quotes") {
151
+ getCartShipmentOptions === null || getCartShipmentOptions === void 0 || getCartShipmentOptions();
152
+ }
153
+ }, [cart === null || cart === void 0 ? void 0 : cart.id, cart === null || cart === void 0 ? void 0 : cart.receiverAddress, cart === null || cart === void 0 ? void 0 : cart.shipmentGroups, domainId, getCartShipmentOptions, updateCartShipmentAddress]);
133
154
  function saveCartShipmentAddressAndGoToNextTab(_x) {
134
155
  return _saveCartShipmentAddressAndGoToNextTab.apply(this, arguments);
135
156
  }
@@ -12,7 +12,7 @@ import * as React from 'react';
12
12
  import { useEffect, useState } from 'react';
13
13
  import { ButtonPay } from '../buttons';
14
14
  import FormStripeCardFields from './StripeCardFields';
15
- import { stripeCardFormSubmit, stripeInitPromise, stripePaymentButtonSubmit } from './actions';
15
+ import { fetchTestPublishableKey, stripeCardFormSubmit, stripeInitPromise, stripePaymentButtonSubmit } from './actions';
16
16
  import { companyStripePubKeyOrTestPubKey } from './utils';
17
17
  import { useCartContext } from '../CartProvider';
18
18
  import { tabIdPaymentSuccess } from '../utilities/tabs';
@@ -47,6 +47,7 @@ function StripeCardForm() {
47
47
  error = _useState2[0],
48
48
  setError = _useState2[1];
49
49
  var company = domain.company;
50
+ var isTestCheckout = Boolean(cart.isTest);
50
51
  var hasCompanyPubKey = Boolean(company.isStripeValid && companyStripePubKeyOrTestPubKey(company));
51
52
  var companyPubKey = hasCompanyPubKey ? companyStripePubKeyOrTestPubKey(company) : '';
52
53
  var canUseConnect = !!company.stripeAccountId;
@@ -133,15 +134,21 @@ function StripeCardForm() {
133
134
  }));
134
135
  return _doStripePaymentRequestForButton.apply(this, arguments);
135
136
  }
136
- var _useState7 = useState(companyPubKey),
137
+ var _useState7 = useState(isTestCheckout ? '' : companyPubKey),
137
138
  _useState8 = _slicedToArray(_useState7, 2),
138
139
  stripePublicKey = _useState8[0],
139
140
  setStripePublicKey = _useState8[1];
140
141
  useEffect(function () {
142
+ if (isTestCheckout) {
143
+ fetchTestPublishableKey(url).then(setStripePublicKey)["catch"](function () {
144
+ return setStripePublicKey('');
145
+ });
146
+ return;
147
+ }
141
148
  if (!stripePublicKey && canUseConnect) stripeInitPromise(url).then(setStripePublicKey);
142
- }, [stripePublicKey, canUseConnect]);
149
+ }, [stripePublicKey, canUseConnect, isTestCheckout, url]);
143
150
  return /*#__PURE__*/_jsxs(_Fragment, {
144
- children: [company.isTesting && badgeTestMode, /*#__PURE__*/_jsx(FormStripeCardFields, {
151
+ children: [!isTestCheckout && company.isTesting && badgeTestMode, /*#__PURE__*/_jsx(FormStripeCardFields, {
145
152
  doStripePayment: doStripePayment,
146
153
  doStripePaymentRequestForButton: doStripePaymentRequestForButton,
147
154
  cart: cart,
@@ -1,33 +1,139 @@
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
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
8
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
1
11
  import * as React from 'react';
12
+ import { useEffect, useState } from 'react';
2
13
  import { StripePaymentForm, StripePaymentGate } from '@merchi/invoice';
3
14
  import LegacyStripeCardForm from './LegacyStripeCardForm';
15
+ import { completeTestPayment, fetchTestPublishableKey } from './actions';
4
16
  import { useCartContext } from '../CartProvider';
5
17
  import { tabIdPaymentSuccess } from '../utilities/tabs';
6
- import { jsx as _jsx } from "react/jsx-runtime";
18
+ import { TEST_CARD_NUMBER } from '../utilities/test_checkout';
19
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
20
+ var testCheckoutHint = /*#__PURE__*/_jsxs("div", {
21
+ style: {
22
+ marginBottom: '12px'
23
+ },
24
+ children: [/*#__PURE__*/_jsx("div", {
25
+ style: {
26
+ color: 'red',
27
+ fontWeight: 600
28
+ },
29
+ children: "Test checkout"
30
+ }), /*#__PURE__*/_jsxs("p", {
31
+ style: {
32
+ margin: '4px 0 0',
33
+ fontSize: '13px'
34
+ },
35
+ children: ["No real charge. Use card ", TEST_CARD_NUMBER, ", any future expiry, any CVC, any ZIP."]
36
+ })]
37
+ });
7
38
  export default function StripeCardForm() {
8
39
  var _useCartContext = useCartContext(),
9
40
  alertError = _useCartContext.alertError,
10
41
  apiUrl = _useCartContext.apiUrl,
11
42
  cart = _useCartContext.cart,
43
+ classNameBtnPay = _useCartContext.classNameBtnPay,
12
44
  setActiveTabIndex = _useCartContext.setActiveTabIndex,
13
45
  setInvoiceJson = _useCartContext.setInvoiceJson;
14
- return /*#__PURE__*/_jsx(StripePaymentGate, {
15
- engine: cart.stripePaymentEngine,
16
- apiUrl: apiUrl || 'https://api.merchi.co/v6/',
17
- resource: "cart",
18
- resourceId: cart.id,
19
- resourceToken: cart.token || cart.cartToken,
20
- legacy: /*#__PURE__*/_jsx(LegacyStripeCardForm, {}),
21
- children: /*#__PURE__*/_jsx(StripePaymentForm, {
22
- apiUrl: apiUrl || 'https://api.merchi.co/v6/',
46
+ var isTestCheckout = Boolean(cart.isTest);
47
+ var url = apiUrl || 'https://api.merchi.co/v6/';
48
+ var _useState = useState(false),
49
+ _useState2 = _slicedToArray(_useState, 2),
50
+ testKeyMissing = _useState2[0],
51
+ setTestKeyMissing = _useState2[1];
52
+ var _useState3 = useState(false),
53
+ _useState4 = _slicedToArray(_useState3, 2),
54
+ loadingTestPayment = _useState4[0],
55
+ setLoadingTestPayment = _useState4[1];
56
+ useEffect(function () {
57
+ if (!isTestCheckout) {
58
+ setTestKeyMissing(false);
59
+ return;
60
+ }
61
+ fetchTestPublishableKey(url).then(function () {
62
+ return setTestKeyMissing(false);
63
+ })["catch"](function () {
64
+ return setTestKeyMissing(true);
65
+ });
66
+ }, [isTestCheckout, url]);
67
+ function doCompleteTestPayment() {
68
+ return _doCompleteTestPayment.apply(this, arguments);
69
+ }
70
+ function _doCompleteTestPayment() {
71
+ _doCompleteTestPayment = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
72
+ var invoice, _t;
73
+ return _regenerator().w(function (_context) {
74
+ while (1) switch (_context.p = _context.n) {
75
+ case 0:
76
+ setLoadingTestPayment(true);
77
+ _context.p = 1;
78
+ _context.n = 2;
79
+ return completeTestPayment(url, cart);
80
+ case 2:
81
+ invoice = _context.v;
82
+ setInvoiceJson(invoice);
83
+ setActiveTabIndex(tabIdPaymentSuccess);
84
+ _context.n = 4;
85
+ break;
86
+ case 3:
87
+ _context.p = 3;
88
+ _t = _context.v;
89
+ alertError(_t.message);
90
+ case 4:
91
+ _context.p = 4;
92
+ setLoadingTestPayment(false);
93
+ return _context.f(4);
94
+ case 5:
95
+ return _context.a(2);
96
+ }
97
+ }, _callee, null, [[1, 3, 4, 5]]);
98
+ }));
99
+ return _doCompleteTestPayment.apply(this, arguments);
100
+ }
101
+ if (isTestCheckout && testKeyMissing) {
102
+ return /*#__PURE__*/_jsxs(_Fragment, {
103
+ children: [testCheckoutHint, /*#__PURE__*/_jsx("p", {
104
+ style: {
105
+ fontSize: '13px',
106
+ marginBottom: '12px'
107
+ },
108
+ children: "Stripe test keys are not configured. Complete this as a test order without a card."
109
+ }), /*#__PURE__*/_jsx("button", {
110
+ type: "button",
111
+ className: classNameBtnPay,
112
+ disabled: loadingTestPayment,
113
+ onClick: doCompleteTestPayment,
114
+ children: loadingTestPayment ? 'Completing…' : 'Complete test order'
115
+ })]
116
+ });
117
+ }
118
+ return /*#__PURE__*/_jsxs(_Fragment, {
119
+ children: [isTestCheckout && testCheckoutHint, /*#__PURE__*/_jsx(StripePaymentGate, {
120
+ engine: isTestCheckout ? 'legacy' : cart.stripePaymentEngine,
121
+ apiUrl: url,
23
122
  resource: "cart",
24
123
  resourceId: cart.id,
25
124
  resourceToken: cart.token || cart.cartToken,
26
- onError: alertError,
27
- onSuccess: function onSuccess(invoice) {
28
- setInvoiceJson(invoice);
29
- setActiveTabIndex(tabIdPaymentSuccess);
30
- }
31
- })
125
+ legacy: /*#__PURE__*/_jsx(LegacyStripeCardForm, {}),
126
+ children: /*#__PURE__*/_jsx(StripePaymentForm, {
127
+ apiUrl: url,
128
+ resource: "cart",
129
+ resourceId: cart.id,
130
+ resourceToken: cart.token || cart.cartToken,
131
+ onError: alertError,
132
+ onSuccess: function onSuccess(invoice) {
133
+ setInvoiceJson(invoice);
134
+ setActiveTabIndex(tabIdPaymentSuccess);
135
+ }
136
+ })
137
+ })]
32
138
  });
33
139
  }