strapi-plugin-payone-provider 4.6.10 → 4.6.11
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 +64 -0
- package/admin/src/pages/App/components/AppHeader.jsx +3 -2
- package/admin/src/pages/App/components/AppTabs.jsx +34 -88
- package/admin/src/pages/App/components/DocsPanel.jsx +1726 -1726
- package/admin/src/pages/App/components/GooglePaybutton.jsx +300 -300
- package/admin/src/pages/App/components/StatusBadge.jsx +1 -1
- package/admin/src/pages/App/components/common/InfoTooltip.jsx +16 -0
- package/admin/src/pages/App/components/{ApplePayConfig.jsx → configuration/ApplePayConfig.jsx} +191 -62
- package/admin/src/pages/App/components/{ApplePayConfigPanel.jsx → configuration/ApplePayConfigPanel.jsx} +71 -70
- package/admin/src/pages/App/components/configuration/ConfigurationFields.jsx +408 -0
- package/admin/src/pages/App/components/configuration/ConfigurationPanel.jsx +67 -0
- package/admin/src/pages/App/components/{GooglePayConfig.jsx → configuration/GooglePayConfig.jsx} +254 -254
- package/admin/src/pages/App/components/{GooglePayConfigPanel.jsx → configuration/GooglePayConfigPanel.jsx} +82 -82
- package/admin/src/pages/App/components/configuration/TestConnection.jsx +129 -0
- package/admin/src/pages/App/components/paymentActions/ApplePayPanel.jsx +137 -95
- package/admin/src/pages/App/components/paymentActions/CaptureForm.jsx +119 -14
- package/admin/src/pages/App/components/paymentActions/CardDetailsInput.jsx +85 -24
- package/admin/src/pages/App/components/paymentActions/PaymentActionsPanel.jsx +361 -0
- package/admin/src/pages/App/components/paymentActions/PaymentMethodSelector.jsx +22 -4
- package/admin/src/pages/App/components/paymentActions/RefundForm.jsx +91 -20
- package/admin/src/pages/App/components/paymentActions/authorization/AuthorizationForm.jsx +157 -0
- package/admin/src/pages/App/components/paymentActions/authorization/AuthorizationFormFields.jsx +308 -0
- package/admin/src/pages/App/components/paymentActions/authorization/AuthorizationFormHeader.jsx +27 -0
- package/admin/src/pages/App/components/paymentActions/authorization/AuthorizationPaymentButtons.jsx +93 -0
- package/admin/src/pages/App/components/paymentActions/preauthorization/PreauthorizationForm.jsx +134 -0
- package/admin/src/pages/App/components/paymentActions/preauthorization/PreauthorizationFormFields.jsx +295 -0
- package/admin/src/pages/App/components/paymentActions/preauthorization/PreauthorizationFormHeader.jsx +27 -0
- package/admin/src/pages/App/components/paymentActions/preauthorization/PreauthorizationPaymentButtons.jsx +53 -0
- package/admin/src/pages/App/components/transaction-history/FiltersPanel.jsx +182 -0
- package/admin/src/pages/App/components/transaction-history/HistoryPanel.jsx +49 -0
- package/admin/src/pages/App/components/transaction-history/TransactionTable.jsx +169 -0
- package/admin/src/pages/App/components/transaction-history/TransactionTablePagination.jsx +28 -0
- package/admin/src/pages/App/components/transaction-history/details/TransactionDetails.jsx +155 -0
- package/admin/src/pages/App/index.jsx +5 -29
- package/admin/src/pages/hooks/usePaymentActions.js +87 -11
- package/admin/src/pages/hooks/useSettings.js +64 -22
- package/admin/src/pages/hooks/useTransactionHistory.js +100 -88
- package/admin/src/pages/utils/api.js +31 -3
- package/admin/src/pages/utils/countryLanguageUtils.js +236 -0
- package/admin/src/pages/utils/transactionTableUtils.js +60 -0
- package/package.json +1 -1
- package/server/bootstrap.js +6 -6
- package/server/controllers/payone.js +27 -3
- package/server/policies/index.js +2 -1
- package/server/policies/is-payone-notification.js +31 -0
- package/server/routes/index.js +10 -0
- package/server/services/payone.js +11 -4
- package/server/services/settingsService.js +8 -2
- package/server/services/testConnectionService.js +11 -72
- package/server/services/transactionService.js +58 -78
- package/server/services/transactionStatusService.js +87 -0
- package/admin/src/pages/App/components/ConfigurationPanel.jsx +0 -517
- package/admin/src/pages/App/components/CustomerInfoPopover.jsx +0 -147
- package/admin/src/pages/App/components/HistoryPanel.jsx +0 -94
- package/admin/src/pages/App/components/PaymentActionsPanel.jsx +0 -280
- package/admin/src/pages/App/components/RawDataPopover.jsx +0 -113
- package/admin/src/pages/App/components/TransactionHistoryItem.jsx +0 -522
- package/admin/src/pages/App/components/TransactionHistoryTable/TransactionHistoryTableFilters.jsx +0 -113
- package/admin/src/pages/App/components/TransactionHistoryTable/TransactionHistoryTablePagination.jsx +0 -180
- package/admin/src/pages/App/components/TransactionHistoryTable/index.jsx +0 -225
- package/admin/src/pages/App/components/paymentActions/AuthorizationForm.jsx +0 -197
- package/admin/src/pages/App/components/paymentActions/PreauthorizationForm.jsx +0 -142
|
@@ -1,300 +1,300 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from "react";
|
|
2
|
-
import { Box, Flex, Typography } from "@strapi/design-system";
|
|
3
|
-
import { injectGooglePayScript } from "../../utils/injectGooglePayScript";
|
|
4
|
-
|
|
5
|
-
const GooglePayButton = ({
|
|
6
|
-
amount,
|
|
7
|
-
currency = "EUR",
|
|
8
|
-
onTokenReceived,
|
|
9
|
-
onError,
|
|
10
|
-
settings
|
|
11
|
-
}) => {
|
|
12
|
-
const [isReady, setIsReady] = useState(false);
|
|
13
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
14
|
-
const buttonContainerRef = useRef(null);
|
|
15
|
-
const paymentsClientRef = useRef(null);
|
|
16
|
-
|
|
17
|
-
const baseRequest = {
|
|
18
|
-
apiVersion: 2,
|
|
19
|
-
apiVersionMinor: 0
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const getGooglePayConfig = (settings) => {
|
|
23
|
-
const gatewayMerchantId = settings?.mid || settings?.portalid || '';
|
|
24
|
-
|
|
25
|
-
const allowedCardNetworks = ["MASTERCARD", "VISA"];
|
|
26
|
-
const allowedAuthMethods = ["PAN_ONLY", "CRYPTOGRAM_3DS"];
|
|
27
|
-
|
|
28
|
-
const tokenizationSpecification = {
|
|
29
|
-
type: 'PAYMENT_GATEWAY',
|
|
30
|
-
parameters: {
|
|
31
|
-
'gateway': 'payonegmbh',
|
|
32
|
-
'gatewayMerchantId': gatewayMerchantId
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const baseCardPaymentMethod = {
|
|
37
|
-
type: "CARD",
|
|
38
|
-
parameters: {
|
|
39
|
-
allowedCardNetworks,
|
|
40
|
-
allowedAuthMethods
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const cardPaymentMethod = {
|
|
45
|
-
...baseCardPaymentMethod,
|
|
46
|
-
tokenizationSpecification
|
|
47
|
-
};
|
|
48
|
-
return {
|
|
49
|
-
baseCardPaymentMethod,
|
|
50
|
-
cardPaymentMethod,
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
injectGooglePayScript();
|
|
56
|
-
|
|
57
|
-
const checkGooglePay = () => {
|
|
58
|
-
try {
|
|
59
|
-
return typeof window !== 'undefined' &&
|
|
60
|
-
typeof window.google !== 'undefined' &&
|
|
61
|
-
window.google.payments?.api?.PaymentsClient;
|
|
62
|
-
} catch (e) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
if (checkGooglePay()) {
|
|
68
|
-
initializeGooglePay();
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const handleScriptLoaded = () => {
|
|
73
|
-
setTimeout(() => {
|
|
74
|
-
if (checkGooglePay()) {
|
|
75
|
-
initializeGooglePay();
|
|
76
|
-
}
|
|
77
|
-
}, 500);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const handleScriptError = () => {
|
|
81
|
-
setIsLoading(false);
|
|
82
|
-
if (onError) {
|
|
83
|
-
onError(new Error("Failed to load Google Pay script. Please check CSP settings."));
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
window.addEventListener("googlePayScriptLoaded", handleScriptLoaded);
|
|
88
|
-
window.addEventListener("googlePayScriptError", handleScriptError);
|
|
89
|
-
|
|
90
|
-
const checkInterval = setInterval(() => {
|
|
91
|
-
if (checkGooglePay()) {
|
|
92
|
-
clearInterval(checkInterval);
|
|
93
|
-
initializeGooglePay();
|
|
94
|
-
}
|
|
95
|
-
}, 200);
|
|
96
|
-
|
|
97
|
-
const timeout = setTimeout(() => {
|
|
98
|
-
clearInterval(checkInterval);
|
|
99
|
-
if (!checkGooglePay()) {
|
|
100
|
-
setIsLoading(false);
|
|
101
|
-
if (onError) {
|
|
102
|
-
onError(new Error("Google Pay API is not available. Please check if the script is loaded and CSP allows pay.google.com"));
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}, 15000);
|
|
106
|
-
|
|
107
|
-
return () => {
|
|
108
|
-
window.removeEventListener("googlePayScriptLoaded", handleScriptLoaded);
|
|
109
|
-
window.removeEventListener("googlePayScriptError", handleScriptError);
|
|
110
|
-
clearInterval(checkInterval);
|
|
111
|
-
clearTimeout(timeout);
|
|
112
|
-
};
|
|
113
|
-
}, [settings, amount, currency]);
|
|
114
|
-
|
|
115
|
-
const initializeGooglePay = () => {
|
|
116
|
-
if (!settings || (!settings.mid && !settings.portalid)) {
|
|
117
|
-
setIsLoading(false);
|
|
118
|
-
if (onError) {
|
|
119
|
-
onError(new Error("Google Pay settings missing. Please configure mid or portalid in settings."));
|
|
120
|
-
}
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
try {
|
|
125
|
-
if (typeof window === 'undefined' || typeof window.google === 'undefined' || !window.google.payments?.api?.PaymentsClient) {
|
|
126
|
-
setIsLoading(false);
|
|
127
|
-
if (onError) {
|
|
128
|
-
onError(new Error("Google Pay API is not loaded. Please check browser console for CSP errors."));
|
|
129
|
-
}
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const environment = settings?.mode === "live" ? "PRODUCTION" : "TEST";
|
|
135
|
-
paymentsClientRef.current = new window.google.payments.api.PaymentsClient({
|
|
136
|
-
environment: environment
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
const config = getGooglePayConfig(settings);
|
|
140
|
-
|
|
141
|
-
const isReadyToPayRequest = Object.assign({}, baseRequest);
|
|
142
|
-
isReadyToPayRequest.allowedPaymentMethods = [config.baseCardPaymentMethod];
|
|
143
|
-
|
|
144
|
-
paymentsClientRef.current.isReadyToPay(isReadyToPayRequest)
|
|
145
|
-
.then((response) => {
|
|
146
|
-
if (response.result) {
|
|
147
|
-
setIsReady(true);
|
|
148
|
-
const tryAddButton = () => {
|
|
149
|
-
if (buttonContainerRef.current) {
|
|
150
|
-
addGooglePayButton(config);
|
|
151
|
-
} else {
|
|
152
|
-
setTimeout(tryAddButton, 100);
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
setTimeout(tryAddButton, 100);
|
|
156
|
-
} else {
|
|
157
|
-
setIsLoading(false);
|
|
158
|
-
if (onError) {
|
|
159
|
-
onError(new Error("Google Pay is not available on this device"));
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
})
|
|
163
|
-
.catch((err) => {
|
|
164
|
-
setIsLoading(false);
|
|
165
|
-
if (onError) {
|
|
166
|
-
onError(err);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
} catch (error) {
|
|
170
|
-
setIsLoading(false);
|
|
171
|
-
if (onError) {
|
|
172
|
-
onError(error);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
const addGooglePayButton = (config) => {
|
|
178
|
-
if (!buttonContainerRef.current) {
|
|
179
|
-
setTimeout(() => {
|
|
180
|
-
if (buttonContainerRef.current) {
|
|
181
|
-
addGooglePayButton(config);
|
|
182
|
-
} else {
|
|
183
|
-
setIsLoading(false);
|
|
184
|
-
}
|
|
185
|
-
}, 500);
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (!paymentsClientRef.current) {
|
|
190
|
-
setIsLoading(false);
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
buttonContainerRef.current.innerHTML = "";
|
|
195
|
-
|
|
196
|
-
const gatewayMerchantId = settings?.mid || settings?.portalid || '';
|
|
197
|
-
const paymentDataRequest = Object.assign({}, baseRequest);
|
|
198
|
-
paymentDataRequest.allowedPaymentMethods = [config.cardPaymentMethod];
|
|
199
|
-
paymentDataRequest.transactionInfo = {
|
|
200
|
-
totalPriceStatus: "FINAL",
|
|
201
|
-
totalPrice: (parseFloat(amount) / 100).toFixed(2),
|
|
202
|
-
currencyCode: currency
|
|
203
|
-
};
|
|
204
|
-
paymentDataRequest.merchantInfo = {
|
|
205
|
-
merchantId: gatewayMerchantId,
|
|
206
|
-
merchantName: settings?.merchantName || 'Demo Shop'
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
try {
|
|
210
|
-
const button = paymentsClientRef.current.createButton({
|
|
211
|
-
onClick: () => handleGooglePayClick(paymentDataRequest),
|
|
212
|
-
buttonColor: "black",
|
|
213
|
-
buttonType: "pay",
|
|
214
|
-
buttonSizeMode: "fill"
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
if (buttonContainerRef.current) {
|
|
218
|
-
buttonContainerRef.current.appendChild(button);
|
|
219
|
-
setIsLoading(false);
|
|
220
|
-
setIsReady(true);
|
|
221
|
-
} else {
|
|
222
|
-
setIsLoading(false);
|
|
223
|
-
}
|
|
224
|
-
} catch (error) {
|
|
225
|
-
setIsLoading(false);
|
|
226
|
-
if (onError) {
|
|
227
|
-
onError(error);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
const handleGooglePayClick = async (paymentDataRequest) => {
|
|
233
|
-
try {
|
|
234
|
-
if (!paymentsClientRef.current) {
|
|
235
|
-
throw new Error("Google Pay client not initialized");
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const paymentData = await paymentsClientRef.current.loadPaymentData(paymentDataRequest);
|
|
239
|
-
const rawToken = paymentData.paymentMethodData?.tokenizationData?.token;
|
|
240
|
-
|
|
241
|
-
if (!rawToken) {
|
|
242
|
-
throw new Error("Google Pay token is missing from payment data");
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
let token = rawToken;
|
|
246
|
-
|
|
247
|
-
try {
|
|
248
|
-
const tokenObj = JSON.parse(token);
|
|
249
|
-
if (!tokenObj.signature || !tokenObj.protocolVersion || !tokenObj.signedMessage) {
|
|
250
|
-
throw new Error("Google Pay token is missing required fields");
|
|
251
|
-
}
|
|
252
|
-
token = btoa(unescape(encodeURIComponent(rawToken)));
|
|
253
|
-
} catch (e) {
|
|
254
|
-
if (typeof token === 'string') {
|
|
255
|
-
token = btoa(unescape(encodeURIComponent(token)));
|
|
256
|
-
} else {
|
|
257
|
-
throw new Error(`Invalid Google Pay token format: ${e.message}`);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
if (onTokenReceived) {
|
|
262
|
-
onTokenReceived(token, paymentData);
|
|
263
|
-
}
|
|
264
|
-
} catch (error) {
|
|
265
|
-
if (onError) {
|
|
266
|
-
onError(error);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
return (
|
|
272
|
-
<Box width="100%">
|
|
273
|
-
<Flex direction="column" gap={3} alignItems="stretch">
|
|
274
|
-
{isLoading && (
|
|
275
|
-
<Typography variant="pi" textColor="neutral600" style={{ textAlign: "left" }}>
|
|
276
|
-
Loading Google Pay...
|
|
277
|
-
</Typography>
|
|
278
|
-
)}
|
|
279
|
-
{!isLoading && !isReady && (
|
|
280
|
-
<Typography variant="pi" textColor="neutral600" style={{ textAlign: "left" }}>
|
|
281
|
-
Google Pay is not available
|
|
282
|
-
</Typography>
|
|
283
|
-
)}
|
|
284
|
-
{!isLoading && isReady && (
|
|
285
|
-
<>
|
|
286
|
-
<Typography variant="sigma" textColor="neutral700" fontWeight="semiBold" style={{ textAlign: "left" }}>
|
|
287
|
-
Google Pay Payment
|
|
288
|
-
</Typography>
|
|
289
|
-
<Typography variant="pi" textColor="neutral600" style={{ textAlign: "left" }}>
|
|
290
|
-
Click the button below to pay with Google Pay. The token will be automatically sent to Payone.
|
|
291
|
-
</Typography>
|
|
292
|
-
</>
|
|
293
|
-
)}
|
|
294
|
-
<Box ref={buttonContainerRef} style={{ minHeight: "40px", width: "100%", maxWidth: "200px", display: "flex", justifyContent: "flex-start", }} />
|
|
295
|
-
</Flex>
|
|
296
|
-
</Box>
|
|
297
|
-
);
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
export default GooglePayButton;
|
|
1
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { Box, Flex, Typography } from "@strapi/design-system";
|
|
3
|
+
import { injectGooglePayScript } from "../../utils/injectGooglePayScript";
|
|
4
|
+
|
|
5
|
+
const GooglePayButton = ({
|
|
6
|
+
amount,
|
|
7
|
+
currency = "EUR",
|
|
8
|
+
onTokenReceived,
|
|
9
|
+
onError,
|
|
10
|
+
settings
|
|
11
|
+
}) => {
|
|
12
|
+
const [isReady, setIsReady] = useState(false);
|
|
13
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
14
|
+
const buttonContainerRef = useRef(null);
|
|
15
|
+
const paymentsClientRef = useRef(null);
|
|
16
|
+
|
|
17
|
+
const baseRequest = {
|
|
18
|
+
apiVersion: 2,
|
|
19
|
+
apiVersionMinor: 0
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const getGooglePayConfig = (settings) => {
|
|
23
|
+
const gatewayMerchantId = settings?.mid || settings?.portalid || '';
|
|
24
|
+
|
|
25
|
+
const allowedCardNetworks = ["MASTERCARD", "VISA"];
|
|
26
|
+
const allowedAuthMethods = ["PAN_ONLY", "CRYPTOGRAM_3DS"];
|
|
27
|
+
|
|
28
|
+
const tokenizationSpecification = {
|
|
29
|
+
type: 'PAYMENT_GATEWAY',
|
|
30
|
+
parameters: {
|
|
31
|
+
'gateway': 'payonegmbh',
|
|
32
|
+
'gatewayMerchantId': gatewayMerchantId
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const baseCardPaymentMethod = {
|
|
37
|
+
type: "CARD",
|
|
38
|
+
parameters: {
|
|
39
|
+
allowedCardNetworks,
|
|
40
|
+
allowedAuthMethods
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const cardPaymentMethod = {
|
|
45
|
+
...baseCardPaymentMethod,
|
|
46
|
+
tokenizationSpecification
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
baseCardPaymentMethod,
|
|
50
|
+
cardPaymentMethod,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
injectGooglePayScript();
|
|
56
|
+
|
|
57
|
+
const checkGooglePay = () => {
|
|
58
|
+
try {
|
|
59
|
+
return typeof window !== 'undefined' &&
|
|
60
|
+
typeof window.google !== 'undefined' &&
|
|
61
|
+
window.google.payments?.api?.PaymentsClient;
|
|
62
|
+
} catch (e) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
if (checkGooglePay()) {
|
|
68
|
+
initializeGooglePay();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const handleScriptLoaded = () => {
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
if (checkGooglePay()) {
|
|
75
|
+
initializeGooglePay();
|
|
76
|
+
}
|
|
77
|
+
}, 500);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const handleScriptError = () => {
|
|
81
|
+
setIsLoading(false);
|
|
82
|
+
if (onError) {
|
|
83
|
+
onError(new Error("Failed to load Google Pay script. Please check CSP settings."));
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
window.addEventListener("googlePayScriptLoaded", handleScriptLoaded);
|
|
88
|
+
window.addEventListener("googlePayScriptError", handleScriptError);
|
|
89
|
+
|
|
90
|
+
const checkInterval = setInterval(() => {
|
|
91
|
+
if (checkGooglePay()) {
|
|
92
|
+
clearInterval(checkInterval);
|
|
93
|
+
initializeGooglePay();
|
|
94
|
+
}
|
|
95
|
+
}, 200);
|
|
96
|
+
|
|
97
|
+
const timeout = setTimeout(() => {
|
|
98
|
+
clearInterval(checkInterval);
|
|
99
|
+
if (!checkGooglePay()) {
|
|
100
|
+
setIsLoading(false);
|
|
101
|
+
if (onError) {
|
|
102
|
+
onError(new Error("Google Pay API is not available. Please check if the script is loaded and CSP allows pay.google.com"));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}, 15000);
|
|
106
|
+
|
|
107
|
+
return () => {
|
|
108
|
+
window.removeEventListener("googlePayScriptLoaded", handleScriptLoaded);
|
|
109
|
+
window.removeEventListener("googlePayScriptError", handleScriptError);
|
|
110
|
+
clearInterval(checkInterval);
|
|
111
|
+
clearTimeout(timeout);
|
|
112
|
+
};
|
|
113
|
+
}, [settings, amount, currency]);
|
|
114
|
+
|
|
115
|
+
const initializeGooglePay = () => {
|
|
116
|
+
if (!settings || (!settings.mid && !settings.portalid)) {
|
|
117
|
+
setIsLoading(false);
|
|
118
|
+
if (onError) {
|
|
119
|
+
onError(new Error("Google Pay settings missing. Please configure mid or portalid in settings."));
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
if (typeof window === 'undefined' || typeof window.google === 'undefined' || !window.google.payments?.api?.PaymentsClient) {
|
|
126
|
+
setIsLoading(false);
|
|
127
|
+
if (onError) {
|
|
128
|
+
onError(new Error("Google Pay API is not loaded. Please check browser console for CSP errors."));
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
const environment = settings?.mode === "live" ? "PRODUCTION" : "TEST";
|
|
135
|
+
paymentsClientRef.current = new window.google.payments.api.PaymentsClient({
|
|
136
|
+
environment: environment
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const config = getGooglePayConfig(settings);
|
|
140
|
+
|
|
141
|
+
const isReadyToPayRequest = Object.assign({}, baseRequest);
|
|
142
|
+
isReadyToPayRequest.allowedPaymentMethods = [config.baseCardPaymentMethod];
|
|
143
|
+
|
|
144
|
+
paymentsClientRef.current.isReadyToPay(isReadyToPayRequest)
|
|
145
|
+
.then((response) => {
|
|
146
|
+
if (response.result) {
|
|
147
|
+
setIsReady(true);
|
|
148
|
+
const tryAddButton = () => {
|
|
149
|
+
if (buttonContainerRef.current) {
|
|
150
|
+
addGooglePayButton(config);
|
|
151
|
+
} else {
|
|
152
|
+
setTimeout(tryAddButton, 100);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
setTimeout(tryAddButton, 100);
|
|
156
|
+
} else {
|
|
157
|
+
setIsLoading(false);
|
|
158
|
+
if (onError) {
|
|
159
|
+
onError(new Error("Google Pay is not available on this device"));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
.catch((err) => {
|
|
164
|
+
setIsLoading(false);
|
|
165
|
+
if (onError) {
|
|
166
|
+
onError(err);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
} catch (error) {
|
|
170
|
+
setIsLoading(false);
|
|
171
|
+
if (onError) {
|
|
172
|
+
onError(error);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const addGooglePayButton = (config) => {
|
|
178
|
+
if (!buttonContainerRef.current) {
|
|
179
|
+
setTimeout(() => {
|
|
180
|
+
if (buttonContainerRef.current) {
|
|
181
|
+
addGooglePayButton(config);
|
|
182
|
+
} else {
|
|
183
|
+
setIsLoading(false);
|
|
184
|
+
}
|
|
185
|
+
}, 500);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (!paymentsClientRef.current) {
|
|
190
|
+
setIsLoading(false);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
buttonContainerRef.current.innerHTML = "";
|
|
195
|
+
|
|
196
|
+
const gatewayMerchantId = settings?.mid || settings?.portalid || '';
|
|
197
|
+
const paymentDataRequest = Object.assign({}, baseRequest);
|
|
198
|
+
paymentDataRequest.allowedPaymentMethods = [config.cardPaymentMethod];
|
|
199
|
+
paymentDataRequest.transactionInfo = {
|
|
200
|
+
totalPriceStatus: "FINAL",
|
|
201
|
+
totalPrice: (parseFloat(amount) / 100).toFixed(2),
|
|
202
|
+
currencyCode: currency
|
|
203
|
+
};
|
|
204
|
+
paymentDataRequest.merchantInfo = {
|
|
205
|
+
merchantId: gatewayMerchantId,
|
|
206
|
+
merchantName: settings?.merchantName || 'Demo Shop'
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
const button = paymentsClientRef.current.createButton({
|
|
211
|
+
onClick: () => handleGooglePayClick(paymentDataRequest),
|
|
212
|
+
buttonColor: "black",
|
|
213
|
+
buttonType: "pay",
|
|
214
|
+
buttonSizeMode: "fill"
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
if (buttonContainerRef.current) {
|
|
218
|
+
buttonContainerRef.current.appendChild(button);
|
|
219
|
+
setIsLoading(false);
|
|
220
|
+
setIsReady(true);
|
|
221
|
+
} else {
|
|
222
|
+
setIsLoading(false);
|
|
223
|
+
}
|
|
224
|
+
} catch (error) {
|
|
225
|
+
setIsLoading(false);
|
|
226
|
+
if (onError) {
|
|
227
|
+
onError(error);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const handleGooglePayClick = async (paymentDataRequest) => {
|
|
233
|
+
try {
|
|
234
|
+
if (!paymentsClientRef.current) {
|
|
235
|
+
throw new Error("Google Pay client not initialized");
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const paymentData = await paymentsClientRef.current.loadPaymentData(paymentDataRequest);
|
|
239
|
+
const rawToken = paymentData.paymentMethodData?.tokenizationData?.token;
|
|
240
|
+
|
|
241
|
+
if (!rawToken) {
|
|
242
|
+
throw new Error("Google Pay token is missing from payment data");
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
let token = rawToken;
|
|
246
|
+
|
|
247
|
+
try {
|
|
248
|
+
const tokenObj = JSON.parse(token);
|
|
249
|
+
if (!tokenObj.signature || !tokenObj.protocolVersion || !tokenObj.signedMessage) {
|
|
250
|
+
throw new Error("Google Pay token is missing required fields");
|
|
251
|
+
}
|
|
252
|
+
token = btoa(unescape(encodeURIComponent(rawToken)));
|
|
253
|
+
} catch (e) {
|
|
254
|
+
if (typeof token === 'string') {
|
|
255
|
+
token = btoa(unescape(encodeURIComponent(token)));
|
|
256
|
+
} else {
|
|
257
|
+
throw new Error(`Invalid Google Pay token format: ${e.message}`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (onTokenReceived) {
|
|
262
|
+
onTokenReceived(token, paymentData);
|
|
263
|
+
}
|
|
264
|
+
} catch (error) {
|
|
265
|
+
if (onError) {
|
|
266
|
+
onError(error);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
return (
|
|
272
|
+
<Box width="100%">
|
|
273
|
+
<Flex direction="column" gap={3} alignItems="stretch">
|
|
274
|
+
{isLoading && (
|
|
275
|
+
<Typography variant="pi" textColor="neutral600" style={{ textAlign: "left" }}>
|
|
276
|
+
Loading Google Pay...
|
|
277
|
+
</Typography>
|
|
278
|
+
)}
|
|
279
|
+
{!isLoading && !isReady && (
|
|
280
|
+
<Typography variant="pi" textColor="neutral600" style={{ textAlign: "left" }}>
|
|
281
|
+
Google Pay is not available
|
|
282
|
+
</Typography>
|
|
283
|
+
)}
|
|
284
|
+
{!isLoading && isReady && (
|
|
285
|
+
<>
|
|
286
|
+
<Typography variant="sigma" textColor="neutral700" fontWeight="semiBold" style={{ textAlign: "left" }}>
|
|
287
|
+
Google Pay Payment
|
|
288
|
+
</Typography>
|
|
289
|
+
<Typography variant="pi" textColor="neutral600" style={{ textAlign: "left" }}>
|
|
290
|
+
Click the button below to pay with Google Pay. The token will be automatically sent to Payone.
|
|
291
|
+
</Typography>
|
|
292
|
+
</>
|
|
293
|
+
)}
|
|
294
|
+
<Box ref={buttonContainerRef} style={{ minHeight: "40px", width: "100%", maxWidth: "200px", display: "flex", justifyContent: "flex-start", }} />
|
|
295
|
+
</Flex>
|
|
296
|
+
</Box>
|
|
297
|
+
);
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
export default GooglePayButton;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IconButton, Tooltip } from "@strapi/design-system";
|
|
2
|
+
import { Information } from "@strapi/icons";
|
|
3
|
+
|
|
4
|
+
const InfoTooltip = ({ label, description, id }) => {
|
|
5
|
+
return (
|
|
6
|
+
<Tooltip label={description} description={description} id={id}>
|
|
7
|
+
<IconButton
|
|
8
|
+
noBorder
|
|
9
|
+
background="transparent"
|
|
10
|
+
icon={<Information fontSize={16} color="#c7c8c7" />}
|
|
11
|
+
/>
|
|
12
|
+
</Tooltip>
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default InfoTooltip;
|