@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
@@ -24,14 +24,112 @@ function _stripeInitPromise() {
24
24
  }));
25
25
  return _stripeInitPromise.apply(this, arguments);
26
26
  }
27
- function createPaymentIntent(_x2, _x3, _x4) {
27
+ export function fetchTestPublishableKey(_x2) {
28
+ return _fetchTestPublishableKey.apply(this, arguments);
29
+ }
30
+ function _fetchTestPublishableKey() {
31
+ _fetchTestPublishableKey = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(apiUrl) {
32
+ var response, data;
33
+ return _regenerator().w(function (_context2) {
34
+ while (1) switch (_context2.n) {
35
+ case 0:
36
+ _context2.n = 1;
37
+ return fetch("".concat(apiUrl, "stripe/test_publishable_key/"), {
38
+ method: 'GET',
39
+ mode: 'cors'
40
+ });
41
+ case 1:
42
+ response = _context2.v;
43
+ if (!(response && typeof response.json === 'function')) {
44
+ _context2.n = 5;
45
+ break;
46
+ }
47
+ if (response.ok) {
48
+ _context2.n = 2;
49
+ break;
50
+ }
51
+ throw new Error('Stripe test keys are not configured');
52
+ case 2:
53
+ _context2.n = 3;
54
+ return response.json();
55
+ case 3:
56
+ data = _context2.v;
57
+ if (!(!data || !data.key)) {
58
+ _context2.n = 4;
59
+ break;
60
+ }
61
+ throw new Error('Stripe test keys are not configured');
62
+ case 4:
63
+ return _context2.a(2, data.key);
64
+ case 5:
65
+ if (!(!response || !response.key)) {
66
+ _context2.n = 6;
67
+ break;
68
+ }
69
+ throw new Error('Stripe test keys are not configured');
70
+ case 6:
71
+ return _context2.a(2, response.key);
72
+ }
73
+ }, _callee2);
74
+ }));
75
+ return _fetchTestPublishableKey.apply(this, arguments);
76
+ }
77
+ export function completeTestPayment(_x3, _x4) {
78
+ return _completeTestPayment.apply(this, arguments);
79
+ }
80
+ function _completeTestPayment() {
81
+ _completeTestPayment = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(apiUrl, cart) {
82
+ var query, response, message, _data, data, _t;
83
+ return _regenerator().w(function (_context3) {
84
+ while (1) switch (_context3.p = _context3.n) {
85
+ case 0:
86
+ query = new URLSearchParams({
87
+ cart_token: cart.token
88
+ }).toString();
89
+ _context3.n = 1;
90
+ return fetch("".concat(apiUrl, "carts/").concat(cart.id, "/complete_test_payment/?").concat(query), {
91
+ method: 'POST',
92
+ mode: 'cors'
93
+ });
94
+ case 1:
95
+ response = _context3.v;
96
+ if (response.ok) {
97
+ _context3.n = 6;
98
+ break;
99
+ }
100
+ message = 'Unable to complete the test order.';
101
+ _context3.p = 2;
102
+ _context3.n = 3;
103
+ return response.json();
104
+ case 3:
105
+ _data = _context3.v;
106
+ message = _data.message || _data.errorMessage || message;
107
+ _context3.n = 5;
108
+ break;
109
+ case 4:
110
+ _context3.p = 4;
111
+ _t = _context3.v;
112
+ case 5:
113
+ throw new Error(message);
114
+ case 6:
115
+ _context3.n = 7;
116
+ return response.json();
117
+ case 7:
118
+ data = _context3.v;
119
+ return _context3.a(2, data.invoice);
120
+ }
121
+ }, _callee3, null, [[2, 4]]);
122
+ }));
123
+ return _completeTestPayment.apply(this, arguments);
124
+ }
125
+ function createPaymentIntent(_x5, _x6, _x7) {
28
126
  return _createPaymentIntent.apply(this, arguments);
29
127
  }
30
128
  function _createPaymentIntent() {
31
- _createPaymentIntent = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(apiUrl, cart, paymentMethodType) {
129
+ _createPaymentIntent = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(apiUrl, cart, paymentMethodType) {
32
130
  var id, token, fetchOptions, queryParams, queryString, uri, url, response;
33
- return _regenerator().w(function (_context2) {
34
- while (1) switch (_context2.n) {
131
+ return _regenerator().w(function (_context4) {
132
+ while (1) switch (_context4.n) {
35
133
  case 0:
36
134
  id = cart.id, token = cart.token;
37
135
  fetchOptions = {
@@ -45,33 +143,33 @@ function _createPaymentIntent() {
45
143
  queryString = new URLSearchParams(queryParams).toString();
46
144
  uri = "stripe/payment_intent/cart/".concat(id, "/");
47
145
  url = "".concat(apiUrl).concat(uri, "?").concat(queryString);
48
- _context2.n = 1;
146
+ _context4.n = 1;
49
147
  return fetch(url, fetchOptions);
50
148
  case 1:
51
- response = _context2.v;
149
+ response = _context4.v;
52
150
  if (response.ok) {
53
- _context2.n = 2;
151
+ _context4.n = 2;
54
152
  break;
55
153
  }
56
154
  throw new Error("Failed to create payment intent.");
57
155
  case 2:
58
- _context2.n = 3;
156
+ _context4.n = 3;
59
157
  return response.json();
60
158
  case 3:
61
- return _context2.a(2, _context2.v);
159
+ return _context4.a(2, _context4.v);
62
160
  }
63
- }, _callee2);
161
+ }, _callee4);
64
162
  }));
65
163
  return _createPaymentIntent.apply(this, arguments);
66
164
  }
67
- function checkPaymentIntnetIsComplete(_x5, _x6) {
165
+ function checkPaymentIntnetIsComplete(_x8, _x9) {
68
166
  return _checkPaymentIntnetIsComplete.apply(this, arguments);
69
167
  }
70
168
  function _checkPaymentIntnetIsComplete() {
71
- _checkPaymentIntnetIsComplete = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(apiUrl, cart) {
169
+ _checkPaymentIntnetIsComplete = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(apiUrl, cart) {
72
170
  var url, fetchOptions, queryString, response, i;
73
- return _regenerator().w(function (_context3) {
74
- while (1) switch (_context3.n) {
171
+ return _regenerator().w(function (_context5) {
172
+ while (1) switch (_context5.n) {
75
173
  case 0:
76
174
  url = "stripe/payment_intent/cart/complete/".concat(cart.id, "/");
77
175
  fetchOptions = {
@@ -81,112 +179,112 @@ function _checkPaymentIntnetIsComplete() {
81
179
  queryString = new URLSearchParams({
82
180
  cart_token: cart.token
83
181
  }).toString();
84
- _context3.n = 1;
182
+ _context5.n = 1;
85
183
  return fetch("".concat(apiUrl).concat(url, "?").concat(queryString), fetchOptions);
86
184
  case 1:
87
- response = _context3.v;
185
+ response = _context5.v;
88
186
  if (response.ok) {
89
- _context3.n = 2;
187
+ _context5.n = 2;
90
188
  break;
91
189
  }
92
190
  throw new Error("Failed to check if payment intent is complete.");
93
191
  case 2:
94
- _context3.n = 3;
192
+ _context5.n = 3;
95
193
  return response.json();
96
194
  case 3:
97
- i = _context3.v;
98
- return _context3.a(2, i.invoice);
195
+ i = _context5.v;
196
+ return _context5.a(2, i.invoice);
99
197
  }
100
- }, _callee3);
198
+ }, _callee5);
101
199
  }));
102
200
  return _checkPaymentIntnetIsComplete.apply(this, arguments);
103
201
  }
104
- export function stripeCardFormSubmit(_x7, _x8, _x9, _x0) {
202
+ export function stripeCardFormSubmit(_x0, _x1, _x10, _x11) {
105
203
  return _stripeCardFormSubmit.apply(this, arguments);
106
204
  }
107
205
  function _stripeCardFormSubmit() {
108
- _stripeCardFormSubmit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(apiUrl, stripe, card, cart) {
109
- var intent, stripePayment, _t;
110
- return _regenerator().w(function (_context4) {
111
- while (1) switch (_context4.p = _context4.n) {
206
+ _stripeCardFormSubmit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(apiUrl, stripe, card, cart) {
207
+ var intent, stripePayment, _t2;
208
+ return _regenerator().w(function (_context6) {
209
+ while (1) switch (_context6.p = _context6.n) {
112
210
  case 0:
113
- _context4.p = 0;
114
- _context4.n = 1;
211
+ _context6.p = 0;
212
+ _context6.n = 1;
115
213
  return createPaymentIntent(apiUrl, cart);
116
214
  case 1:
117
- intent = _context4.v;
118
- _context4.n = 2;
215
+ intent = _context6.v;
216
+ _context6.n = 2;
119
217
  return stripe.confirmCardPayment(intent.stripeClientSecret, {
120
218
  payment_method: {
121
219
  card: card
122
220
  }
123
221
  });
124
222
  case 2:
125
- stripePayment = _context4.v;
223
+ stripePayment = _context6.v;
126
224
  if (!stripePayment.error) {
127
- _context4.n = 3;
225
+ _context6.n = 3;
128
226
  break;
129
227
  }
130
228
  throw new Error(stripePayment.error.message || 'Stripe connect unknown error');
131
229
  case 3:
132
- _context4.n = 4;
230
+ _context6.n = 4;
133
231
  return checkPaymentIntnetIsComplete(apiUrl, cart);
134
232
  case 4:
135
- return _context4.a(2, _context4.v);
233
+ return _context6.a(2, _context6.v);
136
234
  case 5:
137
- _context4.p = 5;
138
- _t = _context4.v;
139
- throw _t;
235
+ _context6.p = 5;
236
+ _t2 = _context6.v;
237
+ throw _t2;
140
238
  case 6:
141
- return _context4.a(2);
239
+ return _context6.a(2);
142
240
  }
143
- }, _callee4, null, [[0, 5]]);
241
+ }, _callee6, null, [[0, 5]]);
144
242
  }));
145
243
  return _stripeCardFormSubmit.apply(this, arguments);
146
244
  }
147
- export function stripePaymentButtonSubmit(_x1, _x10, _x11, _x12) {
245
+ export function stripePaymentButtonSubmit(_x12, _x13, _x14, _x15) {
148
246
  return _stripePaymentButtonSubmit.apply(this, arguments);
149
247
  }
150
248
  function _stripePaymentButtonSubmit() {
151
- _stripePaymentButtonSubmit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(apiUrl, stripe, cart, paymentMethodEvent) {
152
- var complete, paymentMethod, intent, stripePayment, _t2;
153
- return _regenerator().w(function (_context5) {
154
- while (1) switch (_context5.p = _context5.n) {
249
+ _stripePaymentButtonSubmit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(apiUrl, stripe, cart, paymentMethodEvent) {
250
+ var complete, paymentMethod, intent, stripePayment, _t3;
251
+ return _regenerator().w(function (_context7) {
252
+ while (1) switch (_context7.p = _context7.n) {
155
253
  case 0:
156
254
  complete = paymentMethodEvent.complete, paymentMethod = paymentMethodEvent.paymentMethod;
157
- _context5.p = 1;
158
- _context5.n = 2;
255
+ _context7.p = 1;
256
+ _context7.n = 2;
159
257
  return createPaymentIntent(apiUrl, cart);
160
258
  case 2:
161
- intent = _context5.v;
162
- _context5.n = 3;
259
+ intent = _context7.v;
260
+ _context7.n = 3;
163
261
  return stripe.confirmCardPayment(intent.stripeClientSecret, {
164
262
  payment_method: paymentMethod.id
165
263
  }, {
166
264
  handleActions: false
167
265
  });
168
266
  case 3:
169
- stripePayment = _context5.v;
267
+ stripePayment = _context7.v;
170
268
  if (!stripePayment.error) {
171
- _context5.n = 4;
269
+ _context7.n = 4;
172
270
  break;
173
271
  }
174
272
  throw new Error(stripePayment.error.message || 'Stripe unknown error');
175
273
  case 4:
176
274
  complete('success');
177
- _context5.n = 5;
275
+ _context7.n = 5;
178
276
  return checkPaymentIntnetIsComplete(apiUrl, cart);
179
277
  case 5:
180
- return _context5.a(2, _context5.v);
278
+ return _context7.a(2, _context7.v);
181
279
  case 6:
182
- _context5.p = 6;
183
- _t2 = _context5.v;
280
+ _context7.p = 6;
281
+ _t3 = _context7.v;
184
282
  complete('fail');
185
- throw _t2;
283
+ throw _t3;
186
284
  case 7:
187
- return _context5.a(2);
285
+ return _context7.a(2);
188
286
  }
189
- }, _callee5, null, [[1, 6]]);
287
+ }, _callee7, null, [[1, 6]]);
190
288
  }));
191
289
  return _stripePaymentButtonSubmit.apply(this, arguments);
192
290
  }
@@ -0,0 +1,120 @@
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 { completeTestPayment, fetchTestPublishableKey } from './actions';
6
+ describe('test checkout stripe actions', function () {
7
+ var originalFetch = global.fetch;
8
+ afterEach(function () {
9
+ global.fetch = originalFetch;
10
+ });
11
+ it('loads the master test publishable key', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
12
+ return _regenerator().w(function (_context2) {
13
+ while (1) switch (_context2.n) {
14
+ case 0:
15
+ global.fetch = jest.fn().mockResolvedValue({
16
+ ok: true,
17
+ json: function () {
18
+ var _json = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
19
+ return _regenerator().w(function (_context) {
20
+ while (1) switch (_context.n) {
21
+ case 0:
22
+ return _context.a(2, {
23
+ key: 'pk_test_master'
24
+ });
25
+ }
26
+ }, _callee);
27
+ }));
28
+ function json() {
29
+ return _json.apply(this, arguments);
30
+ }
31
+ return json;
32
+ }()
33
+ });
34
+ _context2.n = 1;
35
+ return expect(fetchTestPublishableKey('https://api.test/v6/')).resolves.toBe('pk_test_master');
36
+ case 1:
37
+ expect(global.fetch).toHaveBeenCalledWith('https://api.test/v6/stripe/test_publishable_key/', {
38
+ method: 'GET',
39
+ mode: 'cors'
40
+ });
41
+ case 2:
42
+ return _context2.a(2);
43
+ }
44
+ }, _callee2);
45
+ })));
46
+ it('fails over when the test-key request is rejected', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
47
+ return _regenerator().w(function (_context4) {
48
+ while (1) switch (_context4.n) {
49
+ case 0:
50
+ global.fetch = jest.fn().mockResolvedValue({
51
+ ok: false,
52
+ json: function () {
53
+ var _json2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
54
+ return _regenerator().w(function (_context3) {
55
+ while (1) switch (_context3.n) {
56
+ case 0:
57
+ return _context3.a(2, {
58
+ message: 'missing'
59
+ });
60
+ }
61
+ }, _callee3);
62
+ }));
63
+ function json() {
64
+ return _json2.apply(this, arguments);
65
+ }
66
+ return json;
67
+ }()
68
+ });
69
+ _context4.n = 1;
70
+ return expect(fetchTestPublishableKey('https://api.test/v6/')).rejects.toThrow('Stripe test keys are not configured');
71
+ case 1:
72
+ return _context4.a(2);
73
+ }
74
+ }, _callee4);
75
+ })));
76
+ it('completes a no-Stripe test payment with the cart token', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
77
+ return _regenerator().w(function (_context6) {
78
+ while (1) switch (_context6.n) {
79
+ case 0:
80
+ global.fetch = jest.fn().mockResolvedValue({
81
+ ok: true,
82
+ json: function () {
83
+ var _json3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
84
+ return _regenerator().w(function (_context5) {
85
+ while (1) switch (_context5.n) {
86
+ case 0:
87
+ return _context5.a(2, {
88
+ invoice: {
89
+ id: 9,
90
+ isTest: true
91
+ }
92
+ });
93
+ }
94
+ }, _callee5);
95
+ }));
96
+ function json() {
97
+ return _json3.apply(this, arguments);
98
+ }
99
+ return json;
100
+ }()
101
+ });
102
+ _context6.n = 1;
103
+ return expect(completeTestPayment('https://api.test/v6/', {
104
+ id: 4,
105
+ token: 'tok'
106
+ })).resolves.toEqual({
107
+ id: 9,
108
+ isTest: true
109
+ });
110
+ case 1:
111
+ expect(global.fetch).toHaveBeenCalledWith('https://api.test/v6/carts/4/complete_test_payment/?cart_token=tok', {
112
+ method: 'POST',
113
+ mode: 'cors'
114
+ });
115
+ case 2:
116
+ return _context6.a(2);
117
+ }
118
+ }, _callee6);
119
+ })));
120
+ });
@@ -3,6 +3,7 @@ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try {
3
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
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
5
  import { isBrowser } from "browser-or-node";
6
+ import { cartCookieName, readTestCheckoutFlag } from "./test_checkout";
6
7
  export function getCookie(_x, _x2) {
7
8
  return _getCookie.apply(this, arguments);
8
9
  }
@@ -52,17 +53,18 @@ function _getCookie() {
52
53
  }));
53
54
  return _getCookie.apply(this, arguments);
54
55
  }
55
- export function getCartCookie(_x3) {
56
+ export function getCartCookie(_x3, _x4) {
56
57
  return _getCartCookie.apply(this, arguments);
57
58
  }
58
59
  function _getCartCookie() {
59
- _getCartCookie = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(domainId) {
60
- var idAndToken;
60
+ _getCartCookie = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(domainId, isTest) {
61
+ var test, idAndToken;
61
62
  return _regenerator().w(function (_context3) {
62
63
  while (1) switch (_context3.n) {
63
64
  case 0:
65
+ test = isTest !== null && isTest !== void 0 ? isTest : readTestCheckoutFlag();
64
66
  _context3.n = 1;
65
- return getCookie("cart-".concat(domainId), null);
67
+ return getCookie(cartCookieName(domainId, test), null);
66
68
  case 1:
67
69
  idAndToken = _context3.v;
68
70
  return _context3.a(2, idAndToken ? idAndToken.split(',') : null);
@@ -71,11 +73,11 @@ function _getCartCookie() {
71
73
  }));
72
74
  return _getCartCookie.apply(this, arguments);
73
75
  }
74
- export function getCartCookieToken(_x4) {
76
+ export function getCartCookieToken(_x5, _x6) {
75
77
  return _getCartCookieToken.apply(this, arguments);
76
78
  }
77
79
  function _getCartCookieToken() {
78
- _getCartCookieToken = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(domainId) {
80
+ _getCartCookieToken = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(domainId, isTest) {
79
81
  var cartIdAndToken, _t;
80
82
  return _regenerator().w(function (_context4) {
81
83
  while (1) switch (_context4.n) {
@@ -85,7 +87,7 @@ function _getCartCookieToken() {
85
87
  break;
86
88
  }
87
89
  _context4.n = 1;
88
- return getCartCookie(Number(domainId));
90
+ return getCartCookie(Number(domainId), isTest);
89
91
  case 1:
90
92
  _t = _context4.v;
91
93
  _context4.n = 3;
@@ -100,7 +102,7 @@ function _getCartCookieToken() {
100
102
  }));
101
103
  return _getCartCookieToken.apply(this, arguments);
102
104
  }
103
- function setSessionCookie(_x5, _x6, _x7) {
105
+ function setSessionCookie(_x7, _x8, _x9) {
104
106
  return _setSessionCookie.apply(this, arguments);
105
107
  }
106
108
  function _setSessionCookie() {
@@ -137,20 +139,21 @@ function _setSessionCookie() {
137
139
  return _setSessionCookie.apply(this, arguments);
138
140
  }
139
141
  export var setCartCookie = /*#__PURE__*/function () {
140
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(storeId, cart, domain) {
141
- var cookieValue;
142
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(storeId, cart, domain, isTest) {
143
+ var test, cookieValue;
142
144
  return _regenerator().w(function (_context) {
143
145
  while (1) switch (_context.n) {
144
146
  case 0:
147
+ test = isTest !== null && isTest !== void 0 ? isTest : cart ? Boolean(cart.isTest) : readTestCheckoutFlag();
145
148
  cookieValue = cart ? cart.id + ',' + cart.token : '';
146
149
  _context.n = 1;
147
- return setSessionCookie('cart-' + String(storeId), cookieValue, domain);
150
+ return setSessionCookie(cartCookieName(storeId, test), cookieValue, domain);
148
151
  case 1:
149
152
  return _context.a(2);
150
153
  }
151
154
  }, _callee);
152
155
  }));
153
- return function setCartCookie(_x8, _x9, _x0) {
156
+ return function setCartCookie(_x0, _x1, _x10, _x11) {
154
157
  return _ref.apply(this, arguments);
155
158
  };
156
159
  }();
@@ -6,9 +6,11 @@ export * from './currency';
6
6
  export * from './helpers';
7
7
  export * from './invoice';
8
8
  export * from './job';
9
+ export * from './job_source';
9
10
  export * from './local_storage';
10
11
  export * from './product';
11
12
  export * from './shipment';
12
13
  export * from './tabs';
14
+ export * from './test_checkout';
13
15
  export * from './user';
14
16
  export * from './variations';