@pelcro/react-pelcro-js 3.21.1 → 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
@@ -14002,12 +14002,9 @@ class SelectModal extends React.Component {
14002
14002
  const userCurrency = (_window$Pelcro = window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$user = _window$Pelcro.user) === null || _window$Pelcro$user === void 0 ? void 0 : _window$Pelcro$user.read().currency;
14003
14003
  const userCountry = (_window$Pelcro2 = window.Pelcro) === null || _window$Pelcro2 === void 0 ? void 0 : (_window$Pelcro2$user = _window$Pelcro2.user) === null || _window$Pelcro2$user === void 0 ? void 0 : _window$Pelcro2$user.location.countryCode;
14004
14004
  const userLanguage = (_window$Pelcro3 = window.Pelcro) === null || _window$Pelcro3 === void 0 ? void 0 : (_window$Pelcro3$user = _window$Pelcro3.user) === null || _window$Pelcro3$user === void 0 ? void 0 : _window$Pelcro3$user.read().language;
14005
- const productsMatchingUserCurrency = (_window$Pelcro4 = window.Pelcro) === null || _window$Pelcro4 === void 0 ? void 0 : (_window$Pelcro4$site = _window$Pelcro4.site) === null || _window$Pelcro4$site === void 0 ? void 0 : _window$Pelcro4$site.read().products.map(product => {
14005
+ const productsMatchingUserCurrency = (_window$Pelcro4 = window.Pelcro) === null || _window$Pelcro4 === void 0 ? void 0 : (_window$Pelcro4$site = _window$Pelcro4.site) === null || _window$Pelcro4$site === void 0 ? void 0 : _window$Pelcro4$site.read().products.filter(product => {
14006
14006
  const filteredPlans = product.plans.filter(plan => plan.currency === userCurrency || !userCurrency);
14007
- return {
14008
- ...product,
14009
- plans: filteredPlans
14010
- };
14007
+ if (filteredPlans.length) return filteredPlans;
14011
14008
  });
14012
14009
  const productsMatchingUserCountry = productsMatchingUserCurrency.filter(product => {
14013
14010
  const filteredPlans = product.plans.filter(plan => {
@@ -14018,7 +14015,7 @@ class SelectModal extends React.Component {
14018
14015
  });
14019
14016
  notifyBugsnag(() => {
14020
14017
  Bugsnag.notify("SelectModal - No data viewed", event => {
14021
- var _window$Pelcro5, _window$Pelcro5$site, _window$Pelcro6, _window$Pelcro6$user, _window$Pelcro7, _window$Pelcro7$uiSet, _window$Pelcro8, _this$props, _window$Pelcro9, _window$Pelcro9$helpe;
14018
+ var _window$Pelcro5, _window$Pelcro5$site, _window$Pelcro6, _window$Pelcro6$user, _window$Pelcro7, _window$Pelcro7$uiSet, _window$Pelcro8, _this$props, _window$Pelcro9, _window$Pelcro9$helpe, _window$Pelcro10, _window$Pelcro10$site;
14022
14019
  event.addMetadata("MetaData", {
14023
14020
  site: (_window$Pelcro5 = window.Pelcro) === null || _window$Pelcro5 === void 0 ? void 0 : (_window$Pelcro5$site = _window$Pelcro5.site) === null || _window$Pelcro5$site === void 0 ? void 0 : _window$Pelcro5$site.read(),
14024
14021
  user: (_window$Pelcro6 = window.Pelcro) === null || _window$Pelcro6 === void 0 ? void 0 : (_window$Pelcro6$user = _window$Pelcro6.user) === null || _window$Pelcro6$user === void 0 ? void 0 : _window$Pelcro6$user.read(),
@@ -14035,9 +14032,10 @@ class SelectModal extends React.Component {
14035
14032
  userCountry: userCountry,
14036
14033
  userLanguage: userLanguage,
14037
14034
  siteLanguage: (_window$Pelcro9 = window.Pelcro) === null || _window$Pelcro9 === void 0 ? void 0 : (_window$Pelcro9$helpe = _window$Pelcro9.helpers) === null || _window$Pelcro9$helpe === void 0 ? void 0 : _window$Pelcro9$helpe.getHtmlLanguageAttribute(),
14038
- currency_mismatch: productsMatchingUserCurrency.length === 0,
14039
- country_restrictions: productsMatchingUserCountry.length === 0,
14040
- language_mismatch: productsMatchingUserCountry.filter(product => product.plans.length).filter(productMatchPageLanguage).length === 0
14035
+ products: (_window$Pelcro10 = window.Pelcro) === null || _window$Pelcro10 === void 0 ? void 0 : (_window$Pelcro10$site = _window$Pelcro10.site) === null || _window$Pelcro10$site === void 0 ? void 0 : _window$Pelcro10$site.read().products.length,
14036
+ currency_matching_filter: `${productsMatchingUserCurrency.length} Products Passed`,
14037
+ country_matching_filter: `${productsMatchingUserCountry.length} Products Passed`,
14038
+ language_matching_filter: `${productsMatchingUserCountry.filter(productMatchPageLanguage).length} Products Passed`
14041
14039
  });
14042
14040
  });
14043
14041
  });
@@ -16317,6 +16315,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16317
16315
  onFailure = () => {},
16318
16316
  ...props
16319
16317
  } = _ref;
16318
+ const [vantivPaymentRequest, setVantivPaymentRequest] = React.useState(null);
16319
+ const [updatedCouponCode, setUpdatedCouponCode] = React.useState("");
16320
16320
  const {
16321
16321
  t
16322
16322
  } = useTranslation("payment");
@@ -16359,7 +16359,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16359
16359
  }, []);
16360
16360
 
16361
16361
  /*====== Start Tap integration ========*/
16362
- const submitUsingTap = () => {
16362
+ const submitUsingTap = state => {
16363
16363
  var _ref2, _ref3, _ref4, _state$updatedPrice;
16364
16364
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
16365
16365
  if (isUsingExistingPaymentMethod) {
@@ -16454,7 +16454,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16454
16454
  content: null
16455
16455
  }
16456
16456
  });
16457
- handleTapPayment(tapID);
16457
+ handleTapPayment(tapID, state);
16458
16458
  }
16459
16459
  };
16460
16460
 
@@ -16467,7 +16467,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16467
16467
  }
16468
16468
  });
16469
16469
  };
16470
- function handleTapPayment(paymentRequest) {
16470
+ function handleTapPayment(paymentRequest, state) {
16471
16471
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
16472
16472
  if (type === "createPayment") {
16473
16473
  handleTapSubscription();
@@ -16645,7 +16645,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16645
16645
  };
16646
16646
  /*====== End Tap integration ========*/
16647
16647
 
16648
- const submitUsingVantiv = () => {
16648
+ const submitUsingVantiv = state => {
16649
16649
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
16650
16650
  if (isUsingExistingPaymentMethod) {
16651
16651
  // no need to create a new source using vantiv
@@ -16663,7 +16663,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16663
16663
  orderId: orderId
16664
16664
  });
16665
16665
  };
16666
- function handleVantivPayment(paymentRequest) {
16666
+ function handleVantivPayment(paymentRequest, couponCode) {
16667
16667
  if (paymentRequest) {
16668
16668
  const SUCCESS_STATUS = "870";
16669
16669
  if (paymentRequest.response !== SUCCESS_STATUS) {
@@ -16729,7 +16729,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16729
16729
  const renewSubscription = !isGift && subscriptionIdToRenew;
16730
16730
  const giftSubscriprition = isGift && !subscriptionIdToRenew;
16731
16731
  const renewGift = isRenewingGift;
16732
- const couponCode = state.couponCode || window.Pelcro.coupon.getFromUrl() || "";
16733
16732
  if (renewGift) {
16734
16733
  return payment.execute({
16735
16734
  type: PAYMENT_TYPES.RENEW_GIFTED_SUBSCRIPTION,
@@ -16815,7 +16814,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16815
16814
  height: "245",
16816
16815
  timeout: 50000,
16817
16816
  div: "eProtectiframe",
16818
- callback: handleVantivPayment,
16817
+ callback: paymentRequest => setVantivPaymentRequest(paymentRequest),
16819
16818
  showCvv: true,
16820
16819
  numYears: 8,
16821
16820
  placeholderText: {
@@ -16830,6 +16829,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16830
16829
  });
16831
16830
  }
16832
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]);
16833
16839
  React.useEffect(() => {
16834
16840
  whenUserReady(() => {
16835
16841
  if (skipPayment && (plan === null || plan === void 0 ? void 0 : plan.amount) === 0) return;
@@ -16958,6 +16964,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16958
16964
  });
16959
16965
  if (err) {
16960
16966
  onFailure(err);
16967
+
16968
+ //reset the coupon code in local state
16969
+ setUpdatedCouponCode("");
16961
16970
  dispatch({
16962
16971
  type: SET_COUPON_ERROR,
16963
16972
  payload: getErrorMessages(err)
@@ -17016,6 +17025,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17016
17025
  type: SET_COUPON,
17017
17026
  payload: res.data.coupon
17018
17027
  });
17028
+
17029
+ //set the coupon code in local state to be able to use with Vantiv
17030
+ setUpdatedCouponCode(res.data.coupon.code);
17019
17031
  dispatch({
17020
17032
  type: SET_PERCENT_OFF,
17021
17033
  payload: `${(_res$data$coupon = res.data.coupon) === null || _res$data$coupon === void 0 ? void 0 : _res$data$coupon.percent_off}%`
@@ -17086,6 +17098,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17086
17098
  const debouncedApplyCouponCode = React.useRef(debounce(onApplyCouponCode, 1000)).current;
17087
17099
  const removeAppliedCoupon = state => {
17088
17100
  state.couponCode = "";
17101
+
17102
+ //reset the coupon code in local state
17103
+ setUpdatedCouponCode("");
17089
17104
  dispatch({
17090
17105
  type: SET_COUPON_ERROR,
17091
17106
  payload: ""
@@ -17747,7 +17762,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17747
17762
  return submitUsingVantiv();
17748
17763
  }
17749
17764
  if (getSiteCardProcessor() === "tap") {
17750
- return submitUsingTap();
17765
+ return submitUsingTap(state);
17751
17766
  }
17752
17767
  if (selectedPaymentMethodId) {
17753
17768
  // pay with selected method (source) if exists already
package/dist/index.esm.js CHANGED
@@ -13972,12 +13972,9 @@ class SelectModal extends Component {
13972
13972
  const userCurrency = (_window$Pelcro = window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$user = _window$Pelcro.user) === null || _window$Pelcro$user === void 0 ? void 0 : _window$Pelcro$user.read().currency;
13973
13973
  const userCountry = (_window$Pelcro2 = window.Pelcro) === null || _window$Pelcro2 === void 0 ? void 0 : (_window$Pelcro2$user = _window$Pelcro2.user) === null || _window$Pelcro2$user === void 0 ? void 0 : _window$Pelcro2$user.location.countryCode;
13974
13974
  const userLanguage = (_window$Pelcro3 = window.Pelcro) === null || _window$Pelcro3 === void 0 ? void 0 : (_window$Pelcro3$user = _window$Pelcro3.user) === null || _window$Pelcro3$user === void 0 ? void 0 : _window$Pelcro3$user.read().language;
13975
- const productsMatchingUserCurrency = (_window$Pelcro4 = window.Pelcro) === null || _window$Pelcro4 === void 0 ? void 0 : (_window$Pelcro4$site = _window$Pelcro4.site) === null || _window$Pelcro4$site === void 0 ? void 0 : _window$Pelcro4$site.read().products.map(product => {
13975
+ const productsMatchingUserCurrency = (_window$Pelcro4 = window.Pelcro) === null || _window$Pelcro4 === void 0 ? void 0 : (_window$Pelcro4$site = _window$Pelcro4.site) === null || _window$Pelcro4$site === void 0 ? void 0 : _window$Pelcro4$site.read().products.filter(product => {
13976
13976
  const filteredPlans = product.plans.filter(plan => plan.currency === userCurrency || !userCurrency);
13977
- return {
13978
- ...product,
13979
- plans: filteredPlans
13980
- };
13977
+ if (filteredPlans.length) return filteredPlans;
13981
13978
  });
13982
13979
  const productsMatchingUserCountry = productsMatchingUserCurrency.filter(product => {
13983
13980
  const filteredPlans = product.plans.filter(plan => {
@@ -13988,7 +13985,7 @@ class SelectModal extends Component {
13988
13985
  });
13989
13986
  notifyBugsnag(() => {
13990
13987
  Bugsnag.notify("SelectModal - No data viewed", event => {
13991
- var _window$Pelcro5, _window$Pelcro5$site, _window$Pelcro6, _window$Pelcro6$user, _window$Pelcro7, _window$Pelcro7$uiSet, _window$Pelcro8, _this$props, _window$Pelcro9, _window$Pelcro9$helpe;
13988
+ var _window$Pelcro5, _window$Pelcro5$site, _window$Pelcro6, _window$Pelcro6$user, _window$Pelcro7, _window$Pelcro7$uiSet, _window$Pelcro8, _this$props, _window$Pelcro9, _window$Pelcro9$helpe, _window$Pelcro10, _window$Pelcro10$site;
13992
13989
  event.addMetadata("MetaData", {
13993
13990
  site: (_window$Pelcro5 = window.Pelcro) === null || _window$Pelcro5 === void 0 ? void 0 : (_window$Pelcro5$site = _window$Pelcro5.site) === null || _window$Pelcro5$site === void 0 ? void 0 : _window$Pelcro5$site.read(),
13994
13991
  user: (_window$Pelcro6 = window.Pelcro) === null || _window$Pelcro6 === void 0 ? void 0 : (_window$Pelcro6$user = _window$Pelcro6.user) === null || _window$Pelcro6$user === void 0 ? void 0 : _window$Pelcro6$user.read(),
@@ -14005,9 +14002,10 @@ class SelectModal extends Component {
14005
14002
  userCountry: userCountry,
14006
14003
  userLanguage: userLanguage,
14007
14004
  siteLanguage: (_window$Pelcro9 = window.Pelcro) === null || _window$Pelcro9 === void 0 ? void 0 : (_window$Pelcro9$helpe = _window$Pelcro9.helpers) === null || _window$Pelcro9$helpe === void 0 ? void 0 : _window$Pelcro9$helpe.getHtmlLanguageAttribute(),
14008
- currency_mismatch: productsMatchingUserCurrency.length === 0,
14009
- country_restrictions: productsMatchingUserCountry.length === 0,
14010
- language_mismatch: productsMatchingUserCountry.filter(product => product.plans.length).filter(productMatchPageLanguage).length === 0
14005
+ products: (_window$Pelcro10 = window.Pelcro) === null || _window$Pelcro10 === void 0 ? void 0 : (_window$Pelcro10$site = _window$Pelcro10.site) === null || _window$Pelcro10$site === void 0 ? void 0 : _window$Pelcro10$site.read().products.length,
14006
+ currency_matching_filter: `${productsMatchingUserCurrency.length} Products Passed`,
14007
+ country_matching_filter: `${productsMatchingUserCountry.length} Products Passed`,
14008
+ language_matching_filter: `${productsMatchingUserCountry.filter(productMatchPageLanguage).length} Products Passed`
14011
14009
  });
14012
14010
  });
14013
14011
  });
@@ -16287,6 +16285,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16287
16285
  onFailure = () => {},
16288
16286
  ...props
16289
16287
  } = _ref;
16288
+ const [vantivPaymentRequest, setVantivPaymentRequest] = useState(null);
16289
+ const [updatedCouponCode, setUpdatedCouponCode] = useState("");
16290
16290
  const {
16291
16291
  t
16292
16292
  } = useTranslation("payment");
@@ -16329,7 +16329,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16329
16329
  }, []);
16330
16330
 
16331
16331
  /*====== Start Tap integration ========*/
16332
- const submitUsingTap = () => {
16332
+ const submitUsingTap = state => {
16333
16333
  var _ref2, _ref3, _ref4, _state$updatedPrice;
16334
16334
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
16335
16335
  if (isUsingExistingPaymentMethod) {
@@ -16424,7 +16424,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16424
16424
  content: null
16425
16425
  }
16426
16426
  });
16427
- handleTapPayment(tapID);
16427
+ handleTapPayment(tapID, state);
16428
16428
  }
16429
16429
  };
16430
16430
 
@@ -16437,7 +16437,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16437
16437
  }
16438
16438
  });
16439
16439
  };
16440
- function handleTapPayment(paymentRequest) {
16440
+ function handleTapPayment(paymentRequest, state) {
16441
16441
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
16442
16442
  if (type === "createPayment") {
16443
16443
  handleTapSubscription();
@@ -16615,7 +16615,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16615
16615
  };
16616
16616
  /*====== End Tap integration ========*/
16617
16617
 
16618
- const submitUsingVantiv = () => {
16618
+ const submitUsingVantiv = state => {
16619
16619
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
16620
16620
  if (isUsingExistingPaymentMethod) {
16621
16621
  // no need to create a new source using vantiv
@@ -16633,7 +16633,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16633
16633
  orderId: orderId
16634
16634
  });
16635
16635
  };
16636
- function handleVantivPayment(paymentRequest) {
16636
+ function handleVantivPayment(paymentRequest, couponCode) {
16637
16637
  if (paymentRequest) {
16638
16638
  const SUCCESS_STATUS = "870";
16639
16639
  if (paymentRequest.response !== SUCCESS_STATUS) {
@@ -16699,7 +16699,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16699
16699
  const renewSubscription = !isGift && subscriptionIdToRenew;
16700
16700
  const giftSubscriprition = isGift && !subscriptionIdToRenew;
16701
16701
  const renewGift = isRenewingGift;
16702
- const couponCode = state.couponCode || window.Pelcro.coupon.getFromUrl() || "";
16703
16702
  if (renewGift) {
16704
16703
  return payment.execute({
16705
16704
  type: PAYMENT_TYPES.RENEW_GIFTED_SUBSCRIPTION,
@@ -16785,7 +16784,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16785
16784
  height: "245",
16786
16785
  timeout: 50000,
16787
16786
  div: "eProtectiframe",
16788
- callback: handleVantivPayment,
16787
+ callback: paymentRequest => setVantivPaymentRequest(paymentRequest),
16789
16788
  showCvv: true,
16790
16789
  numYears: 8,
16791
16790
  placeholderText: {
@@ -16800,6 +16799,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16800
16799
  });
16801
16800
  }
16802
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]);
16803
16809
  useEffect(() => {
16804
16810
  whenUserReady(() => {
16805
16811
  if (skipPayment && (plan === null || plan === void 0 ? void 0 : plan.amount) === 0) return;
@@ -16928,6 +16934,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16928
16934
  });
16929
16935
  if (err) {
16930
16936
  onFailure(err);
16937
+
16938
+ //reset the coupon code in local state
16939
+ setUpdatedCouponCode("");
16931
16940
  dispatch({
16932
16941
  type: SET_COUPON_ERROR,
16933
16942
  payload: getErrorMessages(err)
@@ -16986,6 +16995,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
16986
16995
  type: SET_COUPON,
16987
16996
  payload: res.data.coupon
16988
16997
  });
16998
+
16999
+ //set the coupon code in local state to be able to use with Vantiv
17000
+ setUpdatedCouponCode(res.data.coupon.code);
16989
17001
  dispatch({
16990
17002
  type: SET_PERCENT_OFF,
16991
17003
  payload: `${(_res$data$coupon = res.data.coupon) === null || _res$data$coupon === void 0 ? void 0 : _res$data$coupon.percent_off}%`
@@ -17056,6 +17068,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17056
17068
  const debouncedApplyCouponCode = useRef(debounce(onApplyCouponCode, 1000)).current;
17057
17069
  const removeAppliedCoupon = state => {
17058
17070
  state.couponCode = "";
17071
+
17072
+ //reset the coupon code in local state
17073
+ setUpdatedCouponCode("");
17059
17074
  dispatch({
17060
17075
  type: SET_COUPON_ERROR,
17061
17076
  payload: ""
@@ -17717,7 +17732,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17717
17732
  return submitUsingVantiv();
17718
17733
  }
17719
17734
  if (getSiteCardProcessor() === "tap") {
17720
- return submitUsingTap();
17735
+ return submitUsingTap(state);
17721
17736
  }
17722
17737
  if (selectedPaymentMethodId) {
17723
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.1",
4
+ "version": "3.21.3",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",