strapi-plugin-payone-provider 1.5.8-beta.1 → 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} +4 -46
- 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 -77
- package/server/routes/index.js +1 -1
- package/server/services/applePayService.js +51 -509
- 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
package/admin/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import pluginPkg from "../../package.json";
|
|
2
2
|
import pluginId from "./pluginId";
|
|
3
|
-
import Initializer from "./components/Initializer";
|
|
4
|
-
import PluginIcon from "./components/PluginIcon";
|
|
3
|
+
import Initializer from "./components/Initializer/index.jsx";
|
|
4
|
+
import PluginIcon from "./components/PluginIcon/index.jsx";
|
|
5
5
|
import { injectGooglePayScript } from "./pages/utils/injectGooglePayScript";
|
|
6
6
|
|
|
7
7
|
const name = pluginPkg.strapi.name;
|
|
@@ -16,7 +16,7 @@ export default {
|
|
|
16
16
|
defaultMessage: "Payone Provider"
|
|
17
17
|
},
|
|
18
18
|
Component: async () => {
|
|
19
|
-
const component = await import("./pages/App");
|
|
19
|
+
const component = await import("./pages/App/index.jsx");
|
|
20
20
|
return component;
|
|
21
21
|
},
|
|
22
22
|
permissions: []
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import ApplePayButton from "apple-pay-button";
|
|
3
|
+
import { Box, Typography, Alert } from "@strapi/design-system";
|
|
4
|
+
import { request } from "@strapi/helper-plugin";
|
|
5
|
+
import pluginId from "../../../pluginId";
|
|
6
|
+
|
|
7
|
+
const ApplePayBtn = ({
|
|
8
|
+
amount,
|
|
9
|
+
onTokenReceived,
|
|
10
|
+
onError,
|
|
11
|
+
settings,
|
|
12
|
+
buttonStyle = "black",
|
|
13
|
+
type = "pay",
|
|
14
|
+
}) => {
|
|
15
|
+
const handleEventsForApplePay = (session, amountValue, currencyCode) => {
|
|
16
|
+
session.onvalidatemerchant = async (event) => {
|
|
17
|
+
try {
|
|
18
|
+
const merchantSession = await request(
|
|
19
|
+
`/${pluginId}/validate-apple-pay-merchant`,
|
|
20
|
+
{
|
|
21
|
+
method: "POST",
|
|
22
|
+
body: {
|
|
23
|
+
domain: window.location.hostname,
|
|
24
|
+
displayName: settings?.merchantName || "Store",
|
|
25
|
+
currency: currencyCode,
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
if (merchantSession.error) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
merchantSession.error.message || "Merchant validation failed"
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const sessionData = merchantSession.data || merchantSession;
|
|
37
|
+
|
|
38
|
+
if (!sessionData || !sessionData.merchantIdentifier) {
|
|
39
|
+
console.error(
|
|
40
|
+
"[Apple Pay Button] Invalid merchant session: missing merchantIdentifier"
|
|
41
|
+
);
|
|
42
|
+
throw new Error(
|
|
43
|
+
"Invalid merchant session: missing merchantIdentifier"
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
session.completeMerchantValidation(sessionData);
|
|
48
|
+
console.log(
|
|
49
|
+
"[Apple Pay Button] Merchant validation completed successfully"
|
|
50
|
+
);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error("[Apple Pay Button] Merchant validation error:", error);
|
|
53
|
+
if (onError) {
|
|
54
|
+
onError(error);
|
|
55
|
+
}
|
|
56
|
+
session.completeMerchantValidation({});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
session.onpaymentmethodselected = (event) => {
|
|
61
|
+
const update = {
|
|
62
|
+
newTotal: {
|
|
63
|
+
label: settings?.merchantName || "Total",
|
|
64
|
+
type: "final",
|
|
65
|
+
amount: amountValue,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
session.completePaymentMethodSelection(update);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
session.onshippingmethodselected = (event) => {
|
|
72
|
+
const update = {
|
|
73
|
+
newTotal: {
|
|
74
|
+
label: settings?.merchantName || "Total",
|
|
75
|
+
type: "final",
|
|
76
|
+
amount: amountValue,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
session.completeShippingMethodSelection(update);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
session.onshippingcontactselected = (event) => {
|
|
83
|
+
const update = {
|
|
84
|
+
newTotal: {
|
|
85
|
+
label: settings?.merchantName || "Total",
|
|
86
|
+
type: "final",
|
|
87
|
+
amount: amountValue,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
session.completeShippingContactSelection(update);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
session.onpaymentauthorized = async (event) => {
|
|
94
|
+
try {
|
|
95
|
+
const paymentData = event.payment;
|
|
96
|
+
|
|
97
|
+
if (!paymentData || !paymentData.token) {
|
|
98
|
+
const result = {
|
|
99
|
+
status: window.ApplePaySession.STATUS_FAILURE,
|
|
100
|
+
};
|
|
101
|
+
session.completePayment(result);
|
|
102
|
+
if (onError) {
|
|
103
|
+
onError(new Error("Payment token is missing"));
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const tokenObject = paymentData.token;
|
|
109
|
+
|
|
110
|
+
if (!tokenObject.paymentData) {
|
|
111
|
+
console.error(
|
|
112
|
+
"[Apple Pay] Invalid token structure: missing paymentData"
|
|
113
|
+
);
|
|
114
|
+
const result = {
|
|
115
|
+
status: window.ApplePaySession.STATUS_FAILURE,
|
|
116
|
+
};
|
|
117
|
+
session.completePayment(result);
|
|
118
|
+
if (onError) {
|
|
119
|
+
onError(new Error("Invalid Apple Pay token structure"));
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Encode token as Base64 for transmission
|
|
125
|
+
let tokenString;
|
|
126
|
+
try {
|
|
127
|
+
tokenString = btoa(
|
|
128
|
+
unescape(encodeURIComponent(JSON.stringify(tokenObject)))
|
|
129
|
+
);
|
|
130
|
+
} catch (e) {
|
|
131
|
+
console.error("[Apple Pay] Token encoding error:", e);
|
|
132
|
+
tokenString = btoa(
|
|
133
|
+
unescape(encodeURIComponent(JSON.stringify(tokenObject)))
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (onTokenReceived) {
|
|
138
|
+
const result = await onTokenReceived(tokenString, {
|
|
139
|
+
paymentToken: tokenObject,
|
|
140
|
+
billingContact: paymentData.billingContact,
|
|
141
|
+
shippingContact: paymentData.shippingContact,
|
|
142
|
+
amount: amountValue, //
|
|
143
|
+
currency: currencyCode,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
if (result && typeof result.then === "function") {
|
|
147
|
+
await result;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const paymentResult = {
|
|
151
|
+
status: window.ApplePaySession.STATUS_SUCCESS,
|
|
152
|
+
};
|
|
153
|
+
session.completePayment(paymentResult);
|
|
154
|
+
} else {
|
|
155
|
+
const paymentResult = {
|
|
156
|
+
status: window.ApplePaySession.STATUS_SUCCESS,
|
|
157
|
+
};
|
|
158
|
+
session.completePayment(paymentResult);
|
|
159
|
+
}
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error("[Apple Pay] Payment authorization error:", error);
|
|
162
|
+
const result = {
|
|
163
|
+
status: window.ApplePaySession.STATUS_FAILURE,
|
|
164
|
+
};
|
|
165
|
+
session.completePayment(result);
|
|
166
|
+
if (onError) {
|
|
167
|
+
onError(error);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
session.oncancel = (event) => {
|
|
173
|
+
console.log("[Apple Pay Button] Session cancelled by user");
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const handleApplePayClick = () => {
|
|
178
|
+
if (!settings?.mid) {
|
|
179
|
+
const error = new Error(
|
|
180
|
+
"Merchant ID is not configured. Please set Merchant ID in plugin settings."
|
|
181
|
+
);
|
|
182
|
+
if (onError) {
|
|
183
|
+
onError(error);
|
|
184
|
+
}
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (typeof window === "undefined" || !window.ApplePaySession) {
|
|
189
|
+
if (onError) {
|
|
190
|
+
onError(new Error("Apple Pay is not supported in this environment."));
|
|
191
|
+
}
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const amountValue = amount ? (parseFloat(amount) / 100).toFixed(2) : "0.00";
|
|
196
|
+
const applePayConfig = settings?.applePayConfig || {};
|
|
197
|
+
const supportedNetworks = applePayConfig.supportedNetworks || [
|
|
198
|
+
"visa",
|
|
199
|
+
"masterCard",
|
|
200
|
+
"amex",
|
|
201
|
+
];
|
|
202
|
+
const merchantCapabilities = applePayConfig.merchantCapabilities || [
|
|
203
|
+
"supports3DS",
|
|
204
|
+
];
|
|
205
|
+
const currencyCode = applePayConfig.currencyCode || "EUR";
|
|
206
|
+
const countryCode = applePayConfig.countryCode || "DE";
|
|
207
|
+
|
|
208
|
+
const applePayRequest = {
|
|
209
|
+
countryCode: countryCode,
|
|
210
|
+
currencyCode: currencyCode,
|
|
211
|
+
merchantCapabilities: merchantCapabilities,
|
|
212
|
+
supportedNetworks: supportedNetworks,
|
|
213
|
+
total: {
|
|
214
|
+
label: settings?.merchantName || "Total",
|
|
215
|
+
type: "final",
|
|
216
|
+
amount: amountValue,
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const session = new window.ApplePaySession(3, applePayRequest);
|
|
221
|
+
|
|
222
|
+
handleEventsForApplePay(session, amountValue, currencyCode);
|
|
223
|
+
|
|
224
|
+
session.begin();
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const mode = (settings?.mode || 'test').toLowerCase();
|
|
228
|
+
const isLiveMode = mode === 'live';
|
|
229
|
+
|
|
230
|
+
if (!settings?.mid) {
|
|
231
|
+
return (
|
|
232
|
+
<Box>
|
|
233
|
+
<Alert closeLabel="Close" title="Merchant ID Missing" variant="warning">
|
|
234
|
+
<Typography variant="pi" marginTop={2}>
|
|
235
|
+
Merchant ID is not configured. Please set Merchant ID in plugin
|
|
236
|
+
settings. You can find your merchantIdentifier in PMI at:
|
|
237
|
+
CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Payment type
|
|
238
|
+
configuration tab.
|
|
239
|
+
</Typography>
|
|
240
|
+
</Alert>
|
|
241
|
+
</Box>
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (!isLiveMode) {
|
|
246
|
+
return (
|
|
247
|
+
<Box>
|
|
248
|
+
<Alert closeLabel="Close" title="⚠️ Apple Pay Only Works in Live Mode" variant="danger">
|
|
249
|
+
<Typography variant="pi" marginTop={2}>
|
|
250
|
+
<strong>Apple Pay is only supported in live mode.</strong> According to Payone documentation, test mode support will be available at a later time.
|
|
251
|
+
</Typography>
|
|
252
|
+
<Typography variant="pi" marginTop={2}>
|
|
253
|
+
Please switch to <strong>live mode</strong> in plugin settings to use Apple Pay.
|
|
254
|
+
</Typography>
|
|
255
|
+
<Typography variant="pi" marginTop={2} fontWeight="bold" textColor="danger600">
|
|
256
|
+
⚠️ Apple Pay will NOT work in test mode!
|
|
257
|
+
</Typography>
|
|
258
|
+
</Alert>
|
|
259
|
+
</Box>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const buttonStyleMap = {
|
|
264
|
+
black: "black",
|
|
265
|
+
white: "white",
|
|
266
|
+
"white-outline": "white-outline",
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const buttonTypeMap = {
|
|
270
|
+
pay: "plain",
|
|
271
|
+
buy: "buy",
|
|
272
|
+
donate: "donate",
|
|
273
|
+
"check-out": "check-out",
|
|
274
|
+
book: "book",
|
|
275
|
+
subscribe: "subscribe",
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const nativeButtonStyle = buttonStyleMap[buttonStyle] || "black";
|
|
279
|
+
const nativeButtonType = buttonTypeMap[type] || "plain";
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<Box style={{ minHeight: "40px", width: "100%" }}>
|
|
283
|
+
<ApplePayButton
|
|
284
|
+
onClick={handleApplePayClick}
|
|
285
|
+
buttonStyle={nativeButtonStyle}
|
|
286
|
+
type={nativeButtonType}
|
|
287
|
+
style={{
|
|
288
|
+
width: "100%",
|
|
289
|
+
borderRadius: "8px",
|
|
290
|
+
}}
|
|
291
|
+
/>
|
|
292
|
+
<Typography
|
|
293
|
+
variant="pi"
|
|
294
|
+
textColor="neutral600"
|
|
295
|
+
style={{ fontSize: "12px", marginTop: "8px", marginRight: "6px" }}
|
|
296
|
+
>
|
|
297
|
+
Apple Pay does NOT work on localhost. Use a production domain with
|
|
298
|
+
HTTPS.
|
|
299
|
+
</Typography>
|
|
300
|
+
</Box>
|
|
301
|
+
);
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
export default ApplePayBtn;
|
|
@@ -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,25 +27,13 @@ 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:", {
|
|
@@ -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,
|
|
@@ -79,12 +56,8 @@ const ApplePayButton = ({
|
|
|
79
56
|
});
|
|
80
57
|
}
|
|
81
58
|
|
|
82
|
-
// First, check if Payment Request API is available
|
|
83
|
-
// Payment Request API works on HTTP too, but Apple Pay JS API requires HTTPS
|
|
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();
|
|
@@ -106,20 +79,17 @@ const ApplePayButton = ({
|
|
|
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,7 +117,6 @@ 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();
|
|
@@ -157,7 +126,6 @@ const ApplePayButton = ({
|
|
|
157
126
|
return { available: true, method: 'paymentRequest' };
|
|
158
127
|
}
|
|
159
128
|
|
|
160
|
-
// If PaymentRequest says no, try Apple Pay JS API as fallback (only on HTTPS)
|
|
161
129
|
if (typeof window !== 'undefined' && window.ApplePaySession && isSecure) {
|
|
162
130
|
try {
|
|
163
131
|
const canMakePaymentsJS = ApplePaySession.canMakePayments();
|
|
@@ -165,9 +133,7 @@ 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
|
}
|
|
@@ -177,7 +143,6 @@ const ApplePayButton = ({
|
|
|
177
143
|
} catch (e) {
|
|
178
144
|
console.error("[Apple Pay] Error checking canMakePayment:", e);
|
|
179
145
|
|
|
180
|
-
// If it's insecure context error, we can't use Apple Pay JS API
|
|
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' };
|
|
@@ -198,8 +163,6 @@ const ApplePayButton = ({
|
|
|
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';
|
|
@@ -220,14 +183,11 @@ const ApplePayButton = ({
|
|
|
220
183
|
} catch (error) {
|
|
221
184
|
console.error("[Apple Pay] Error checking availability:", error);
|
|
222
185
|
|
|
223
|
-
// Check if it's insecure context error
|
|
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
190
|
|
|
229
|
-
// Fallback: Try Apple Pay JS API (only on HTTPS)
|
|
230
|
-
// Re-check secure context
|
|
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';
|
|
@@ -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: {
|
|
@@ -773,7 +732,6 @@ const ApplePayButton = ({
|
|
|
773
732
|
}
|
|
774
733
|
};
|
|
775
734
|
|
|
776
|
-
// Validate merchant with Payone
|
|
777
735
|
const validateMerchantWithPayone = async (validationURL, config) => {
|
|
778
736
|
console.log("[Apple Pay] Validating merchant with Payone:", {
|
|
779
737
|
validationURL,
|