paymob-pixel-alpha 1.0.8 → 1.0.9

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 (3) hide show
  1. package/main.js +182 -83
  2. package/package.json +1 -1
  3. package/styles.css +4 -0
package/main.js CHANGED
@@ -10055,10 +10055,18 @@ function useWidth() {
10055
10055
  const [isMobile, setIsMobile] = (0,react.useState)(false);
10056
10056
  (0,react.useEffect)(() => {
10057
10057
  const handleResize = () => {
10058
- if (window.innerWidth <= 644) {
10059
- setIsMobile(true);
10058
+ if (window.visualViewport) {
10059
+ if (window.visualViewport.width <= 644) {
10060
+ setIsMobile(true);
10061
+ } else {
10062
+ setIsMobile(false);
10063
+ }
10060
10064
  } else {
10061
- setIsMobile(false);
10065
+ if (window.innerWidth <= 644) {
10066
+ setIsMobile(true);
10067
+ } else {
10068
+ setIsMobile(false);
10069
+ }
10062
10070
  }
10063
10071
  };
10064
10072
  handleResize();
@@ -17637,6 +17645,7 @@ function TermsConditions_TermsConditions() {
17637
17645
 
17638
17646
 
17639
17647
 
17648
+
17640
17649
 
17641
17650
 
17642
17651
  ;// CONCATENATED MODULE: ../../node_modules/react-loading-skeleton/dist/index.js
@@ -18753,12 +18762,16 @@ function mobileCardFormViewTwo_MobileCard(props) {
18753
18762
 
18754
18763
 
18755
18764
  function IframeCard(props) {
18756
- var _subType$type;
18757
18765
  const {
18758
18766
  loading,
18759
18767
  handleCardSubmit,
18768
+ handleOTPSubmit,
18760
18769
  getCardLogo,
18761
- useHookForm
18770
+ useHookForm,
18771
+ isOmanNetCard,
18772
+ setIsOmanNetCard,
18773
+ hasOmanNetIntegration,
18774
+ setHasOmanNetIntegration
18762
18775
  } = props;
18763
18776
  const [iframeCardHight, setIframeCardHight] = useState();
18764
18777
  const [iframeCustomStyles, setIframeCustomStyles] = useState({});
@@ -18771,7 +18784,6 @@ function IframeCard(props) {
18771
18784
  const [cardHolderError, setCardHolderError] = useState();
18772
18785
  const [cardHolderNameHidden, setCardHolderNameHidden] = useState(false);
18773
18786
  const [currency, setCurrency] = useState('');
18774
- const hasOmanNetIntegration = (subType == null || (_subType$type = subType.type) == null ? void 0 : _subType$type.toLowerCase()) === CARD_TYPES.OMAN;
18775
18787
  const {
18776
18788
  handleSubmit,
18777
18789
  errors,
@@ -18791,11 +18803,16 @@ function IframeCard(props) {
18791
18803
  window.addEventListener('message', handleDataFromSDK);
18792
18804
  return () => window.removeEventListener('message', handleDataFromSDK);
18793
18805
  }, []);
18806
+ useEffect(() => {
18807
+ setIsOmanNetCard == null || setIsOmanNetCard(cardType === CARD_TYPES.OMAN);
18808
+ }, [cardType, setIsOmanNetCard]);
18794
18809
  const handleDataFromSDK = event => {
18795
18810
  if (event.data.type === 'setPrevFocus') {
18796
18811
  handlePrevFocusFromSDK(event.data.payload);
18797
18812
  } else if (event.data.type === 'cardData') {
18798
18813
  handleCardDataFromSDK(event.data.payload);
18814
+ } else if (event.data.type === 'otpData') {
18815
+ handleOTPSubmit(event.data.payload);
18799
18816
  } else if (event.data.type === 'customStyles') {
18800
18817
  handleCardStylesFromSDK(event.data.payload);
18801
18818
  } else if (event.data.type === 'cardHolderError') {
@@ -18825,7 +18842,9 @@ function IframeCard(props) {
18825
18842
  setPaymentToken(payload.paymentToken);
18826
18843
  }
18827
18844
  if ((_payload$subType = payload.subType) != null && _payload$subType.paymentToken && (_payload$subType2 = payload.subType) != null && _payload$subType2.type) {
18845
+ var _payload$subType$type;
18828
18846
  setSubType(payload.subType);
18847
+ setHasOmanNetIntegration(((_payload$subType$type = payload.subType.type) == null ? void 0 : _payload$subType$type.toLowerCase()) === CARD_TYPES.OMAN);
18829
18848
  }
18830
18849
  if (payload.tenure) {
18831
18850
  setTenure(payload.tenure);
@@ -18870,8 +18889,8 @@ function IframeCard(props) {
18870
18889
  handleCardSubmit({
18871
18890
  data,
18872
18891
  cardHolderName,
18873
- paymentToken: hasOmanNetIntegration && cardType === CARD_TYPES.OMAN ? subType.paymentToken : paymentToken,
18874
- subType: hasOmanNetIntegration && cardType === CARD_TYPES.OMAN ? subType.type : 'CARD',
18892
+ paymentToken: hasOmanNetIntegration && isOmanNetCard ? subType.paymentToken : paymentToken,
18893
+ subType: hasOmanNetIntegration && isOmanNetCard ? subType.type : 'CARD',
18875
18894
  saveCard,
18876
18895
  tenure
18877
18896
  });
@@ -19869,7 +19888,9 @@ function CardElement({
19869
19888
  onCardValidationChanged,
19870
19889
  showPaymobLogo,
19871
19890
  hideCardHolderName,
19872
- isLoading
19891
+ isLoading,
19892
+ onProcessingPayment,
19893
+ isProcessingPayment
19873
19894
  }) {
19874
19895
  var _customStyle$containe;
19875
19896
  const {
@@ -19882,6 +19903,7 @@ function CardElement({
19882
19903
  const {
19883
19904
  t
19884
19905
  } = useTranslation_useTranslation('card');
19906
+ const isMobile = useWidth();
19885
19907
  const [loading, setLoading] = (0,react.useState)(false);
19886
19908
  const [cardHolderName, setCardHolderName] = (0,react.useState)('');
19887
19909
  const [isActionBtnDisabled, setIsActionBtnDisabled] = (0,react.useState)(false);
@@ -19899,6 +19921,10 @@ function CardElement({
19899
19921
  const [selectedCardCVV, setSelectedCardCVV] = (0,react.useState)('');
19900
19922
  const [showCardModal, setShowCardModal] = (0,react.useState)(false);
19901
19923
  const [showCVVTooltipModal, setShowCVVTooltipModal] = (0,react.useState)(false);
19924
+ const [showOTP, setShowOTP] = (0,react.useState)(false);
19925
+ const [sendOTPLoading, setSendOTPLoading] = (0,react.useState)(false);
19926
+ const previousValidationRef = (0,react.useRef)(false);
19927
+ const [startCardPay, setStartCardPay] = (0,react.useState)(false);
19902
19928
  const isCardValid = hideCardHolderName ? !isActionBtnDisabled : !(isActionBtnDisabled || !cardHolderName);
19903
19929
  const isAmexCardSelected = (selectedCard == null ? void 0 : selectedCard.type) === constants_CARD_TYPES.AMEX;
19904
19930
  const selectedCardCvvLength = selectedCardCVV.length;
@@ -19941,24 +19967,31 @@ function CardElement({
19941
19967
  setShowCVVTooltipModal(true);
19942
19968
  }
19943
19969
  };
19944
- const handlePaymentResponse = res => {
19945
- var _res$data, _res$data2;
19970
+ const handlePaymentResponse = ({
19971
+ res,
19972
+ requiresOTP
19973
+ }) => {
19974
+ var _res$data, _res$data2, _res$data3;
19946
19975
  setShouldSubmitData(false);
19976
+ setSendOTPLoading(false);
19947
19977
  const cardHolderInput = document.getElementById('name');
19948
19978
  if (cardHolderInput) {
19949
19979
  setTimeout(() => cardHolderInput.disabled = false, 1000);
19950
19980
  }
19951
- if (onAfterPaymentComplete && ((_res$data = res.data) == null ? void 0 : _res$data.is_3d_secure) !== 'true') {
19981
+ if (requiresOTP) {
19982
+ setShowOTP(true);
19983
+ } else if (onAfterPaymentComplete && ((_res$data = res.data) == null ? void 0 : _res$data.is_3d_secure) !== 'true') {
19952
19984
  onAfterPaymentComplete(res);
19953
- } else if (res.status === 200 && (_res$data2 = res.data) != null && _res$data2.redirection_url) {
19954
- window.location.href = res.data.redirection_url;
19985
+ } else if (res.status === 200 && ((_res$data2 = res.data) != null && _res$data2.redirection_url || (_res$data3 = res.data) != null && _res$data3.redirect_url)) {
19986
+ var _res$data4, _res$data5;
19987
+ window.location.href = ((_res$data4 = res.data) == null ? void 0 : _res$data4.redirection_url) || ((_res$data5 = res.data) == null ? void 0 : _res$data5.redirect_url);
19955
19988
  } else if (res.status === 400) {
19956
- var _res$data3, _res$data4, _res$data5;
19957
- if (res.data instanceof Array && res.data[0] === 'Retry limit reached.' || ((_res$data3 = res.data) == null ? void 0 : _res$data3.msg) === 'Retry limit reached.') {
19989
+ var _res$data6, _res$data7, _res$data8;
19990
+ if (res.data instanceof Array && res.data[0] === 'Retry limit reached.' || ((_res$data6 = res.data) == null ? void 0 : _res$data6.msg) === 'Retry limit reached.') {
19958
19991
  setErrorMessage(t('ERR_MSG_EXCEEDED_TRIALS'));
19959
- } else if (((_res$data4 = res.data) == null ? void 0 : _res$data4.message) === 'Session Error') {
19992
+ } else if (((_res$data7 = res.data) == null ? void 0 : _res$data7.message) === 'Session Error') {
19960
19993
  setErrorMessage(t('ERR_MSG_ALREADY_PROCESSED'));
19961
- } else if (res.data instanceof Array && res.data[0] === 'Order has already paid.' || ((_res$data5 = res.data) == null ? void 0 : _res$data5.msg) === 'Order has already paid.') {
19994
+ } else if (res.data instanceof Array && res.data[0] === 'Order has already paid.' || ((_res$data8 = res.data) == null ? void 0 : _res$data8.msg) === 'Order has already paid.') {
19962
19995
  setErrorMessage(t('ERR_MSG_ALREADY_PAID'));
19963
19996
  } else {
19964
19997
  setErrorMessage(t('ERR_MSG_DECLINED'));
@@ -20006,7 +20039,6 @@ function CardElement({
20006
20039
  (0,react.useEffect)(() => {
20007
20040
  if (iframe && shouldSubmitData) {
20008
20041
  const handlePay = async () => {
20009
- var _iframe$contentWindow;
20010
20042
  if (loading) return;
20011
20043
  const cardHolderInput = document.getElementById('name');
20012
20044
  if (cardHolderInput) {
@@ -20014,56 +20046,46 @@ function CardElement({
20014
20046
  }
20015
20047
  setLoading(true);
20016
20048
  if (onBeforePaymentComplete) {
20017
- const result = await onBeforePaymentComplete();
20049
+ const result = await onBeforePaymentComplete(payment.name);
20018
20050
  if (!result) {
20019
20051
  setShouldSubmitData(false);
20020
20052
  setLoading(false);
20021
20053
  return;
20022
20054
  }
20023
20055
  }
20024
- (_iframe$contentWindow = iframe.contentWindow) == null || _iframe$contentWindow.postMessage({
20025
- type: 'cardData',
20026
- payload: {
20027
- cardHolderName,
20028
- saveCard: forceSaveCard || saveCard,
20029
- tenure,
20030
- shouldSubmitData
20031
- }
20032
- }, '*');
20056
+ setStartCardPay(true);
20057
+ onProcessingPayment(true);
20033
20058
  setShouldSubmitData(false);
20034
20059
  };
20035
20060
  handlePay();
20036
20061
  }
20037
20062
  }, [cardHolderName, saveCard, shouldSubmitData, iframe]);
20038
20063
  (0,react.useEffect)(() => {
20039
- if (isIframeLoaded) {
20040
- var _iframe$contentWindow2, _payment$subType, _payment$subType2, _iframe$contentWindow3;
20041
- (_iframe$contentWindow2 = iframe.contentWindow) == null || _iframe$contentWindow2.postMessage({
20064
+ if (isIframeLoaded || startCardPay && isProcessingPayment) {
20065
+ var _iframe$contentWindow, _payment$subType, _payment$subType2;
20066
+ (_iframe$contentWindow = iframe.contentWindow) == null || _iframe$contentWindow.postMessage({
20042
20067
  type: 'cardData',
20043
20068
  payload: {
20044
- paymentToken: token,
20069
+ paymentToken: payment.token,
20045
20070
  subType: {
20046
20071
  paymentToken: (_payment$subType = payment.subType) == null ? void 0 : _payment$subType.token,
20047
20072
  type: (_payment$subType2 = payment.subType) == null ? void 0 : _payment$subType2.type
20048
20073
  },
20049
- currency: currency
20050
- }
20051
- }, '*');
20052
- (_iframe$contentWindow3 = iframe.contentWindow) == null || _iframe$contentWindow3.postMessage({
20053
- type: 'paymentInfo',
20054
- payload: {
20055
- amount,
20056
20074
  currency,
20057
- showSaveCard,
20058
- payment
20075
+ cardHolderName,
20076
+ saveCard: forceSaveCard || saveCard,
20077
+ tenure,
20078
+ shouldSubmitData: startCardPay && isProcessingPayment
20059
20079
  }
20060
20080
  }, '*');
20081
+ setStartCardPay(false);
20082
+ onProcessingPayment(false);
20061
20083
  }
20062
- }, [isIframeLoaded, payment]);
20084
+ }, [isIframeLoaded, payment, isProcessingPayment]);
20063
20085
  (0,react.useEffect)(() => {
20064
20086
  if (isIframeLoaded) {
20065
- var _iframe$contentWindow4;
20066
- (_iframe$contentWindow4 = iframe.contentWindow) == null || _iframe$contentWindow4.postMessage({
20087
+ var _iframe$contentWindow2;
20088
+ (_iframe$contentWindow2 = iframe.contentWindow) == null || _iframe$contentWindow2.postMessage({
20067
20089
  type: 'customStyles',
20068
20090
  payload: {
20069
20091
  styling: customStyle,
@@ -20075,8 +20097,8 @@ function CardElement({
20075
20097
  }
20076
20098
  }, [isIframeLoaded, iframeRef.current]);
20077
20099
  (0,react.useEffect)(() => {
20078
- var _iframe$contentWindow5;
20079
- iframe == null || (_iframe$contentWindow5 = iframe.contentWindow) == null || _iframe$contentWindow5.postMessage({
20100
+ var _iframe$contentWindow3;
20101
+ iframe == null || (_iframe$contentWindow3 = iframe.contentWindow) == null || _iframe$contentWindow3.postMessage({
20080
20102
  type: 'cardHolderError',
20081
20103
  payload: {
20082
20104
  error: errors['name']
@@ -20084,16 +20106,22 @@ function CardElement({
20084
20106
  }, '*');
20085
20107
  }, [errors.name]);
20086
20108
  (0,react.useEffect)(() => {
20087
- if (Object.keys(errors).length === 4) {
20109
+ const isSavedCardView = (savedCards == null ? void 0 : savedCards.length) && !showCardModal;
20110
+ const correctErrorsCount = Object.keys(errors).length === 4;
20111
+ if (isSavedCardView && previousValidationRef.current !== !shouldDisablePayBtn) {
20112
+ onCardValidationChanged == null || onCardValidationChanged(!shouldDisablePayBtn);
20113
+ previousValidationRef.current = !shouldDisablePayBtn;
20114
+ } else if (correctErrorsCount && previousValidationRef.current !== isCardValid) {
20088
20115
  onCardValidationChanged == null || onCardValidationChanged(isCardValid);
20116
+ previousValidationRef.current = isCardValid;
20089
20117
  }
20090
- }, [isCardValid]);
20118
+ }, [isCardValid, shouldDisablePayBtn]);
20091
20119
  const handlePayWithoutButton = () => {
20092
20120
  setShouldSubmitData(true);
20093
20121
  };
20094
20122
  const handleFocusToPrevInput = () => {
20095
- var _iframe$contentWindow6;
20096
- (_iframe$contentWindow6 = iframe.contentWindow) == null || _iframe$contentWindow6.postMessage({
20123
+ var _iframe$contentWindow4;
20124
+ (_iframe$contentWindow4 = iframe.contentWindow) == null || _iframe$contentWindow4.postMessage({
20097
20125
  type: 'setPrevFocus',
20098
20126
  payload: {
20099
20127
  shouldFocusOnCVV: true
@@ -20124,7 +20152,7 @@ function CardElement({
20124
20152
  if (loading) return;
20125
20153
  setLoading(true);
20126
20154
  if (onBeforePaymentComplete) {
20127
- const result = await onBeforePaymentComplete();
20155
+ const result = await onBeforePaymentComplete(payment.name);
20128
20156
  if (!result) {
20129
20157
  setSelectedCard(null);
20130
20158
  setSelectedCardCVV('');
@@ -20155,12 +20183,12 @@ function CardElement({
20155
20183
  window.location.href = res.data.redirection_url;
20156
20184
  }
20157
20185
  } else if (res.status === 400) {
20158
- var _res$data6, _res$data7, _res$data8;
20159
- if (res.data instanceof Array && res.data[0] === 'Retry limit reached.' || ((_res$data6 = res.data) == null ? void 0 : _res$data6.msg) === 'Retry limit reached.') {
20186
+ var _res$data9, _res$data10, _res$data11;
20187
+ if (res.data instanceof Array && res.data[0] === 'Retry limit reached.' || ((_res$data9 = res.data) == null ? void 0 : _res$data9.msg) === 'Retry limit reached.') {
20160
20188
  setErrorMessage(t('ERR_MSG_EXCEEDED_TRIALS'));
20161
- } else if (((_res$data7 = res.data) == null ? void 0 : _res$data7.message) === 'Session Error') {
20189
+ } else if (((_res$data10 = res.data) == null ? void 0 : _res$data10.message) === 'Session Error') {
20162
20190
  setErrorMessage(t('ERR_MSG_ALREADY_PROCESSED'));
20163
- } else if (res.data instanceof Array && res.data[0] === 'Order has already paid.' || ((_res$data8 = res.data) == null ? void 0 : _res$data8.msg) === 'Order has already paid.') {
20191
+ } 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.') {
20164
20192
  setErrorMessage(t('ERR_MSG_ALREADY_PAID'));
20165
20193
  } else {
20166
20194
  setErrorMessage(t('ERR_MSG_DECLINED'));
@@ -20177,22 +20205,65 @@ function CardElement({
20177
20205
  setErrorMessage(t('ERR_MSG_SOMETHING_WENT_WRONG'));
20178
20206
  }
20179
20207
  };
20208
+ const handleOTPSubmit = async otp => {
20209
+ var _iframe$contentWindow5, _payment$subType3;
20210
+ setSendOTPLoading(true);
20211
+ (_iframe$contentWindow5 = iframe.contentWindow) == null || _iframe$contentWindow5.postMessage({
20212
+ type: 'otpData',
20213
+ payload: {
20214
+ paymentToken: payment.token,
20215
+ subType: {
20216
+ paymentToken: (_payment$subType3 = payment.subType) == null ? void 0 : _payment$subType3.token
20217
+ },
20218
+ otp
20219
+ }
20220
+ }, '*');
20221
+ };
20180
20222
  const handleShowNewCardForm = () => {
20181
20223
  if (loading) return;
20182
20224
  setSelectedCard(null);
20183
20225
  setSelectedCardCVV('');
20184
20226
  setShowCardModal(true);
20227
+ if (previousValidationRef.current) {
20228
+ onCardValidationChanged == null || onCardValidationChanged(false);
20229
+ previousValidationRef.current = false;
20230
+ }
20185
20231
  };
20186
20232
  const handleViewSavedCards = () => {
20187
20233
  setShowCardModal(false);
20188
20234
  setIsIframeLoaded(false);
20235
+ setCardHolderName('');
20236
+ if (previousValidationRef.current) {
20237
+ onCardValidationChanged == null || onCardValidationChanged(false);
20238
+ previousValidationRef.current = false;
20239
+ }
20240
+ };
20241
+ const handleCloseOTP = () => {
20242
+ setShowOTP(false);
20243
+ setErrorMessage('');
20189
20244
  };
20190
20245
  return /*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
20191
20246
  className: customStyle != null && (_customStyle$containe = customStyle.container) != null && _customStyle$containe.fontFamily ? '' : card_module['gotham'],
20192
20247
  style: Object.assign({}, customStyle == null ? void 0 : customStyle.container, isList && {
20193
20248
  padding: 'unset'
20194
20249
  }),
20195
- children: [/*#__PURE__*/(0,jsx_runtime.jsx)(CVVToolTipModal_CVVToolTipModal, {
20250
+ children: [isMobile && showOTP && /*#__PURE__*/(0,jsx_runtime.jsx)(MobileOTPModal_MobileOTPModal, {
20251
+ onClose: handleCloseOTP,
20252
+ onSubmit: handleOTPSubmit,
20253
+ length: 4,
20254
+ modalHeader: `${4}-digit code`,
20255
+ loading: sendOTPLoading
20256
+ }), !isMobile && showOTP && /*#__PURE__*/(0,jsx_runtime.jsx)(ModalView_ModalView, {
20257
+ showModal: showOTP,
20258
+ onClose: handleCloseOTP,
20259
+ children: /*#__PURE__*/(0,jsx_runtime.jsx)(OTPModal_OTPModal, {
20260
+ onClose: handleCloseOTP,
20261
+ onSubmit: handleOTPSubmit,
20262
+ length: 4,
20263
+ modalHeader: `${4}-digit code`,
20264
+ loading: sendOTPLoading
20265
+ })
20266
+ }), /*#__PURE__*/(0,jsx_runtime.jsx)(CVVToolTipModal_CVVToolTipModal, {
20196
20267
  onClose: () => setShowCVVTooltipModal(false),
20197
20268
  showModal: showCVVTooltipModal
20198
20269
  }), errorMessage && /*#__PURE__*/(0,jsx_runtime.jsx)(ErrorMessageViewTwo_ErrorMessage, {
@@ -26818,7 +26889,8 @@ function ApplePay(props) {
26818
26889
  customStyle,
26819
26890
  checkDiscount,
26820
26891
  isPixel,
26821
- isLoading
26892
+ isLoading,
26893
+ paymentName
26822
26894
  } = props;
26823
26895
  const [loading, setLoading] = (0,react.useState)(false);
26824
26896
  const [discount, setDiscount] = (0,react.useState)({
@@ -26866,7 +26938,7 @@ function ApplePay(props) {
26866
26938
  }
26867
26939
  const session = new window.ApplePaySession(3, payload);
26868
26940
  if (onBeforePaymentComplete) {
26869
- const result = await onBeforePaymentComplete();
26941
+ const result = await onBeforePaymentComplete(paymentName);
26870
26942
  if (!result) {
26871
26943
  setLoading(false);
26872
26944
  return;
@@ -27170,7 +27242,9 @@ function GooglePayElement({
27170
27242
  onBeforePaymentComplete,
27171
27243
  onAfterPaymentComplete,
27172
27244
  onErrorMessage,
27173
- isLoading
27245
+ isLoading,
27246
+ onProcessingPayment,
27247
+ isProcessingPayment
27174
27248
  }) {
27175
27249
  var _String;
27176
27250
  const {
@@ -27179,22 +27253,36 @@ function GooglePayElement({
27179
27253
  keyPrefix: 'googlePay'
27180
27254
  });
27181
27255
  const [loading, setLoading] = (0,react.useState)(false);
27256
+ const [googlePayload, setGooglePayload] = (0,react.useState)(null);
27257
+ const [startGooglePay, setStartGooglePay] = (0,react.useState)(false);
27182
27258
  const {
27183
27259
  amount,
27184
27260
  currency
27185
27261
  } = payment;
27186
27262
  const googlePay = payment;
27187
27263
  const integrationId = googlePay == null ? void 0 : googlePay.integrationId;
27264
+ (0,react.useEffect)(() => {
27265
+ if (startGooglePay && isProcessingPayment) {
27266
+ handlePay(googlePay == null ? void 0 : googlePay.token, googlePayload);
27267
+ setStartGooglePay(false);
27268
+ onProcessingPayment(false);
27269
+ }
27270
+ }, [startGooglePay, isProcessingPayment]);
27188
27271
  const handleSubmit = async (paymentToken, googlePayload) => {
27189
- var _res$data;
27190
27272
  setLoading(true);
27191
27273
  if (onBeforePaymentComplete) {
27192
- const result = await onBeforePaymentComplete();
27274
+ const result = await onBeforePaymentComplete(payment.name);
27193
27275
  if (!result) {
27194
27276
  setLoading(false);
27195
27277
  return;
27196
27278
  }
27197
27279
  }
27280
+ setStartGooglePay(true);
27281
+ onProcessingPayment(true);
27282
+ setGooglePayload(googlePayload);
27283
+ };
27284
+ const handlePay = async (paymentToken, googlePayload) => {
27285
+ var _res$data;
27198
27286
  const res = await payWithGooglePay(paymentToken, integrationId, googlePayload);
27199
27287
  setLoading(false);
27200
27288
  const redirectionUrl = (_res$data = res.data) == null ? void 0 : _res$data.redirection_url;
@@ -27320,7 +27408,8 @@ function ApplePayElements({
27320
27408
  customStyle: customStyle,
27321
27409
  checkDiscount: checkDiscount,
27322
27410
  isPixel: true,
27323
- isLoading: isLoading
27411
+ isLoading: isLoading,
27412
+ paymentName: payment.name
27324
27413
  });
27325
27414
  }
27326
27415
  /* harmony default export */ const Payments_ApplePay = (ApplePayElements);
@@ -27431,25 +27520,29 @@ function PaymentsList(props) {
27431
27520
  const [savedCardsList, setSavedCardsList] = (0,react.useState)(savedCards);
27432
27521
  const [errorMessage, setErrorMessage] = (0,react.useState)('');
27433
27522
  const [isLoading, setIsLoading] = (0,react.useState)(false);
27523
+ const [isProcessingPayment, setIsProcessingPayment] = (0,react.useState)(false);
27434
27524
  (0,react.useEffect)(() => {
27435
- async function getData() {
27436
- setIsLoading(true);
27437
- const {
27438
- res,
27439
- paymentList,
27440
- savedCards
27441
- } = await fetchPayments(publicKey, clientSecret, selectedPaymentMethods);
27442
- setIsLoading(false);
27443
- if (res.status === 200) {
27444
- setPaymentList(paymentList);
27445
- setSavedCardsList(savedCards);
27446
- }
27447
- }
27448
27525
  window.addEventListener('updateIntentionData', getData);
27449
27526
  return () => {
27450
27527
  window.removeEventListener('updateIntentionData', getData);
27451
27528
  };
27452
27529
  }, []);
27530
+ const getData = async () => {
27531
+ setIsLoading(true);
27532
+ const {
27533
+ res,
27534
+ paymentList,
27535
+ savedCards
27536
+ } = await fetchPayments(publicKey, clientSecret, selectedPaymentMethods);
27537
+ setIsLoading(false);
27538
+ if (res.status === 200) {
27539
+ setPaymentList(paymentList);
27540
+ setSavedCardsList(savedCards);
27541
+ }
27542
+ };
27543
+ const handleOnBeforePaymentComplete = async paymentMethod => {
27544
+ return await onBeforePaymentComplete(paymentMethod, getData);
27545
+ };
27453
27546
  const hasOnlyXPays = () => {
27454
27547
  const xPays = ['apple-pay', 'google-pay'];
27455
27548
  return paymentList.every(method => xPays.includes(method.name));
@@ -27494,18 +27587,22 @@ function PaymentsList(props) {
27494
27587
  }) : /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, {
27495
27588
  children: [isApplePay() && /*#__PURE__*/(0,jsx_runtime.jsx)(Payments_ApplePay, {
27496
27589
  payment: applePaymentMethod,
27497
- onBeforePaymentComplete: onBeforePaymentComplete,
27590
+ onBeforePaymentComplete: onBeforePaymentComplete && handleOnBeforePaymentComplete,
27498
27591
  onAfterPaymentComplete: onAfterPaymentComplete,
27499
27592
  onPaymentCancel: onPaymentCancel,
27500
27593
  customStyle: customStyle == null ? void 0 : customStyle.button,
27501
- isLoading: isLoading
27594
+ isLoading: isLoading,
27595
+ onProcessingPayment: setIsProcessingPayment,
27596
+ isProcessingPayment: isProcessingPayment
27502
27597
  }), isGooglePay() && /*#__PURE__*/(0,jsx_runtime.jsx)(GooglePayElement, {
27503
27598
  payment: googlePaymentMethod,
27504
27599
  customStyle: customStyle == null ? void 0 : customStyle.button,
27505
- onBeforePaymentComplete: onBeforePaymentComplete,
27600
+ onBeforePaymentComplete: onBeforePaymentComplete && handleOnBeforePaymentComplete,
27506
27601
  onAfterPaymentComplete: onAfterPaymentComplete,
27507
27602
  onErrorMessage: setErrorMessage,
27508
- isLoading: isLoading
27603
+ isLoading: isLoading,
27604
+ onProcessingPayment: setIsProcessingPayment,
27605
+ isProcessingPayment: isProcessingPayment
27509
27606
  })]
27510
27607
  })
27511
27608
  }), paymentList.length === 0 ? /*#__PURE__*/(0,jsx_runtime.jsx)("div", {
@@ -27538,12 +27635,14 @@ function PaymentsList(props) {
27538
27635
  savedCards: savedCardsList,
27539
27636
  forceSaveCard,
27540
27637
  showSaveCard,
27541
- onBeforePaymentComplete,
27638
+ onBeforePaymentComplete: onBeforePaymentComplete && handleOnBeforePaymentComplete,
27542
27639
  onAfterPaymentComplete,
27543
27640
  onCardValidationChanged,
27544
27641
  showPaymobLogo,
27545
27642
  hideCardHolderName,
27546
27643
  isLoading,
27644
+ onProcessingPayment: setIsProcessingPayment,
27645
+ isProcessingPayment,
27547
27646
  isList: true
27548
27647
  })
27549
27648
  })]
@@ -31437,9 +31536,9 @@ class Pixel {
31437
31536
  this.render();
31438
31537
  }
31439
31538
  }
31440
- async handleBeforePaymentComplete() {
31539
+ async handleBeforePaymentComplete(paymentMethod, updateIntentionData) {
31441
31540
  if (this._options.beforePaymentComplete) {
31442
- const result = await this._options.beforePaymentComplete();
31541
+ const result = await this._options.beforePaymentComplete(paymentMethod, updateIntentionData);
31443
31542
  if (result === false) return false;
31444
31543
  return true;
31445
31544
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paymob-pixel-alpha",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "keywords": ["paymob","pixel","paymob-pixel"],
5
5
  "main": "./main.js",
6
6
  "homepage": "https://developers.paymob.com",
package/styles.css CHANGED
@@ -604,6 +604,10 @@ video {
604
604
  visibility: visible !important;
605
605
  }
606
606
 
607
+ .visible {
608
+ visibility: visible;
609
+ }
610
+
607
611
  .invisible {
608
612
  visibility: hidden;
609
613
  }