paymob-pixel-alpha 1.1.0 → 1.1.2

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # pixel
1
+ # `pixel`
2
2
  Paymob Web SDK, help our merchant to have the native payment experience.
3
3
 
4
4
  ## Installing
@@ -8,13 +8,13 @@ Paymob Web SDK, help our merchant to have the native payment experience.
8
8
  Using npm:
9
9
 
10
10
  ```bash
11
- $ npm install paymob-pixel-alpha --save
11
+ $ npm install paymob-pixel --save
12
12
  ```
13
13
 
14
14
  Once the package is installed, you can import the library using `import`:
15
15
 
16
16
  ```js
17
- import { Pixel } from 'paymob-pixel-alpha';
17
+ import { Pixel } from 'paymob-pixel';
18
18
  ``` -->
19
19
 
20
20
  ### CDN
@@ -27,14 +27,13 @@ Using jsDelivr:
27
27
  <script src="https://cdn.jsdelivr.net/npm/paymob-pixel-alpha@latest/main.js" type="module"></script>
28
28
  ```
29
29
 
30
- Using unpkg:
30
+ <!-- Using unpkg:
31
31
 
32
32
  ```html
33
33
  <link rel="stylesheet" href="https://unpkg.com/paymob-pixel-alpha/styles.css">
34
34
  <link rel="stylesheet" href="https://unpkg.com/paymob-pixel-alpha/main.css">
35
35
  <script src="https://unpkg.com/paymob-pixel-alpha/main.js" type="module"></script>
36
- ```
37
-
36
+ ``` -->
38
37
 
39
38
  ## Usage
40
39
 
@@ -52,7 +51,7 @@ new Pixel({
52
51
  > <script src="https://pay.google.com/gp/p/js/pay.js"></script>
53
52
  > ```
54
53
 
55
- ## properties
54
+ ## Properties
56
55
 
57
56
  The full list of properties is as follows:
58
57
  | Property | Type | Definition |
@@ -64,12 +63,52 @@ The full list of properties is as follows:
64
63
  | disablePay | Boolean | pass true If you don’t want to use Paymob’s Pay Button for Card Payment, in this case you will dispatchEvent with name (payFromOutside) to fire the pay. |
65
64
  | showSaveCard | Boolean | If this option is set to TRUE, users will have the option to save their card details for future payment. |
66
65
  | forceSaveCard | Boolean | If this option is set to true, the user's card details will be saved automatically without requiring their consent |
66
+ | cardValidationChanged | Function | This Functionality will be processed whenever card validation status changed. |
67
67
  | beforePaymentComplete | Function | Merchants can implement their own custom logic or functions before the payment is processed by Paymob. check the full example below. |
68
- | afterPaymentComplete | Function | This Functionality will be processed fter payment is processed by Paymob. check the full example below. |
68
+ | afterPaymentComplete | Function | This Functionality will be processed after payment is processed by Paymob. check the full example below. |
69
69
  | onPaymentCancel | Function | This function applies exclusively to Apple Pay. Merchants can implement their own custom logic to handle scenarios where a user cancels the Apple Pay payment by closing the Apple Pay SDK. |
70
70
  | customStyle | Object | You can pass custom styles, for more details check the full example below.
71
71
 
72
72
 
73
+ ## Events
74
+ The full list of events is as follows:
75
+ | Event | Definition |
76
+ | ------- | --------- |
77
+ | payFromOutside | In case you need to use you pay button instead of SDK pay button.
78
+
79
+
80
+ ## Functions
81
+ The full list of functions is as follows:
82
+ | Function | Props | Definition |
83
+ | --------------------- | -------------- | -------------- |
84
+ | updateIntentionData | - | Update intention data inside the SDK, in case any updates happend on the intention.
85
+
86
+
87
+ ## Custom Pay Button Example
88
+ > Add **disablePay** to hide SDK pay button
89
+ > ```js
90
+ > new Pixel({
91
+ > publicKey: 'are_pk_live_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
92
+ > clientSecret: 'are_csk_live_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
93
+ > paymentMethods: ['card', 'google-pay', 'apple-pay'],
94
+ > elementId: 'example',
95
+ > disablePay: true,
96
+ > });
97
+ > ```
98
+ > Then you can fire **payFromOutside** event when ever you want to start the payment, this will not work with Google-pay or Apple-pay
99
+ > ```js
100
+ > window.dispatchEvent(new Event('payFromOutside'));
101
+ > ```
102
+
103
+
104
+
105
+ ## Update Intention Example
106
+ > Whenever you made any update to the intention via API, you will need to update the intention data inside the SDK.
107
+ > ```js
108
+ > const response = await Pixel.updateIntentionData();
109
+ > ```
110
+ > **updateIntentionData** will return the response of the latest retrieve intention request.
111
+
73
112
  ## Full Example
74
113
 
75
114
  ```html
@@ -80,20 +119,19 @@ The full list of properties is as follows:
80
119
  <title>Pixels</title>
81
120
  <base href="/">
82
121
  <meta name="viewport" content="width=device-width, initial-scale=1" />
83
- <link rel="stylesheet" href="https://unpkg.com/paymob-pixel-alpha/styles.css">
84
- <link rel="stylesheet" href="https://unpkg.com/paymob-pixel-alpha/main.css">
122
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/paymob-pixel-alpha@latest/styles.css">
123
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/paymob-pixel-alpha@latest/main.css">
85
124
  </head>
86
125
  <body>
87
126
  <div style="position: absolute; width: 80%; margin-top: 10%;" id="example"></div>
88
127
  <button id="payFromOutsideButton">Pay From Outside Button</button>
89
128
 
90
- <script src="https://unpkg.com/paymob-pixel-alpha/main.js" type="module"></script>
129
+ <script src="https://cdn.jsdelivr.net/npm/paymob-pixel-alpha@latest/main.js" type="module"></script>
91
130
  <script>
92
131
  const button = document.getElementById('payFromOutsideButton');
93
132
  button.addEventListener('click', function () {
94
133
  // Calling pay request
95
- const event = new Event('payFromOutside');
96
- window.dispatchEvent(event);
134
+ window.dispatchEvent(new Event('payFromOutside'));
97
135
  });
98
136
  onload = (event) => {
99
137
  new Pixel({
@@ -107,7 +145,7 @@ The full list of properties is as follows:
107
145
  cardValidationChanged: (isValid) => {
108
146
  console.log("Is valid ? ", isValid)
109
147
  },
110
- beforePaymentComplete: async () => {
148
+ beforePaymentComplete: async (paymentMethod) => {
111
149
  console.log('Before payment start');
112
150
  console.log('We are waiting for 5 seconds');
113
151
  await new Promise(res => setTimeout(() => res(''),5000))
package/main.js CHANGED
@@ -10216,7 +10216,8 @@ function ModalView_ModalView(props) {
10216
10216
  const {
10217
10217
  onClose,
10218
10218
  showModal,
10219
- children
10219
+ children,
10220
+ customStyle
10220
10221
  } = props;
10221
10222
  const stopPropagation = e => {
10222
10223
  e.stopPropagation();
@@ -10233,6 +10234,9 @@ function ModalView_ModalView(props) {
10233
10234
  className: "relative w-auto max-h-full mobile:w-11/12",
10234
10235
  children: /*#__PURE__*/(0,jsx_runtime.jsx)("div", {
10235
10236
  className: `relative bg-white shadow ${borderStyle === borderStyle_borderStyleConstants.RECTANGULAR ? 'rounded-none' : 'rounded-lg'}`,
10237
+ style: {
10238
+ borderRadius: (customStyle == null ? void 0 : customStyle['borderRadius']) || ''
10239
+ },
10236
10240
  children: children
10237
10241
  })
10238
10242
  })
@@ -10488,7 +10492,7 @@ function OTPViewTwo_OTP(props) {
10488
10492
  const [value, setValue] = (0,react.useState)(otpValue || '');
10489
10493
  const {
10490
10494
  borderStyle
10491
- } = useSelector_useSelector(state => state.customization);
10495
+ } = useSafeSelector(state => state.customization);
10492
10496
 
10493
10497
  //regular expression to tests whether a string is a digit
10494
10498
  const RExp_DIGIT = new RegExp(/^\d+$/);
@@ -10644,7 +10648,7 @@ const GenericOTP = props => {
10644
10648
  } = props;
10645
10649
  const {
10646
10650
  borderStyle
10647
- } = useSelector_useSelector(state => state.customization);
10651
+ } = useSafeSelector(state => state.customization);
10648
10652
  const [otp, setOTP] = (0,react.useState)('');
10649
10653
  const handleOTPChange = e => {
10650
10654
  const value = e.target.value.replace(/\D/g, '');
@@ -10696,7 +10700,8 @@ function OTPModal_OTPModal(props) {
10696
10700
  setResetCounter,
10697
10701
  loading,
10698
10702
  error,
10699
- onErrorMessage
10703
+ onErrorMessage,
10704
+ customStyle
10700
10705
  } = props;
10701
10706
  const {
10702
10707
  t
@@ -10706,7 +10711,7 @@ function OTPModal_OTPModal(props) {
10706
10711
  const [resendingOTP, setResendingOTP] = (0,react.useState)(false);
10707
10712
  const {
10708
10713
  borderStyle
10709
- } = useSelector_useSelector(state => state.customization);
10714
+ } = useSafeSelector(state => state.customization);
10710
10715
  (0,react.useEffect)(() => {
10711
10716
  if (!loading && resendingOTP) {
10712
10717
  if (error) {
@@ -10733,8 +10738,10 @@ function OTPModal_OTPModal(props) {
10733
10738
  };
10734
10739
  return /*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
10735
10740
  className: "max-w-[400px]",
10741
+ style: customStyle == null ? void 0 : customStyle['container'],
10736
10742
  children: [/*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
10737
10743
  className: "flex px-6 py-6 flex-col gap-2 items-start",
10744
+ style: customStyle == null ? void 0 : customStyle['label'],
10738
10745
  children: [length && /*#__PURE__*/(0,jsx_runtime.jsx)("p", {
10739
10746
  className: "text-lg font-semibold",
10740
10747
  children: modalHeader
@@ -10756,6 +10763,7 @@ function OTPModal_OTPModal(props) {
10756
10763
  onErrorMessage: onErrorMessage
10757
10764
  }), error && /*#__PURE__*/(0,jsx_runtime.jsx)("p", {
10758
10765
  className: "text-red-600 text-sm font-normal leading-[1.125rem] tracking-[.01rem]",
10766
+ style: customStyle == null ? void 0 : customStyle['error'],
10759
10767
  children: error
10760
10768
  })]
10761
10769
  }, resetOtpComponent.toString()), onResend && /*#__PURE__*/(0,jsx_runtime.jsx)("div", {
@@ -10769,6 +10777,7 @@ function OTPModal_OTPModal(props) {
10769
10777
  })]
10770
10778
  }), (loading || resendingOTP) && /*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
10771
10779
  className: "flex justify-center items-center bg-white w-full h-20 flex-col gap-4",
10780
+ style: customStyle == null ? void 0 : customStyle['container'],
10772
10781
  children: [/*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
10773
10782
  className: "flex animate-pulse",
10774
10783
  children: [/*#__PURE__*/(0,jsx_runtime.jsx)("span", {
@@ -10792,17 +10801,18 @@ function OTPModal_OTPModal(props) {
10792
10801
  onClick: onClose,
10793
10802
  type: "button",
10794
10803
  className: `py-[10px] px-4 md:py-3 md:px-4 text-gray-500 bg-white hover:bg-gray-200 focus:ring-4 focus:outline-none focus:ring-gray-200 ${borderStyle === borderStyle_borderStyleConstants.RECTANGULAR ? 'rounded-none' : 'rounded-lg'} border border-gray-200 text-base hover:text-gray-900 focus:z-10`,
10804
+ style: customStyle == null ? void 0 : customStyle['cancelButton'],
10795
10805
  children: "Cancel"
10796
10806
  }), /*#__PURE__*/(0,jsx_runtime.jsx)(Button_Button, {
10797
10807
  label: "Submit",
10798
10808
  id: "pay-button",
10799
10809
  onClick: handleOtpSubmit,
10800
10810
  disabled: !otp || loading,
10801
- customStyle: {
10811
+ customStyle: Object.assign({
10802
10812
  height: 'unset',
10803
10813
  padding: '0.625rem 1rem'
10804
- },
10805
- className: "mt-0"
10814
+ }, customStyle == null ? void 0 : customStyle['button']),
10815
+ className: "!mt-0"
10806
10816
  })]
10807
10817
  })]
10808
10818
  });
@@ -17089,38 +17099,8 @@ function SecureCheckout(props) {
17089
17099
  });
17090
17100
  }
17091
17101
  /* harmony default export */ const components_SecureCheckout = ((/* unused pure expression or super */ null && (SecureCheckout)));
17092
- ;// CONCATENATED MODULE: ../../libs/kit-components/src/assets/icons/close-icon.svg
17093
- var close_icon_path;
17094
- var close_icon_excluded = (/* unused pure expression or super */ null && (["title", "titleId"]));
17095
- function close_icon_extends() { return close_icon_extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, close_icon_extends.apply(null, arguments); }
17096
- function close_icon_objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = close_icon_objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
17097
- function close_icon_objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
17098
-
17099
-
17100
- var SvgCloseIcon = function SvgCloseIcon(_ref, ref) {
17101
- var title = _ref.title,
17102
- titleId = _ref.titleId,
17103
- props = close_icon_objectWithoutProperties(_ref, close_icon_excluded);
17104
- return /*#__PURE__*/React.createElement("svg", close_icon_extends({
17105
- width: "800px",
17106
- height: "800px",
17107
- viewBox: "0 0 24 24",
17108
- fill: "none",
17109
- xmlns: "http://www.w3.org/2000/svg",
17110
- ref: ref,
17111
- "aria-labelledby": titleId
17112
- }, props), title ? /*#__PURE__*/React.createElement("title", {
17113
- id: titleId
17114
- }, title) : null, close_icon_path || (close_icon_path = /*#__PURE__*/React.createElement("path", {
17115
- fillRule: "evenodd",
17116
- clipRule: "evenodd",
17117
- d: "M5.29289 5.29289C5.68342 4.90237 6.31658 4.90237 6.70711 5.29289L12 10.5858L17.2929 5.29289C17.6834 4.90237 18.3166 4.90237 18.7071 5.29289C19.0976 5.68342 19.0976 6.31658 18.7071 6.70711L13.4142 12L18.7071 17.2929C19.0976 17.6834 19.0976 18.3166 18.7071 18.7071C18.3166 19.0976 17.6834 19.0976 17.2929 18.7071L12 13.4142L6.70711 18.7071C6.31658 19.0976 5.68342 19.0976 5.29289 18.7071C4.90237 18.3166 4.90237 17.6834 5.29289 17.2929L10.5858 12L5.29289 6.70711C4.90237 6.31658 4.90237 5.68342 5.29289 5.29289Z",
17118
- fill: "#667085"
17119
- })));
17120
- };
17121
- var close_icon_ForwardRef = /*#__PURE__*/(/* unused pure expression or super */ null && (forwardRef(SvgCloseIcon)));
17122
-
17123
- /* harmony default export */ const close_icon = (__webpack_require__.p + "close-icon.371f61902d3cf35dc76286080a72af1f.svg");
17102
+ ;// CONCATENATED MODULE: ../../libs/kit-components/src/assets/icons/close-icon.png
17103
+ const close_icon_namespaceObject = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAABGCAYAAABxLuKEAAAACXBIWXMAAAFKAAABSgHphfmiAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAu5JREFUeJztms9u2kAQh38D4U6u8AwR4pGCgpq0lYLEIZIvlg9N6aGCtLRCUJEnqpTkHeAa7q69uQQRFY0x+9eR5rtwwMyOPtZrz+ySUgrCPrXQCVQVEcMgYhhEDIOIYRAxDCKGQcQwiBgGEcMgYhhEDIOIYTgxDXA1HHVVlp/lhKf5OHqwkVQVciGTtsOHwZevILoBQACUAqbtZjqI4zg3SepYkiSprTaNCQGft7kQMJqNo0g3praYq+Gom+f539dE3rJsNdO+LzlJktTWm8YCQO+/rxTV6t3Z95tHnbjaa4zK8jPsSwGA3nrTWCRJ4nz9KpACAIQs6+jG1k4+JzwB4KabczkHpACAQr2uNVsAAzHzcfSggGnBJc7klJACBUx1byPA8HG9mETXSmFWcElv/Xzyx6YcItDqufELBVKg1H27mQ5MxjFKWCmoxV30sVAO0bktOUSg/vXtbyJcFiR13zr9d2G6+Bsn60uOTymApTdf13J8SwEslgSu5ISQAliulWzLCSUFcFBE2pITUgrgqLo2lRNaCuCw7aArpwpSAMf9mGPlVEUKYNh2KEuZV3gAy9fPwmt8Ve5exAAlb5EiPM2ULd5am6VuK/7HXqUAnnu+WnICSAECNMOPkhNICiC7BCzexRy1CFtsWRyL1wG1nkyB5HgbzOhxHUCOvOAxOP8HyvZoW820P59EF757yBxOBzi29vHdQy7CWXDdgrAqcpwENq2SqyDHelBbrYPQcqwGtN1PCSnH6g6hiyZTKDlWArnuvIWQ8262TX3LMQrgu0frU47Rj/uD27sDtc/Sdj9FKaj2afoJuxJiH6Lz1aYxMRnHxVGzLU7rmjIHh6p21AzwUOzFcZy3mmkf/Myp3FEzbxXwATnhjpoRMMJOjgLRD58nNoGdHAX8fJsLASOTo2bG/ZjL4bcOsqyDev3RJBEb2MzF24bbe0N2CRhEDIOIYRAxDCKGQcQwiBgGEcMgYhhEDIOIYRAxDCKG4QXD79JL5r6MQwAAAABJRU5ErkJggg==";
17124
17104
  ;// CONCATENATED MODULE: ../../libs/kit-components/src/components/OrderDetailsModal/index.tsx
17125
17105
 
17126
17106
 
@@ -17377,7 +17357,8 @@ function MobileOTPModal_MobileOTPModal(props) {
17377
17357
  setResetCounter,
17378
17358
  error,
17379
17359
  onErrorMessage,
17380
- loading
17360
+ loading,
17361
+ customStyle
17381
17362
  } = props;
17382
17363
  const {
17383
17364
  t
@@ -17421,13 +17402,15 @@ function MobileOTPModal_MobileOTPModal(props) {
17421
17402
  children: /*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
17422
17403
  onClick: e => e.stopPropagation(),
17423
17404
  className: "flex relative flex-col gap-2 py-8 w-full bg-white h-[88%] rounded-3xl",
17405
+ style: customStyle == null ? void 0 : customStyle['container'],
17424
17406
  children: [/*#__PURE__*/(0,jsx_runtime.jsx)("img", {
17425
17407
  onClick: onClose,
17426
17408
  className: "absolute top-4 right-4 w-6 cursor-pointer",
17427
- src: close_icon,
17409
+ src: close_icon_namespaceObject,
17428
17410
  alt: "close"
17429
17411
  }), /*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
17430
17412
  className: "flex flex-col gap-2 px-6 items-start",
17413
+ style: customStyle == null ? void 0 : customStyle['label'],
17431
17414
  children: [length && /*#__PURE__*/(0,jsx_runtime.jsx)("p", {
17432
17415
  className: "text-lg font-semibold",
17433
17416
  children: modalHeader
@@ -17449,6 +17432,7 @@ function MobileOTPModal_MobileOTPModal(props) {
17449
17432
  onErrorMessage: onErrorMessage
17450
17433
  }), error && /*#__PURE__*/(0,jsx_runtime.jsx)("p", {
17451
17434
  className: "text-red-600 text-sm font-normal leading-[1.125rem] tracking-[.01rem]",
17435
+ style: customStyle == null ? void 0 : customStyle['error'],
17452
17436
  children: error
17453
17437
  })]
17454
17438
  }, resetOtpComponent.toString()), onResend && /*#__PURE__*/(0,jsx_runtime.jsx)("div", {
@@ -17462,6 +17446,7 @@ function MobileOTPModal_MobileOTPModal(props) {
17462
17446
  })]
17463
17447
  }), (loading || resendingOTP) && /*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
17464
17448
  className: "flex justify-center items-center bg-white w-full h-20 flex-col gap-4",
17449
+ style: customStyle == null ? void 0 : customStyle['container'],
17465
17450
  children: [/*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
17466
17451
  className: "flex animate-pulse",
17467
17452
  children: [/*#__PURE__*/(0,jsx_runtime.jsx)("span", {
@@ -17486,7 +17471,8 @@ function MobileOTPModal_MobileOTPModal(props) {
17486
17471
  id: "pay-button",
17487
17472
  onClick: handleOtpSubmit,
17488
17473
  disabled: !otp || loading,
17489
- className: "w-full"
17474
+ className: "w-full",
17475
+ customStyle: customStyle == null ? void 0 : customStyle['button']
17490
17476
  })
17491
17477
  })]
17492
17478
  })
@@ -19862,6 +19848,45 @@ const payWithSavedCard = payload => {
19862
19848
  api_source: 'PIXEL'
19863
19849
  }).then(res => res).catch(err => err == null ? void 0 : err.response);
19864
19850
  };
19851
+ ;// CONCATENATED MODULE: ./src/utils/getErrorMsg.ts
19852
+ const getErrorMsg_isString = data => typeof data === 'string';
19853
+ const DECLINED_MESSAGE = 'Payment is declined';
19854
+ const getErrorMsg = err => {
19855
+ var _data$data, _data$data2;
19856
+ const data = err == null ? void 0 : err.data;
19857
+ if (!err) {
19858
+ return DECLINED_MESSAGE;
19859
+ }
19860
+ if (getErrorMsg_isString(err)) {
19861
+ return err;
19862
+ }
19863
+ if (data != null && data['data.message'] && getErrorMsg_isString(data['data.message'])) {
19864
+ return data['data.message'];
19865
+ }
19866
+ if (data != null && data.message && getErrorMsg_isString(data.message)) {
19867
+ return data.message;
19868
+ }
19869
+ if (data != null && data.msg && getErrorMsg_isString(data.msg)) {
19870
+ return data.msg;
19871
+ }
19872
+ if (data != null && data.detail && getErrorMsg_isString(data.detail)) {
19873
+ return data.detail;
19874
+ }
19875
+ if (data != null && data.error && getErrorMsg_isString(data.error)) {
19876
+ return data.error;
19877
+ }
19878
+ if (data != null && data.error_message && getErrorMsg_isString(data.error_message)) {
19879
+ return data.error_message;
19880
+ }
19881
+ if (data != null && (_data$data = data.data) != null && _data$data.message && getErrorMsg_isString((_data$data2 = data.data) == null ? void 0 : _data$data2.message)) {
19882
+ var _data$data3;
19883
+ return (_data$data3 = data.data) == null ? void 0 : _data$data3.message;
19884
+ }
19885
+ if (Array.isArray(data) && getErrorMsg_isString(data[0])) {
19886
+ return data[0];
19887
+ }
19888
+ return DECLINED_MESSAGE;
19889
+ };
19865
19890
  ;// CONCATENATED MODULE: ./src/components/Payments/Card/index.tsx
19866
19891
 
19867
19892
 
@@ -19873,6 +19898,7 @@ const payWithSavedCard = payload => {
19873
19898
  // import { DeleteCard } from '@unified-checkout/card';
19874
19899
 
19875
19900
 
19901
+
19876
19902
  function CardElement({
19877
19903
  payment,
19878
19904
  customStyle,
@@ -19888,11 +19914,9 @@ function CardElement({
19888
19914
  onCardValidationChanged,
19889
19915
  showPaymobLogo,
19890
19916
  hideCardHolderName,
19891
- isLoading,
19892
- onProcessingPayment,
19893
- isProcessingPayment
19917
+ isLoading
19894
19918
  }) {
19895
- var _customStyle$containe;
19919
+ var _customStyle$containe, _customStyle$containe2, _customStyle$button, _customStyle$containe3;
19896
19920
  const {
19897
19921
  token,
19898
19922
  amount,
@@ -19921,10 +19945,11 @@ function CardElement({
19921
19945
  const [selectedCardCVV, setSelectedCardCVV] = (0,react.useState)('');
19922
19946
  const [showCardModal, setShowCardModal] = (0,react.useState)(false);
19923
19947
  const [showCVVTooltipModal, setShowCVVTooltipModal] = (0,react.useState)(false);
19948
+ const previousValidationRef = (0,react.useRef)(false);
19924
19949
  const [showOTP, setShowOTP] = (0,react.useState)(false);
19925
19950
  const [sendOTPLoading, setSendOTPLoading] = (0,react.useState)(false);
19926
- const previousValidationRef = (0,react.useRef)(false);
19927
- const [startCardPay, setStartCardPay] = (0,react.useState)(false);
19951
+ const [paymentId, setPaymentId] = (0,react.useState)('');
19952
+ const [otpErrorMessage, setOTPErrorMessage] = (0,react.useState)('');
19928
19953
  const isCardValid = hideCardHolderName ? !isActionBtnDisabled : !(isActionBtnDisabled || !cardHolderName);
19929
19954
  const isAmexCardSelected = (selectedCard == null ? void 0 : selectedCard.type) === constants_CARD_TYPES.AMEX;
19930
19955
  const selectedCardCvvLength = selectedCardCVV.length;
@@ -19969,7 +19994,8 @@ function CardElement({
19969
19994
  };
19970
19995
  const handlePaymentResponse = ({
19971
19996
  res,
19972
- requiresOTP
19997
+ requiresOTP,
19998
+ isOTPResponse
19973
19999
  }) => {
19974
20000
  var _res$data, _res$data2, _res$data3;
19975
20001
  setShouldSubmitData(false);
@@ -19978,20 +20004,29 @@ function CardElement({
19978
20004
  if (cardHolderInput) {
19979
20005
  setTimeout(() => cardHolderInput.disabled = false, 1000);
19980
20006
  }
20007
+ const redirectionUrl = ((_res$data = res.data) == null ? void 0 : _res$data.redirection_url) || ((_res$data2 = res.data) == null ? void 0 : _res$data2.redirect_url);
19981
20008
  if (requiresOTP) {
20009
+ setPaymentId(res.data.payment_id);
19982
20010
  setShowOTP(true);
19983
- } else if (onAfterPaymentComplete && ((_res$data = res.data) == null ? void 0 : _res$data.is_3d_secure) !== 'true') {
20011
+ } else if (onAfterPaymentComplete && ((_res$data3 = res.data) == null ? void 0 : _res$data3.is_3d_secure) !== 'true') {
19984
20012
  onAfterPaymentComplete(res);
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);
20013
+ } else if (res.status === 200 && isOTPResponse) {
20014
+ if (redirectionUrl && (res.data.result === 'CAPTURED' || res.data.result === 'APPROVED')) {
20015
+ window.location.href = redirectionUrl;
20016
+ } else {
20017
+ setOTPErrorMessage(getErrorMsg(res));
20018
+ }
20019
+ } else if (res.status !== 200 && isOTPResponse) {
20020
+ setOTPErrorMessage(getErrorMsg(res));
20021
+ } else if (res.status === 200 && redirectionUrl) {
20022
+ window.location.href = redirectionUrl;
19988
20023
  } else if (res.status === 400) {
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.') {
20024
+ var _res$data4, _res$data5, _res$data6;
20025
+ if (res.data instanceof Array && res.data[0] === 'Retry limit reached.' || ((_res$data4 = res.data) == null ? void 0 : _res$data4.msg) === 'Retry limit reached.') {
19991
20026
  setErrorMessage(t('ERR_MSG_EXCEEDED_TRIALS'));
19992
- } else if (((_res$data7 = res.data) == null ? void 0 : _res$data7.message) === 'Session Error') {
20027
+ } else if (((_res$data5 = res.data) == null ? void 0 : _res$data5.message) === 'Session Error') {
19993
20028
  setErrorMessage(t('ERR_MSG_ALREADY_PROCESSED'));
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.') {
20029
+ } else if (res.data instanceof Array && res.data[0] === 'Order has already paid.' || ((_res$data6 = res.data) == null ? void 0 : _res$data6.msg) === 'Order has already paid.') {
19995
20030
  setErrorMessage(t('ERR_MSG_ALREADY_PAID'));
19996
20031
  } else {
19997
20032
  setErrorMessage(t('ERR_MSG_DECLINED'));
@@ -20053,39 +20088,21 @@ function CardElement({
20053
20088
  return;
20054
20089
  }
20055
20090
  }
20056
- setStartCardPay(true);
20057
- onProcessingPayment(true);
20091
+ sendCardData(true);
20058
20092
  setShouldSubmitData(false);
20059
20093
  };
20060
20094
  handlePay();
20061
20095
  }
20062
20096
  }, [cardHolderName, saveCard, shouldSubmitData, iframe]);
20063
20097
  (0,react.useEffect)(() => {
20064
- if (isIframeLoaded || startCardPay && isProcessingPayment) {
20065
- var _iframe$contentWindow, _payment$subType, _payment$subType2;
20066
- (_iframe$contentWindow = iframe.contentWindow) == null || _iframe$contentWindow.postMessage({
20067
- type: 'cardData',
20068
- payload: {
20069
- paymentToken: payment.token,
20070
- subType: {
20071
- paymentToken: (_payment$subType = payment.subType) == null ? void 0 : _payment$subType.token,
20072
- type: (_payment$subType2 = payment.subType) == null ? void 0 : _payment$subType2.type
20073
- },
20074
- currency,
20075
- cardHolderName,
20076
- saveCard: forceSaveCard || saveCard,
20077
- tenure,
20078
- shouldSubmitData: startCardPay && isProcessingPayment
20079
- }
20080
- }, '*');
20081
- setStartCardPay(false);
20082
- onProcessingPayment(false);
20098
+ if (isIframeLoaded) {
20099
+ sendCardData();
20083
20100
  }
20084
- }, [isIframeLoaded, payment, isProcessingPayment]);
20101
+ }, [isIframeLoaded, payment]);
20085
20102
  (0,react.useEffect)(() => {
20086
20103
  if (isIframeLoaded) {
20087
- var _iframe$contentWindow2;
20088
- (_iframe$contentWindow2 = iframe.contentWindow) == null || _iframe$contentWindow2.postMessage({
20104
+ var _iframe$contentWindow;
20105
+ (_iframe$contentWindow = iframe.contentWindow) == null || _iframe$contentWindow.postMessage({
20089
20106
  type: 'customStyles',
20090
20107
  payload: {
20091
20108
  styling: customStyle,
@@ -20097,8 +20114,8 @@ function CardElement({
20097
20114
  }
20098
20115
  }, [isIframeLoaded, iframeRef.current]);
20099
20116
  (0,react.useEffect)(() => {
20100
- var _iframe$contentWindow3;
20101
- iframe == null || (_iframe$contentWindow3 = iframe.contentWindow) == null || _iframe$contentWindow3.postMessage({
20117
+ var _iframe$contentWindow2;
20118
+ iframe == null || (_iframe$contentWindow2 = iframe.contentWindow) == null || _iframe$contentWindow2.postMessage({
20102
20119
  type: 'cardHolderError',
20103
20120
  payload: {
20104
20121
  error: errors['name']
@@ -20116,6 +20133,24 @@ function CardElement({
20116
20133
  previousValidationRef.current = isCardValid;
20117
20134
  }
20118
20135
  }, [isCardValid, shouldDisablePayBtn]);
20136
+ const sendCardData = shouldSubmitData => {
20137
+ var _iframe$contentWindow3, _payment$subType, _payment$subType2;
20138
+ (_iframe$contentWindow3 = iframe.contentWindow) == null || _iframe$contentWindow3.postMessage({
20139
+ type: 'cardData',
20140
+ payload: {
20141
+ paymentToken: payment.token,
20142
+ subType: {
20143
+ paymentToken: (_payment$subType = payment.subType) == null ? void 0 : _payment$subType.token,
20144
+ type: (_payment$subType2 = payment.subType) == null ? void 0 : _payment$subType2.type
20145
+ },
20146
+ currency,
20147
+ cardHolderName,
20148
+ saveCard: forceSaveCard || saveCard,
20149
+ tenure,
20150
+ shouldSubmitData: shouldSubmitData
20151
+ }
20152
+ }, '*');
20153
+ };
20119
20154
  const handlePayWithoutButton = () => {
20120
20155
  setShouldSubmitData(true);
20121
20156
  };
@@ -20183,12 +20218,12 @@ function CardElement({
20183
20218
  window.location.href = res.data.redirection_url;
20184
20219
  }
20185
20220
  } else if (res.status === 400) {
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.') {
20221
+ var _res$data7, _res$data8, _res$data9;
20222
+ if (res.data instanceof Array && res.data[0] === 'Retry limit reached.' || ((_res$data7 = res.data) == null ? void 0 : _res$data7.msg) === 'Retry limit reached.') {
20188
20223
  setErrorMessage(t('ERR_MSG_EXCEEDED_TRIALS'));
20189
- } else if (((_res$data10 = res.data) == null ? void 0 : _res$data10.message) === 'Session Error') {
20224
+ } else if (((_res$data8 = res.data) == null ? void 0 : _res$data8.message) === 'Session Error') {
20190
20225
  setErrorMessage(t('ERR_MSG_ALREADY_PROCESSED'));
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.') {
20226
+ } else if (res.data instanceof Array && res.data[0] === 'Order has already paid.' || ((_res$data9 = res.data) == null ? void 0 : _res$data9.msg) === 'Order has already paid.') {
20192
20227
  setErrorMessage(t('ERR_MSG_ALREADY_PAID'));
20193
20228
  } else {
20194
20229
  setErrorMessage(t('ERR_MSG_DECLINED'));
@@ -20215,7 +20250,8 @@ function CardElement({
20215
20250
  subType: {
20216
20251
  paymentToken: (_payment$subType3 = payment.subType) == null ? void 0 : _payment$subType3.token
20217
20252
  },
20218
- otp
20253
+ otp,
20254
+ paymentId
20219
20255
  }
20220
20256
  }, '*');
20221
20257
  };
@@ -20252,16 +20288,42 @@ function CardElement({
20252
20288
  onSubmit: handleOTPSubmit,
20253
20289
  length: 4,
20254
20290
  modalHeader: `${4}-digit code`,
20255
- loading: sendOTPLoading
20291
+ loading: sendOTPLoading,
20292
+ onErrorMessage: setOTPErrorMessage,
20293
+ error: otpErrorMessage,
20294
+ customStyle: {
20295
+ container: {
20296
+ backgroundColor: (customStyle == null || (_customStyle$containe2 = customStyle.container) == null ? void 0 : _customStyle$containe2.backgroundColor) || '',
20297
+ borderRadius: (customStyle == null || (_customStyle$button = customStyle.button) == null ? void 0 : _customStyle$button.borderRadius) || ''
20298
+ },
20299
+ button: customStyle == null ? void 0 : customStyle.button,
20300
+ label: customStyle == null ? void 0 : customStyle.label,
20301
+ error: customStyle == null ? void 0 : customStyle.error
20302
+ }
20256
20303
  }), !isMobile && showOTP && /*#__PURE__*/(0,jsx_runtime.jsx)(ModalView_ModalView, {
20257
20304
  showModal: showOTP,
20258
20305
  onClose: handleCloseOTP,
20306
+ customStyle: customStyle == null ? void 0 : customStyle.button,
20259
20307
  children: /*#__PURE__*/(0,jsx_runtime.jsx)(OTPModal_OTPModal, {
20260
20308
  onClose: handleCloseOTP,
20261
20309
  onSubmit: handleOTPSubmit,
20262
20310
  length: 4,
20263
20311
  modalHeader: `${4}-digit code`,
20264
- loading: sendOTPLoading
20312
+ loading: sendOTPLoading,
20313
+ onErrorMessage: setOTPErrorMessage,
20314
+ error: otpErrorMessage,
20315
+ customStyle: {
20316
+ container: {
20317
+ backgroundColor: (customStyle == null || (_customStyle$containe3 = customStyle.container) == null ? void 0 : _customStyle$containe3.backgroundColor) || ''
20318
+ },
20319
+ cancelButton: Object.assign({}, customStyle == null ? void 0 : customStyle.button, {
20320
+ backgroundColor: '#fff',
20321
+ lineHeight: 'normal'
20322
+ }),
20323
+ button: customStyle == null ? void 0 : customStyle.button,
20324
+ label: customStyle == null ? void 0 : customStyle.label,
20325
+ error: customStyle == null ? void 0 : customStyle.error
20326
+ }
20265
20327
  })
20266
20328
  }), /*#__PURE__*/(0,jsx_runtime.jsx)(CVVToolTipModal_CVVToolTipModal, {
20267
20329
  onClose: () => setShowCVVTooltipModal(false),
@@ -26890,8 +26952,7 @@ function ApplePay(props) {
26890
26952
  checkDiscount,
26891
26953
  isPixel,
26892
26954
  isLoading,
26893
- paymentName,
26894
- onLayerClick
26955
+ paymentName
26895
26956
  } = props;
26896
26957
  const [loading, setLoading] = (0,react.useState)(false);
26897
26958
  const [discount, setDiscount] = (0,react.useState)({
@@ -26938,6 +26999,13 @@ function ApplePay(props) {
26938
26999
  payload.requiredShippingContactFields = ['email', 'phone', 'name'];
26939
27000
  }
26940
27001
  const session = new window.ApplePaySession(3, payload);
27002
+ if (onBeforePaymentComplete) {
27003
+ const result = await onBeforePaymentComplete(paymentName);
27004
+ if (!result) {
27005
+ setLoading(false);
27006
+ return;
27007
+ }
27008
+ }
26941
27009
  session.onvalidatemerchant = async event => {
26942
27010
  console.log("start validation request");
26943
27011
  console.log(`validationURL: ${event.validationURL}`);
@@ -27033,7 +27101,7 @@ function ApplePay(props) {
27033
27101
  session.begin();
27034
27102
  };
27035
27103
  return /*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
27036
- className: `w-full ${isPixel ? 'relative' : ''} ${discount.hasDiscount ? `flex flex-col gap-2 !h-auto ${!isPixel ? 'sm:mb-6' : ''}` : ''}`,
27104
+ className: `w-full ${discount.hasDiscount ? `flex flex-col gap-2 !h-auto ${!isPixel ? 'sm:mb-6' : ''}` : ''}`,
27037
27105
  children: [/*#__PURE__*/(0,jsx_runtime.jsx)(Button_Button, {
27038
27106
  id: "apple-pay-button",
27039
27107
  icon: apple_pay_namespaceObject,
@@ -27043,9 +27111,6 @@ function ApplePay(props) {
27043
27111
  customStyle: customStyle,
27044
27112
  disabled: loading || isLoading,
27045
27113
  loading: loading || isLoading
27046
- }), isPixel && /*#__PURE__*/(0,jsx_runtime.jsx)("button", {
27047
- onClick: () => onLayerClick == null ? void 0 : onLayerClick(setLoading),
27048
- className: "absolute inset-0 cursor-pointer"
27049
27114
  }), discount.hasDiscount && /*#__PURE__*/(0,jsx_runtime.jsx)("p", {
27050
27115
  className: "flex text-center flex-col justify-center text-green-400 text-sm font-medium leading-6 tracking-[0.01rem]",
27051
27116
  children: discount.discountMessage
@@ -27239,9 +27304,7 @@ function GooglePayElement({
27239
27304
  onBeforePaymentComplete,
27240
27305
  onAfterPaymentComplete,
27241
27306
  onErrorMessage,
27242
- isLoading,
27243
- onProcessingPayment,
27244
- isProcessingPayment
27307
+ isLoading
27245
27308
  }) {
27246
27309
  var _String;
27247
27310
  const {
@@ -27250,20 +27313,14 @@ function GooglePayElement({
27250
27313
  keyPrefix: 'googlePay'
27251
27314
  });
27252
27315
  const [loading, setLoading] = (0,react.useState)(false);
27253
- const [startGooglePay, setStartGooglePay] = (0,react.useState)(false);
27254
27316
  const {
27255
27317
  amount,
27256
27318
  currency
27257
27319
  } = payment;
27258
27320
  const googlePay = payment;
27259
27321
  const integrationId = googlePay == null ? void 0 : googlePay.integrationId;
27260
- (0,react.useEffect)(() => {
27261
- if (startGooglePay && isProcessingPayment) {
27262
- const googlePayButton = document.getElementById('gpay-button-online-api-id');
27263
- googlePayButton == null || googlePayButton.click();
27264
- }
27265
- }, [startGooglePay, isProcessingPayment]);
27266
- const handleLayerClick = async () => {
27322
+ const handleSubmit = async (paymentToken, googlePayload) => {
27323
+ var _res$data;
27267
27324
  setLoading(true);
27268
27325
  if (onBeforePaymentComplete) {
27269
27326
  const result = await onBeforePaymentComplete(payment.name);
@@ -27272,11 +27329,6 @@ function GooglePayElement({
27272
27329
  return;
27273
27330
  }
27274
27331
  }
27275
- setStartGooglePay(true);
27276
- onProcessingPayment(true);
27277
- };
27278
- const handleSubmit = async (paymentToken, googlePayload) => {
27279
- var _res$data;
27280
27332
  const res = await payWithGooglePay(paymentToken, integrationId, googlePayload);
27281
27333
  setLoading(false);
27282
27334
  const redirectionUrl = (_res$data = res.data) == null ? void 0 : _res$data.redirection_url;
@@ -27322,23 +27374,17 @@ function GooglePayElement({
27322
27374
  }
27323
27375
  };
27324
27376
  return /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, {
27325
- children: [/*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
27326
- className: "relative w-full",
27327
- children: [/*#__PURE__*/(0,jsx_runtime.jsx)(GooglePay, {
27328
- onSubmit: handleSubmit,
27329
- paymentToken: (googlePay == null ? void 0 : googlePay.token) || '',
27330
- paymentGateway: (googlePay == null ? void 0 : googlePay.gateway) || '',
27331
- isLiveIntegration: googlePay == null ? void 0 : googlePay.live,
27332
- merchantIdentifier: googlePay == null ? void 0 : googlePay.merchantIdentifier,
27333
- amount: (_String = String(amount)) == null ? void 0 : _String.replace(/,/g, ''),
27334
- currency: currency,
27335
- countryCode: currency == null ? void 0 : currency.slice(0, 2),
27336
- customStyle: customStyle,
27337
- isLoading: isLoading
27338
- }), /*#__PURE__*/(0,jsx_runtime.jsx)("button", {
27339
- onClick: handleLayerClick,
27340
- className: "absolute inset-0 cursor-pointer"
27341
- })]
27377
+ children: [/*#__PURE__*/(0,jsx_runtime.jsx)(GooglePay, {
27378
+ onSubmit: handleSubmit,
27379
+ paymentToken: (googlePay == null ? void 0 : googlePay.token) || '',
27380
+ paymentGateway: (googlePay == null ? void 0 : googlePay.gateway) || '',
27381
+ isLiveIntegration: googlePay == null ? void 0 : googlePay.live,
27382
+ merchantIdentifier: googlePay == null ? void 0 : googlePay.merchantIdentifier,
27383
+ amount: (_String = String(amount)) == null ? void 0 : _String.replace(/,/g, ''),
27384
+ currency: currency,
27385
+ countryCode: currency == null ? void 0 : currency.slice(0, 2),
27386
+ customStyle: customStyle,
27387
+ isLoading: isLoading
27342
27388
  }), /*#__PURE__*/(0,jsx_runtime.jsx)(LoadingModal, {
27343
27389
  show: loading,
27344
27390
  text: t('LOADING_MSG')
@@ -27374,43 +27420,21 @@ const checkDiscount = paymentToken => {
27374
27420
 
27375
27421
 
27376
27422
 
27377
-
27378
27423
  function ApplePayElements({
27379
27424
  payment,
27380
27425
  customStyle,
27381
27426
  onBeforePaymentComplete,
27382
27427
  onAfterPaymentComplete,
27383
27428
  onPaymentCancel,
27384
- isLoading,
27385
- onProcessingPayment,
27386
- isProcessingPayment
27429
+ isLoading
27387
27430
  }) {
27388
27431
  var _amount$toString;
27389
- const [startApplePay, setStartApplePay] = (0,react.useState)(false);
27390
27432
  const {
27391
27433
  amount,
27392
27434
  currency,
27393
27435
  merchantName
27394
27436
  } = payment;
27395
27437
  const applePay = payment;
27396
- (0,react.useEffect)(() => {
27397
- if (startApplePay && isProcessingPayment) {
27398
- const applePayButton = document.getElementById('apple-pay-button');
27399
- applePayButton == null || applePayButton.click();
27400
- }
27401
- }, [startApplePay, isProcessingPayment]);
27402
- const handleLayerClick = async setLoading => {
27403
- setLoading(true);
27404
- if (onBeforePaymentComplete) {
27405
- const result = await onBeforePaymentComplete(payment.name);
27406
- if (!result) {
27407
- setLoading(false);
27408
- return;
27409
- }
27410
- }
27411
- setStartApplePay(true);
27412
- onProcessingPayment(true);
27413
- };
27414
27438
  const handleSubmit = (status, resData) => {
27415
27439
  window.location.href = resData.redirection_url;
27416
27440
  };
@@ -27431,8 +27455,7 @@ function ApplePayElements({
27431
27455
  checkDiscount: checkDiscount,
27432
27456
  isPixel: true,
27433
27457
  isLoading: isLoading,
27434
- paymentName: payment.name,
27435
- onLayerClick: handleLayerClick
27458
+ paymentName: payment.name
27436
27459
  });
27437
27460
  }
27438
27461
  /* harmony default export */ const Payments_ApplePay = (ApplePayElements);
@@ -27514,7 +27537,7 @@ async function fetchPayments(publicKey, clientSecret, paymentMethods) {
27514
27537
 
27515
27538
 
27516
27539
 
27517
- function PaymentsList(props) {
27540
+ const PaymentsList = /*#__PURE__*/(0,react.forwardRef)((props, ref) => {
27518
27541
  var _customStyle$containe;
27519
27542
  const {
27520
27543
  payments,
@@ -27543,28 +27566,24 @@ function PaymentsList(props) {
27543
27566
  const [savedCardsList, setSavedCardsList] = (0,react.useState)(savedCards);
27544
27567
  const [errorMessage, setErrorMessage] = (0,react.useState)('');
27545
27568
  const [isLoading, setIsLoading] = (0,react.useState)(false);
27546
- const [isProcessingPayment, setIsProcessingPayment] = (0,react.useState)(false);
27547
- (0,react.useEffect)(() => {
27548
- window.addEventListener('updateIntentionData', getData);
27549
- return () => {
27550
- window.removeEventListener('updateIntentionData', getData);
27551
- };
27552
- }, []);
27553
- const getData = async () => {
27554
- setIsLoading(true);
27555
- const {
27556
- res,
27557
- paymentList,
27558
- savedCards
27559
- } = await fetchPayments(publicKey, clientSecret, selectedPaymentMethods);
27560
- setIsLoading(false);
27561
- if (res.status === 200) {
27562
- setPaymentList(paymentList);
27563
- setSavedCardsList(savedCards);
27569
+ (0,react.useImperativeHandle)(ref, () => ({
27570
+ getData: async () => {
27571
+ setIsLoading(true);
27572
+ const {
27573
+ res,
27574
+ paymentList,
27575
+ savedCards
27576
+ } = await fetchPayments(publicKey, clientSecret, selectedPaymentMethods);
27577
+ setIsLoading(false);
27578
+ if (res.status === 200) {
27579
+ setPaymentList(paymentList);
27580
+ setSavedCardsList(savedCards);
27581
+ }
27582
+ return res;
27564
27583
  }
27565
- };
27584
+ }));
27566
27585
  const handleOnBeforePaymentComplete = async paymentMethod => {
27567
- return await onBeforePaymentComplete(paymentMethod, getData);
27586
+ return await onBeforePaymentComplete(paymentMethod);
27568
27587
  };
27569
27588
  const hasOnlyXPays = () => {
27570
27589
  const xPays = ['apple-pay', 'google-pay'];
@@ -27614,18 +27633,14 @@ function PaymentsList(props) {
27614
27633
  onAfterPaymentComplete: onAfterPaymentComplete,
27615
27634
  onPaymentCancel: onPaymentCancel,
27616
27635
  customStyle: customStyle == null ? void 0 : customStyle.button,
27617
- isLoading: isLoading,
27618
- onProcessingPayment: setIsProcessingPayment,
27619
- isProcessingPayment: isProcessingPayment
27636
+ isLoading: isLoading
27620
27637
  }), isGooglePay() && /*#__PURE__*/(0,jsx_runtime.jsx)(GooglePayElement, {
27621
27638
  payment: googlePaymentMethod,
27622
27639
  customStyle: customStyle == null ? void 0 : customStyle.button,
27623
27640
  onBeforePaymentComplete: onBeforePaymentComplete && handleOnBeforePaymentComplete,
27624
27641
  onAfterPaymentComplete: onAfterPaymentComplete,
27625
27642
  onErrorMessage: setErrorMessage,
27626
- isLoading: isLoading,
27627
- onProcessingPayment: setIsProcessingPayment,
27628
- isProcessingPayment: isProcessingPayment
27643
+ isLoading: isLoading
27629
27644
  })]
27630
27645
  })
27631
27646
  }), paymentList.length === 0 ? /*#__PURE__*/(0,jsx_runtime.jsx)("div", {
@@ -27664,13 +27679,11 @@ function PaymentsList(props) {
27664
27679
  showPaymobLogo,
27665
27680
  hideCardHolderName,
27666
27681
  isLoading,
27667
- onProcessingPayment: setIsProcessingPayment,
27668
- isProcessingPayment,
27669
27682
  isList: true
27670
27683
  })
27671
27684
  })]
27672
27685
  });
27673
- }
27686
+ });
27674
27687
  /* harmony default export */ const List = (PaymentsList);
27675
27688
  ;// CONCATENATED MODULE: ./src/utils/getStyles.ts
27676
27689
  function getStyles(customStyle) {
@@ -27805,7 +27818,7 @@ function getStyles(customStyle) {
27805
27818
 
27806
27819
 
27807
27820
 
27808
- function Payments_Payments(props) {
27821
+ const Payments_Payments = /*#__PURE__*/(0,react.forwardRef)((props, ref) => {
27809
27822
  const {
27810
27823
  payment,
27811
27824
  customStyle,
@@ -27941,13 +27954,14 @@ function Payments_Payments(props) {
27941
27954
  hideCardHolderName: hideCardHolderName,
27942
27955
  publicKey: publicKey,
27943
27956
  clientSecret: clientSecret,
27944
- selectedPaymentMethods: selectedPaymentMethods
27957
+ selectedPaymentMethods: selectedPaymentMethods,
27958
+ ref: ref
27945
27959
  });
27946
27960
  };
27947
27961
  return /*#__PURE__*/(0,jsx_runtime.jsx)(jsx_runtime.Fragment, {
27948
27962
  children: render()
27949
27963
  });
27950
- }
27964
+ });
27951
27965
  /* harmony default export */ const components_Payments = (Payments_Payments);
27952
27966
  ;// CONCATENATED MODULE: ./src/utils/apiUrl.ts
27953
27967
 
@@ -31494,6 +31508,7 @@ i18next.use(initReactI18next).init({
31494
31508
  });
31495
31509
  /* harmony default export */ const localization_i18n = ((/* unused pure expression or super */ null && (i18n)));
31496
31510
  ;// CONCATENATED MODULE: ./src/lib/pixel.tsx
31511
+ var _Pixel;
31497
31512
 
31498
31513
 
31499
31514
 
@@ -31514,10 +31529,13 @@ class Pixel {
31514
31529
  this._showSaveCard = void 0;
31515
31530
  this._root = null;
31516
31531
  this._error = null;
31532
+ this._paymentsRef = null;
31517
31533
  this._options = Object.assign({}, options, {
31518
31534
  showPaymobLogo: (_options$showPaymobLo = options.showPaymobLogo) != null ? _options$showPaymobLo : true
31519
31535
  });
31520
31536
  this._baseURL = this.updateAPIBaseURL();
31537
+ this._paymentsRef = /*#__PURE__*/react.createRef();
31538
+ Pixel._instance = this;
31521
31539
  this.getData();
31522
31540
  }
31523
31541
  updateAPIBaseURL() {
@@ -31559,9 +31577,9 @@ class Pixel {
31559
31577
  this.render();
31560
31578
  }
31561
31579
  }
31562
- async handleBeforePaymentComplete(paymentMethod, updateIntentionData) {
31580
+ async handleBeforePaymentComplete(paymentMethod) {
31563
31581
  if (this._options.beforePaymentComplete) {
31564
- const result = await this._options.beforePaymentComplete(paymentMethod, updateIntentionData);
31582
+ const result = await this._options.beforePaymentComplete(paymentMethod);
31565
31583
  if (result === false) return false;
31566
31584
  return true;
31567
31585
  }
@@ -31581,6 +31599,13 @@ class Pixel {
31581
31599
  this._options.cardValidationChanged(isValid);
31582
31600
  }
31583
31601
  }
31602
+ static async updateIntentionData() {
31603
+ var _Pixel$_instance;
31604
+ if (!((_Pixel$_instance = Pixel._instance) != null && (_Pixel$_instance = _Pixel$_instance._paymentsRef) != null && (_Pixel$_instance = _Pixel$_instance.current) != null && _Pixel$_instance.getData)) {
31605
+ throw new Error('Pixel not initialized');
31606
+ }
31607
+ return await Pixel._instance._paymentsRef.current.getData();
31608
+ }
31584
31609
  render() {
31585
31610
  const container = document.getElementById(this._options['elementId']);
31586
31611
  if (!container) {
@@ -31610,7 +31635,8 @@ class Pixel {
31610
31635
  hideCardHolderName: this._options['hideCardHolderName'],
31611
31636
  publicKey: this._options['publicKey'],
31612
31637
  clientSecret: this._options['clientSecret'],
31613
- selectedPaymentMethods: this._options['paymentMethods']
31638
+ selectedPaymentMethods: this._options['paymentMethods'],
31639
+ ref: this._paymentsRef
31614
31640
  }, this._options.beforePaymentComplete && {
31615
31641
  onBeforePaymentComplete: this.handleBeforePaymentComplete.bind(this)
31616
31642
  }, this._options.afterPaymentComplete && {
@@ -31623,6 +31649,8 @@ class Pixel {
31623
31649
  }));
31624
31650
  }
31625
31651
  }
31652
+ _Pixel = Pixel;
31653
+ Pixel._instance = null;
31626
31654
  window.Pixel = Pixel;
31627
31655
  /* harmony default export */ const pixel = ((/* unused pure expression or super */ null && (Pixel)));
31628
31656
  ;// CONCATENATED MODULE: ./src/index.ts
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "paymob-pixel-alpha",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "keywords": ["paymob","pixel","paymob-pixel"],
5
5
  "main": "./main.js",
6
+ "license": "MIT",
6
7
  "homepage": "https://developers.paymob.com",
7
8
  "author": "Paymob <support@paymob.com> (https://developers.paymob.com)",
8
9
  "exports": {
package/styles.css CHANGED
@@ -612,6 +612,10 @@ video {
612
612
  visibility: hidden;
613
613
  }
614
614
 
615
+ .static {
616
+ position: static;
617
+ }
618
+
615
619
  .fixed {
616
620
  position: fixed;
617
621
  }
@@ -1,19 +0,0 @@
1
- var _path;
2
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
- import * as React from "react";
4
- var SvgCloseIcon = function SvgCloseIcon(props) {
5
- return /*#__PURE__*/React.createElement("svg", _extends({
6
- xmlns: "http://www.w3.org/2000/svg",
7
- width: 800,
8
- height: 800,
9
- fill: "none",
10
- viewBox: "0 0 24 24"
11
- }, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
12
- fill: "#667085",
13
- fillRule: "evenodd",
14
- d: "M5.293 5.293a1 1 0 0 1 1.414 0L12 10.586l5.293-5.293a1 1 0 1 1 1.414 1.414L13.414 12l5.293 5.293a1 1 0 0 1-1.414 1.414L12 13.414l-5.293 5.293a1 1 0 0 1-1.414-1.414L10.586 12 5.293 6.707a1 1 0 0 1 0-1.414",
15
- clipRule: "evenodd"
16
- })));
17
- };
18
- export { SvgCloseIcon as ReactComponent };
19
- export default "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPgo8c3ZnIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTUuMjkyODkgNS4yOTI4OUM1LjY4MzQyIDQuOTAyMzcgNi4zMTY1OCA0LjkwMjM3IDYuNzA3MTEgNS4yOTI4OUwxMiAxMC41ODU4TDE3LjI5MjkgNS4yOTI4OUMxNy42ODM0IDQuOTAyMzcgMTguMzE2NiA0LjkwMjM3IDE4LjcwNzEgNS4yOTI4OUMxOS4wOTc2IDUuNjgzNDIgMTkuMDk3NiA2LjMxNjU4IDE4LjcwNzEgNi43MDcxMUwxMy40MTQyIDEyTDE4LjcwNzEgMTcuMjkyOUMxOS4wOTc2IDE3LjY4MzQgMTkuMDk3NiAxOC4zMTY2IDE4LjcwNzEgMTguNzA3MUMxOC4zMTY2IDE5LjA5NzYgMTcuNjgzNCAxOS4wOTc2IDE3LjI5MjkgMTguNzA3MUwxMiAxMy40MTQyTDYuNzA3MTEgMTguNzA3MUM2LjMxNjU4IDE5LjA5NzYgNS42ODM0MiAxOS4wOTc2IDUuMjkyODkgMTguNzA3MUM0LjkwMjM3IDE4LjMxNjYgNC45MDIzNyAxNy42ODM0IDUuMjkyODkgMTcuMjkyOUwxMC41ODU4IDEyTDUuMjkyODkgNi43MDcxMUM0LjkwMjM3IDYuMzE2NTggNC45MDIzNyA1LjY4MzQyIDUuMjkyODkgNS4yOTI4OVoiIGZpbGw9IiM2NjcwODUiLz4KPC9zdmc+";