paymob-pixel-alpha 1.1.4 → 1.1.6
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/main.js +51 -35
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -18914,7 +18914,7 @@ function IframeCard(props) {
|
|
|
18914
18914
|
} else {
|
|
18915
18915
|
handleCardSubmit({
|
|
18916
18916
|
data,
|
|
18917
|
-
cardHolderName,
|
|
18917
|
+
cardHolderName: cardHolderName || 'n/a',
|
|
18918
18918
|
paymentToken: hasOmanNetIntegration && isOmanNetCard ? subType.paymentToken : paymentToken,
|
|
18919
18919
|
subType: hasOmanNetIntegration && isOmanNetCard ? subType.type : 'CARD',
|
|
18920
18920
|
saveCard,
|
|
@@ -19987,7 +19987,6 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
|
|
|
19987
19987
|
const [errorMessage, setErrorMessage] = (0,react.useState)('');
|
|
19988
19988
|
const iframeRef = (0,react.useRef)(null);
|
|
19989
19989
|
const [errors, setErrors] = (0,react.useState)({});
|
|
19990
|
-
const iframe = document.getElementById('iFrame');
|
|
19991
19990
|
const [isIframeLoaded, setIsIframeLoaded] = (0,react.useState)(false);
|
|
19992
19991
|
const [showDeleteCardModal, setShowDeleteCardModal] = (0,react.useState)(false);
|
|
19993
19992
|
const [selectedDeleteCard, setSelectedDeleteCard] = (0,react.useState)();
|
|
@@ -20009,13 +20008,15 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
|
|
|
20009
20008
|
const shouldDisablePayBtn = showCvvInput ? loading || (isAmexCardSelected ? selectedCardCvvLength !== constants_AMEX_CVV_LENGTH : selectedCardCvvLength !== constants_CVV_LENGTH) : !selectedCardId;
|
|
20010
20009
|
(0,react.useEffect)(() => {
|
|
20011
20010
|
const handleDataFromIframe = event => {
|
|
20012
|
-
var _event$data, _event$data2, _event$data3;
|
|
20011
|
+
var _iframeRef$current, _event$data, _event$data2, _event$data3;
|
|
20013
20012
|
if (!event.data) return;
|
|
20014
20013
|
if (!event.data.type) return;
|
|
20014
|
+
if (event.source !== ((_iframeRef$current = iframeRef.current) == null ? void 0 : _iframeRef$current.contentWindow)) return;
|
|
20015
20015
|
if (event.data.shouldFocusOnCardName) {
|
|
20016
|
-
|
|
20016
|
+
var _iframeRef$current2;
|
|
20017
|
+
const cardNameField = (_iframeRef$current2 = iframeRef.current) == null || (_iframeRef$current2 = _iframeRef$current2.nextElementSibling) == null ? void 0 : _iframeRef$current2.querySelector(`input[name=name]`);
|
|
20017
20018
|
if (cardNameField !== null) {
|
|
20018
|
-
cardNameField.focus();
|
|
20019
|
+
cardNameField == null || cardNameField.focus();
|
|
20019
20020
|
}
|
|
20020
20021
|
}
|
|
20021
20022
|
if (event.data.iframeCardHight) {
|
|
@@ -20052,10 +20053,10 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
|
|
|
20052
20053
|
requiresOTP,
|
|
20053
20054
|
isOTPResponse
|
|
20054
20055
|
}) => {
|
|
20055
|
-
var _res$data, _res$data2, _res$data3;
|
|
20056
|
+
var _iframeRef$current3, _res$data, _res$data2, _res$data3;
|
|
20056
20057
|
setShouldSubmitData(false);
|
|
20057
20058
|
setSendOTPLoading(false);
|
|
20058
|
-
const cardHolderInput =
|
|
20059
|
+
const cardHolderInput = (_iframeRef$current3 = iframeRef.current) == null || (_iframeRef$current3 = _iframeRef$current3.nextElementSibling) == null ? void 0 : _iframeRef$current3.querySelector(`input[name=name]`);
|
|
20059
20060
|
if (cardHolderInput) {
|
|
20060
20061
|
setTimeout(() => cardHolderInput.disabled = false, 1000);
|
|
20061
20062
|
}
|
|
@@ -20127,10 +20128,11 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
|
|
|
20127
20128
|
};
|
|
20128
20129
|
}, [isCardValid, shouldDisablePayBtn, showCardModal, savedCards == null ? void 0 : savedCards.length]);
|
|
20129
20130
|
(0,react.useEffect)(() => {
|
|
20130
|
-
if (
|
|
20131
|
+
if (iframeRef.current && shouldSubmitData) {
|
|
20131
20132
|
const handlePay = async () => {
|
|
20133
|
+
var _iframeRef$current4;
|
|
20132
20134
|
if (loading) return;
|
|
20133
|
-
const cardHolderInput =
|
|
20135
|
+
const cardHolderInput = (_iframeRef$current4 = iframeRef.current) == null || (_iframeRef$current4 = _iframeRef$current4.nextElementSibling) == null ? void 0 : _iframeRef$current4.querySelector(`input[name=name]`);
|
|
20134
20136
|
if (cardHolderInput) {
|
|
20135
20137
|
cardHolderInput.disabled = true;
|
|
20136
20138
|
}
|
|
@@ -20148,7 +20150,7 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
|
|
|
20148
20150
|
};
|
|
20149
20151
|
handlePay();
|
|
20150
20152
|
}
|
|
20151
|
-
}, [cardHolderName, saveCard, shouldSubmitData,
|
|
20153
|
+
}, [cardHolderName, saveCard, shouldSubmitData, iframeRef.current]);
|
|
20152
20154
|
(0,react.useEffect)(() => {
|
|
20153
20155
|
if (isIframeLoaded) {
|
|
20154
20156
|
sendCardData();
|
|
@@ -20157,8 +20159,8 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
|
|
|
20157
20159
|
(0,react.useEffect)(() => {
|
|
20158
20160
|
let resizeObserver = null;
|
|
20159
20161
|
if (isIframeLoaded) {
|
|
20160
|
-
var
|
|
20161
|
-
(
|
|
20162
|
+
var _iframeRef$current5, _iframeRef$current6;
|
|
20163
|
+
(_iframeRef$current5 = iframeRef.current) == null || (_iframeRef$current5 = _iframeRef$current5.contentWindow) == null || _iframeRef$current5.postMessage({
|
|
20162
20164
|
type: 'customStyles',
|
|
20163
20165
|
payload: {
|
|
20164
20166
|
styling: customStyle,
|
|
@@ -20167,7 +20169,7 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
|
|
|
20167
20169
|
}
|
|
20168
20170
|
}
|
|
20169
20171
|
}, '*');
|
|
20170
|
-
const nextElement =
|
|
20172
|
+
const nextElement = (_iframeRef$current6 = iframeRef.current) == null ? void 0 : _iframeRef$current6.nextElementSibling;
|
|
20171
20173
|
resizeObserver = new ResizeObserver(entries => {
|
|
20172
20174
|
for (let entry of entries) {
|
|
20173
20175
|
const width = Math.floor(entry.contentRect.width - 0.5);
|
|
@@ -20176,7 +20178,7 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
|
|
|
20176
20178
|
}
|
|
20177
20179
|
}
|
|
20178
20180
|
});
|
|
20179
|
-
resizeObserver.observe(
|
|
20181
|
+
iframeRef.current && resizeObserver.observe(iframeRef.current);
|
|
20180
20182
|
}
|
|
20181
20183
|
return () => {
|
|
20182
20184
|
var _resizeObserver;
|
|
@@ -20184,8 +20186,8 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
|
|
|
20184
20186
|
};
|
|
20185
20187
|
}, [isIframeLoaded, iframeRef.current]);
|
|
20186
20188
|
(0,react.useEffect)(() => {
|
|
20187
|
-
var
|
|
20188
|
-
|
|
20189
|
+
var _iframeRef$current7;
|
|
20190
|
+
(_iframeRef$current7 = iframeRef.current) == null || (_iframeRef$current7 = _iframeRef$current7.contentWindow) == null || _iframeRef$current7.postMessage({
|
|
20189
20191
|
type: 'cardHolderError',
|
|
20190
20192
|
payload: {
|
|
20191
20193
|
error: errors['name']
|
|
@@ -20208,12 +20210,12 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
|
|
|
20208
20210
|
}));
|
|
20209
20211
|
async function handleGenerateToken() {
|
|
20210
20212
|
return new Promise((resolve, reject) => {
|
|
20211
|
-
var
|
|
20213
|
+
var _iframeRef$current8;
|
|
20212
20214
|
if (loading || !isCardValid || isLoading) {
|
|
20213
20215
|
return reject();
|
|
20214
20216
|
}
|
|
20215
20217
|
tokenizationResolve.current = resolve;
|
|
20216
|
-
(
|
|
20218
|
+
(_iframeRef$current8 = iframeRef.current) == null || (_iframeRef$current8 = _iframeRef$current8.contentWindow) == null || _iframeRef$current8.postMessage({
|
|
20217
20219
|
type: 'tokenizeCard',
|
|
20218
20220
|
payload: {
|
|
20219
20221
|
publicKey,
|
|
@@ -20225,8 +20227,8 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
|
|
|
20225
20227
|
}
|
|
20226
20228
|
;
|
|
20227
20229
|
const sendCardData = shouldSubmitData => {
|
|
20228
|
-
var
|
|
20229
|
-
(
|
|
20230
|
+
var _iframeRef$current9, _payment$subType, _payment$subType2;
|
|
20231
|
+
(_iframeRef$current9 = iframeRef.current) == null || (_iframeRef$current9 = _iframeRef$current9.contentWindow) == null || _iframeRef$current9.postMessage({
|
|
20230
20232
|
type: 'cardData',
|
|
20231
20233
|
payload: {
|
|
20232
20234
|
paymentToken: payment == null ? void 0 : payment.token,
|
|
@@ -20247,8 +20249,8 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
|
|
|
20247
20249
|
setShouldSubmitData(true);
|
|
20248
20250
|
};
|
|
20249
20251
|
const handleFocusToPrevInput = () => {
|
|
20250
|
-
var
|
|
20251
|
-
(
|
|
20252
|
+
var _iframeRef$current10;
|
|
20253
|
+
(_iframeRef$current10 = iframeRef.current) == null || (_iframeRef$current10 = _iframeRef$current10.contentWindow) == null || _iframeRef$current10.postMessage({
|
|
20252
20254
|
type: 'setPrevFocus',
|
|
20253
20255
|
payload: {
|
|
20254
20256
|
shouldFocusOnCVV: true
|
|
@@ -20333,9 +20335,9 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
|
|
|
20333
20335
|
}
|
|
20334
20336
|
};
|
|
20335
20337
|
const handleOTPSubmit = async otp => {
|
|
20336
|
-
var
|
|
20338
|
+
var _iframeRef$current11, _payment$subType3;
|
|
20337
20339
|
setSendOTPLoading(true);
|
|
20338
|
-
(
|
|
20340
|
+
(_iframeRef$current11 = iframeRef.current) == null || (_iframeRef$current11 = _iframeRef$current11.contentWindow) == null || _iframeRef$current11.postMessage({
|
|
20339
20341
|
type: 'otpData',
|
|
20340
20342
|
payload: {
|
|
20341
20343
|
paymentToken: payment.token,
|
|
@@ -20453,7 +20455,7 @@ const CardElement = /*#__PURE__*/(0,react.forwardRef)(({
|
|
|
20453
20455
|
}), /*#__PURE__*/(0,jsx_runtime.jsx)(dist_Skeleton, {
|
|
20454
20456
|
height: 37
|
|
20455
20457
|
})]
|
|
20456
|
-
}), /*#__PURE__*/(0,jsx_runtime.jsx)(dist_Skeleton, {
|
|
20458
|
+
}), !hideCardHolderName && /*#__PURE__*/(0,jsx_runtime.jsx)(dist_Skeleton, {
|
|
20457
20459
|
height: 37
|
|
20458
20460
|
})]
|
|
20459
20461
|
}), /*#__PURE__*/(0,jsx_runtime.jsx)("iframe", {
|
|
@@ -31679,7 +31681,8 @@ class Pixel {
|
|
|
31679
31681
|
});
|
|
31680
31682
|
this._baseURL = this.updateAPIBaseURL();
|
|
31681
31683
|
this._paymentsRef = /*#__PURE__*/react.createRef();
|
|
31682
|
-
Pixel.
|
|
31684
|
+
Pixel._instances[options.elementId] = this;
|
|
31685
|
+
Pixel._lastInstanceId = options.elementId;
|
|
31683
31686
|
if (this._options['clientSecret'] && this._options['paymentMethods']) {
|
|
31684
31687
|
this._integrationType = 'directPayment';
|
|
31685
31688
|
this.getData();
|
|
@@ -31758,19 +31761,31 @@ class Pixel {
|
|
|
31758
31761
|
this._options.cardValidationChanged(isValid);
|
|
31759
31762
|
}
|
|
31760
31763
|
}
|
|
31761
|
-
static
|
|
31762
|
-
|
|
31763
|
-
|
|
31764
|
+
static getInstance(instanceId, callingMethodName) {
|
|
31765
|
+
if (Object.keys(this._instances).length > 1 && !instanceId) {
|
|
31766
|
+
throw new Error(`Multiple Pixel instances detected. Please provide an instance ID for the ${callingMethodName || 'requested'} method.`);
|
|
31767
|
+
}
|
|
31768
|
+
const targetId = instanceId || this._lastInstanceId;
|
|
31769
|
+
if (!targetId || !this._instances[targetId]) {
|
|
31770
|
+
throw new Error('Invalid ID or Pixel not initialized');
|
|
31771
|
+
}
|
|
31772
|
+
return this._instances[targetId];
|
|
31773
|
+
}
|
|
31774
|
+
static async updateIntentionData(instanceId) {
|
|
31775
|
+
var _instance$_paymentsRe;
|
|
31776
|
+
const instance = this.getInstance(instanceId, 'updateIntentionData');
|
|
31777
|
+
if (!((_instance$_paymentsRe = instance._paymentsRef) != null && (_instance$_paymentsRe = _instance$_paymentsRe.current) != null && _instance$_paymentsRe.getData)) {
|
|
31764
31778
|
throw new Error('Pixel not initialized');
|
|
31765
31779
|
}
|
|
31766
|
-
return await
|
|
31780
|
+
return await instance._paymentsRef.current.getData();
|
|
31767
31781
|
}
|
|
31768
|
-
static async submit() {
|
|
31769
|
-
var
|
|
31770
|
-
|
|
31782
|
+
static async submit(instanceId) {
|
|
31783
|
+
var _instance$_paymentsRe2;
|
|
31784
|
+
const instance = this.getInstance(instanceId, 'submit');
|
|
31785
|
+
if (!((_instance$_paymentsRe2 = instance._paymentsRef) != null && (_instance$_paymentsRe2 = _instance$_paymentsRe2.current) != null && _instance$_paymentsRe2.handleGenerateToken)) {
|
|
31771
31786
|
throw new Error('Pixel not initialized');
|
|
31772
31787
|
}
|
|
31773
|
-
return await
|
|
31788
|
+
return await instance._paymentsRef.current.handleGenerateToken();
|
|
31774
31789
|
}
|
|
31775
31790
|
render() {
|
|
31776
31791
|
const container = document.getElementById(this._options['elementId']);
|
|
@@ -31818,7 +31833,8 @@ class Pixel {
|
|
|
31818
31833
|
}
|
|
31819
31834
|
}
|
|
31820
31835
|
_Pixel = Pixel;
|
|
31821
|
-
Pixel.
|
|
31836
|
+
Pixel._instances = {};
|
|
31837
|
+
Pixel._lastInstanceId = null;
|
|
31822
31838
|
window.Pixel = Pixel;
|
|
31823
31839
|
/* harmony default export */ const pixel = ((/* unused pure expression or super */ null && (Pixel)));
|
|
31824
31840
|
;// CONCATENATED MODULE: ./src/index.ts
|