paymob-pixel-alpha 1.1.0 → 1.1.1
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 +52 -14
- package/main.js +93 -130
- package/package.json +2 -1
- package/styles.css +4 -0
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
|
|
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
|
|
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
|
-
##
|
|
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
|
|
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://
|
|
84
|
-
<link rel="stylesheet" href="https://
|
|
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://
|
|
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
|
-
|
|
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
|
@@ -19888,9 +19888,7 @@ function CardElement({
|
|
|
19888
19888
|
onCardValidationChanged,
|
|
19889
19889
|
showPaymobLogo,
|
|
19890
19890
|
hideCardHolderName,
|
|
19891
|
-
isLoading
|
|
19892
|
-
onProcessingPayment,
|
|
19893
|
-
isProcessingPayment
|
|
19891
|
+
isLoading
|
|
19894
19892
|
}) {
|
|
19895
19893
|
var _customStyle$containe;
|
|
19896
19894
|
const {
|
|
@@ -19924,7 +19922,6 @@ function CardElement({
|
|
|
19924
19922
|
const [showOTP, setShowOTP] = (0,react.useState)(false);
|
|
19925
19923
|
const [sendOTPLoading, setSendOTPLoading] = (0,react.useState)(false);
|
|
19926
19924
|
const previousValidationRef = (0,react.useRef)(false);
|
|
19927
|
-
const [startCardPay, setStartCardPay] = (0,react.useState)(false);
|
|
19928
19925
|
const isCardValid = hideCardHolderName ? !isActionBtnDisabled : !(isActionBtnDisabled || !cardHolderName);
|
|
19929
19926
|
const isAmexCardSelected = (selectedCard == null ? void 0 : selectedCard.type) === constants_CARD_TYPES.AMEX;
|
|
19930
19927
|
const selectedCardCvvLength = selectedCardCVV.length;
|
|
@@ -20053,39 +20050,21 @@ function CardElement({
|
|
|
20053
20050
|
return;
|
|
20054
20051
|
}
|
|
20055
20052
|
}
|
|
20056
|
-
|
|
20057
|
-
onProcessingPayment(true);
|
|
20053
|
+
sendCardData(true);
|
|
20058
20054
|
setShouldSubmitData(false);
|
|
20059
20055
|
};
|
|
20060
20056
|
handlePay();
|
|
20061
20057
|
}
|
|
20062
20058
|
}, [cardHolderName, saveCard, shouldSubmitData, iframe]);
|
|
20063
20059
|
(0,react.useEffect)(() => {
|
|
20064
|
-
if (isIframeLoaded
|
|
20065
|
-
|
|
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);
|
|
20060
|
+
if (isIframeLoaded) {
|
|
20061
|
+
sendCardData();
|
|
20083
20062
|
}
|
|
20084
|
-
}, [isIframeLoaded, payment
|
|
20063
|
+
}, [isIframeLoaded, payment]);
|
|
20085
20064
|
(0,react.useEffect)(() => {
|
|
20086
20065
|
if (isIframeLoaded) {
|
|
20087
|
-
var _iframe$
|
|
20088
|
-
(_iframe$
|
|
20066
|
+
var _iframe$contentWindow;
|
|
20067
|
+
(_iframe$contentWindow = iframe.contentWindow) == null || _iframe$contentWindow.postMessage({
|
|
20089
20068
|
type: 'customStyles',
|
|
20090
20069
|
payload: {
|
|
20091
20070
|
styling: customStyle,
|
|
@@ -20097,8 +20076,8 @@ function CardElement({
|
|
|
20097
20076
|
}
|
|
20098
20077
|
}, [isIframeLoaded, iframeRef.current]);
|
|
20099
20078
|
(0,react.useEffect)(() => {
|
|
20100
|
-
var _iframe$
|
|
20101
|
-
iframe == null || (_iframe$
|
|
20079
|
+
var _iframe$contentWindow2;
|
|
20080
|
+
iframe == null || (_iframe$contentWindow2 = iframe.contentWindow) == null || _iframe$contentWindow2.postMessage({
|
|
20102
20081
|
type: 'cardHolderError',
|
|
20103
20082
|
payload: {
|
|
20104
20083
|
error: errors['name']
|
|
@@ -20116,6 +20095,24 @@ function CardElement({
|
|
|
20116
20095
|
previousValidationRef.current = isCardValid;
|
|
20117
20096
|
}
|
|
20118
20097
|
}, [isCardValid, shouldDisablePayBtn]);
|
|
20098
|
+
const sendCardData = shouldSubmitData => {
|
|
20099
|
+
var _iframe$contentWindow3, _payment$subType, _payment$subType2;
|
|
20100
|
+
(_iframe$contentWindow3 = iframe.contentWindow) == null || _iframe$contentWindow3.postMessage({
|
|
20101
|
+
type: 'cardData',
|
|
20102
|
+
payload: {
|
|
20103
|
+
paymentToken: payment.token,
|
|
20104
|
+
subType: {
|
|
20105
|
+
paymentToken: (_payment$subType = payment.subType) == null ? void 0 : _payment$subType.token,
|
|
20106
|
+
type: (_payment$subType2 = payment.subType) == null ? void 0 : _payment$subType2.type
|
|
20107
|
+
},
|
|
20108
|
+
currency,
|
|
20109
|
+
cardHolderName,
|
|
20110
|
+
saveCard: forceSaveCard || saveCard,
|
|
20111
|
+
tenure,
|
|
20112
|
+
shouldSubmitData: shouldSubmitData
|
|
20113
|
+
}
|
|
20114
|
+
}, '*');
|
|
20115
|
+
};
|
|
20119
20116
|
const handlePayWithoutButton = () => {
|
|
20120
20117
|
setShouldSubmitData(true);
|
|
20121
20118
|
};
|
|
@@ -26890,8 +26887,7 @@ function ApplePay(props) {
|
|
|
26890
26887
|
checkDiscount,
|
|
26891
26888
|
isPixel,
|
|
26892
26889
|
isLoading,
|
|
26893
|
-
paymentName
|
|
26894
|
-
onLayerClick
|
|
26890
|
+
paymentName
|
|
26895
26891
|
} = props;
|
|
26896
26892
|
const [loading, setLoading] = (0,react.useState)(false);
|
|
26897
26893
|
const [discount, setDiscount] = (0,react.useState)({
|
|
@@ -26938,6 +26934,13 @@ function ApplePay(props) {
|
|
|
26938
26934
|
payload.requiredShippingContactFields = ['email', 'phone', 'name'];
|
|
26939
26935
|
}
|
|
26940
26936
|
const session = new window.ApplePaySession(3, payload);
|
|
26937
|
+
if (onBeforePaymentComplete) {
|
|
26938
|
+
const result = await onBeforePaymentComplete(paymentName);
|
|
26939
|
+
if (!result) {
|
|
26940
|
+
setLoading(false);
|
|
26941
|
+
return;
|
|
26942
|
+
}
|
|
26943
|
+
}
|
|
26941
26944
|
session.onvalidatemerchant = async event => {
|
|
26942
26945
|
console.log("start validation request");
|
|
26943
26946
|
console.log(`validationURL: ${event.validationURL}`);
|
|
@@ -27033,7 +27036,7 @@ function ApplePay(props) {
|
|
|
27033
27036
|
session.begin();
|
|
27034
27037
|
};
|
|
27035
27038
|
return /*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
|
|
27036
|
-
className: `w-full ${
|
|
27039
|
+
className: `w-full ${discount.hasDiscount ? `flex flex-col gap-2 !h-auto ${!isPixel ? 'sm:mb-6' : ''}` : ''}`,
|
|
27037
27040
|
children: [/*#__PURE__*/(0,jsx_runtime.jsx)(Button_Button, {
|
|
27038
27041
|
id: "apple-pay-button",
|
|
27039
27042
|
icon: apple_pay_namespaceObject,
|
|
@@ -27043,9 +27046,6 @@ function ApplePay(props) {
|
|
|
27043
27046
|
customStyle: customStyle,
|
|
27044
27047
|
disabled: loading || isLoading,
|
|
27045
27048
|
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
27049
|
}), discount.hasDiscount && /*#__PURE__*/(0,jsx_runtime.jsx)("p", {
|
|
27050
27050
|
className: "flex text-center flex-col justify-center text-green-400 text-sm font-medium leading-6 tracking-[0.01rem]",
|
|
27051
27051
|
children: discount.discountMessage
|
|
@@ -27239,9 +27239,7 @@ function GooglePayElement({
|
|
|
27239
27239
|
onBeforePaymentComplete,
|
|
27240
27240
|
onAfterPaymentComplete,
|
|
27241
27241
|
onErrorMessage,
|
|
27242
|
-
isLoading
|
|
27243
|
-
onProcessingPayment,
|
|
27244
|
-
isProcessingPayment
|
|
27242
|
+
isLoading
|
|
27245
27243
|
}) {
|
|
27246
27244
|
var _String;
|
|
27247
27245
|
const {
|
|
@@ -27250,20 +27248,14 @@ function GooglePayElement({
|
|
|
27250
27248
|
keyPrefix: 'googlePay'
|
|
27251
27249
|
});
|
|
27252
27250
|
const [loading, setLoading] = (0,react.useState)(false);
|
|
27253
|
-
const [startGooglePay, setStartGooglePay] = (0,react.useState)(false);
|
|
27254
27251
|
const {
|
|
27255
27252
|
amount,
|
|
27256
27253
|
currency
|
|
27257
27254
|
} = payment;
|
|
27258
27255
|
const googlePay = payment;
|
|
27259
27256
|
const integrationId = googlePay == null ? void 0 : googlePay.integrationId;
|
|
27260
|
-
(
|
|
27261
|
-
|
|
27262
|
-
const googlePayButton = document.getElementById('gpay-button-online-api-id');
|
|
27263
|
-
googlePayButton == null || googlePayButton.click();
|
|
27264
|
-
}
|
|
27265
|
-
}, [startGooglePay, isProcessingPayment]);
|
|
27266
|
-
const handleLayerClick = async () => {
|
|
27257
|
+
const handleSubmit = async (paymentToken, googlePayload) => {
|
|
27258
|
+
var _res$data;
|
|
27267
27259
|
setLoading(true);
|
|
27268
27260
|
if (onBeforePaymentComplete) {
|
|
27269
27261
|
const result = await onBeforePaymentComplete(payment.name);
|
|
@@ -27272,11 +27264,6 @@ function GooglePayElement({
|
|
|
27272
27264
|
return;
|
|
27273
27265
|
}
|
|
27274
27266
|
}
|
|
27275
|
-
setStartGooglePay(true);
|
|
27276
|
-
onProcessingPayment(true);
|
|
27277
|
-
};
|
|
27278
|
-
const handleSubmit = async (paymentToken, googlePayload) => {
|
|
27279
|
-
var _res$data;
|
|
27280
27267
|
const res = await payWithGooglePay(paymentToken, integrationId, googlePayload);
|
|
27281
27268
|
setLoading(false);
|
|
27282
27269
|
const redirectionUrl = (_res$data = res.data) == null ? void 0 : _res$data.redirection_url;
|
|
@@ -27322,23 +27309,17 @@ function GooglePayElement({
|
|
|
27322
27309
|
}
|
|
27323
27310
|
};
|
|
27324
27311
|
return /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, {
|
|
27325
|
-
children: [/*#__PURE__*/(0,jsx_runtime.
|
|
27326
|
-
|
|
27327
|
-
|
|
27328
|
-
|
|
27329
|
-
|
|
27330
|
-
|
|
27331
|
-
|
|
27332
|
-
|
|
27333
|
-
|
|
27334
|
-
|
|
27335
|
-
|
|
27336
|
-
customStyle: customStyle,
|
|
27337
|
-
isLoading: isLoading
|
|
27338
|
-
}), /*#__PURE__*/(0,jsx_runtime.jsx)("button", {
|
|
27339
|
-
onClick: handleLayerClick,
|
|
27340
|
-
className: "absolute inset-0 cursor-pointer"
|
|
27341
|
-
})]
|
|
27312
|
+
children: [/*#__PURE__*/(0,jsx_runtime.jsx)(GooglePay, {
|
|
27313
|
+
onSubmit: handleSubmit,
|
|
27314
|
+
paymentToken: (googlePay == null ? void 0 : googlePay.token) || '',
|
|
27315
|
+
paymentGateway: (googlePay == null ? void 0 : googlePay.gateway) || '',
|
|
27316
|
+
isLiveIntegration: googlePay == null ? void 0 : googlePay.live,
|
|
27317
|
+
merchantIdentifier: googlePay == null ? void 0 : googlePay.merchantIdentifier,
|
|
27318
|
+
amount: (_String = String(amount)) == null ? void 0 : _String.replace(/,/g, ''),
|
|
27319
|
+
currency: currency,
|
|
27320
|
+
countryCode: currency == null ? void 0 : currency.slice(0, 2),
|
|
27321
|
+
customStyle: customStyle,
|
|
27322
|
+
isLoading: isLoading
|
|
27342
27323
|
}), /*#__PURE__*/(0,jsx_runtime.jsx)(LoadingModal, {
|
|
27343
27324
|
show: loading,
|
|
27344
27325
|
text: t('LOADING_MSG')
|
|
@@ -27374,43 +27355,21 @@ const checkDiscount = paymentToken => {
|
|
|
27374
27355
|
|
|
27375
27356
|
|
|
27376
27357
|
|
|
27377
|
-
|
|
27378
27358
|
function ApplePayElements({
|
|
27379
27359
|
payment,
|
|
27380
27360
|
customStyle,
|
|
27381
27361
|
onBeforePaymentComplete,
|
|
27382
27362
|
onAfterPaymentComplete,
|
|
27383
27363
|
onPaymentCancel,
|
|
27384
|
-
isLoading
|
|
27385
|
-
onProcessingPayment,
|
|
27386
|
-
isProcessingPayment
|
|
27364
|
+
isLoading
|
|
27387
27365
|
}) {
|
|
27388
27366
|
var _amount$toString;
|
|
27389
|
-
const [startApplePay, setStartApplePay] = (0,react.useState)(false);
|
|
27390
27367
|
const {
|
|
27391
27368
|
amount,
|
|
27392
27369
|
currency,
|
|
27393
27370
|
merchantName
|
|
27394
27371
|
} = payment;
|
|
27395
27372
|
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
27373
|
const handleSubmit = (status, resData) => {
|
|
27415
27374
|
window.location.href = resData.redirection_url;
|
|
27416
27375
|
};
|
|
@@ -27431,8 +27390,7 @@ function ApplePayElements({
|
|
|
27431
27390
|
checkDiscount: checkDiscount,
|
|
27432
27391
|
isPixel: true,
|
|
27433
27392
|
isLoading: isLoading,
|
|
27434
|
-
paymentName: payment.name
|
|
27435
|
-
onLayerClick: handleLayerClick
|
|
27393
|
+
paymentName: payment.name
|
|
27436
27394
|
});
|
|
27437
27395
|
}
|
|
27438
27396
|
/* harmony default export */ const Payments_ApplePay = (ApplePayElements);
|
|
@@ -27514,7 +27472,7 @@ async function fetchPayments(publicKey, clientSecret, paymentMethods) {
|
|
|
27514
27472
|
|
|
27515
27473
|
|
|
27516
27474
|
|
|
27517
|
-
|
|
27475
|
+
const PaymentsList = /*#__PURE__*/(0,react.forwardRef)((props, ref) => {
|
|
27518
27476
|
var _customStyle$containe;
|
|
27519
27477
|
const {
|
|
27520
27478
|
payments,
|
|
@@ -27543,28 +27501,24 @@ function PaymentsList(props) {
|
|
|
27543
27501
|
const [savedCardsList, setSavedCardsList] = (0,react.useState)(savedCards);
|
|
27544
27502
|
const [errorMessage, setErrorMessage] = (0,react.useState)('');
|
|
27545
27503
|
const [isLoading, setIsLoading] = (0,react.useState)(false);
|
|
27546
|
-
|
|
27547
|
-
|
|
27548
|
-
|
|
27549
|
-
|
|
27550
|
-
|
|
27551
|
-
|
|
27552
|
-
|
|
27553
|
-
|
|
27554
|
-
|
|
27555
|
-
|
|
27556
|
-
|
|
27557
|
-
|
|
27558
|
-
|
|
27559
|
-
|
|
27560
|
-
setIsLoading(false);
|
|
27561
|
-
if (res.status === 200) {
|
|
27562
|
-
setPaymentList(paymentList);
|
|
27563
|
-
setSavedCardsList(savedCards);
|
|
27504
|
+
(0,react.useImperativeHandle)(ref, () => ({
|
|
27505
|
+
getData: async () => {
|
|
27506
|
+
setIsLoading(true);
|
|
27507
|
+
const {
|
|
27508
|
+
res,
|
|
27509
|
+
paymentList,
|
|
27510
|
+
savedCards
|
|
27511
|
+
} = await fetchPayments(publicKey, clientSecret, selectedPaymentMethods);
|
|
27512
|
+
setIsLoading(false);
|
|
27513
|
+
if (res.status === 200) {
|
|
27514
|
+
setPaymentList(paymentList);
|
|
27515
|
+
setSavedCardsList(savedCards);
|
|
27516
|
+
}
|
|
27517
|
+
return res;
|
|
27564
27518
|
}
|
|
27565
|
-
};
|
|
27519
|
+
}));
|
|
27566
27520
|
const handleOnBeforePaymentComplete = async paymentMethod => {
|
|
27567
|
-
return await onBeforePaymentComplete(paymentMethod
|
|
27521
|
+
return await onBeforePaymentComplete(paymentMethod);
|
|
27568
27522
|
};
|
|
27569
27523
|
const hasOnlyXPays = () => {
|
|
27570
27524
|
const xPays = ['apple-pay', 'google-pay'];
|
|
@@ -27614,18 +27568,14 @@ function PaymentsList(props) {
|
|
|
27614
27568
|
onAfterPaymentComplete: onAfterPaymentComplete,
|
|
27615
27569
|
onPaymentCancel: onPaymentCancel,
|
|
27616
27570
|
customStyle: customStyle == null ? void 0 : customStyle.button,
|
|
27617
|
-
isLoading: isLoading
|
|
27618
|
-
onProcessingPayment: setIsProcessingPayment,
|
|
27619
|
-
isProcessingPayment: isProcessingPayment
|
|
27571
|
+
isLoading: isLoading
|
|
27620
27572
|
}), isGooglePay() && /*#__PURE__*/(0,jsx_runtime.jsx)(GooglePayElement, {
|
|
27621
27573
|
payment: googlePaymentMethod,
|
|
27622
27574
|
customStyle: customStyle == null ? void 0 : customStyle.button,
|
|
27623
27575
|
onBeforePaymentComplete: onBeforePaymentComplete && handleOnBeforePaymentComplete,
|
|
27624
27576
|
onAfterPaymentComplete: onAfterPaymentComplete,
|
|
27625
27577
|
onErrorMessage: setErrorMessage,
|
|
27626
|
-
isLoading: isLoading
|
|
27627
|
-
onProcessingPayment: setIsProcessingPayment,
|
|
27628
|
-
isProcessingPayment: isProcessingPayment
|
|
27578
|
+
isLoading: isLoading
|
|
27629
27579
|
})]
|
|
27630
27580
|
})
|
|
27631
27581
|
}), paymentList.length === 0 ? /*#__PURE__*/(0,jsx_runtime.jsx)("div", {
|
|
@@ -27664,13 +27614,11 @@ function PaymentsList(props) {
|
|
|
27664
27614
|
showPaymobLogo,
|
|
27665
27615
|
hideCardHolderName,
|
|
27666
27616
|
isLoading,
|
|
27667
|
-
onProcessingPayment: setIsProcessingPayment,
|
|
27668
|
-
isProcessingPayment,
|
|
27669
27617
|
isList: true
|
|
27670
27618
|
})
|
|
27671
27619
|
})]
|
|
27672
27620
|
});
|
|
27673
|
-
}
|
|
27621
|
+
});
|
|
27674
27622
|
/* harmony default export */ const List = (PaymentsList);
|
|
27675
27623
|
;// CONCATENATED MODULE: ./src/utils/getStyles.ts
|
|
27676
27624
|
function getStyles(customStyle) {
|
|
@@ -27805,7 +27753,7 @@ function getStyles(customStyle) {
|
|
|
27805
27753
|
|
|
27806
27754
|
|
|
27807
27755
|
|
|
27808
|
-
|
|
27756
|
+
const Payments_Payments = /*#__PURE__*/(0,react.forwardRef)((props, ref) => {
|
|
27809
27757
|
const {
|
|
27810
27758
|
payment,
|
|
27811
27759
|
customStyle,
|
|
@@ -27941,13 +27889,14 @@ function Payments_Payments(props) {
|
|
|
27941
27889
|
hideCardHolderName: hideCardHolderName,
|
|
27942
27890
|
publicKey: publicKey,
|
|
27943
27891
|
clientSecret: clientSecret,
|
|
27944
|
-
selectedPaymentMethods: selectedPaymentMethods
|
|
27892
|
+
selectedPaymentMethods: selectedPaymentMethods,
|
|
27893
|
+
ref: ref
|
|
27945
27894
|
});
|
|
27946
27895
|
};
|
|
27947
27896
|
return /*#__PURE__*/(0,jsx_runtime.jsx)(jsx_runtime.Fragment, {
|
|
27948
27897
|
children: render()
|
|
27949
27898
|
});
|
|
27950
|
-
}
|
|
27899
|
+
});
|
|
27951
27900
|
/* harmony default export */ const components_Payments = (Payments_Payments);
|
|
27952
27901
|
;// CONCATENATED MODULE: ./src/utils/apiUrl.ts
|
|
27953
27902
|
|
|
@@ -31494,6 +31443,7 @@ i18next.use(initReactI18next).init({
|
|
|
31494
31443
|
});
|
|
31495
31444
|
/* harmony default export */ const localization_i18n = ((/* unused pure expression or super */ null && (i18n)));
|
|
31496
31445
|
;// CONCATENATED MODULE: ./src/lib/pixel.tsx
|
|
31446
|
+
var _Pixel;
|
|
31497
31447
|
|
|
31498
31448
|
|
|
31499
31449
|
|
|
@@ -31514,10 +31464,13 @@ class Pixel {
|
|
|
31514
31464
|
this._showSaveCard = void 0;
|
|
31515
31465
|
this._root = null;
|
|
31516
31466
|
this._error = null;
|
|
31467
|
+
this._paymentsRef = null;
|
|
31517
31468
|
this._options = Object.assign({}, options, {
|
|
31518
31469
|
showPaymobLogo: (_options$showPaymobLo = options.showPaymobLogo) != null ? _options$showPaymobLo : true
|
|
31519
31470
|
});
|
|
31520
31471
|
this._baseURL = this.updateAPIBaseURL();
|
|
31472
|
+
this._paymentsRef = /*#__PURE__*/react.createRef();
|
|
31473
|
+
Pixel._instance = this;
|
|
31521
31474
|
this.getData();
|
|
31522
31475
|
}
|
|
31523
31476
|
updateAPIBaseURL() {
|
|
@@ -31559,9 +31512,9 @@ class Pixel {
|
|
|
31559
31512
|
this.render();
|
|
31560
31513
|
}
|
|
31561
31514
|
}
|
|
31562
|
-
async handleBeforePaymentComplete(paymentMethod
|
|
31515
|
+
async handleBeforePaymentComplete(paymentMethod) {
|
|
31563
31516
|
if (this._options.beforePaymentComplete) {
|
|
31564
|
-
const result = await this._options.beforePaymentComplete(paymentMethod
|
|
31517
|
+
const result = await this._options.beforePaymentComplete(paymentMethod);
|
|
31565
31518
|
if (result === false) return false;
|
|
31566
31519
|
return true;
|
|
31567
31520
|
}
|
|
@@ -31581,6 +31534,13 @@ class Pixel {
|
|
|
31581
31534
|
this._options.cardValidationChanged(isValid);
|
|
31582
31535
|
}
|
|
31583
31536
|
}
|
|
31537
|
+
static async updateIntentionData() {
|
|
31538
|
+
var _Pixel$_instance;
|
|
31539
|
+
if (!((_Pixel$_instance = Pixel._instance) != null && (_Pixel$_instance = _Pixel$_instance._paymentsRef) != null && (_Pixel$_instance = _Pixel$_instance.current) != null && _Pixel$_instance.getData)) {
|
|
31540
|
+
throw new Error('Pixel not initialized');
|
|
31541
|
+
}
|
|
31542
|
+
return await Pixel._instance._paymentsRef.current.getData();
|
|
31543
|
+
}
|
|
31584
31544
|
render() {
|
|
31585
31545
|
const container = document.getElementById(this._options['elementId']);
|
|
31586
31546
|
if (!container) {
|
|
@@ -31610,7 +31570,8 @@ class Pixel {
|
|
|
31610
31570
|
hideCardHolderName: this._options['hideCardHolderName'],
|
|
31611
31571
|
publicKey: this._options['publicKey'],
|
|
31612
31572
|
clientSecret: this._options['clientSecret'],
|
|
31613
|
-
selectedPaymentMethods: this._options['paymentMethods']
|
|
31573
|
+
selectedPaymentMethods: this._options['paymentMethods'],
|
|
31574
|
+
ref: this._paymentsRef
|
|
31614
31575
|
}, this._options.beforePaymentComplete && {
|
|
31615
31576
|
onBeforePaymentComplete: this.handleBeforePaymentComplete.bind(this)
|
|
31616
31577
|
}, this._options.afterPaymentComplete && {
|
|
@@ -31623,6 +31584,8 @@ class Pixel {
|
|
|
31623
31584
|
}));
|
|
31624
31585
|
}
|
|
31625
31586
|
}
|
|
31587
|
+
_Pixel = Pixel;
|
|
31588
|
+
Pixel._instance = null;
|
|
31626
31589
|
window.Pixel = Pixel;
|
|
31627
31590
|
/* harmony default export */ const pixel = ((/* unused pure expression or super */ null && (Pixel)));
|
|
31628
31591
|
;// 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.
|
|
3
|
+
"version": "1.1.1",
|
|
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": {
|