paymob-pixel-alpha 1.1.27 → 1.1.29

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 (2) hide show
  1. package/main.js +87 -57
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -13604,6 +13604,9 @@ const ContactForm = /*#__PURE__*/(/* unused pure expression or super */ null &&
13604
13604
  needsName,
13605
13605
  needsEmail,
13606
13606
  needsPhone,
13607
+ emailRequired = true,
13608
+ phoneRequired = true,
13609
+ nameRequired = true,
13607
13610
  defaultCountryISO = 'EG',
13608
13611
  defaultValues,
13609
13612
  hideLabels,
@@ -13623,7 +13626,8 @@ const ContactForm = /*#__PURE__*/(/* unused pure expression or super */ null &&
13623
13626
  formState: {
13624
13627
  errors,
13625
13628
  isDirty,
13626
- isValid
13629
+ isValid,
13630
+ dirtyFields
13627
13631
  },
13628
13632
  setValue,
13629
13633
  trigger,
@@ -13729,8 +13733,8 @@ const ContactForm = /*#__PURE__*/(/* unused pure expression or super */ null &&
13729
13733
  } else if (onClientData) {
13730
13734
  onClientData(null);
13731
13735
  }
13732
- onValidityChange == null || onValidityChange(isValid && (isDirty || !!defaultValues), isDirty || !(verifiedFields != null && verifiedFields.email) || !(verifiedFields != null && verifiedFields.phone));
13733
- }, [isDirty, isValid, watchFieldsJson]);
13736
+ onValidityChange == null || onValidityChange(isValid && (isDirty || !!defaultValues), !!Object.keys(dirtyFields).length || !(verifiedFields != null && verifiedFields.email) && !!getValues('email') || !(verifiedFields != null && verifiedFields.phone) && !!getValues('phone'));
13737
+ }, [isDirty, isValid, watchFieldsJson, Object.keys(dirtyFields).length]);
13734
13738
  useEffect(() => {
13735
13739
  const getRegionData = async () => {
13736
13740
  setIsLoadingRegionData(true);
@@ -13780,11 +13784,12 @@ const ContactForm = /*#__PURE__*/(/* unused pure expression or super */ null &&
13780
13784
  setValue(_field, e.target.value);
13781
13785
  }
13782
13786
  },
13783
- required: {
13787
+ required: emailRequired ? {
13784
13788
  value: true,
13785
13789
  message: t('EMAIL_IS_REQUIRED')
13786
- },
13790
+ } : false,
13787
13791
  validate: value => {
13792
+ if (!value) return !emailRequired || t('EMAIL_IS_REQUIRED');
13788
13793
  const regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
13789
13794
  return regex.test(value) || t('EMAIL_NOT_VALID');
13790
13795
  }
@@ -13819,10 +13824,10 @@ const ContactForm = /*#__PURE__*/(/* unused pure expression or super */ null &&
13819
13824
  }
13820
13825
  }
13821
13826
  },
13822
- required: {
13827
+ required: nameRequired ? {
13823
13828
  value: true,
13824
13829
  message: t('NAME_IS_REQUIRED')
13825
- }
13830
+ } : false
13826
13831
  });
13827
13832
  }, []);
13828
13833
  const createPhoneRegister = useCallback(({
@@ -13836,12 +13841,13 @@ const ContactForm = /*#__PURE__*/(/* unused pure expression or super */ null &&
13836
13841
  const trimmedNumber = phoneNumber.replace(/\D/g, '');
13837
13842
  setValue(_field3, trimmedNumber);
13838
13843
  },
13839
- required: {
13844
+ required: phoneRequired ? {
13840
13845
  value: true,
13841
13846
  message: t('PHONE_IS_REQUIRED')
13842
- },
13847
+ } : false,
13843
13848
  validate: value => {
13844
13849
  var _parseMax;
13850
+ if (!value) return !phoneRequired || t('PHONE_IS_REQUIRED');
13845
13851
  return ((_parseMax = parseMax(countryCode + value)) == null ? void 0 : _parseMax.isValid()) || t('PHONE_NOT_VALID');
13846
13852
  }
13847
13853
  });
@@ -21007,6 +21013,7 @@ function formatAmountBasedOnCurrency_formatAmountBasedOnCurrency(amount, currenc
21007
21013
 
21008
21014
 
21009
21015
 
21016
+
21010
21017
 
21011
21018
 
21012
21019
  ;// ../../node_modules/react-loading-skeleton/dist/index.js
@@ -21530,8 +21537,12 @@ function cardFormViewTwo_Card(props) {
21530
21537
  setIsOmanNetCard == null || setIsOmanNetCard(cardType === CARD_TYPES.OMAN);
21531
21538
  }, [cardType, setIsOmanNetCard]);
21532
21539
  useEffect(() => {
21533
- onDiscount == null || onDiscount(cardNum, isValidCard);
21534
- }, [isValidCard, cardNum]);
21540
+ onDiscount == null || onDiscount({
21541
+ cardNum,
21542
+ isValidCard,
21543
+ cardType
21544
+ });
21545
+ }, [isValidCard, cardNum, cardType]);
21535
21546
  return /*#__PURE__*/_jsxs("form", {
21536
21547
  onSubmit: handleSubmit(onSubmit),
21537
21548
  noValidate: true,
@@ -21861,8 +21872,12 @@ function mobileCardFormViewTwo_MobileCard(props) {
21861
21872
  }
21862
21873
  }, [expiryWatch, cvcWatch]);
21863
21874
  useEffect(() => {
21864
- onDiscount == null || onDiscount(cardNum, isValidCard);
21865
- }, [isValidCard, cardNum]);
21875
+ onDiscount == null || onDiscount({
21876
+ cardNum,
21877
+ isValidCard,
21878
+ cardType
21879
+ });
21880
+ }, [isValidCard, cardNum, cardType]);
21866
21881
  return /*#__PURE__*/_jsxs(_Fragment, {
21867
21882
  children: [/*#__PURE__*/_jsxs("form", {
21868
21883
  onSubmit: handleSubmit(onSubmit),
@@ -22063,7 +22078,6 @@ function IframeCard(props) {
22063
22078
  const {
22064
22079
  loading,
22065
22080
  handleCardSubmit,
22066
- handleOTPSubmit,
22067
22081
  getCardLogo,
22068
22082
  useHookForm,
22069
22083
  isOmanNetCard,
@@ -22120,17 +22134,15 @@ function IframeCard(props) {
22120
22134
  cardNum,
22121
22135
  isValidCard,
22122
22136
  discountsCount,
22123
- integrationId: hasOmanNetIntegration && isOmanNetCard ? subType.integrationId : integrationId,
22124
- paymentToken: hasOmanNetIntegration && isOmanNetCard ? subType.paymentToken : paymentToken
22137
+ integrationId: hasOmanNetIntegration && cardType === CARD_TYPES.OMAN ? subType.integrationId : integrationId,
22138
+ paymentToken: hasOmanNetIntegration && cardType === CARD_TYPES.OMAN ? subType.paymentToken : paymentToken
22125
22139
  });
22126
- }, [cardNum, isValidCard, discountsCount, hasOmanNetIntegration, isOmanNetCard, subType, paymentToken, integrationId]);
22140
+ }, [cardNum, isValidCard, discountsCount, hasOmanNetIntegration, cardType, subType, paymentToken, integrationId]);
22127
22141
  const handleDataFromSDK = event => {
22128
22142
  if (event.data.type === 'setPrevFocus') {
22129
22143
  handlePrevFocusFromSDK(event.data.payload);
22130
22144
  } else if (event.data.type === 'cardData') {
22131
22145
  handleCardDataFromSDK(event.data.payload);
22132
- } else if (event.data.type === 'otpData') {
22133
- handleOTPSubmit(event.data.payload);
22134
22146
  } else if (event.data.type === 'customStyles') {
22135
22147
  handleCardStylesFromSDK(event.data.payload);
22136
22148
  } else if (event.data.type === 'cardHolderError') {
@@ -23001,9 +23013,12 @@ function SavedCardsViewTwo(props) {
23001
23013
  setSelectedCardCVV('');
23002
23014
  if ((selectedCard == null ? void 0 : selectedCard.id) === card.id) setSelectedCard(null);else {
23003
23015
  setSelectedCard(card);
23004
- onDiscount == null || onDiscount(card.identifier, !!card.identifier && !!card.hasDiscount, true);
23016
+ onDiscount == null || onDiscount({
23017
+ cardNum: card.identifier,
23018
+ isValidCard: !!card.identifier && !!card.hasDiscount,
23019
+ savedCardType: card.type
23020
+ });
23005
23021
  }
23006
- ;
23007
23022
  };
23008
23023
  const handleSelectDeleteCard = (e, card) => {
23009
23024
  e.stopPropagation();
@@ -23397,7 +23412,14 @@ const checkDiscount = (payment_token, integration_id, identifier, isSavedCard) =
23397
23412
  identifier: identifier.replace(/\s/g, '')
23398
23413
  }, isSavedCard && {
23399
23414
  saved_card_token: identifier
23400
- })).then(res => res).catch(err => err == null ? void 0 : err.response);
23415
+ }));
23416
+ };
23417
+ const sendOTP = payload => {
23418
+ return lib_axios.post(`/api/acceptance/omannet_callback/otp_verify`, {
23419
+ payment_id: payload.paymentId,
23420
+ otp: payload.otp,
23421
+ payment_token: payload.token
23422
+ }).then(res => res).catch(err => err == null ? void 0 : err.response);
23401
23423
  };
23402
23424
  ;// ./src/utils/getErrorMsg.ts
23403
23425
  const getErrorMsg_isString = data => typeof data === 'string';
@@ -23533,6 +23555,7 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
23533
23555
  const [sendOTPLoading, setSendOTPLoading] = (0,react.useState)(false);
23534
23556
  const [paymentId, setPaymentId] = (0,react.useState)('');
23535
23557
  const [otpErrorMessage, setOTPErrorMessage] = (0,react.useState)('');
23558
+ const [isOmanNetCard, setIsOmanNetCard] = (0,react.useState)(false);
23536
23559
  const tokenizationResolve = (0,react.useRef)(null);
23537
23560
  const isCardValid = hideCardHolderName ? !isActionBtnDisabled : !(isActionBtnDisabled || !cardHolderName);
23538
23561
  const isAmexCardSelected = (selectedCard == null ? void 0 : selectedCard.type) === src_constants_CARD_TYPES.AMEX;
@@ -23602,29 +23625,23 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
23602
23625
  const handlePaymentResponse = ({
23603
23626
  res,
23604
23627
  requiresOTP,
23605
- isOTPResponse
23628
+ isOmanNetCard
23606
23629
  }) => {
23607
23630
  var _iframeRef$current3, _res$data, _res$data2, _res$data3;
23608
23631
  setShouldSubmitData(false);
23609
23632
  setSendOTPLoading(false);
23633
+ setIsOmanNetCard(false);
23610
23634
  const cardHolderInput = (_iframeRef$current3 = iframeRef.current) == null || (_iframeRef$current3 = _iframeRef$current3.nextElementSibling) == null ? void 0 : _iframeRef$current3.querySelector(`input[name=name]`);
23611
23635
  if (cardHolderInput) {
23612
23636
  setTimeout(() => cardHolderInput.disabled = false, 1000);
23613
23637
  }
23614
23638
  const redirectionUrl = ((_res$data = res.data) == null ? void 0 : _res$data.redirection_url) || ((_res$data2 = res.data) == null ? void 0 : _res$data2.redirect_url);
23615
23639
  if (requiresOTP) {
23640
+ setIsOmanNetCard(!!isOmanNetCard);
23616
23641
  setPaymentId(res.data.payment_id);
23617
23642
  setShowOTP(true);
23618
23643
  } else if (onAfterPaymentComplete && ((_res$data3 = res.data) == null ? void 0 : _res$data3.is_3d_secure) !== 'true') {
23619
23644
  onAfterPaymentComplete(res);
23620
- } else if (res.status === 200 && isOTPResponse) {
23621
- if (redirectionUrl && (res.data.result === 'CAPTURED' || res.data.result === 'APPROVED')) {
23622
- window.location.href = redirectionUrl;
23623
- } else {
23624
- setOTPErrorMessage(getErrorMsg(res));
23625
- }
23626
- } else if (res.status !== 200 && isOTPResponse) {
23627
- setOTPErrorMessage(getErrorMsg(res));
23628
23645
  } else if (res.status === 200 && redirectionUrl) {
23629
23646
  window.location.href = redirectionUrl;
23630
23647
  } else if (res.status === 400) {
@@ -23819,10 +23836,13 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
23819
23836
  setDiscountAppliedMessage(null);
23820
23837
  setTotalAmount("");
23821
23838
  };
23822
- const handleSavedCardDiscount = async (identifier, hasDiscount) => {
23839
+ const handleSavedCardDiscount = async (identifier, hasDiscount, savedCardType) => {
23840
+ var _payment$subType4, _payment$subType5;
23823
23841
  handleResetDiscountMessages();
23824
23842
  if (!hasDiscount) return;
23825
- const res = await checkDiscount(payment.token, payment.id, identifier, true);
23843
+ const paymentToken = savedCardType === constants_SAVED_CARD_TYPES.OMAN_NET ? payment == null || (_payment$subType4 = payment.subType) == null ? void 0 : _payment$subType4.token : payment == null ? void 0 : payment.token;
23844
+ const integrationId = savedCardType === constants_SAVED_CARD_TYPES.OMAN_NET ? payment == null || (_payment$subType5 = payment.subType) == null ? void 0 : _payment$subType5.integrationId : payment == null ? void 0 : payment.id;
23845
+ const res = await checkDiscount(paymentToken, integrationId, identifier, savedCardType);
23826
23846
  handleDiscount(res);
23827
23847
  };
23828
23848
  const handleDiscount = res => {
@@ -23874,7 +23894,7 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
23874
23894
  setSelectedCardCVV('');
23875
23895
  if ((selectedCard == null ? void 0 : selectedCard.id) === card.id) setSelectedCard(null);else {
23876
23896
  setSelectedCard(card);
23877
- handleSavedCardDiscount == null || handleSavedCardDiscount(card.identifier, !!card.identifier && !!card.hasDiscount);
23897
+ handleSavedCardDiscount == null || handleSavedCardDiscount(card.identifier, !!card.identifier && !!card.hasDiscount, card.type);
23878
23898
  }
23879
23899
  ;
23880
23900
  };
@@ -23884,7 +23904,7 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
23884
23904
  setSelectedDeleteCard(card);
23885
23905
  };
23886
23906
  const handleSavedCardSubmit = async () => {
23887
- var _payment$subType4;
23907
+ var _payment$subType6, _res$data8, _res$data9, _res$data0;
23888
23908
  if (loading) return;
23889
23909
  setLoading(true);
23890
23910
  if (onBeforePaymentComplete) {
@@ -23896,13 +23916,14 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
23896
23916
  return;
23897
23917
  }
23898
23918
  }
23919
+ const isOmanNet = (selectedCard == null ? void 0 : selectedCard.type) === constants_SAVED_CARD_TYPES.OMAN_NET;
23899
23920
  const data = {
23900
23921
  identifier: selectedCard == null ? void 0 : selectedCard.identifier,
23901
23922
  cvv: selectedCardCVV
23902
23923
  };
23903
23924
  const payload = Object.assign({
23904
23925
  identifier: data.identifier,
23905
- token: (selectedCard == null ? void 0 : selectedCard.type) === constants_SAVED_CARD_TYPES.OMAN_NET ? payment == null || (_payment$subType4 = payment.subType) == null ? void 0 : _payment$subType4.token : payment == null ? void 0 : payment.token
23926
+ token: isOmanNet ? payment == null || (_payment$subType6 = payment.subType) == null ? void 0 : _payment$subType6.token : payment == null ? void 0 : payment.token
23906
23927
  }, data.cvv && {
23907
23928
  cvv: data.cvv
23908
23929
  }, {
@@ -23910,21 +23931,25 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
23910
23931
  });
23911
23932
  const res = await payWithSavedCard(payload);
23912
23933
  setLoading(false);
23934
+ setIsOmanNetCard(false);
23935
+ const isSuccess = String((_res$data8 = res.data) == null ? void 0 : _res$data8.success) === 'true';
23936
+ const isPending = String((_res$data9 = res.data) == null ? void 0 : _res$data9.pending) === 'true';
23937
+ const isOTPGeneration = String((_res$data0 = res.data) == null ? void 0 : _res$data0.otp_generation) === 'true';
23913
23938
  if (res.status === 200) {
23914
- if (res.data && res.data.is_3d_secure === 'true' && res.data.redirection_url) {
23915
- window.location.href = res.data.redirection_url;
23916
- } else if (res.data.success === 'true' && res.data.pending === 'false') {
23917
- window.location.href = res.data.redirection_url;
23939
+ if (isOmanNet && isOTPGeneration && !isSuccess && isPending) {
23940
+ setIsOmanNetCard(true);
23941
+ setPaymentId(res.data.payment_id);
23942
+ setShowOTP(true);
23918
23943
  } else {
23919
23944
  window.location.href = res.data.redirection_url;
23920
23945
  }
23921
23946
  } else if (res.status === 400) {
23922
- var _res$data8, _res$data9, _res$data0;
23923
- if (res.data instanceof Array && res.data[0] === 'Retry limit reached.' || ((_res$data8 = res.data) == null ? void 0 : _res$data8.msg) === 'Retry limit reached.') {
23947
+ var _res$data1, _res$data10, _res$data11;
23948
+ if (res.data instanceof Array && res.data[0] === 'Retry limit reached.' || ((_res$data1 = res.data) == null ? void 0 : _res$data1.msg) === 'Retry limit reached.') {
23924
23949
  setErrorMessage(t('ERR_MSG_EXCEEDED_TRIALS'));
23925
- } else if (((_res$data9 = res.data) == null ? void 0 : _res$data9.message) === 'Session Error') {
23950
+ } else if (((_res$data10 = res.data) == null ? void 0 : _res$data10.message) === 'Session Error') {
23926
23951
  setErrorMessage(t('ERR_MSG_ALREADY_PROCESSED'));
23927
- } else if (res.data instanceof Array && res.data[0] === 'Order has already paid.' || ((_res$data0 = res.data) == null ? void 0 : _res$data0.msg) === 'Order has already paid.') {
23952
+ } else if (res.data instanceof Array && res.data[0] === 'Order has already paid.' || ((_res$data11 = res.data) == null ? void 0 : _res$data11.msg) === 'Order has already paid.') {
23928
23953
  setErrorMessage(t('ERR_MSG_ALREADY_PAID'));
23929
23954
  } else {
23930
23955
  setErrorMessage(t('ERR_MSG_DECLINED'));
@@ -23942,19 +23967,24 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
23942
23967
  }
23943
23968
  };
23944
23969
  const handleOTPSubmit = async otp => {
23945
- var _iframeRef$current1, _payment$subType5;
23970
+ var _payment$subType7, _res$data12, _res$data13;
23946
23971
  setSendOTPLoading(true);
23947
- (_iframeRef$current1 = iframeRef.current) == null || (_iframeRef$current1 = _iframeRef$current1.contentWindow) == null || _iframeRef$current1.postMessage({
23948
- type: 'otpData',
23949
- payload: {
23950
- paymentToken: payment.token,
23951
- subType: {
23952
- paymentToken: (_payment$subType5 = payment.subType) == null ? void 0 : _payment$subType5.token
23953
- },
23954
- otp,
23955
- paymentId
23972
+ const res = await sendOTP({
23973
+ token: isOmanNetCard ? (_payment$subType7 = payment.subType) == null ? void 0 : _payment$subType7.token : payment.token,
23974
+ otp,
23975
+ paymentId
23976
+ });
23977
+ const redirectionUrl = ((_res$data12 = res.data) == null ? void 0 : _res$data12.redirection_url) || ((_res$data13 = res.data) == null ? void 0 : _res$data13.redirect_url);
23978
+ if (res.status === 200) {
23979
+ if (redirectionUrl && (res.data.result === 'CAPTURED' || res.data.result === 'APPROVED')) {
23980
+ window.location.href = redirectionUrl;
23981
+ } else {
23982
+ setOTPErrorMessage(getErrorMsg(res));
23956
23983
  }
23957
- }, '*');
23984
+ } else if (res.status !== 200) {
23985
+ setOTPErrorMessage(getErrorMsg(res));
23986
+ }
23987
+ setSendOTPLoading(false);
23958
23988
  };
23959
23989
  const handleShowNewCardForm = () => {
23960
23990
  if (loading) return;
@@ -27682,7 +27712,7 @@ const payForsa = (phone, down_payment, selected_plan, tenure, token) => {
27682
27712
  payment_token: token
27683
27713
  }).then(res => res).catch(err => err == null ? void 0 : err.response);
27684
27714
  };
27685
- const sendOTP = (otp, token, reference) => {
27715
+ const forsaService_sendOTP = (otp, token, reference) => {
27686
27716
  return lib_axios.post(`/api/acceptance/forsa_online/submit_loan`, {
27687
27717
  otp: otp,
27688
27718
  payment_token: token,
@@ -27845,7 +27875,7 @@ function ForsaElements({
27845
27875
  const handleOTPSubmit = async otp => {
27846
27876
  setLoading(true);
27847
27877
  resetErrorMessage();
27848
- const res = await sendOTP(otp, token, reference);
27878
+ const res = await forsaService_sendOTP(otp, token, reference);
27849
27879
  if (res.status === 200) {
27850
27880
  if (window.top) {
27851
27881
  window.top.location.href = res.data.redirection_url;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paymob-pixel-alpha",
3
- "version": "1.1.27",
3
+ "version": "1.1.29",
4
4
  "keywords": ["paymob","pixel","paymob-pixel"],
5
5
  "main": "./main.js",
6
6
  "license": "MIT",