strapi-plugin-payone-provider 1.5.8 → 1.6.0
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/admin/src/index.js +3 -3
- package/admin/src/pages/App/components/ApplePayBtn.jsx +304 -0
- package/admin/src/pages/App/components/{ApplePayButton.js → ApplePayButton.jsx} +141 -137
- package/admin/src/pages/App/components/{ApplePayConfig.js → ApplePayConfig.jsx} +64 -130
- package/admin/src/pages/App/components/{PaymentActionsPanel.js → PaymentActionsPanel.jsx} +62 -14
- package/admin/src/pages/App/components/icons/index.jsx +11 -0
- package/admin/src/pages/App/components/paymentActions/{AuthorizationForm.js → AuthorizationForm.jsx} +45 -35
- package/admin/src/pages/App/components/paymentActions/{PaymentMethodSelector.js → PaymentMethodSelector.jsx} +111 -31
- package/admin/src/pages/App/components/paymentActions/{PreauthorizationForm.js → PreauthorizationForm.jsx} +3 -70
- package/admin/src/pages/constants/paymentConstants.js +1 -2
- package/admin/src/pages/hooks/usePaymentActions.js +1 -76
- package/package.json +49 -49
- package/server/bootstrap.js +59 -1
- package/server/controllers/payone.js +6 -48
- package/server/routes/index.js +1 -1
- package/server/services/applePayService.js +51 -407
- package/server/services/paymentService.js +0 -68
- package/server/services/payone.js +0 -3
- package/server/services/settingsService.js +0 -21
- package/server/services/testConnectionService.js +0 -14
- package/server/services/transactionService.js +2 -16
- package/server/utils/paymentMethodParams.js +60 -21
- package/server/utils/requestBuilder.js +0 -22
- package/admin/src/pages/App/components/icons/index.js +0 -11
- /package/admin/src/components/Initializer/{index.js → index.jsx} +0 -0
- /package/admin/src/components/PluginIcon/{index.js → index.jsx} +0 -0
- /package/admin/src/pages/App/components/{AppHeader.js → AppHeader.jsx} +0 -0
- /package/admin/src/pages/App/components/{AppTabs.js → AppTabs.jsx} +0 -0
- /package/admin/src/pages/App/components/{ApplePayConfigPanel.js → ApplePayConfigPanel.jsx} +0 -0
- /package/admin/src/pages/App/components/{ConfigurationPanel.js → ConfigurationPanel.jsx} +0 -0
- /package/admin/src/pages/App/components/{DocsPanel.js → DocsPanel.jsx} +0 -0
- /package/admin/src/pages/App/components/{GooglePayConfig.js → GooglePayConfig.jsx} +0 -0
- /package/admin/src/pages/App/components/{GooglePayConfigPanel.js → GooglePayConfigPanel.jsx} +0 -0
- /package/admin/src/pages/App/components/{GooglePaybutton.js → GooglePaybutton.jsx} +0 -0
- /package/admin/src/pages/App/components/{HistoryPanel.js → HistoryPanel.jsx} +0 -0
- /package/admin/src/pages/App/components/{StatusBadge.js → StatusBadge.jsx} +0 -0
- /package/admin/src/pages/App/components/{TransactionHistoryItem.js → TransactionHistoryItem.jsx} +0 -0
- /package/admin/src/pages/App/components/icons/{BankIcon.js → BankIcon.jsx} +0 -0
- /package/admin/src/pages/App/components/icons/{ChevronDownIcon.js → ChevronDownIcon.jsx} +0 -0
- /package/admin/src/pages/App/components/icons/{ChevronUpIcon.js → ChevronUpIcon.jsx} +0 -0
- /package/admin/src/pages/App/components/icons/{CreditCardIcon.js → CreditCardIcon.jsx} +0 -0
- /package/admin/src/pages/App/components/icons/{ErrorIcon.js → ErrorIcon.jsx} +0 -0
- /package/admin/src/pages/App/components/icons/{InfoIcon.js → InfoIcon.jsx} +0 -0
- /package/admin/src/pages/App/components/icons/{PaymentIcon.js → PaymentIcon.jsx} +0 -0
- /package/admin/src/pages/App/components/icons/{PendingIcon.js → PendingIcon.jsx} +0 -0
- /package/admin/src/pages/App/components/icons/{PersonIcon.js → PersonIcon.jsx} +0 -0
- /package/admin/src/pages/App/components/icons/{SuccessIcon.js → SuccessIcon.jsx} +0 -0
- /package/admin/src/pages/App/components/icons/{WalletIcon.js → WalletIcon.jsx} +0 -0
- /package/admin/src/pages/App/components/paymentActions/{CaptureForm.js → CaptureForm.jsx} +0 -0
- /package/admin/src/pages/App/components/paymentActions/{CardDetailsInput.js → CardDetailsInput.jsx} +0 -0
- /package/admin/src/pages/App/components/paymentActions/{PaymentResult.js → PaymentResult.jsx} +0 -0
- /package/admin/src/pages/App/components/paymentActions/{RefundForm.js → RefundForm.jsx} +0 -0
- /package/admin/src/pages/App/{index.js → index.jsx} +0 -0
|
@@ -2,17 +2,7 @@ import React, { useEffect, useRef, useState } from "react";
|
|
|
2
2
|
import { Box, Flex, Typography } from "@strapi/design-system";
|
|
3
3
|
import { request } from "@strapi/helper-plugin";
|
|
4
4
|
import pluginId from "../../../pluginId";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Apple Pay Button Component using Payment Request API
|
|
9
|
-
* Based on Apple Pay documentation:
|
|
10
|
-
* https://developer.apple.com/documentation/applepayontheweb/creating-an-apple-pay-session
|
|
11
|
-
* https://developer.apple.com/documentation/applepayontheweb/displaying-apple-pay-buttons-using-css
|
|
12
|
-
*
|
|
13
|
-
* Supports Payment Request API (works in Chrome, Edge, Safari, etc.)
|
|
14
|
-
* and falls back to Apple Pay JS API if needed
|
|
15
|
-
*/
|
|
5
|
+
|
|
16
6
|
const ApplePayButton = ({
|
|
17
7
|
amount,
|
|
18
8
|
currency = "EUR",
|
|
@@ -37,27 +27,15 @@ const ApplePayButton = ({
|
|
|
37
27
|
const [isAvailable, setIsAvailable] = useState(false);
|
|
38
28
|
const [errorMessage, setErrorMessage] = useState(null);
|
|
39
29
|
const buttonContainerRef = useRef(null);
|
|
40
|
-
const paymentRequestRef = useRef(null);
|
|
41
30
|
|
|
42
31
|
const checkApplePayAvailability = async () => {
|
|
43
32
|
try {
|
|
44
|
-
console.log("[Apple Pay] Checking availability...");
|
|
45
|
-
|
|
46
|
-
// Check secure context using browser's native property
|
|
47
|
-
// This is the most reliable way to check if we're in a secure context
|
|
48
33
|
const isSecureContext = typeof window !== 'undefined' && window.isSecureContext;
|
|
49
34
|
const protocol = typeof window !== 'undefined' ? window.location.protocol : '';
|
|
50
35
|
const hostname = typeof window !== 'undefined' ? window.location.hostname : '';
|
|
51
36
|
const isLocalhost = hostname === 'localhost' || hostname === '127.0.0.1';
|
|
52
|
-
|
|
53
|
-
// For Apple Pay, we need a secure context (HTTPS or localhost)
|
|
54
|
-
// window.isSecureContext is true for:
|
|
55
|
-
// - HTTPS pages
|
|
56
|
-
// - localhost (even on HTTP)
|
|
57
|
-
// - 127.0.0.1 (even on HTTP)
|
|
58
|
-
// - file:// URLs
|
|
59
37
|
const isSecure = isSecureContext || isLocalhost;
|
|
60
|
-
|
|
38
|
+
|
|
61
39
|
console.log("[Apple Pay] Secure context check:", {
|
|
62
40
|
isSecureContext: isSecureContext,
|
|
63
41
|
protocol: protocol,
|
|
@@ -67,7 +45,6 @@ const ApplePayButton = ({
|
|
|
67
45
|
fullUrl: typeof window !== 'undefined' ? window.location.href : ''
|
|
68
46
|
});
|
|
69
47
|
|
|
70
|
-
// If not secure, log detailed information
|
|
71
48
|
if (!isSecure) {
|
|
72
49
|
console.error("[Apple Pay] NOT in secure context!", {
|
|
73
50
|
isSecureContext: isSecureContext,
|
|
@@ -78,13 +55,9 @@ const ApplePayButton = ({
|
|
|
78
55
|
reason: !isSecureContext ? "window.isSecureContext is false" : "Unknown"
|
|
79
56
|
});
|
|
80
57
|
}
|
|
81
|
-
|
|
82
|
-
// First, check if Payment Request API is available
|
|
83
|
-
// Payment Request API works on HTTP too, but Apple Pay JS API requires HTTPS
|
|
58
|
+
|
|
84
59
|
if (typeof window === 'undefined' || !window.PaymentRequest) {
|
|
85
60
|
console.log("[Apple Pay] Payment Request API not available");
|
|
86
|
-
|
|
87
|
-
// Fallback: Check Apple Pay JS API (for Safari, requires HTTPS)
|
|
88
61
|
if (typeof window !== 'undefined' && window.ApplePaySession && isSecure) {
|
|
89
62
|
try {
|
|
90
63
|
const canMakePayments = ApplePaySession.canMakePayments();
|
|
@@ -95,31 +68,28 @@ const ApplePayButton = ({
|
|
|
95
68
|
return { available: false, method: null, error: 'insecure_context' };
|
|
96
69
|
}
|
|
97
70
|
}
|
|
98
|
-
|
|
71
|
+
|
|
99
72
|
if (!isSecure && typeof window !== 'undefined' && window.ApplePaySession) {
|
|
100
73
|
console.warn("[Apple Pay] Apple Pay JS API requires HTTPS. Using Payment Request API fallback.");
|
|
101
74
|
}
|
|
102
|
-
|
|
75
|
+
|
|
103
76
|
console.log("[Apple Pay] No Apple Pay support found");
|
|
104
77
|
return { available: false, method: null };
|
|
105
78
|
}
|
|
106
79
|
|
|
107
80
|
console.log("[Apple Pay] Payment Request API available, checking Apple Pay support...");
|
|
108
81
|
|
|
109
|
-
// Check if Apple Pay payment method is supported
|
|
110
82
|
const applePayMethod = {
|
|
111
83
|
supportedMethods: "https://apple.com/apple-pay",
|
|
112
84
|
data: {
|
|
113
85
|
version: 3,
|
|
114
|
-
merchantIdentifier:
|
|
86
|
+
merchantIdentifier: settings?.mid,
|
|
115
87
|
merchantCapabilities: merchantCapabilities,
|
|
116
88
|
supportedNetworks: supportedNetworks,
|
|
117
89
|
countryCode: countryCode
|
|
118
90
|
}
|
|
119
91
|
};
|
|
120
92
|
|
|
121
|
-
// Create a test payment request
|
|
122
|
-
// Payment Request API works on HTTP too, but Apple Pay may require HTTPS
|
|
123
93
|
let testRequest;
|
|
124
94
|
try {
|
|
125
95
|
testRequest = new PaymentRequest(
|
|
@@ -147,17 +117,15 @@ const ApplePayButton = ({
|
|
|
147
117
|
return { available: false, method: null };
|
|
148
118
|
}
|
|
149
119
|
|
|
150
|
-
// Check if can make payment
|
|
151
120
|
if (testRequest.canMakePayment) {
|
|
152
121
|
try {
|
|
153
122
|
const canPay = await testRequest.canMakePayment();
|
|
154
123
|
console.log("[Apple Pay] canMakePayment result:", canPay);
|
|
155
|
-
|
|
124
|
+
|
|
156
125
|
if (canPay) {
|
|
157
126
|
return { available: true, method: 'paymentRequest' };
|
|
158
127
|
}
|
|
159
|
-
|
|
160
|
-
// If PaymentRequest says no, try Apple Pay JS API as fallback (only on HTTPS)
|
|
128
|
+
|
|
161
129
|
if (typeof window !== 'undefined' && window.ApplePaySession && isSecure) {
|
|
162
130
|
try {
|
|
163
131
|
const canMakePaymentsJS = ApplePaySession.canMakePayments();
|
|
@@ -165,24 +133,21 @@ const ApplePayButton = ({
|
|
|
165
133
|
return { available: canMakePaymentsJS, method: 'applePayJS' };
|
|
166
134
|
} catch (e) {
|
|
167
135
|
console.error("[Apple Pay] Apple Pay JS API error:", e.message);
|
|
168
|
-
// If it's insecure context error, Payment Request API might still work
|
|
169
136
|
if (e.message && e.message.includes('insecure')) {
|
|
170
|
-
// Payment Request API might work even on HTTP
|
|
171
137
|
return { available: false, method: null, error: 'insecure_context' };
|
|
172
138
|
}
|
|
173
139
|
}
|
|
174
140
|
}
|
|
175
|
-
|
|
141
|
+
|
|
176
142
|
return { available: false, method: null };
|
|
177
143
|
} catch (e) {
|
|
178
144
|
console.error("[Apple Pay] Error checking canMakePayment:", e);
|
|
179
|
-
|
|
180
|
-
// If it's insecure context error, we can't use Apple Pay JS API
|
|
145
|
+
|
|
181
146
|
if (e.message && e.message.includes('insecure')) {
|
|
182
147
|
console.warn("[Apple Pay] Insecure context detected. Apple Pay requires HTTPS.");
|
|
183
148
|
return { available: false, method: null, error: 'insecure_context' };
|
|
184
149
|
}
|
|
185
|
-
|
|
150
|
+
|
|
186
151
|
// For other errors, try Apple Pay JS API as fallback (only on HTTPS)
|
|
187
152
|
if (typeof window !== 'undefined' && window.ApplePaySession && isSecure) {
|
|
188
153
|
try {
|
|
@@ -193,18 +158,16 @@ const ApplePayButton = ({
|
|
|
193
158
|
return { available: false, method: null };
|
|
194
159
|
}
|
|
195
160
|
}
|
|
196
|
-
|
|
161
|
+
|
|
197
162
|
return { available: false, method: null };
|
|
198
163
|
}
|
|
199
164
|
}
|
|
200
165
|
|
|
201
|
-
// If canMakePayment is not available, check secure context again
|
|
202
|
-
// Re-check secure context to ensure we have the latest state
|
|
203
166
|
const isSecureContextFinal = typeof window !== 'undefined' && window.isSecureContext;
|
|
204
167
|
const hostnameFinal = typeof window !== 'undefined' ? window.location.hostname : '';
|
|
205
168
|
const isLocalhostFinal = hostnameFinal === 'localhost' || hostnameFinal === '127.0.0.1';
|
|
206
169
|
const isSecureFinal = isSecureContextFinal || isLocalhostFinal;
|
|
207
|
-
|
|
170
|
+
|
|
208
171
|
if (isSecureFinal) {
|
|
209
172
|
console.log("[Apple Pay] canMakePayment not available, assuming support (secure context)");
|
|
210
173
|
return { available: true, method: 'paymentRequest' };
|
|
@@ -219,20 +182,17 @@ const ApplePayButton = ({
|
|
|
219
182
|
}
|
|
220
183
|
} catch (error) {
|
|
221
184
|
console.error("[Apple Pay] Error checking availability:", error);
|
|
222
|
-
|
|
223
|
-
// Check if it's insecure context error
|
|
185
|
+
|
|
224
186
|
if (error.message && error.message.includes('insecure')) {
|
|
225
187
|
console.warn("[Apple Pay] Insecure context - Apple Pay requires HTTPS");
|
|
226
188
|
return { available: false, method: null, error: 'insecure_context' };
|
|
227
189
|
}
|
|
228
|
-
|
|
229
|
-
// Fallback: Try Apple Pay JS API (only on HTTPS)
|
|
230
|
-
// Re-check secure context
|
|
190
|
+
|
|
231
191
|
const isSecureContextFallback = typeof window !== 'undefined' && window.isSecureContext;
|
|
232
192
|
const hostnameFallback = typeof window !== 'undefined' ? window.location.hostname : '';
|
|
233
193
|
const isLocalhostFallback = hostnameFallback === 'localhost' || hostnameFallback === '127.0.0.1';
|
|
234
194
|
const isSecureFallback = isSecureContextFallback || isLocalhostFallback;
|
|
235
|
-
|
|
195
|
+
|
|
236
196
|
if (typeof window !== 'undefined' && window.ApplePaySession && isSecureFallback) {
|
|
237
197
|
try {
|
|
238
198
|
const canMakePayments = ApplePaySession.canMakePayments();
|
|
@@ -244,16 +204,16 @@ const ApplePayButton = ({
|
|
|
244
204
|
}
|
|
245
205
|
}
|
|
246
206
|
}
|
|
247
|
-
|
|
207
|
+
|
|
248
208
|
return { available: false, method: null };
|
|
249
209
|
}
|
|
250
210
|
};
|
|
251
211
|
|
|
252
212
|
useEffect(() => {
|
|
253
213
|
const scriptUrl = "https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js";
|
|
254
|
-
|
|
214
|
+
|
|
255
215
|
console.log("[Apple Pay] Loading Apple Pay SDK script...");
|
|
256
|
-
|
|
216
|
+
|
|
257
217
|
if (document.querySelector(`script[src="${scriptUrl}"]`)) {
|
|
258
218
|
console.log("[Apple Pay] Script already loaded");
|
|
259
219
|
// Script already loaded, check if it's ready
|
|
@@ -270,20 +230,20 @@ const ApplePayButton = ({
|
|
|
270
230
|
script.src = scriptUrl;
|
|
271
231
|
script.crossOrigin = "anonymous";
|
|
272
232
|
script.async = true;
|
|
273
|
-
|
|
233
|
+
|
|
274
234
|
script.onload = () => {
|
|
275
235
|
console.log("[Apple Pay] SDK script loaded successfully");
|
|
276
236
|
setTimeout(() => {
|
|
277
237
|
initializeButton();
|
|
278
238
|
}, 500);
|
|
279
239
|
};
|
|
280
|
-
|
|
240
|
+
|
|
281
241
|
script.onerror = (error) => {
|
|
282
242
|
console.error("[Apple Pay] Failed to load SDK script:", error);
|
|
283
243
|
setIsLoading(false);
|
|
284
244
|
setIsAvailable(false);
|
|
285
245
|
setErrorMessage("Failed to load Apple Pay SDK. Please check Content Security Policy settings.");
|
|
286
|
-
|
|
246
|
+
|
|
287
247
|
// Even if script fails, try to use Payment Request API
|
|
288
248
|
console.log("[Apple Pay] Trying Payment Request API as fallback...");
|
|
289
249
|
setTimeout(() => {
|
|
@@ -306,22 +266,22 @@ const ApplePayButton = ({
|
|
|
306
266
|
const initializeButton = async () => {
|
|
307
267
|
try {
|
|
308
268
|
console.log("[Apple Pay] Initializing button...");
|
|
309
|
-
|
|
310
|
-
const isSecure = typeof window !== 'undefined' &&
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
269
|
+
|
|
270
|
+
const isSecure = typeof window !== 'undefined' &&
|
|
271
|
+
(window.location.protocol === 'https:' ||
|
|
272
|
+
window.location.hostname === 'localhost' ||
|
|
273
|
+
window.location.hostname === '127.0.0.1');
|
|
274
|
+
|
|
315
275
|
console.log("[Apple Pay] Secure context check:", {
|
|
316
276
|
protocol: window.location?.protocol,
|
|
317
277
|
hostname: window.location?.hostname,
|
|
318
278
|
isSecure: isSecure
|
|
319
279
|
});
|
|
320
|
-
|
|
321
|
-
const isLocalhost = typeof window !== 'undefined' &&
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
280
|
+
|
|
281
|
+
const isLocalhost = typeof window !== 'undefined' &&
|
|
282
|
+
(window.location.hostname === 'localhost' ||
|
|
283
|
+
window.location.hostname === '127.0.0.1');
|
|
284
|
+
|
|
325
285
|
if (!isSecure && !isLocalhost && window.location?.protocol === 'http:') {
|
|
326
286
|
const errorMsg = "Apple Pay requires HTTPS. Please access this page via HTTPS (https://yourdomain.com) instead of HTTP. Localhost (http://localhost) is allowed for development.";
|
|
327
287
|
setErrorMessage(errorMsg);
|
|
@@ -331,7 +291,7 @@ const ApplePayButton = ({
|
|
|
331
291
|
console.warn("[Apple Pay] Current URL:", window.location.href);
|
|
332
292
|
return;
|
|
333
293
|
}
|
|
334
|
-
|
|
294
|
+
|
|
335
295
|
// Log context information
|
|
336
296
|
console.log("[Apple Pay] Context info:", {
|
|
337
297
|
protocol: window.location?.protocol,
|
|
@@ -340,16 +300,16 @@ const ApplePayButton = ({
|
|
|
340
300
|
isLocalhost: isLocalhost,
|
|
341
301
|
fullUrl: window.location?.href
|
|
342
302
|
});
|
|
343
|
-
|
|
303
|
+
|
|
344
304
|
// Check availability
|
|
345
305
|
const availability = await checkApplePayAvailability();
|
|
346
306
|
console.log("[Apple Pay] Availability check result:", availability);
|
|
347
|
-
|
|
307
|
+
|
|
348
308
|
setIsAvailable(availability.available);
|
|
349
|
-
|
|
309
|
+
|
|
350
310
|
if (!availability.available) {
|
|
351
311
|
let errorMsg = "Apple Pay is not available on this device or browser.";
|
|
352
|
-
|
|
312
|
+
|
|
353
313
|
if (isLocalhost) {
|
|
354
314
|
errorMsg = "Apple Pay is not available on localhost. Apple Pay requires a registered domain with HTTPS. " +
|
|
355
315
|
"For testing, please use a production domain with HTTPS or test on a device with Safari (iOS/macOS). " +
|
|
@@ -366,7 +326,7 @@ const ApplePayButton = ({
|
|
|
366
326
|
} else {
|
|
367
327
|
errorMsg += " Please use Safari on iOS, macOS, or iPadOS, or a browser that supports Payment Request API (Chrome, Edge, Safari).";
|
|
368
328
|
}
|
|
369
|
-
|
|
329
|
+
|
|
370
330
|
setErrorMessage(errorMsg);
|
|
371
331
|
setIsLoading(false);
|
|
372
332
|
console.warn("[Apple Pay] Not available:", errorMsg);
|
|
@@ -380,14 +340,14 @@ const ApplePayButton = ({
|
|
|
380
340
|
console.error("[Apple Pay] Initialization error:", error);
|
|
381
341
|
setIsLoading(false);
|
|
382
342
|
setIsAvailable(false);
|
|
383
|
-
|
|
343
|
+
|
|
384
344
|
// Check for insecure context error
|
|
385
345
|
if (error.message && error.message.includes('insecure')) {
|
|
386
346
|
setErrorMessage("Apple Pay requires HTTPS. Please access this page via HTTPS (https://yourdomain.com) instead of HTTP. Localhost is allowed for development.");
|
|
387
347
|
} else {
|
|
388
348
|
setErrorMessage(error.message || "Failed to initialize Apple Pay");
|
|
389
349
|
}
|
|
390
|
-
|
|
350
|
+
|
|
391
351
|
if (onError) {
|
|
392
352
|
onError(error);
|
|
393
353
|
}
|
|
@@ -406,11 +366,11 @@ const ApplePayButton = ({
|
|
|
406
366
|
});
|
|
407
367
|
|
|
408
368
|
// Check HTTPS requirement
|
|
409
|
-
const isSecure = typeof window !== 'undefined' &&
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
369
|
+
const isSecure = typeof window !== 'undefined' &&
|
|
370
|
+
(window.location.protocol === 'https:' ||
|
|
371
|
+
window.location.hostname === 'localhost' ||
|
|
372
|
+
window.location.hostname === '127.0.0.1');
|
|
373
|
+
|
|
414
374
|
if (!isSecure && window.location?.protocol === 'http:') {
|
|
415
375
|
const errorMsg = "Apple Pay requires HTTPS. Please access this page via HTTPS.";
|
|
416
376
|
console.error("[Apple Pay]", errorMsg);
|
|
@@ -430,8 +390,8 @@ const ApplePayButton = ({
|
|
|
430
390
|
|
|
431
391
|
try {
|
|
432
392
|
const amountValue = (parseFloat(amount) / 100).toFixed(2);
|
|
433
|
-
const gatewayMerchantId = settings?.mid
|
|
434
|
-
const merchantId =
|
|
393
|
+
const gatewayMerchantId = settings?.mid;
|
|
394
|
+
const merchantId = gatewayMerchantId
|
|
435
395
|
|
|
436
396
|
console.log("[Apple Pay] Starting payment request:", {
|
|
437
397
|
amount: amountValue,
|
|
@@ -442,7 +402,6 @@ const ApplePayButton = ({
|
|
|
442
402
|
merchantCapabilities
|
|
443
403
|
});
|
|
444
404
|
|
|
445
|
-
// Define PaymentMethodData for Apple Pay
|
|
446
405
|
const paymentMethodData = [{
|
|
447
406
|
supportedMethods: "https://apple.com/apple-pay",
|
|
448
407
|
data: {
|
|
@@ -496,16 +455,35 @@ const ApplePayButton = ({
|
|
|
496
455
|
});
|
|
497
456
|
|
|
498
457
|
merchantSessionPromise.then(session => {
|
|
499
|
-
console.log("[Apple Pay]
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
458
|
+
console.log("[Apple Pay] ========== MERCHANT SESSION RECEIVED ==========");
|
|
459
|
+
console.log("[Apple Pay] Full Merchant Session (JSON):", JSON.stringify(session, null, 2));
|
|
460
|
+
console.log("[Apple Pay] Session Type:", typeof session);
|
|
461
|
+
console.log("[Apple Pay] Is Object:", session instanceof Object);
|
|
462
|
+
console.log("[Apple Pay] Session Keys:", Object.keys(session || {}));
|
|
463
|
+
console.log("[Apple Pay] Session Keys Count:", Object.keys(session || {}).length);
|
|
464
|
+
console.log("[Apple Pay] Has Merchant Identifier:", !!session?.merchantIdentifier);
|
|
465
|
+
console.log("[Apple Pay] Merchant Identifier:", session?.merchantIdentifier);
|
|
466
|
+
console.log("[Apple Pay] Has Merchant Session Identifier:", !!session?.merchantSessionIdentifier);
|
|
467
|
+
console.log("[Apple Pay] Merchant Session Identifier:", session?.merchantSessionIdentifier);
|
|
468
|
+
console.log("[Apple Pay] Domain Name:", session?.domainName);
|
|
469
|
+
console.log("[Apple Pay] Display Name:", session?.displayName);
|
|
470
|
+
console.log("[Apple Pay] Epoch Timestamp:", session?.epochTimestamp);
|
|
471
|
+
console.log("[Apple Pay] Expires At:", session?.expiresAt);
|
|
472
|
+
console.log("[Apple Pay] Nonce:", session?.nonce);
|
|
473
|
+
|
|
474
|
+
// Log all properties
|
|
475
|
+
console.log("[Apple Pay] All Session Properties:");
|
|
476
|
+
if (session && typeof session === 'object') {
|
|
477
|
+
for (const [key, value] of Object.entries(session)) {
|
|
478
|
+
if (typeof value === 'string' && value.length > 200) {
|
|
479
|
+
console.log(`[Apple Pay] ${key}:`, value.substring(0, 200) + "... (truncated, length: " + value.length + ")");
|
|
480
|
+
} else {
|
|
481
|
+
console.log(`[Apple Pay] ${key}:`, value);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
console.log("[Apple Pay] ==========================================");
|
|
486
|
+
|
|
509
487
|
// Validate merchant session
|
|
510
488
|
if (!session || (!session.merchantIdentifier && !session.merchantSessionIdentifier)) {
|
|
511
489
|
console.error("[Apple Pay] Invalid merchant session - missing merchantIdentifier");
|
|
@@ -528,12 +506,12 @@ const ApplePayButton = ({
|
|
|
528
506
|
stack: error.stack,
|
|
529
507
|
response: error.response
|
|
530
508
|
});
|
|
531
|
-
|
|
509
|
+
|
|
532
510
|
// Call onError to notify the user
|
|
533
511
|
if (typeof onError === 'function') {
|
|
534
512
|
onError(new Error(`Apple Pay merchant validation failed: ${error.message}. Please check your Payone Apple Pay configuration in PMI (CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Apple Pay).`));
|
|
535
513
|
}
|
|
536
|
-
|
|
514
|
+
|
|
537
515
|
// Complete with a rejected promise
|
|
538
516
|
// This will cause Apple Pay to close the dialog, which is expected behavior
|
|
539
517
|
// We cannot proceed without a valid merchant session from Payone
|
|
@@ -576,20 +554,20 @@ const ApplePayButton = ({
|
|
|
576
554
|
message: error.message,
|
|
577
555
|
stack: error.stack
|
|
578
556
|
});
|
|
579
|
-
|
|
557
|
+
|
|
580
558
|
// Check if error is due to cancellation (user cancelled)
|
|
581
559
|
// Payment Request API throws "AbortError" when user cancels
|
|
582
|
-
if (error.name === 'AbortError' ||
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
560
|
+
if (error.name === 'AbortError' ||
|
|
561
|
+
(error.message && (
|
|
562
|
+
error.message.includes('Cancelled') ||
|
|
563
|
+
error.message.includes('cancel') ||
|
|
564
|
+
error.message.includes('abort')
|
|
565
|
+
))) {
|
|
588
566
|
console.log("[Apple Pay] User cancelled the payment");
|
|
589
567
|
// Don't call onError for user cancellation
|
|
590
568
|
return;
|
|
591
569
|
}
|
|
592
|
-
|
|
570
|
+
|
|
593
571
|
// If it's a merchant validation error, log it specifically
|
|
594
572
|
if (error.message && (
|
|
595
573
|
error.message.includes('merchant') ||
|
|
@@ -617,11 +595,11 @@ const ApplePayButton = ({
|
|
|
617
595
|
|
|
618
596
|
// Extract payment token
|
|
619
597
|
const paymentToken = response.details?.paymentToken || response.details?.token;
|
|
620
|
-
|
|
598
|
+
|
|
621
599
|
if (!paymentToken) {
|
|
622
600
|
console.error("[Apple Pay] Payment token is missing from response");
|
|
623
601
|
try {
|
|
624
|
-
|
|
602
|
+
await response.complete("fail");
|
|
625
603
|
} catch (completeError) {
|
|
626
604
|
console.error("[Apple Pay] Error completing payment with fail:", completeError);
|
|
627
605
|
}
|
|
@@ -663,11 +641,11 @@ const ApplePayButton = ({
|
|
|
663
641
|
// The callback should set the token in state and return success immediately
|
|
664
642
|
// It should NOT process the payment yet - that will happen when user clicks the button
|
|
665
643
|
const callbackResult = onTokenReceived(tokenString, {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
644
|
+
paymentToken: paymentToken,
|
|
645
|
+
billingContact: response.payerName || response.details?.billingContact,
|
|
646
|
+
shippingContact: response.shippingAddress || response.details?.shippingAddress,
|
|
647
|
+
shippingOption: response.shippingOption || response.details?.shippingOption
|
|
648
|
+
});
|
|
671
649
|
|
|
672
650
|
// If callback returns a promise, wait for it to resolve or reject
|
|
673
651
|
if (callbackResult && typeof callbackResult.then === 'function') {
|
|
@@ -754,7 +732,6 @@ const ApplePayButton = ({
|
|
|
754
732
|
}
|
|
755
733
|
};
|
|
756
734
|
|
|
757
|
-
// Validate merchant with Payone
|
|
758
735
|
const validateMerchantWithPayone = async (validationURL, config) => {
|
|
759
736
|
console.log("[Apple Pay] Validating merchant with Payone:", {
|
|
760
737
|
validationURL,
|
|
@@ -779,29 +756,56 @@ const ApplePayButton = ({
|
|
|
779
756
|
}
|
|
780
757
|
});
|
|
781
758
|
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
759
|
+
console.log("[Apple Pay] ========== BACKEND RESPONSE START ==========");
|
|
760
|
+
console.log("[Apple Pay] Full Backend Response:", JSON.stringify(merchantSession, null, 2));
|
|
761
|
+
console.log("[Apple Pay] Response Type:", typeof merchantSession);
|
|
762
|
+
console.log("[Apple Pay] Has Data:", !!merchantSession.data);
|
|
763
|
+
console.log("[Apple Pay] Has Error:", !!merchantSession.error);
|
|
764
|
+
|
|
765
|
+
if (merchantSession.data) {
|
|
766
|
+
console.log("[Apple Pay] Data Object:", merchantSession.data);
|
|
767
|
+
console.log("[Apple Pay] Data Type:", typeof merchantSession.data);
|
|
768
|
+
console.log("[Apple Pay] Data Keys:", Object.keys(merchantSession.data));
|
|
769
|
+
console.log("[Apple Pay] Data Keys Count:", Object.keys(merchantSession.data).length);
|
|
770
|
+
console.log("[Apple Pay] Merchant Identifier:", merchantSession.data.merchantIdentifier);
|
|
771
|
+
console.log("[Apple Pay] Domain Name:", merchantSession.data.domainName);
|
|
772
|
+
console.log("[Apple Pay] Display Name:", merchantSession.data.displayName);
|
|
773
|
+
console.log("[Apple Pay] Epoch Timestamp:", merchantSession.data.epochTimestamp);
|
|
774
|
+
console.log("[Apple Pay] Expires At:", merchantSession.data.expiresAt);
|
|
775
|
+
}
|
|
789
776
|
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
777
|
+
if (merchantSession.error) {
|
|
778
|
+
console.log("[Apple Pay] Error Object:", merchantSession.error);
|
|
779
|
+
console.log("[Apple Pay] Error Message:", merchantSession.error.message);
|
|
780
|
+
console.log("[Apple Pay] Error Details:", merchantSession.error.details);
|
|
781
|
+
}
|
|
795
782
|
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
783
|
+
console.log("[Apple Pay] ========== BACKEND RESPONSE END ==========");
|
|
784
|
+
|
|
785
|
+
// Check if there's an error in the response
|
|
786
|
+
if (merchantSession.error) {
|
|
787
|
+
console.error("[Apple Pay] Backend returned error:", merchantSession.error);
|
|
788
|
+
throw new Error(merchantSession.error.message || "Apple Pay merchant validation failed");
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
// Validate merchant session
|
|
792
|
+
const session = merchantSession.data || merchantSession;
|
|
793
|
+
|
|
794
|
+
// Check if session is empty object
|
|
795
|
+
if (!session || Object.keys(session).length === 0) {
|
|
796
|
+
console.error("[Apple Pay] Empty merchant session received from backend");
|
|
797
|
+
console.error("[Apple Pay] Full response:", JSON.stringify(merchantSession, null, 2));
|
|
798
|
+
throw new Error("Empty merchant session received. This usually means Payone did not return a valid merchant session. Please check your Payone Apple Pay configuration in PMI (CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Apple Pay).");
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
if (!session.merchantIdentifier && !session.merchantSessionIdentifier) {
|
|
802
|
+
console.error("[Apple Pay] Invalid merchant session - missing merchantIdentifier");
|
|
803
|
+
console.error("[Apple Pay] Session object:", JSON.stringify(session, null, 2));
|
|
804
|
+
console.error("[Apple Pay] Full response:", JSON.stringify(merchantSession, null, 2));
|
|
805
|
+
throw new Error("Invalid merchant session: missing merchantIdentifier. Please check your Payone Apple Pay configuration in PMI (CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Apple Pay). The merchant session must come from Payone after successful Apple Pay onboarding.");
|
|
806
|
+
}
|
|
803
807
|
|
|
804
|
-
|
|
808
|
+
return session;
|
|
805
809
|
} catch (error) {
|
|
806
810
|
console.error("[Apple Pay] Merchant validation error:", {
|
|
807
811
|
message: error.message,
|