@pelcro/react-pelcro-js 3.21.2 → 3.21.3

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/dist/index.cjs.js CHANGED
@@ -16315,6 +16315,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16315
16315
  onFailure = () => {},
16316
16316
  ...props
16317
16317
  } = _ref;
16318
+ const [vantivPaymentRequest, setVantivPaymentRequest] = React.useState(null);
16319
+ const [updatedCouponCode, setUpdatedCouponCode] = React.useState("");
16318
16320
  const {
16319
16321
  t
16320
16322
  } = useTranslation("payment");
@@ -16357,7 +16359,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16357
16359
  }, []);
16358
16360
 
16359
16361
  /*====== Start Tap integration ========*/
16360
- const submitUsingTap = () => {
16362
+ const submitUsingTap = state => {
16361
16363
  var _ref2, _ref3, _ref4, _state$updatedPrice;
16362
16364
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
16363
16365
  if (isUsingExistingPaymentMethod) {
@@ -16452,7 +16454,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16452
16454
  content: null
16453
16455
  }
16454
16456
  });
16455
- handleTapPayment(tapID);
16457
+ handleTapPayment(tapID, state);
16456
16458
  }
16457
16459
  };
16458
16460
 
@@ -16465,7 +16467,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16465
16467
  }
16466
16468
  });
16467
16469
  };
16468
- function handleTapPayment(paymentRequest) {
16470
+ function handleTapPayment(paymentRequest, state) {
16469
16471
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
16470
16472
  if (type === "createPayment") {
16471
16473
  handleTapSubscription();
@@ -16643,7 +16645,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16643
16645
  };
16644
16646
  /*====== End Tap integration ========*/
16645
16647
 
16646
- const submitUsingVantiv = () => {
16648
+ const submitUsingVantiv = state => {
16647
16649
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
16648
16650
  if (isUsingExistingPaymentMethod) {
16649
16651
  // no need to create a new source using vantiv
@@ -16661,7 +16663,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16661
16663
  orderId: orderId
16662
16664
  });
16663
16665
  };
16664
- function handleVantivPayment(paymentRequest) {
16666
+ function handleVantivPayment(paymentRequest, couponCode) {
16665
16667
  if (paymentRequest) {
16666
16668
  const SUCCESS_STATUS = "870";
16667
16669
  if (paymentRequest.response !== SUCCESS_STATUS) {
@@ -16727,7 +16729,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16727
16729
  const renewSubscription = !isGift && subscriptionIdToRenew;
16728
16730
  const giftSubscriprition = isGift && !subscriptionIdToRenew;
16729
16731
  const renewGift = isRenewingGift;
16730
- const couponCode = state.couponCode || window.Pelcro.coupon.getFromUrl() || "";
16731
16732
  if (renewGift) {
16732
16733
  return payment.execute({
16733
16734
  type: PAYMENT_TYPES.RENEW_GIFTED_SUBSCRIPTION,
@@ -16813,7 +16814,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16813
16814
  height: "245",
16814
16815
  timeout: 50000,
16815
16816
  div: "eProtectiframe",
16816
- callback: handleVantivPayment,
16817
+ callback: paymentRequest => setVantivPaymentRequest(paymentRequest),
16817
16818
  showCvv: true,
16818
16819
  numYears: 8,
16819
16820
  placeholderText: {
@@ -16828,6 +16829,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16828
16829
  });
16829
16830
  }
16830
16831
  }, [selectedPaymentMethodId]);
16832
+
16833
+ //Trigger the handleVantivPayment method when a vantivePaymentRequest is present
16834
+ React.useEffect(() => {
16835
+ if (vantivPaymentRequest) {
16836
+ handleVantivPayment(vantivPaymentRequest, updatedCouponCode);
16837
+ }
16838
+ }, [vantivPaymentRequest]);
16831
16839
  React.useEffect(() => {
16832
16840
  whenUserReady(() => {
16833
16841
  if (skipPayment && (plan === null || plan === void 0 ? void 0 : plan.amount) === 0) return;
@@ -16956,6 +16964,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16956
16964
  });
16957
16965
  if (err) {
16958
16966
  onFailure(err);
16967
+
16968
+ //reset the coupon code in local state
16969
+ setUpdatedCouponCode("");
16959
16970
  dispatch({
16960
16971
  type: SET_COUPON_ERROR,
16961
16972
  payload: getErrorMessages(err)
@@ -17014,6 +17025,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17014
17025
  type: SET_COUPON,
17015
17026
  payload: res.data.coupon
17016
17027
  });
17028
+
17029
+ //set the coupon code in local state to be able to use with Vantiv
17030
+ setUpdatedCouponCode(res.data.coupon.code);
17017
17031
  dispatch({
17018
17032
  type: SET_PERCENT_OFF,
17019
17033
  payload: `${(_res$data$coupon = res.data.coupon) === null || _res$data$coupon === void 0 ? void 0 : _res$data$coupon.percent_off}%`
@@ -17084,6 +17098,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17084
17098
  const debouncedApplyCouponCode = React.useRef(debounce(onApplyCouponCode, 1000)).current;
17085
17099
  const removeAppliedCoupon = state => {
17086
17100
  state.couponCode = "";
17101
+
17102
+ //reset the coupon code in local state
17103
+ setUpdatedCouponCode("");
17087
17104
  dispatch({
17088
17105
  type: SET_COUPON_ERROR,
17089
17106
  payload: ""
@@ -17745,7 +17762,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17745
17762
  return submitUsingVantiv();
17746
17763
  }
17747
17764
  if (getSiteCardProcessor() === "tap") {
17748
- return submitUsingTap();
17765
+ return submitUsingTap(state);
17749
17766
  }
17750
17767
  if (selectedPaymentMethodId) {
17751
17768
  // pay with selected method (source) if exists already
package/dist/index.esm.js CHANGED
@@ -16285,6 +16285,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16285
16285
  onFailure = () => {},
16286
16286
  ...props
16287
16287
  } = _ref;
16288
+ const [vantivPaymentRequest, setVantivPaymentRequest] = useState(null);
16289
+ const [updatedCouponCode, setUpdatedCouponCode] = useState("");
16288
16290
  const {
16289
16291
  t
16290
16292
  } = useTranslation("payment");
@@ -16327,7 +16329,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16327
16329
  }, []);
16328
16330
 
16329
16331
  /*====== Start Tap integration ========*/
16330
- const submitUsingTap = () => {
16332
+ const submitUsingTap = state => {
16331
16333
  var _ref2, _ref3, _ref4, _state$updatedPrice;
16332
16334
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
16333
16335
  if (isUsingExistingPaymentMethod) {
@@ -16422,7 +16424,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16422
16424
  content: null
16423
16425
  }
16424
16426
  });
16425
- handleTapPayment(tapID);
16427
+ handleTapPayment(tapID, state);
16426
16428
  }
16427
16429
  };
16428
16430
 
@@ -16435,7 +16437,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16435
16437
  }
16436
16438
  });
16437
16439
  };
16438
- function handleTapPayment(paymentRequest) {
16440
+ function handleTapPayment(paymentRequest, state) {
16439
16441
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
16440
16442
  if (type === "createPayment") {
16441
16443
  handleTapSubscription();
@@ -16613,7 +16615,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16613
16615
  };
16614
16616
  /*====== End Tap integration ========*/
16615
16617
 
16616
- const submitUsingVantiv = () => {
16618
+ const submitUsingVantiv = state => {
16617
16619
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
16618
16620
  if (isUsingExistingPaymentMethod) {
16619
16621
  // no need to create a new source using vantiv
@@ -16631,7 +16633,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16631
16633
  orderId: orderId
16632
16634
  });
16633
16635
  };
16634
- function handleVantivPayment(paymentRequest) {
16636
+ function handleVantivPayment(paymentRequest, couponCode) {
16635
16637
  if (paymentRequest) {
16636
16638
  const SUCCESS_STATUS = "870";
16637
16639
  if (paymentRequest.response !== SUCCESS_STATUS) {
@@ -16697,7 +16699,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16697
16699
  const renewSubscription = !isGift && subscriptionIdToRenew;
16698
16700
  const giftSubscriprition = isGift && !subscriptionIdToRenew;
16699
16701
  const renewGift = isRenewingGift;
16700
- const couponCode = state.couponCode || window.Pelcro.coupon.getFromUrl() || "";
16701
16702
  if (renewGift) {
16702
16703
  return payment.execute({
16703
16704
  type: PAYMENT_TYPES.RENEW_GIFTED_SUBSCRIPTION,
@@ -16783,7 +16784,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16783
16784
  height: "245",
16784
16785
  timeout: 50000,
16785
16786
  div: "eProtectiframe",
16786
- callback: handleVantivPayment,
16787
+ callback: paymentRequest => setVantivPaymentRequest(paymentRequest),
16787
16788
  showCvv: true,
16788
16789
  numYears: 8,
16789
16790
  placeholderText: {
@@ -16798,6 +16799,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16798
16799
  });
16799
16800
  }
16800
16801
  }, [selectedPaymentMethodId]);
16802
+
16803
+ //Trigger the handleVantivPayment method when a vantivePaymentRequest is present
16804
+ useEffect(() => {
16805
+ if (vantivPaymentRequest) {
16806
+ handleVantivPayment(vantivPaymentRequest, updatedCouponCode);
16807
+ }
16808
+ }, [vantivPaymentRequest]);
16801
16809
  useEffect(() => {
16802
16810
  whenUserReady(() => {
16803
16811
  if (skipPayment && (plan === null || plan === void 0 ? void 0 : plan.amount) === 0) return;
@@ -16926,6 +16934,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16926
16934
  });
16927
16935
  if (err) {
16928
16936
  onFailure(err);
16937
+
16938
+ //reset the coupon code in local state
16939
+ setUpdatedCouponCode("");
16929
16940
  dispatch({
16930
16941
  type: SET_COUPON_ERROR,
16931
16942
  payload: getErrorMessages(err)
@@ -16984,6 +16995,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16984
16995
  type: SET_COUPON,
16985
16996
  payload: res.data.coupon
16986
16997
  });
16998
+
16999
+ //set the coupon code in local state to be able to use with Vantiv
17000
+ setUpdatedCouponCode(res.data.coupon.code);
16987
17001
  dispatch({
16988
17002
  type: SET_PERCENT_OFF,
16989
17003
  payload: `${(_res$data$coupon = res.data.coupon) === null || _res$data$coupon === void 0 ? void 0 : _res$data$coupon.percent_off}%`
@@ -17054,6 +17068,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17054
17068
  const debouncedApplyCouponCode = useRef(debounce(onApplyCouponCode, 1000)).current;
17055
17069
  const removeAppliedCoupon = state => {
17056
17070
  state.couponCode = "";
17071
+
17072
+ //reset the coupon code in local state
17073
+ setUpdatedCouponCode("");
17057
17074
  dispatch({
17058
17075
  type: SET_COUPON_ERROR,
17059
17076
  payload: ""
@@ -17715,7 +17732,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17715
17732
  return submitUsingVantiv();
17716
17733
  }
17717
17734
  if (getSiteCardProcessor() === "tap") {
17718
- return submitUsingTap();
17735
+ return submitUsingTap(state);
17719
17736
  }
17720
17737
  if (selectedPaymentMethodId) {
17721
17738
  // pay with selected method (source) if exists already
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pelcro/react-pelcro-js",
3
3
  "description": "Pelcro's React UI Elements",
4
- "version": "3.21.2",
4
+ "version": "3.21.3",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",