@merchi/cart 1.4.70 → 1.4.71
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/stripe/actions.js +112 -72
- package/lib/stripe/actions.js +112 -72
- package/package.json +2 -2
- package/src/stripe/actions.ts +20 -5
package/esm/stripe/actions.js
CHANGED
|
@@ -163,20 +163,48 @@ function _createPaymentIntent() {
|
|
|
163
163
|
}));
|
|
164
164
|
return _createPaymentIntent.apply(this, arguments);
|
|
165
165
|
}
|
|
166
|
-
function
|
|
167
|
-
return
|
|
166
|
+
function completeZeroBalanceCheckoutLegacy(_x8, _x9) {
|
|
167
|
+
return _completeZeroBalanceCheckoutLegacy.apply(this, arguments);
|
|
168
168
|
}
|
|
169
|
-
function
|
|
170
|
-
|
|
171
|
-
var
|
|
169
|
+
function _completeZeroBalanceCheckoutLegacy() {
|
|
170
|
+
_completeZeroBalanceCheckoutLegacy = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(apiUrl, cart) {
|
|
171
|
+
var intent;
|
|
172
172
|
return _regenerator().w(function (_context5) {
|
|
173
173
|
while (1) switch (_context5.n) {
|
|
174
|
+
case 0:
|
|
175
|
+
_context5.n = 1;
|
|
176
|
+
return createPaymentIntent(apiUrl, cart);
|
|
177
|
+
case 1:
|
|
178
|
+
intent = _context5.v;
|
|
179
|
+
if (intent.zeroBalance) {
|
|
180
|
+
_context5.n = 2;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
throw new Error('Unable to complete this order.');
|
|
184
|
+
case 2:
|
|
185
|
+
_context5.n = 3;
|
|
186
|
+
return checkPaymentIntnetIsComplete(apiUrl, cart);
|
|
187
|
+
case 3:
|
|
188
|
+
return _context5.a(2, _context5.v);
|
|
189
|
+
}
|
|
190
|
+
}, _callee5);
|
|
191
|
+
}));
|
|
192
|
+
return _completeZeroBalanceCheckoutLegacy.apply(this, arguments);
|
|
193
|
+
}
|
|
194
|
+
function completeZeroBalanceCheckout(_x0, _x1) {
|
|
195
|
+
return _completeZeroBalanceCheckout.apply(this, arguments);
|
|
196
|
+
}
|
|
197
|
+
function _completeZeroBalanceCheckout() {
|
|
198
|
+
_completeZeroBalanceCheckout = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(apiUrl, cart) {
|
|
199
|
+
var url, query, response, data, message;
|
|
200
|
+
return _regenerator().w(function (_context6) {
|
|
201
|
+
while (1) switch (_context6.n) {
|
|
174
202
|
case 0:
|
|
175
203
|
url = "".concat(apiUrl.replace(/\/$/, ''), "/payments/stripe/cart/").concat(cart.id, "/attempts/");
|
|
176
204
|
query = new URLSearchParams({
|
|
177
205
|
cart_token: cart.token
|
|
178
206
|
}).toString();
|
|
179
|
-
|
|
207
|
+
_context6.n = 1;
|
|
180
208
|
return fetch("".concat(url, "?").concat(query), {
|
|
181
209
|
method: 'POST',
|
|
182
210
|
mode: 'cors',
|
|
@@ -188,37 +216,49 @@ function _completeZeroBalanceCheckout() {
|
|
|
188
216
|
})
|
|
189
217
|
});
|
|
190
218
|
case 1:
|
|
191
|
-
response =
|
|
192
|
-
|
|
219
|
+
response = _context6.v;
|
|
220
|
+
_context6.n = 2;
|
|
193
221
|
return response.json();
|
|
194
222
|
case 2:
|
|
195
|
-
data =
|
|
196
|
-
if (response.ok) {
|
|
197
|
-
|
|
223
|
+
data = _context6.v;
|
|
224
|
+
if (!(response.ok && data.invoice)) {
|
|
225
|
+
_context6.n = 3;
|
|
198
226
|
break;
|
|
199
227
|
}
|
|
200
|
-
|
|
228
|
+
return _context6.a(2, data.invoice);
|
|
201
229
|
case 3:
|
|
202
|
-
|
|
203
|
-
|
|
230
|
+
message = data.message || '';
|
|
231
|
+
if (!(response.status === 409 && message.toLowerCase().includes('new payment flow is disabled'))) {
|
|
232
|
+
_context6.n = 5;
|
|
204
233
|
break;
|
|
205
234
|
}
|
|
206
|
-
|
|
235
|
+
_context6.n = 4;
|
|
236
|
+
return completeZeroBalanceCheckoutLegacy(apiUrl, cart);
|
|
207
237
|
case 4:
|
|
208
|
-
return
|
|
238
|
+
return _context6.a(2, _context6.v);
|
|
239
|
+
case 5:
|
|
240
|
+
if (response.ok) {
|
|
241
|
+
_context6.n = 6;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
throw new Error(message || 'Unable to complete this order.');
|
|
245
|
+
case 6:
|
|
246
|
+
throw new Error('Unable to complete this order.');
|
|
247
|
+
case 7:
|
|
248
|
+
return _context6.a(2);
|
|
209
249
|
}
|
|
210
|
-
},
|
|
250
|
+
}, _callee6);
|
|
211
251
|
}));
|
|
212
252
|
return _completeZeroBalanceCheckout.apply(this, arguments);
|
|
213
253
|
}
|
|
214
|
-
function checkPaymentIntnetIsComplete(
|
|
254
|
+
function checkPaymentIntnetIsComplete(_x10, _x11) {
|
|
215
255
|
return _checkPaymentIntnetIsComplete.apply(this, arguments);
|
|
216
256
|
}
|
|
217
257
|
function _checkPaymentIntnetIsComplete() {
|
|
218
|
-
_checkPaymentIntnetIsComplete = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
258
|
+
_checkPaymentIntnetIsComplete = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(apiUrl, cart) {
|
|
219
259
|
var url, fetchOptions, queryString, response, i;
|
|
220
|
-
return _regenerator().w(function (
|
|
221
|
-
while (1) switch (
|
|
260
|
+
return _regenerator().w(function (_context7) {
|
|
261
|
+
while (1) switch (_context7.n) {
|
|
222
262
|
case 0:
|
|
223
263
|
url = "stripe/payment_intent/cart/complete/".concat(cart.id, "/");
|
|
224
264
|
fetchOptions = {
|
|
@@ -228,148 +268,148 @@ function _checkPaymentIntnetIsComplete() {
|
|
|
228
268
|
queryString = new URLSearchParams({
|
|
229
269
|
cart_token: cart.token
|
|
230
270
|
}).toString();
|
|
231
|
-
|
|
271
|
+
_context7.n = 1;
|
|
232
272
|
return fetch("".concat(apiUrl).concat(url, "?").concat(queryString), fetchOptions);
|
|
233
273
|
case 1:
|
|
234
|
-
response =
|
|
274
|
+
response = _context7.v;
|
|
235
275
|
if (response.ok) {
|
|
236
|
-
|
|
276
|
+
_context7.n = 2;
|
|
237
277
|
break;
|
|
238
278
|
}
|
|
239
279
|
throw new Error("Failed to check if payment intent is complete.");
|
|
240
280
|
case 2:
|
|
241
|
-
|
|
281
|
+
_context7.n = 3;
|
|
242
282
|
return response.json();
|
|
243
283
|
case 3:
|
|
244
|
-
i =
|
|
245
|
-
return
|
|
284
|
+
i = _context7.v;
|
|
285
|
+
return _context7.a(2, i.invoice);
|
|
246
286
|
}
|
|
247
|
-
},
|
|
287
|
+
}, _callee7);
|
|
248
288
|
}));
|
|
249
289
|
return _checkPaymentIntnetIsComplete.apply(this, arguments);
|
|
250
290
|
}
|
|
251
|
-
export function stripeCardFormSubmit(
|
|
291
|
+
export function stripeCardFormSubmit(_x12, _x13, _x14, _x15) {
|
|
252
292
|
return _stripeCardFormSubmit.apply(this, arguments);
|
|
253
293
|
}
|
|
254
294
|
function _stripeCardFormSubmit() {
|
|
255
|
-
_stripeCardFormSubmit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
295
|
+
_stripeCardFormSubmit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(apiUrl, stripe, card, cart) {
|
|
256
296
|
var _cart$totalCost, intent, stripePayment, _t2;
|
|
257
|
-
return _regenerator().w(function (
|
|
258
|
-
while (1) switch (
|
|
297
|
+
return _regenerator().w(function (_context8) {
|
|
298
|
+
while (1) switch (_context8.p = _context8.n) {
|
|
259
299
|
case 0:
|
|
260
|
-
|
|
300
|
+
_context8.p = 0;
|
|
261
301
|
if (!(((_cart$totalCost = cart.totalCost) !== null && _cart$totalCost !== void 0 ? _cart$totalCost : 0) <= 0)) {
|
|
262
|
-
|
|
302
|
+
_context8.n = 2;
|
|
263
303
|
break;
|
|
264
304
|
}
|
|
265
|
-
|
|
305
|
+
_context8.n = 1;
|
|
266
306
|
return completeZeroBalanceCheckout(apiUrl, cart);
|
|
267
307
|
case 1:
|
|
268
|
-
return
|
|
308
|
+
return _context8.a(2, _context8.v);
|
|
269
309
|
case 2:
|
|
270
|
-
|
|
310
|
+
_context8.n = 3;
|
|
271
311
|
return createPaymentIntent(apiUrl, cart);
|
|
272
312
|
case 3:
|
|
273
|
-
intent =
|
|
313
|
+
intent = _context8.v;
|
|
274
314
|
if (!intent.zeroBalance) {
|
|
275
|
-
|
|
315
|
+
_context8.n = 5;
|
|
276
316
|
break;
|
|
277
317
|
}
|
|
278
|
-
|
|
318
|
+
_context8.n = 4;
|
|
279
319
|
return checkPaymentIntnetIsComplete(apiUrl, cart);
|
|
280
320
|
case 4:
|
|
281
|
-
return
|
|
321
|
+
return _context8.a(2, _context8.v);
|
|
282
322
|
case 5:
|
|
283
|
-
|
|
323
|
+
_context8.n = 6;
|
|
284
324
|
return stripe.confirmCardPayment(intent.stripeClientSecret, {
|
|
285
325
|
payment_method: {
|
|
286
326
|
card: card
|
|
287
327
|
}
|
|
288
328
|
});
|
|
289
329
|
case 6:
|
|
290
|
-
stripePayment =
|
|
330
|
+
stripePayment = _context8.v;
|
|
291
331
|
if (!stripePayment.error) {
|
|
292
|
-
|
|
332
|
+
_context8.n = 7;
|
|
293
333
|
break;
|
|
294
334
|
}
|
|
295
335
|
throw new Error(stripePayment.error.message || 'Stripe connect unknown error');
|
|
296
336
|
case 7:
|
|
297
|
-
|
|
337
|
+
_context8.n = 8;
|
|
298
338
|
return checkPaymentIntnetIsComplete(apiUrl, cart);
|
|
299
339
|
case 8:
|
|
300
|
-
return
|
|
340
|
+
return _context8.a(2, _context8.v);
|
|
301
341
|
case 9:
|
|
302
|
-
|
|
303
|
-
_t2 =
|
|
342
|
+
_context8.p = 9;
|
|
343
|
+
_t2 = _context8.v;
|
|
304
344
|
throw _t2;
|
|
305
345
|
case 10:
|
|
306
|
-
return
|
|
346
|
+
return _context8.a(2);
|
|
307
347
|
}
|
|
308
|
-
},
|
|
348
|
+
}, _callee8, null, [[0, 9]]);
|
|
309
349
|
}));
|
|
310
350
|
return _stripeCardFormSubmit.apply(this, arguments);
|
|
311
351
|
}
|
|
312
|
-
export function stripePaymentButtonSubmit(
|
|
352
|
+
export function stripePaymentButtonSubmit(_x16, _x17, _x18, _x19) {
|
|
313
353
|
return _stripePaymentButtonSubmit.apply(this, arguments);
|
|
314
354
|
}
|
|
315
355
|
function _stripePaymentButtonSubmit() {
|
|
316
|
-
_stripePaymentButtonSubmit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
356
|
+
_stripePaymentButtonSubmit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(apiUrl, stripe, cart, paymentMethodEvent) {
|
|
317
357
|
var complete, paymentMethod, _cart$totalCost2, intent, stripePayment, _t3;
|
|
318
|
-
return _regenerator().w(function (
|
|
319
|
-
while (1) switch (
|
|
358
|
+
return _regenerator().w(function (_context9) {
|
|
359
|
+
while (1) switch (_context9.p = _context9.n) {
|
|
320
360
|
case 0:
|
|
321
361
|
complete = paymentMethodEvent.complete, paymentMethod = paymentMethodEvent.paymentMethod;
|
|
322
|
-
|
|
362
|
+
_context9.p = 1;
|
|
323
363
|
if (!(((_cart$totalCost2 = cart.totalCost) !== null && _cart$totalCost2 !== void 0 ? _cart$totalCost2 : 0) <= 0)) {
|
|
324
|
-
|
|
364
|
+
_context9.n = 3;
|
|
325
365
|
break;
|
|
326
366
|
}
|
|
327
|
-
|
|
367
|
+
_context9.n = 2;
|
|
328
368
|
return completeZeroBalanceCheckout(apiUrl, cart);
|
|
329
369
|
case 2:
|
|
330
|
-
return
|
|
370
|
+
return _context9.a(2, _context9.v);
|
|
331
371
|
case 3:
|
|
332
|
-
|
|
372
|
+
_context9.n = 4;
|
|
333
373
|
return createPaymentIntent(apiUrl, cart);
|
|
334
374
|
case 4:
|
|
335
|
-
intent =
|
|
375
|
+
intent = _context9.v;
|
|
336
376
|
if (!intent.zeroBalance) {
|
|
337
|
-
|
|
377
|
+
_context9.n = 6;
|
|
338
378
|
break;
|
|
339
379
|
}
|
|
340
|
-
|
|
380
|
+
_context9.n = 5;
|
|
341
381
|
return checkPaymentIntnetIsComplete(apiUrl, cart);
|
|
342
382
|
case 5:
|
|
343
|
-
return
|
|
383
|
+
return _context9.a(2, _context9.v);
|
|
344
384
|
case 6:
|
|
345
|
-
|
|
385
|
+
_context9.n = 7;
|
|
346
386
|
return stripe.confirmCardPayment(intent.stripeClientSecret, {
|
|
347
387
|
payment_method: paymentMethod.id
|
|
348
388
|
}, {
|
|
349
389
|
handleActions: false
|
|
350
390
|
});
|
|
351
391
|
case 7:
|
|
352
|
-
stripePayment =
|
|
392
|
+
stripePayment = _context9.v;
|
|
353
393
|
if (!stripePayment.error) {
|
|
354
|
-
|
|
394
|
+
_context9.n = 8;
|
|
355
395
|
break;
|
|
356
396
|
}
|
|
357
397
|
throw new Error(stripePayment.error.message || 'Stripe unknown error');
|
|
358
398
|
case 8:
|
|
359
399
|
complete('success');
|
|
360
|
-
|
|
400
|
+
_context9.n = 9;
|
|
361
401
|
return checkPaymentIntnetIsComplete(apiUrl, cart);
|
|
362
402
|
case 9:
|
|
363
|
-
return
|
|
403
|
+
return _context9.a(2, _context9.v);
|
|
364
404
|
case 10:
|
|
365
|
-
|
|
366
|
-
_t3 =
|
|
405
|
+
_context9.p = 10;
|
|
406
|
+
_t3 = _context9.v;
|
|
367
407
|
complete('fail');
|
|
368
408
|
throw _t3;
|
|
369
409
|
case 11:
|
|
370
|
-
return
|
|
410
|
+
return _context9.a(2);
|
|
371
411
|
}
|
|
372
|
-
},
|
|
412
|
+
}, _callee9, null, [[1, 10]]);
|
|
373
413
|
}));
|
|
374
414
|
return _stripePaymentButtonSubmit.apply(this, arguments);
|
|
375
415
|
}
|
package/lib/stripe/actions.js
CHANGED
|
@@ -173,20 +173,48 @@ function _createPaymentIntent() {
|
|
|
173
173
|
}));
|
|
174
174
|
return _createPaymentIntent.apply(this, arguments);
|
|
175
175
|
}
|
|
176
|
-
function
|
|
177
|
-
return
|
|
176
|
+
function completeZeroBalanceCheckoutLegacy(_x8, _x9) {
|
|
177
|
+
return _completeZeroBalanceCheckoutLegacy.apply(this, arguments);
|
|
178
178
|
}
|
|
179
|
-
function
|
|
180
|
-
|
|
181
|
-
var
|
|
179
|
+
function _completeZeroBalanceCheckoutLegacy() {
|
|
180
|
+
_completeZeroBalanceCheckoutLegacy = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(apiUrl, cart) {
|
|
181
|
+
var intent;
|
|
182
182
|
return _regenerator().w(function (_context5) {
|
|
183
183
|
while (1) switch (_context5.n) {
|
|
184
|
+
case 0:
|
|
185
|
+
_context5.n = 1;
|
|
186
|
+
return createPaymentIntent(apiUrl, cart);
|
|
187
|
+
case 1:
|
|
188
|
+
intent = _context5.v;
|
|
189
|
+
if (intent.zeroBalance) {
|
|
190
|
+
_context5.n = 2;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
throw new Error('Unable to complete this order.');
|
|
194
|
+
case 2:
|
|
195
|
+
_context5.n = 3;
|
|
196
|
+
return checkPaymentIntnetIsComplete(apiUrl, cart);
|
|
197
|
+
case 3:
|
|
198
|
+
return _context5.a(2, _context5.v);
|
|
199
|
+
}
|
|
200
|
+
}, _callee5);
|
|
201
|
+
}));
|
|
202
|
+
return _completeZeroBalanceCheckoutLegacy.apply(this, arguments);
|
|
203
|
+
}
|
|
204
|
+
function completeZeroBalanceCheckout(_x0, _x1) {
|
|
205
|
+
return _completeZeroBalanceCheckout.apply(this, arguments);
|
|
206
|
+
}
|
|
207
|
+
function _completeZeroBalanceCheckout() {
|
|
208
|
+
_completeZeroBalanceCheckout = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(apiUrl, cart) {
|
|
209
|
+
var url, query, response, data, message;
|
|
210
|
+
return _regenerator().w(function (_context6) {
|
|
211
|
+
while (1) switch (_context6.n) {
|
|
184
212
|
case 0:
|
|
185
213
|
url = "".concat(apiUrl.replace(/\/$/, ''), "/payments/stripe/cart/").concat(cart.id, "/attempts/");
|
|
186
214
|
query = new URLSearchParams({
|
|
187
215
|
cart_token: cart.token
|
|
188
216
|
}).toString();
|
|
189
|
-
|
|
217
|
+
_context6.n = 1;
|
|
190
218
|
return fetch("".concat(url, "?").concat(query), {
|
|
191
219
|
method: 'POST',
|
|
192
220
|
mode: 'cors',
|
|
@@ -198,37 +226,49 @@ function _completeZeroBalanceCheckout() {
|
|
|
198
226
|
})
|
|
199
227
|
});
|
|
200
228
|
case 1:
|
|
201
|
-
response =
|
|
202
|
-
|
|
229
|
+
response = _context6.v;
|
|
230
|
+
_context6.n = 2;
|
|
203
231
|
return response.json();
|
|
204
232
|
case 2:
|
|
205
|
-
data =
|
|
206
|
-
if (response.ok) {
|
|
207
|
-
|
|
233
|
+
data = _context6.v;
|
|
234
|
+
if (!(response.ok && data.invoice)) {
|
|
235
|
+
_context6.n = 3;
|
|
208
236
|
break;
|
|
209
237
|
}
|
|
210
|
-
|
|
238
|
+
return _context6.a(2, data.invoice);
|
|
211
239
|
case 3:
|
|
212
|
-
|
|
213
|
-
|
|
240
|
+
message = data.message || '';
|
|
241
|
+
if (!(response.status === 409 && message.toLowerCase().includes('new payment flow is disabled'))) {
|
|
242
|
+
_context6.n = 5;
|
|
214
243
|
break;
|
|
215
244
|
}
|
|
216
|
-
|
|
245
|
+
_context6.n = 4;
|
|
246
|
+
return completeZeroBalanceCheckoutLegacy(apiUrl, cart);
|
|
217
247
|
case 4:
|
|
218
|
-
return
|
|
248
|
+
return _context6.a(2, _context6.v);
|
|
249
|
+
case 5:
|
|
250
|
+
if (response.ok) {
|
|
251
|
+
_context6.n = 6;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
throw new Error(message || 'Unable to complete this order.');
|
|
255
|
+
case 6:
|
|
256
|
+
throw new Error('Unable to complete this order.');
|
|
257
|
+
case 7:
|
|
258
|
+
return _context6.a(2);
|
|
219
259
|
}
|
|
220
|
-
},
|
|
260
|
+
}, _callee6);
|
|
221
261
|
}));
|
|
222
262
|
return _completeZeroBalanceCheckout.apply(this, arguments);
|
|
223
263
|
}
|
|
224
|
-
function checkPaymentIntnetIsComplete(
|
|
264
|
+
function checkPaymentIntnetIsComplete(_x10, _x11) {
|
|
225
265
|
return _checkPaymentIntnetIsComplete.apply(this, arguments);
|
|
226
266
|
}
|
|
227
267
|
function _checkPaymentIntnetIsComplete() {
|
|
228
|
-
_checkPaymentIntnetIsComplete = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
268
|
+
_checkPaymentIntnetIsComplete = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(apiUrl, cart) {
|
|
229
269
|
var url, fetchOptions, queryString, response, i;
|
|
230
|
-
return _regenerator().w(function (
|
|
231
|
-
while (1) switch (
|
|
270
|
+
return _regenerator().w(function (_context7) {
|
|
271
|
+
while (1) switch (_context7.n) {
|
|
232
272
|
case 0:
|
|
233
273
|
url = "stripe/payment_intent/cart/complete/".concat(cart.id, "/");
|
|
234
274
|
fetchOptions = {
|
|
@@ -238,148 +278,148 @@ function _checkPaymentIntnetIsComplete() {
|
|
|
238
278
|
queryString = new URLSearchParams({
|
|
239
279
|
cart_token: cart.token
|
|
240
280
|
}).toString();
|
|
241
|
-
|
|
281
|
+
_context7.n = 1;
|
|
242
282
|
return fetch("".concat(apiUrl).concat(url, "?").concat(queryString), fetchOptions);
|
|
243
283
|
case 1:
|
|
244
|
-
response =
|
|
284
|
+
response = _context7.v;
|
|
245
285
|
if (response.ok) {
|
|
246
|
-
|
|
286
|
+
_context7.n = 2;
|
|
247
287
|
break;
|
|
248
288
|
}
|
|
249
289
|
throw new Error("Failed to check if payment intent is complete.");
|
|
250
290
|
case 2:
|
|
251
|
-
|
|
291
|
+
_context7.n = 3;
|
|
252
292
|
return response.json();
|
|
253
293
|
case 3:
|
|
254
|
-
i =
|
|
255
|
-
return
|
|
294
|
+
i = _context7.v;
|
|
295
|
+
return _context7.a(2, i.invoice);
|
|
256
296
|
}
|
|
257
|
-
},
|
|
297
|
+
}, _callee7);
|
|
258
298
|
}));
|
|
259
299
|
return _checkPaymentIntnetIsComplete.apply(this, arguments);
|
|
260
300
|
}
|
|
261
|
-
function stripeCardFormSubmit(
|
|
301
|
+
function stripeCardFormSubmit(_x12, _x13, _x14, _x15) {
|
|
262
302
|
return _stripeCardFormSubmit.apply(this, arguments);
|
|
263
303
|
}
|
|
264
304
|
function _stripeCardFormSubmit() {
|
|
265
|
-
_stripeCardFormSubmit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
305
|
+
_stripeCardFormSubmit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(apiUrl, stripe, card, cart) {
|
|
266
306
|
var _cart$totalCost, intent, stripePayment, _t2;
|
|
267
|
-
return _regenerator().w(function (
|
|
268
|
-
while (1) switch (
|
|
307
|
+
return _regenerator().w(function (_context8) {
|
|
308
|
+
while (1) switch (_context8.p = _context8.n) {
|
|
269
309
|
case 0:
|
|
270
|
-
|
|
310
|
+
_context8.p = 0;
|
|
271
311
|
if (!(((_cart$totalCost = cart.totalCost) !== null && _cart$totalCost !== void 0 ? _cart$totalCost : 0) <= 0)) {
|
|
272
|
-
|
|
312
|
+
_context8.n = 2;
|
|
273
313
|
break;
|
|
274
314
|
}
|
|
275
|
-
|
|
315
|
+
_context8.n = 1;
|
|
276
316
|
return completeZeroBalanceCheckout(apiUrl, cart);
|
|
277
317
|
case 1:
|
|
278
|
-
return
|
|
318
|
+
return _context8.a(2, _context8.v);
|
|
279
319
|
case 2:
|
|
280
|
-
|
|
320
|
+
_context8.n = 3;
|
|
281
321
|
return createPaymentIntent(apiUrl, cart);
|
|
282
322
|
case 3:
|
|
283
|
-
intent =
|
|
323
|
+
intent = _context8.v;
|
|
284
324
|
if (!intent.zeroBalance) {
|
|
285
|
-
|
|
325
|
+
_context8.n = 5;
|
|
286
326
|
break;
|
|
287
327
|
}
|
|
288
|
-
|
|
328
|
+
_context8.n = 4;
|
|
289
329
|
return checkPaymentIntnetIsComplete(apiUrl, cart);
|
|
290
330
|
case 4:
|
|
291
|
-
return
|
|
331
|
+
return _context8.a(2, _context8.v);
|
|
292
332
|
case 5:
|
|
293
|
-
|
|
333
|
+
_context8.n = 6;
|
|
294
334
|
return stripe.confirmCardPayment(intent.stripeClientSecret, {
|
|
295
335
|
payment_method: {
|
|
296
336
|
card: card
|
|
297
337
|
}
|
|
298
338
|
});
|
|
299
339
|
case 6:
|
|
300
|
-
stripePayment =
|
|
340
|
+
stripePayment = _context8.v;
|
|
301
341
|
if (!stripePayment.error) {
|
|
302
|
-
|
|
342
|
+
_context8.n = 7;
|
|
303
343
|
break;
|
|
304
344
|
}
|
|
305
345
|
throw new Error(stripePayment.error.message || 'Stripe connect unknown error');
|
|
306
346
|
case 7:
|
|
307
|
-
|
|
347
|
+
_context8.n = 8;
|
|
308
348
|
return checkPaymentIntnetIsComplete(apiUrl, cart);
|
|
309
349
|
case 8:
|
|
310
|
-
return
|
|
350
|
+
return _context8.a(2, _context8.v);
|
|
311
351
|
case 9:
|
|
312
|
-
|
|
313
|
-
_t2 =
|
|
352
|
+
_context8.p = 9;
|
|
353
|
+
_t2 = _context8.v;
|
|
314
354
|
throw _t2;
|
|
315
355
|
case 10:
|
|
316
|
-
return
|
|
356
|
+
return _context8.a(2);
|
|
317
357
|
}
|
|
318
|
-
},
|
|
358
|
+
}, _callee8, null, [[0, 9]]);
|
|
319
359
|
}));
|
|
320
360
|
return _stripeCardFormSubmit.apply(this, arguments);
|
|
321
361
|
}
|
|
322
|
-
function stripePaymentButtonSubmit(
|
|
362
|
+
function stripePaymentButtonSubmit(_x16, _x17, _x18, _x19) {
|
|
323
363
|
return _stripePaymentButtonSubmit.apply(this, arguments);
|
|
324
364
|
}
|
|
325
365
|
function _stripePaymentButtonSubmit() {
|
|
326
|
-
_stripePaymentButtonSubmit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
366
|
+
_stripePaymentButtonSubmit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(apiUrl, stripe, cart, paymentMethodEvent) {
|
|
327
367
|
var complete, paymentMethod, _cart$totalCost2, intent, stripePayment, _t3;
|
|
328
|
-
return _regenerator().w(function (
|
|
329
|
-
while (1) switch (
|
|
368
|
+
return _regenerator().w(function (_context9) {
|
|
369
|
+
while (1) switch (_context9.p = _context9.n) {
|
|
330
370
|
case 0:
|
|
331
371
|
complete = paymentMethodEvent.complete, paymentMethod = paymentMethodEvent.paymentMethod;
|
|
332
|
-
|
|
372
|
+
_context9.p = 1;
|
|
333
373
|
if (!(((_cart$totalCost2 = cart.totalCost) !== null && _cart$totalCost2 !== void 0 ? _cart$totalCost2 : 0) <= 0)) {
|
|
334
|
-
|
|
374
|
+
_context9.n = 3;
|
|
335
375
|
break;
|
|
336
376
|
}
|
|
337
|
-
|
|
377
|
+
_context9.n = 2;
|
|
338
378
|
return completeZeroBalanceCheckout(apiUrl, cart);
|
|
339
379
|
case 2:
|
|
340
|
-
return
|
|
380
|
+
return _context9.a(2, _context9.v);
|
|
341
381
|
case 3:
|
|
342
|
-
|
|
382
|
+
_context9.n = 4;
|
|
343
383
|
return createPaymentIntent(apiUrl, cart);
|
|
344
384
|
case 4:
|
|
345
|
-
intent =
|
|
385
|
+
intent = _context9.v;
|
|
346
386
|
if (!intent.zeroBalance) {
|
|
347
|
-
|
|
387
|
+
_context9.n = 6;
|
|
348
388
|
break;
|
|
349
389
|
}
|
|
350
|
-
|
|
390
|
+
_context9.n = 5;
|
|
351
391
|
return checkPaymentIntnetIsComplete(apiUrl, cart);
|
|
352
392
|
case 5:
|
|
353
|
-
return
|
|
393
|
+
return _context9.a(2, _context9.v);
|
|
354
394
|
case 6:
|
|
355
|
-
|
|
395
|
+
_context9.n = 7;
|
|
356
396
|
return stripe.confirmCardPayment(intent.stripeClientSecret, {
|
|
357
397
|
payment_method: paymentMethod.id
|
|
358
398
|
}, {
|
|
359
399
|
handleActions: false
|
|
360
400
|
});
|
|
361
401
|
case 7:
|
|
362
|
-
stripePayment =
|
|
402
|
+
stripePayment = _context9.v;
|
|
363
403
|
if (!stripePayment.error) {
|
|
364
|
-
|
|
404
|
+
_context9.n = 8;
|
|
365
405
|
break;
|
|
366
406
|
}
|
|
367
407
|
throw new Error(stripePayment.error.message || 'Stripe unknown error');
|
|
368
408
|
case 8:
|
|
369
409
|
complete('success');
|
|
370
|
-
|
|
410
|
+
_context9.n = 9;
|
|
371
411
|
return checkPaymentIntnetIsComplete(apiUrl, cart);
|
|
372
412
|
case 9:
|
|
373
|
-
return
|
|
413
|
+
return _context9.a(2, _context9.v);
|
|
374
414
|
case 10:
|
|
375
|
-
|
|
376
|
-
_t3 =
|
|
415
|
+
_context9.p = 10;
|
|
416
|
+
_t3 = _context9.v;
|
|
377
417
|
complete('fail');
|
|
378
418
|
throw _t3;
|
|
379
419
|
case 11:
|
|
380
|
-
return
|
|
420
|
+
return _context9.a(2);
|
|
381
421
|
}
|
|
382
|
-
},
|
|
422
|
+
}, _callee9, null, [[1, 10]]);
|
|
383
423
|
}));
|
|
384
424
|
return _stripePaymentButtonSubmit.apply(this, arguments);
|
|
385
425
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merchi/cart",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.71",
|
|
4
4
|
"description": "Merchi's cart",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"@fortawesome/free-solid-svg-icons": "6.4.2",
|
|
95
95
|
"@fortawesome/react-fontawesome": "^0.2.0",
|
|
96
96
|
"@merchi/error-catch": "^0.1.11",
|
|
97
|
-
"@merchi/invoice": "^1.3.
|
|
97
|
+
"@merchi/invoice": "^1.3.17",
|
|
98
98
|
"@merchi/product-form": "^1.19.58",
|
|
99
99
|
"@merchi/product-form-sdk": "^1.0.38",
|
|
100
100
|
"@merchi/sdk": "^1.42.27",
|
package/src/stripe/actions.ts
CHANGED
|
@@ -74,6 +74,14 @@ async function createPaymentIntent(apiUrl: string, cart: any, paymentMethodType?
|
|
|
74
74
|
return data;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
async function completeZeroBalanceCheckoutLegacy(apiUrl: string, cart: any) {
|
|
78
|
+
const intent = await createPaymentIntent(apiUrl, cart);
|
|
79
|
+
if (!intent.zeroBalance) {
|
|
80
|
+
throw new Error('Unable to complete this order.');
|
|
81
|
+
}
|
|
82
|
+
return await checkPaymentIntnetIsComplete(apiUrl, cart);
|
|
83
|
+
}
|
|
84
|
+
|
|
77
85
|
async function completeZeroBalanceCheckout(apiUrl: string, cart: any) {
|
|
78
86
|
const url = `${apiUrl.replace(/\/$/, '')}/payments/stripe/cart/${cart.id}/attempts/`;
|
|
79
87
|
const query = new URLSearchParams({ cart_token: cart.token }).toString();
|
|
@@ -86,13 +94,20 @@ async function completeZeroBalanceCheckout(apiUrl: string, cart: any) {
|
|
|
86
94
|
}),
|
|
87
95
|
});
|
|
88
96
|
const data = await response.json();
|
|
89
|
-
if (
|
|
90
|
-
|
|
97
|
+
if (response.ok && data.invoice) {
|
|
98
|
+
return data.invoice;
|
|
91
99
|
}
|
|
92
|
-
|
|
93
|
-
|
|
100
|
+
const message = data.message || '';
|
|
101
|
+
if (
|
|
102
|
+
response.status === 409
|
|
103
|
+
&& message.toLowerCase().includes('new payment flow is disabled')
|
|
104
|
+
) {
|
|
105
|
+
return await completeZeroBalanceCheckoutLegacy(apiUrl, cart);
|
|
94
106
|
}
|
|
95
|
-
|
|
107
|
+
if (!response.ok) {
|
|
108
|
+
throw new Error(message || 'Unable to complete this order.');
|
|
109
|
+
}
|
|
110
|
+
throw new Error('Unable to complete this order.');
|
|
96
111
|
}
|
|
97
112
|
|
|
98
113
|
async function checkPaymentIntnetIsComplete(apiUrl: string, cart: any) {
|