tf-checkout-react 1.7.32-beta.0 → 1.7.32-beta.2

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.
@@ -6606,27 +6606,30 @@ var usePaymentRedirect = function usePaymentRedirect(_ref) {
6606
6606
  }, [stripeRef.current, setError, setLoading, removeReferralKey, removeAdditionalConfigs, handleSubmit, isBrowser]);
6607
6607
  };
6608
6608
 
6609
+ var SUCCESSFUL_INTENT_STATUSES = ['succeeded', 'processing', 'requires_capture'];
6610
+ var PAYMENT_FAILED_MESSAGE = 'Your payment was not completed. Please try again or use another payment method.';
6611
+ var PAYMENT_RECEIVED_MESSAGE = 'Your payment was received and we are confirming your order. ' + 'Please check your email for your tickets before trying again.';
6609
6612
  var useStripePayment = function useStripePayment(_ref) {
6610
6613
  var stripeRef = _ref.stripeRef,
6611
6614
  elementsRef = _ref.elementsRef,
6612
- setError = _ref.setError,
6615
+ _setError = _ref.setError,
6613
6616
  isBrowser = _ref.isBrowser;
6614
6617
  var processPayment = /*#__PURE__*/function () {
6615
6618
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(paymentDataResponse, values, formikHelpers, checkoutResponse, checkoutUpdateResponse, paymentData) {
6616
- var attributes, isFreeTickets, updatedOrderData, eventId, _yield$elementsRef$cu, submitError, paymentContext, confirmParams, rawPhone, e164Phone, _yield$stripeRef$curr, confirmError, paymentResponse;
6619
+ var attributes, isFreeTickets, updatedOrderData, eventId, _yield$elementsRef$cu, submitError, paymentContext, confirmParams, rawPhone, e164Phone, confirmResult, _confirmResult, confirmError, paymentIntent, paymentResponse;
6617
6620
  return _regeneratorRuntime().wrap(function _callee$(_context) {
6618
6621
  while (1) switch (_context.prev = _context.next) {
6619
6622
  case 0:
6620
6623
  attributes = paymentData.attributes, isFreeTickets = paymentData.isFreeTickets, updatedOrderData = paymentData.updatedOrderData, eventId = paymentData.eventId;
6621
6624
  if (isFreeTickets) {
6622
- _context.next = 23;
6625
+ _context.next = 33;
6623
6626
  break;
6624
6627
  }
6625
6628
  if (stripeRef.current) {
6626
6629
  _context.next = 5;
6627
6630
  break;
6628
6631
  }
6629
- setError('Stripe is not ready');
6632
+ _setError('Stripe is not ready');
6630
6633
  return _context.abrupt("return", null);
6631
6634
  case 5:
6632
6635
  _context.next = 7;
@@ -6638,7 +6641,7 @@ var useStripePayment = function useStripePayment(_ref) {
6638
6641
  _context.next = 12;
6639
6642
  break;
6640
6643
  }
6641
- setError('' + (submitError == null ? void 0 : submitError.message));
6644
+ _setError('' + (submitError == null ? void 0 : submitError.message));
6642
6645
  return _context.abrupt("return", null);
6643
6646
  case 12:
6644
6647
  // Step 2: Store payment context before potential redirect
@@ -6667,26 +6670,44 @@ var useStripePayment = function useStripePayment(_ref) {
6667
6670
  }
6668
6671
  };
6669
6672
  }
6670
- _context.next = 18;
6673
+ _context.prev = 16;
6674
+ _context.next = 19;
6671
6675
  return stripeRef.current.confirmPayment({
6672
6676
  clientSecret: paymentDataResponse.data.attributes.payment_method.stripe_client_secret,
6673
6677
  elements: elementsRef.current,
6674
6678
  confirmParams: confirmParams,
6675
6679
  redirect: 'if_required'
6676
6680
  });
6677
- case 18:
6678
- _yield$stripeRef$curr = _context.sent;
6679
- confirmError = _yield$stripeRef$curr.error;
6681
+ case 19:
6682
+ confirmResult = _context.sent;
6683
+ _context.next = 26;
6684
+ break;
6685
+ case 22:
6686
+ _context.prev = 22;
6687
+ _context.t0 = _context["catch"](16);
6688
+ // Stripe.js throws (instead of returning { error }) on integration errors
6689
+ _setError(_get(_context.t0, 'message') || PAYMENT_FAILED_MESSAGE);
6690
+ return _context.abrupt("return", null);
6691
+ case 26:
6692
+ _confirmResult = confirmResult, confirmError = _confirmResult.error, paymentIntent = _confirmResult.paymentIntent;
6680
6693
  if (!confirmError) {
6681
- _context.next = 23;
6694
+ _context.next = 30;
6682
6695
  break;
6683
6696
  }
6684
- setError('' + (confirmError == null ? void 0 : confirmError.message));
6697
+ _setError('' + (confirmError == null ? void 0 : confirmError.message));
6685
6698
  return _context.abrupt("return", null);
6686
- case 23:
6699
+ case 30:
6700
+ if (!(paymentIntent && !SUCCESSFUL_INTENT_STATUSES.includes(paymentIntent.status))) {
6701
+ _context.next = 33;
6702
+ break;
6703
+ }
6704
+ _setError(_get(paymentIntent, 'last_payment_error.message') || PAYMENT_FAILED_MESSAGE);
6705
+ return _context.abrupt("return", null);
6706
+ case 33:
6687
6707
  // Handle payment middleware for non-redirect payments
6688
6708
  paymentResponse = null;
6689
- _context.next = 26;
6709
+ _context.prev = 34;
6710
+ _context.next = 37;
6690
6711
  return handlePaymentMiddleWare(null, {}, {
6691
6712
  reviewData: attributes,
6692
6713
  isFreeTickets: isFreeTickets,
@@ -6696,7 +6717,9 @@ var useStripePayment = function useStripePayment(_ref) {
6696
6717
  paymentResponse = data;
6697
6718
  },
6698
6719
  setPaymentIsLoading: _identity,
6699
- setError: _identity,
6720
+ setError: function setError(message) {
6721
+ if (message && isFreeTickets) _setError(message);
6722
+ },
6700
6723
  orderData: updatedOrderData,
6701
6724
  eventId: eventId,
6702
6725
  isBrowser: isBrowser,
@@ -6704,13 +6727,29 @@ var useStripePayment = function useStripePayment(_ref) {
6704
6727
  throw error;
6705
6728
  }
6706
6729
  });
6707
- case 26:
6730
+ case 37:
6731
+ _context.next = 45;
6732
+ break;
6733
+ case 39:
6734
+ _context.prev = 39;
6735
+ _context.t1 = _context["catch"](34);
6736
+ if (!isFreeTickets) {
6737
+ _context.next = 43;
6738
+ break;
6739
+ }
6740
+ throw _context.t1;
6741
+ case 43:
6742
+ // Stripe has already taken the payment and the webhook will still settle the order,
6743
+ // so never invite a retry (double charge) whatever the backend error looks like
6744
+ _setError(PAYMENT_RECEIVED_MESSAGE);
6745
+ return _context.abrupt("return", null);
6746
+ case 45:
6708
6747
  return _context.abrupt("return", paymentResponse);
6709
- case 27:
6748
+ case 46:
6710
6749
  case "end":
6711
6750
  return _context.stop();
6712
6751
  }
6713
- }, _callee);
6752
+ }, _callee, null, [[16, 22], [34, 39]]);
6714
6753
  }));
6715
6754
  return function processPayment(_x, _x2, _x3, _x4, _x5, _x6) {
6716
6755
  return _ref2.apply(this, arguments);