paymob-pixel-alpha 1.1.68 → 1.1.69

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 +73 -34
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -24082,42 +24082,47 @@ const PhoneInput_PhoneInput = /*#__PURE__*/(/* unused pure expression or super *
24082
24082
  name,
24083
24083
  label,
24084
24084
  labelHint,
24085
- defaultPhoneNumber,
24085
+ phoneNumber,
24086
+ country,
24086
24087
  placeholder,
24087
24088
  disabled,
24088
24089
  autoFocus = false,
24089
24090
  error,
24090
24091
  onChangeHandler,
24091
24092
  onCountryChange,
24092
- defaultCountry = 'eg',
24093
24093
  disableSelectCountry,
24094
24094
  onFocus,
24095
24095
  onBlur,
24096
24096
  canToggleToTextInput = false,
24097
24097
  autoComplete = false
24098
24098
  } = props;
24099
- const [selectedCountry, setSelectedCountry] = useState(Countries[defaultCountry] || Countries.eg);
24099
+ const isPhoneControlled = phoneNumber !== undefined;
24100
+ const isCountryControlled = country !== undefined;
24101
+ const countryIso2 = Countries[country || 'eg'];
24102
+ const [internalCountry, setInternalCountry] = useState(countryIso2);
24103
+ const [internalValue, setInternalValue] = useState(phoneNumber || '');
24100
24104
  const [showDropdown, setShowDropdown] = useState(false);
24101
- const [value, setValue] = useState(defaultPhoneNumber || '');
24105
+ const selectedCountry = isCountryControlled ? countryIso2 : internalCountry;
24106
+ const value = (isPhoneControlled ? phoneNumber : internalValue).replace(selectedCountry.countryCode, '');
24102
24107
  const toggleDropdown = () => {
24103
24108
  setShowDropdown(prevState => !prevState);
24104
24109
  };
24105
24110
  const selectCountry = country => {
24106
- setSelectedCountry(country);
24111
+ if (!isCountryControlled) setInternalCountry(country);
24107
24112
  setShowDropdown(false);
24108
- onChangeHandler == null || onChangeHandler(country.countryCode + value, country.countryIso2);
24113
+ onChangeHandler == null || onChangeHandler(country.countryCode + value, country.countryIso2, value);
24109
24114
  onCountryChange && onCountryChange(country.countryIso2);
24110
24115
  };
24111
24116
  const handlePhoneChange = e => {
24112
- const value = e.target.value;
24113
- if (value === '') {
24114
- setValue('');
24115
- onChangeHandler('', selectedCountry.countryIso2);
24117
+ const newValue = e.target.value;
24118
+ if (newValue === '') {
24119
+ if (!isPhoneControlled) setInternalValue('');
24120
+ onChangeHandler == null || onChangeHandler('', selectedCountry.countryIso2, '');
24116
24121
  return;
24117
24122
  }
24118
- if (!/^[0-9]+$/.test(value) && !canToggleToTextInput) return;
24119
- setValue(value);
24120
- onChangeHandler(selectedCountry.countryCode + value, selectedCountry.countryIso2);
24123
+ if (!/^[0-9]+$/.test(newValue) && !canToggleToTextInput) return;
24124
+ if (!isPhoneControlled) setInternalValue(newValue);
24125
+ onChangeHandler == null || onChangeHandler(selectedCountry.countryCode + newValue, selectedCountry.countryIso2, newValue);
24121
24126
  };
24122
24127
  return /*#__PURE__*/_jsxs("div", {
24123
24128
  className: styles['container'],
@@ -24209,7 +24214,7 @@ const PhoneField_PhoneField = props => {
24209
24214
  onChangeHandler,
24210
24215
  onApplyHandler,
24211
24216
  onCountryChange,
24212
- defaultCountry,
24217
+ country,
24213
24218
  applyBtnText,
24214
24219
  errorMsg,
24215
24220
  closeOnSubmit = true
@@ -24238,7 +24243,7 @@ const PhoneField_PhoneField = props => {
24238
24243
  ref: inputRef,
24239
24244
  name: fieldName,
24240
24245
  placeholder: placeholder,
24241
- defaultCountry: defaultCountry,
24246
+ country: country,
24242
24247
  onChangeHandler: handleChange,
24243
24248
  onCountryChange: onCountryChange,
24244
24249
  onFocus: handleFocus,
@@ -50431,8 +50436,7 @@ const Modal_Modal = props => {
50431
50436
  onCloseHandler && useClickOutside_useClickOutside(dialogRef, onCloseHandler, open && closeOnClickOutside, true);
50432
50437
  return /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, {
50433
50438
  children: [!isTopLayer && open && /*#__PURE__*/(0,jsx_runtime.jsx)("div", {
50434
- className: modal_module['modal__overlay'],
50435
- onClick: closeOnClickOutside ? onCloseHandler : undefined
50439
+ className: modal_module['modal__overlay']
50436
50440
  }), /*#__PURE__*/(0,jsx_runtime.jsxs)("dialog", {
50437
50441
  ref: dialogRef,
50438
50442
  "data-modal-is-mobile": isMobile,
@@ -59959,7 +59963,7 @@ const FiltersBar_FiltersBar = ({
59959
59963
  placeholder: placeholder,
59960
59964
  horizontalPlacement: isMobile ? "center" : "inline_auto",
59961
59965
  verticalPlacement: "auto",
59962
- defaultCountry: COUNTRIES_INFO[country || "EGY"].country_code_iso2.toLowerCase(),
59966
+ country: COUNTRIES_INFO[country || "EGY"].country_code_iso2.toLowerCase(),
59963
59967
  onChangeHandler: phone => handleFieldsErrors(phone, id, validations),
59964
59968
  errorMsg: fieldsErrors[id],
59965
59969
  onApplyHandler: onApply
@@ -70607,7 +70611,7 @@ const ContactForm = /*#__PURE__*/(/* unused pure expression or super */ null &&
70607
70611
  validate: value => {
70608
70612
  if (!value) return !phoneRequired || t('PHONE_IS_REQUIRED');
70609
70613
  const validPhone = parseMax(countryCode + value);
70610
- return (validPhone == null ? void 0 : validPhone.getType()) === 'MOBILE' && (validPhone == null ? void 0 : validPhone.isValid()) || t('PHONE_NOT_VALID');
70614
+ return ((validPhone == null ? void 0 : validPhone.getType()) === 'MOBILE' || (validPhone == null ? void 0 : validPhone.getType()) === 'FIXED_LINE_OR_MOBILE') && (validPhone == null ? void 0 : validPhone.isValid()) || t('PHONE_NOT_VALID');
70611
70615
  }
70612
70616
  });
70613
70617
  }, []);
@@ -79070,10 +79074,13 @@ const ClickOTPModal = ({
79070
79074
  setOtp('');
79071
79075
  };
79072
79076
  const handleSendToEmail = async () => {
79073
- setIsLoading(true);
79074
- await onSendToEmail();
79075
- setIsLoading(false);
79076
- setOtp('');
79077
+ try {
79078
+ setIsLoading(true);
79079
+ await onSendToEmail();
79080
+ } catch (_unused) {} finally {
79081
+ setIsLoading(false);
79082
+ setOtp('');
79083
+ }
79077
79084
  };
79078
79085
  const title = _type === 'phone' ? isPhoneVerified ? t('WELCOME_BACK') : t('VERIFY_YOUR_ACCOUNT') : t('CONFIRM_ITS_YOU');
79079
79086
  const text = (_type === 'phone' ? `${t('LOGGED_IN_AS')} ${email} \n` : '') + `${t('PLEASE_ENTER_CODE_TO_VERIFY', {
@@ -81589,14 +81596,15 @@ function IframeCard(props) {
81589
81596
  expiryRegister,
81590
81597
  cvcRegister,
81591
81598
  getValues,
81592
- cardType
81599
+ cardType,
81600
+ watch
81593
81601
  } = useHookForm({
81594
81602
  isIframe: true,
81595
81603
  hasOmanNetIntegration: hasOmanNetIntegration || integrationType === 'tokenization',
81596
81604
  countryName: country
81597
81605
  });
81598
81606
  const timeoutIdRef = useRef();
81599
- const cardNum = getValues('number');
81607
+ const cardNum = watch('number');
81600
81608
  const isValidCard = valid.number(cardNum).isValid;
81601
81609
  const currentIntegrationId = hasOmanNetIntegration && (cardType === CARD_TYPES.OMAN || cardType === CARD_TYPES.MAAL) ? subType.integrationId : integrationId;
81602
81610
  const currentPaymentToken = hasOmanNetIntegration && (cardType === CARD_TYPES.OMAN || cardType === CARD_TYPES.MAAL) ? subType.paymentToken : paymentToken;
@@ -81777,6 +81785,8 @@ function IframeCard(props) {
81777
81785
  tenure
81778
81786
  }).then(() => {
81779
81787
  isSubmittingRef.current = false;
81788
+ }).catch(() => {
81789
+ isSubmittingRef.current = false;
81780
81790
  });
81781
81791
  }
81782
81792
  setShouldSubmitData(false);
@@ -82796,7 +82806,7 @@ function SavedCardsViewTwo(props) {
82796
82806
  if (loading) return true;
82797
82807
  if (isAddingCard) return false;
82798
82808
  if (isSplitPaymentsView && !splitAmount) return true;
82799
- if (showCvvInput) {
82809
+ if (showCvvInput && !(selectedCard != null && selectedCard.networkToken)) {
82800
82810
  const requiredLength = isAmexCardSelected ? AMEX_CVV_LENGTH : CVV_LENGTH;
82801
82811
  return selectedCardCvvLength !== requiredLength;
82802
82812
  }
@@ -83679,7 +83689,8 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
83679
83689
  publicKey,
83680
83690
  discounts,
83681
83691
  onPaymentCancel,
83682
- isInstantRefundActive
83692
+ isInstantRefundActive,
83693
+ onPaymentStateChanged
83683
83694
  }, ref) => {
83684
83695
  var _customStyle$discount, _customStyle$containe, _customStyle$containe2, _customStyle$button, _customStyle$containe3, _customStyle$labelTex, _customStyle$buttonTe, _customStyle$placehol, _customStyle$discount2, _customStyle$discount3, _customStyle$errorTex, _customStyle$errorTex2, _customStyle$errorTex3, _customStyle$errorTex4, _customStyle$hintText, _customStyle$labelTex2, _customStyle$buttonTe2, _customStyle$labelTex3, _customStyle$buttonTe3, _customStyle$buttonTe4, _customStyle$buttonTe5;
83685
83696
  const {
@@ -83990,6 +84001,20 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
83990
84001
  previousValidationRef.current = isCardValid;
83991
84002
  }
83992
84003
  }, [isCardValid, shouldDisablePayBtn]);
84004
+ (0,react.useEffect)(() => {
84005
+ var _instantRefundData$in, _instantRefundData$el;
84006
+ if (!instantRefundData || !totalAmount || !isInstantRefundActive) return;
84007
+ onPaymentStateChanged == null || onPaymentStateChanged({
84008
+ type: 'INSTANT_REFUND_TOGGLE',
84009
+ payload: {
84010
+ enabled: isInstantRefundChecked,
84011
+ instantRefundAmount: (_instantRefundData$in = instantRefundData == null ? void 0 : instantRefundData.instant_refund_fees) != null ? _instantRefundData$in : '',
84012
+ eligible: (_instantRefundData$el = instantRefundData == null ? void 0 : instantRefundData.eligible) != null ? _instantRefundData$el : false,
84013
+ totalAmount,
84014
+ originalAmount: payment == null ? void 0 : payment.amount
84015
+ }
84016
+ });
84017
+ }, [isInstantRefundChecked, instantRefundData, totalAmount]);
83993
84018
  (0,react.useImperativeHandle)(ref, () => ({
83994
84019
  handleGenerateToken
83995
84020
  }));
@@ -84446,7 +84471,7 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
84446
84471
  fontFamily: currencyFontFamily
84447
84472
  },
84448
84473
  children: displayCurrency
84449
- }), ' ', totalAmount || formattedAmount]
84474
+ }), ' ', amount]
84450
84475
  })]
84451
84476
  }), discountedAmount && /*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
84452
84477
  className: "flex justify-between items-center text-green-600",
@@ -96038,7 +96063,8 @@ const PaymentsList = /*#__PURE__*/(0,react.forwardRef)((props, ref) => {
96038
96063
  discounts,
96039
96064
  viewMode,
96040
96065
  displayName,
96041
- isInstantRefundActive
96066
+ isInstantRefundActive,
96067
+ onPaymentStateChanged
96042
96068
  } = props;
96043
96069
  const {
96044
96070
  t
@@ -96200,7 +96226,8 @@ const PaymentsList = /*#__PURE__*/(0,react.forwardRef)((props, ref) => {
96200
96226
  publicKey,
96201
96227
  ref: cardRef,
96202
96228
  discounts: discounts == null ? void 0 : discounts.cards,
96203
- isInstantRefundActive
96229
+ isInstantRefundActive,
96230
+ onPaymentStateChanged
96204
96231
  }) : /*#__PURE__*/(0,jsx_runtime.jsx)(jsx_runtime.Fragment, {
96205
96232
  children: viewMode === 'list' ? /*#__PURE__*/(0,jsx_runtime.jsx)(ListView, {
96206
96233
  paymentMethods: paymentMethods,
@@ -96221,7 +96248,8 @@ const PaymentsList = /*#__PURE__*/(0,react.forwardRef)((props, ref) => {
96221
96248
  publicKey,
96222
96249
  ref: cardRef,
96223
96250
  discounts: discounts == null ? void 0 : discounts.cards,
96224
- isInstantRefundActive
96251
+ isInstantRefundActive,
96252
+ onPaymentStateChanged
96225
96253
  }) : /*#__PURE__*/(0,jsx_runtime.jsx)(List_TabView, {
96226
96254
  paymentMethods: paymentMethods,
96227
96255
  customStyle,
@@ -96241,7 +96269,8 @@ const PaymentsList = /*#__PURE__*/(0,react.forwardRef)((props, ref) => {
96241
96269
  publicKey,
96242
96270
  ref: cardRef,
96243
96271
  discounts: discounts == null ? void 0 : discounts.cards,
96244
- isInstantRefundActive
96272
+ isInstantRefundActive,
96273
+ onPaymentStateChanged
96245
96274
  })
96246
96275
  })
96247
96276
  })]
@@ -96465,7 +96494,8 @@ const Payments_Payments = /*#__PURE__*/(0,react.forwardRef)((props, ref) => {
96465
96494
  integrationType,
96466
96495
  discounts,
96467
96496
  viewMode = 'tab',
96468
- isInstantRefundActive
96497
+ isInstantRefundActive,
96498
+ onPaymentStateChanged
96469
96499
  } = props;
96470
96500
  const [paymentMethod, setPaymentMethod] = (0,react.useState)(payment);
96471
96501
  const styles = getStyles_getStyles(customStyle);
@@ -96485,6 +96515,7 @@ const Payments_Payments = /*#__PURE__*/(0,react.forwardRef)((props, ref) => {
96485
96515
  onBeforePaymentComplete,
96486
96516
  onAfterPaymentComplete,
96487
96517
  onCardValidationChanged,
96518
+ onPaymentStateChanged,
96488
96519
  showPaymobLogo,
96489
96520
  hideCardHolderName,
96490
96521
  integrationType,
@@ -96601,7 +96632,8 @@ const Payments_Payments = /*#__PURE__*/(0,react.forwardRef)((props, ref) => {
96601
96632
  integrationType: integrationType,
96602
96633
  discounts: discounts,
96603
96634
  viewMode: viewMode,
96604
- isInstantRefundActive: isInstantRefundActive
96635
+ isInstantRefundActive: isInstantRefundActive,
96636
+ onPaymentStateChanged: onPaymentStateChanged
96605
96637
  });
96606
96638
  };
96607
96639
  return /*#__PURE__*/(0,jsx_runtime.jsx)(jsx_runtime.Fragment, {
@@ -97636,6 +97668,11 @@ class Pixel {
97636
97668
  this._options.cardValidationChanged(isValid);
97637
97669
  }
97638
97670
  }
97671
+ handlePaymentStateChanged(state) {
97672
+ if (this._options.paymentStateChanged) {
97673
+ this._options.paymentStateChanged(state);
97674
+ }
97675
+ }
97639
97676
  static getInstance(instanceId, callingMethodName) {
97640
97677
  if (Object.keys(this._instances).length > 1 && !instanceId) {
97641
97678
  throw new Error(`Multiple Pixel instances detected. Please provide an instance ID for the ${callingMethodName || 'requested'} method.`);
@@ -97722,6 +97759,8 @@ class Pixel {
97722
97759
  onPaymentCancel: this.handleOnPaymentCancel.bind(this)
97723
97760
  }, this._options.cardValidationChanged && {
97724
97761
  onCardValidationChanged: this.handleCardValidationChanged.bind(this)
97762
+ }, this._options.paymentStateChanged && {
97763
+ onPaymentStateChanged: this.handlePaymentStateChanged.bind(this)
97725
97764
  }, {
97726
97765
  integrationType: this._integrationType,
97727
97766
  discounts: this._discounts,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paymob-pixel-alpha",
3
- "version": "1.1.68",
3
+ "version": "1.1.69",
4
4
  "keywords": ["paymob","pixel","paymob-pixel"],
5
5
  "main": "./main.js",
6
6
  "license": "MIT",