strapi-plugin-payone-provider 5.7.26 → 5.8.26

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.
Files changed (83) hide show
  1. package/README.md +1191 -1191
  2. package/admin/src/components/Initializer/index.jsx +16 -16
  3. package/admin/src/components/PluginIcon/index.jsx +17 -17
  4. package/admin/src/index.js +57 -57
  5. package/admin/src/pages/App/components/AppHeader.jsx +45 -45
  6. package/admin/src/pages/App/components/AppTabs.jsx +105 -105
  7. package/admin/src/pages/App/components/ApplePayBtn.jsx +355 -355
  8. package/admin/src/pages/App/components/ApplePayConfig.jsx +357 -357
  9. package/admin/src/pages/App/components/DocsPanel.jsx +53 -53
  10. package/admin/src/pages/App/components/RenderInput.jsx +78 -78
  11. package/admin/src/pages/App/components/StatusBadge.jsx +87 -87
  12. package/admin/src/pages/App/components/icons/BankIcon.jsx +10 -10
  13. package/admin/src/pages/App/components/icons/ChevronDownIcon.jsx +9 -9
  14. package/admin/src/pages/App/components/icons/ChevronUpIcon.jsx +9 -9
  15. package/admin/src/pages/App/components/icons/CreditCardIcon.jsx +9 -9
  16. package/admin/src/pages/App/components/icons/ErrorIcon.jsx +10 -10
  17. package/admin/src/pages/App/components/icons/InfoIcon.jsx +9 -9
  18. package/admin/src/pages/App/components/icons/MarkCircle.jsx +19 -19
  19. package/admin/src/pages/App/components/icons/PaymentIcon.jsx +10 -10
  20. package/admin/src/pages/App/components/icons/PendingIcon.jsx +9 -9
  21. package/admin/src/pages/App/components/icons/PersonIcon.jsx +9 -9
  22. package/admin/src/pages/App/components/icons/SuccessIcon.jsx +9 -9
  23. package/admin/src/pages/App/components/icons/WalletIcon.jsx +9 -9
  24. package/admin/src/pages/App/components/icons/index.jsx +12 -12
  25. package/admin/src/pages/App/components/payment-actions/AuthorizationForm.jsx +334 -334
  26. package/admin/src/pages/App/components/payment-actions/CaptureForm.jsx +120 -120
  27. package/admin/src/pages/App/components/payment-actions/PaymentActionsPanel.jsx +183 -183
  28. package/admin/src/pages/App/components/payment-actions/PaymentMethodSelector.jsx +315 -315
  29. package/admin/src/pages/App/components/payment-actions/PaymentResult.jsx +129 -129
  30. package/admin/src/pages/App/components/payment-actions/PreauthorizationForm.jsx +273 -273
  31. package/admin/src/pages/App/components/payment-actions/RefundForm.jsx +114 -114
  32. package/admin/src/pages/App/components/transaction-history/ImportExportBar.jsx +153 -153
  33. package/admin/src/pages/App/components/transaction-history/details/TransactionHistoryItem.jsx +526 -526
  34. package/admin/src/pages/App/index.jsx +96 -96
  35. package/admin/src/pages/App/styles.css +176 -176
  36. package/admin/src/pages/constants/paymentConstants.js +71 -71
  37. package/admin/src/pages/hooks/use-system-theme.js +27 -27
  38. package/admin/src/pages/hooks/usePaymentActions.js +498 -498
  39. package/admin/src/pages/hooks/usePluginTranslations.js +12 -12
  40. package/admin/src/pages/hooks/useSettings.js +183 -183
  41. package/admin/src/pages/hooks/useTransactionHistory.js +148 -148
  42. package/admin/src/pages/utils/api.js +97 -97
  43. package/admin/src/pages/utils/applePayConstants.js +196 -196
  44. package/admin/src/pages/utils/formatTransactionData.js +15 -15
  45. package/admin/src/pages/utils/getInputComponent.jsx +200 -200
  46. package/admin/src/pages/utils/paymentUtils.js +661 -661
  47. package/admin/src/pages/utils/tooltipHelpers.js +18 -18
  48. package/admin/src/pages/utils/transactionTableUtils.js +71 -71
  49. package/admin/src/pluginId.js +9 -9
  50. package/admin/src/translations/de.json +235 -235
  51. package/admin/src/translations/en.json +235 -235
  52. package/admin/src/translations/fr.json +235 -235
  53. package/admin/src/translations/ru.json +235 -235
  54. package/admin/src/utils/prefixPluginTranslations.js +13 -13
  55. package/package.json +45 -45
  56. package/server/bootstrap.js +107 -107
  57. package/server/config/index.js +83 -83
  58. package/server/content-types/index.js +4 -4
  59. package/server/content-types/transactions/index.js +4 -4
  60. package/server/content-types/transactions/schema.json +86 -86
  61. package/server/controllers/index.js +7 -7
  62. package/server/controllers/payone.js +503 -506
  63. package/server/destroy.js +5 -5
  64. package/server/index.js +23 -23
  65. package/server/policies/index.js +7 -7
  66. package/server/policies/is-auth.js +29 -29
  67. package/server/policies/isSuperAdmin.js +20 -20
  68. package/server/register.js +5 -5
  69. package/server/routes/index.js +218 -218
  70. package/server/services/applePayService.js +295 -295
  71. package/server/services/index.js +9 -9
  72. package/server/services/paymentService.js +264 -223
  73. package/server/services/payone.js +78 -78
  74. package/server/services/settingsService.js +59 -59
  75. package/server/services/testConnectionService.js +115 -115
  76. package/server/services/transactionService.js +262 -262
  77. package/server/utils/csvTransactions.js +82 -82
  78. package/server/utils/normalize.js +39 -39
  79. package/server/utils/paymentMethodParams.js +288 -288
  80. package/server/utils/requestBuilder.js +115 -100
  81. package/server/utils/responseParser.js +141 -141
  82. package/strapi-admin.js +4 -4
  83. package/strapi-server.js +3 -3
@@ -1,355 +1,355 @@
1
- import * as React from "react";
2
- import ApplePayButton from "apple-pay-button";
3
- import { Box, Typography, Alert } from "@strapi/design-system";
4
- import { getFetchClient } from "@strapi/strapi/admin";
5
- import pluginId from "../../../pluginId";
6
- import { usePluginTranslations } from "../../hooks/usePluginTranslations";
7
-
8
- const ApplePayBtn = ({
9
- amount,
10
- onTokenReceived,
11
- onError,
12
- settings,
13
- buttonStyle = "black",
14
- type = "pay",
15
- }) => {
16
- const { t } = usePluginTranslations();
17
- const handleEventsForApplePay = (session, amountValue, currencyCode) => {
18
- session.onvalidatemerchant = async (event) => {
19
- try {
20
- const applePayConfig = settings?.applePayConfig || {};
21
- const requestCurrency =
22
- currencyCode || applePayConfig.currencyCode || "EUR";
23
- const requestCountryCode = applePayConfig.countryCode || "DE";
24
-
25
- const { post } = getFetchClient();
26
- const merchantSession = await post(
27
- `/${pluginId}/validate-apple-pay-merchant`,
28
- {
29
- domainName: settings?.domainName || window.location.hostname,
30
- displayName: settings?.displayName || "Store",
31
- currency: requestCurrency,
32
- countryCode: requestCountryCode,
33
- mode: (settings?.mode || "test").toLowerCase() || "test",
34
- }
35
- );
36
- if (merchantSession.error) {
37
- const errorMessage =
38
- merchantSession.error.message || "Merchant validation failed";
39
- const errorDetails = merchantSession.error.details || "";
40
-
41
- console.log(
42
- `[Apple Pay] Merchant validation failed: ${errorMessage} ${errorDetails}`
43
- );
44
-
45
- throw new Error(
46
- errorMessage + (errorDetails ? ` - ${errorDetails}` : "")
47
- );
48
- }
49
-
50
- const sessionData = merchantSession.data || merchantSession;
51
-
52
- if (!sessionData || !sessionData.merchantIdentifier) {
53
- throw new Error(
54
- "Invalid merchant session: missing merchantIdentifier. " +
55
- "Please check your Payone Apple Pay configuration in PMI (CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Payment type configuration tab)."
56
- );
57
- }
58
-
59
- session.completeMerchantValidation(sessionData);
60
- } catch (error) {
61
- if (onError) {
62
- onError(error);
63
- }
64
-
65
- try {
66
- session.completeMerchantValidation({});
67
- } catch (completeError) {
68
- console.error(completeError);
69
- }
70
- }
71
- };
72
-
73
- session.onpaymentmethodselected = (event) => {
74
- const update = {
75
- newTotal: {
76
- label: settings?.merchantName || "Total",
77
- type: "final",
78
- amount: amountValue,
79
- },
80
- };
81
- session.completePaymentMethodSelection(update);
82
- };
83
-
84
- session.onshippingmethodselected = (event) => {
85
- const update = {
86
- newTotal: {
87
- label: settings?.merchantName || "Total",
88
- type: "final",
89
- amount: amountValue,
90
- },
91
- };
92
- session.completeShippingMethodSelection(update);
93
- };
94
-
95
- session.onshippingcontactselected = (event) => {
96
- const update = {
97
- newTotal: {
98
- label: settings?.merchantName || "Total",
99
- type: "final",
100
- amount: amountValue,
101
- },
102
- };
103
- session.completeShippingContactSelection(update);
104
- };
105
-
106
- session.onpaymentauthorized = async (event) => {
107
- try {
108
- const paymentData = event.payment;
109
-
110
- if (!paymentData || !paymentData.token) {
111
- const result = {
112
- status: window.ApplePaySession.STATUS_FAILURE,
113
- };
114
- session.completePayment(result);
115
- if (onError) {
116
- onError(new Error("Payment token is missing"));
117
- }
118
- return;
119
- }
120
-
121
- const tokenObject = paymentData.token;
122
-
123
- if (!tokenObject) {
124
- const result = {
125
- status: window.ApplePaySession.STATUS_FAILURE,
126
- };
127
- session.completePayment(result);
128
- if (onError) {
129
- onError(new Error("Payment token is missing"));
130
- }
131
- return;
132
- }
133
-
134
- if (!tokenObject.paymentData) {
135
- console.error(
136
- "[Apple Pay] Invalid token structure: missing paymentData",
137
- {
138
- tokenKeys: Object.keys(tokenObject),
139
- tokenStructure: JSON.stringify(tokenObject).substring(0, 500),
140
- }
141
- );
142
- const result = {
143
- status: window.ApplePaySession.STATUS_FAILURE,
144
- };
145
- session.completePayment(result);
146
- if (onError) {
147
- onError(
148
- new Error(
149
- "Invalid Apple Pay token structure: missing paymentData field"
150
- )
151
- );
152
- }
153
- return;
154
- }
155
-
156
- const paymentDataObj = tokenObject.paymentData;
157
- const header = paymentDataObj.header || {};
158
-
159
- console.log("[Apple Pay] Token structure validation:", {
160
- hasVersion: !!paymentDataObj.version,
161
- hasData: !!paymentDataObj.data,
162
- hasSignature: !!paymentDataObj.signature,
163
- hasHeader: !!paymentDataObj.header,
164
- hasEphemeralPublicKey: !!header.ephemeralPublicKey,
165
- hasPublicKeyHash: !!header.publicKeyHash,
166
- hasTransactionId:
167
- !!paymentDataObj.transactionId || !!header.transactionId,
168
- dataLength: paymentDataObj.data ? paymentDataObj.data.length : 0,
169
- signatureLength: paymentDataObj.signature
170
- ? paymentDataObj.signature.length
171
- : 0,
172
- });
173
-
174
- let tokenString;
175
- try {
176
- const tokenJson = JSON.stringify(tokenObject);
177
- tokenString = btoa(unescape(encodeURIComponent(tokenJson)));
178
- console.log("[Apple Pay] Token encoded successfully:", {
179
- tokenLength: tokenJson.length,
180
- encodedLength: tokenString.length,
181
- });
182
- } catch (e) {
183
- console.error("[Apple Pay] Error encoding token:", e);
184
- const result = {
185
- status: window.ApplePaySession.STATUS_FAILURE,
186
- };
187
- session.completePayment(result);
188
- if (onError) {
189
- onError(new Error(`Failed to encode token: ${e.message}`));
190
- }
191
- return;
192
- }
193
-
194
- if (onTokenReceived) {
195
- const result = await onTokenReceived(tokenString, {
196
- paymentToken: tokenObject,
197
- billingContact: paymentData.billingContact,
198
- shippingContact: paymentData.shippingContact,
199
- amount: amountValue, //
200
- currency: currencyCode,
201
- });
202
-
203
- if (result && typeof result.then === "function") {
204
- await result;
205
- }
206
-
207
- const paymentResult = {
208
- status: window.ApplePaySession.STATUS_SUCCESS,
209
- };
210
- session.completePayment(paymentResult);
211
- } else {
212
- const paymentResult = {
213
- status: window.ApplePaySession.STATUS_SUCCESS,
214
- };
215
- session.completePayment(paymentResult);
216
- }
217
- } catch (error) {
218
- const result = {
219
- status: window.ApplePaySession.STATUS_FAILURE,
220
- };
221
- session.completePayment(result);
222
- if (onError) {
223
- onError(error);
224
- }
225
- }
226
- };
227
-
228
- session.oncancel = (event) => {
229
- // Session cancelled by user
230
- };
231
- };
232
-
233
- const handleApplePayClick = () => {
234
- if (!settings?.mid) {
235
- const error = new Error(
236
- "Merchant ID is not configured. Please set Merchant ID in plugin settings."
237
- );
238
- if (onError) {
239
- onError(error);
240
- }
241
- return;
242
- }
243
-
244
- if (typeof window === "undefined" || !window.ApplePaySession) {
245
- if (onError) {
246
- onError(new Error("Apple Pay is not supported in this environment."));
247
- }
248
- return;
249
- }
250
-
251
- const amountValue = amount ? (parseFloat(amount) / 100).toFixed(2) : "0.00";
252
- const applePayConfig = settings?.applePayConfig || {};
253
- const supportedNetworks = applePayConfig.supportedNetworks || [
254
- "visa",
255
- "masterCard",
256
- "amex",
257
- ];
258
- const merchantCapabilities = applePayConfig.merchantCapabilities || [
259
- "supports3DS",
260
- ];
261
- const currencyCode = applePayConfig.currencyCode || "EUR";
262
- const countryCode = applePayConfig.countryCode || "DE";
263
-
264
- const applePayRequest = {
265
- countryCode: countryCode,
266
- currencyCode: currencyCode,
267
- merchantCapabilities: merchantCapabilities,
268
- supportedNetworks: supportedNetworks,
269
- total: {
270
- label: settings?.merchantName || "Total",
271
- type: "final",
272
- amount: amountValue,
273
- },
274
- };
275
-
276
- const session = new window.ApplePaySession(3, applePayRequest);
277
-
278
- handleEventsForApplePay(session, amountValue, currencyCode);
279
-
280
- session.begin();
281
- };
282
-
283
- const mode = (settings?.mode || "test").toLowerCase();
284
- const isLiveMode = mode === "live";
285
-
286
- if (!settings?.mid) {
287
- return (
288
- <Box>
289
- <Alert closeLabel="Close" title={t("applePayBtn.merchantIdMissingTitle", "Merchant ID Missing")} variant="warning">
290
- <Typography variant="pi" marginTop={2}>
291
- {t("applePayBtn.merchantIdMissing", "Merchant ID is not configured. Please set Merchant ID in plugin settings.")} {t("applePayBtn.merchantIdHint", "You can find your merchantIdentifier in PMI at: CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Payment type configuration tab.")}
292
- </Typography>
293
- </Alert>
294
- </Box>
295
- );
296
- }
297
-
298
- if (!isLiveMode) {
299
- return (
300
- <Box>
301
- <Alert
302
- closeLabel="Close"
303
- title={t("applePayBtn.liveModeOnly", "Apple Pay Only Works in Live Mode")}
304
- variant="danger"
305
- >
306
- <Typography variant="pi" marginTop={2}>
307
- {t("applePayBtn.liveModeMessage", "Apple Pay is only supported in live mode. According to Payone documentation, test mode support will be available at a later time.")}
308
- </Typography>
309
- <Typography variant="pi" style={{ marginLeft: "8px" }}>
310
- {t("applePayBtn.switchToLive", "Please switch to live mode in plugin settings to use Apple Pay.")}
311
- </Typography>
312
- </Alert>
313
- </Box>
314
- );
315
- }
316
-
317
- const buttonStyleMap = {
318
- black: "black",
319
- white: "white",
320
- "white-outline": "white-outline",
321
- };
322
-
323
- const buttonTypeMap = {
324
- pay: "plain",
325
- buy: "buy",
326
- donate: "donate",
327
- "check-out": "check-out",
328
- book: "book",
329
- subscribe: "subscribe",
330
- };
331
-
332
- const nativeButtonStyle = buttonStyleMap[buttonStyle] || "black";
333
- const nativeButtonType = buttonTypeMap[type] || "plain";
334
-
335
- return (
336
- <Box style={{ minHeight: "40px", width: "100%" }}>
337
- <ApplePayButton
338
- onClick={handleApplePayClick}
339
- buttonStyle={nativeButtonStyle}
340
- type={nativeButtonType}
341
- style={{ width: "220px", height: "40px" }}
342
- />
343
- <br /> <br />
344
- <Typography
345
- variant="pi"
346
- textColor="neutral600"
347
- style={{ fontSize: "12px", marginTop: "8px", marginRight: "6px" }}
348
- >
349
- {t("applePayBtn.noLocalhost", "Apple Pay does NOT work on localhost. Use a production domain with HTTPS.")}
350
- </Typography>
351
- </Box>
352
- );
353
- };
354
-
355
- export default ApplePayBtn;
1
+ import * as React from "react";
2
+ import ApplePayButton from "apple-pay-button";
3
+ import { Box, Typography, Alert } from "@strapi/design-system";
4
+ import { getFetchClient } from "@strapi/strapi/admin";
5
+ import pluginId from "../../../pluginId";
6
+ import { usePluginTranslations } from "../../hooks/usePluginTranslations";
7
+
8
+ const ApplePayBtn = ({
9
+ amount,
10
+ onTokenReceived,
11
+ onError,
12
+ settings,
13
+ buttonStyle = "black",
14
+ type = "pay",
15
+ }) => {
16
+ const { t } = usePluginTranslations();
17
+ const handleEventsForApplePay = (session, amountValue, currencyCode) => {
18
+ session.onvalidatemerchant = async (event) => {
19
+ try {
20
+ const applePayConfig = settings?.applePayConfig || {};
21
+ const requestCurrency =
22
+ currencyCode || applePayConfig.currencyCode || "EUR";
23
+ const requestCountryCode = applePayConfig.countryCode || "DE";
24
+
25
+ const { post } = getFetchClient();
26
+ const merchantSession = await post(
27
+ `/${pluginId}/validate-apple-pay-merchant`,
28
+ {
29
+ domainName: settings?.domainName || window.location.hostname,
30
+ displayName: settings?.displayName || "Store",
31
+ currency: requestCurrency,
32
+ countryCode: requestCountryCode,
33
+ mode: (settings?.mode || "test").toLowerCase() || "test",
34
+ }
35
+ );
36
+ if (merchantSession.error) {
37
+ const errorMessage =
38
+ merchantSession.error.message || "Merchant validation failed";
39
+ const errorDetails = merchantSession.error.details || "";
40
+
41
+ console.log(
42
+ `[Apple Pay] Merchant validation failed: ${errorMessage} ${errorDetails}`
43
+ );
44
+
45
+ throw new Error(
46
+ errorMessage + (errorDetails ? ` - ${errorDetails}` : "")
47
+ );
48
+ }
49
+
50
+ const sessionData = merchantSession.data || merchantSession;
51
+
52
+ if (!sessionData || !sessionData.merchantIdentifier) {
53
+ throw new Error(
54
+ "Invalid merchant session: missing merchantIdentifier. " +
55
+ "Please check your Payone Apple Pay configuration in PMI (CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Payment type configuration tab)."
56
+ );
57
+ }
58
+
59
+ session.completeMerchantValidation(sessionData);
60
+ } catch (error) {
61
+ if (onError) {
62
+ onError(error);
63
+ }
64
+
65
+ try {
66
+ session.completeMerchantValidation({});
67
+ } catch (completeError) {
68
+ console.error(completeError);
69
+ }
70
+ }
71
+ };
72
+
73
+ session.onpaymentmethodselected = (event) => {
74
+ const update = {
75
+ newTotal: {
76
+ label: settings?.merchantName || "Total",
77
+ type: "final",
78
+ amount: amountValue,
79
+ },
80
+ };
81
+ session.completePaymentMethodSelection(update);
82
+ };
83
+
84
+ session.onshippingmethodselected = (event) => {
85
+ const update = {
86
+ newTotal: {
87
+ label: settings?.merchantName || "Total",
88
+ type: "final",
89
+ amount: amountValue,
90
+ },
91
+ };
92
+ session.completeShippingMethodSelection(update);
93
+ };
94
+
95
+ session.onshippingcontactselected = (event) => {
96
+ const update = {
97
+ newTotal: {
98
+ label: settings?.merchantName || "Total",
99
+ type: "final",
100
+ amount: amountValue,
101
+ },
102
+ };
103
+ session.completeShippingContactSelection(update);
104
+ };
105
+
106
+ session.onpaymentauthorized = async (event) => {
107
+ try {
108
+ const paymentData = event.payment;
109
+
110
+ if (!paymentData || !paymentData.token) {
111
+ const result = {
112
+ status: window.ApplePaySession.STATUS_FAILURE,
113
+ };
114
+ session.completePayment(result);
115
+ if (onError) {
116
+ onError(new Error("Payment token is missing"));
117
+ }
118
+ return;
119
+ }
120
+
121
+ const tokenObject = paymentData.token;
122
+
123
+ if (!tokenObject) {
124
+ const result = {
125
+ status: window.ApplePaySession.STATUS_FAILURE,
126
+ };
127
+ session.completePayment(result);
128
+ if (onError) {
129
+ onError(new Error("Payment token is missing"));
130
+ }
131
+ return;
132
+ }
133
+
134
+ if (!tokenObject.paymentData) {
135
+ console.error(
136
+ "[Apple Pay] Invalid token structure: missing paymentData",
137
+ {
138
+ tokenKeys: Object.keys(tokenObject),
139
+ tokenStructure: JSON.stringify(tokenObject).substring(0, 500),
140
+ }
141
+ );
142
+ const result = {
143
+ status: window.ApplePaySession.STATUS_FAILURE,
144
+ };
145
+ session.completePayment(result);
146
+ if (onError) {
147
+ onError(
148
+ new Error(
149
+ "Invalid Apple Pay token structure: missing paymentData field"
150
+ )
151
+ );
152
+ }
153
+ return;
154
+ }
155
+
156
+ const paymentDataObj = tokenObject.paymentData;
157
+ const header = paymentDataObj.header || {};
158
+
159
+ console.log("[Apple Pay] Token structure validation:", {
160
+ hasVersion: !!paymentDataObj.version,
161
+ hasData: !!paymentDataObj.data,
162
+ hasSignature: !!paymentDataObj.signature,
163
+ hasHeader: !!paymentDataObj.header,
164
+ hasEphemeralPublicKey: !!header.ephemeralPublicKey,
165
+ hasPublicKeyHash: !!header.publicKeyHash,
166
+ hasTransactionId:
167
+ !!paymentDataObj.transactionId || !!header.transactionId,
168
+ dataLength: paymentDataObj.data ? paymentDataObj.data.length : 0,
169
+ signatureLength: paymentDataObj.signature
170
+ ? paymentDataObj.signature.length
171
+ : 0,
172
+ });
173
+
174
+ let tokenString;
175
+ try {
176
+ const tokenJson = JSON.stringify(tokenObject);
177
+ tokenString = btoa(unescape(encodeURIComponent(tokenJson)));
178
+ console.log("[Apple Pay] Token encoded successfully:", {
179
+ tokenLength: tokenJson.length,
180
+ encodedLength: tokenString.length,
181
+ });
182
+ } catch (e) {
183
+ console.error("[Apple Pay] Error encoding token:", e);
184
+ const result = {
185
+ status: window.ApplePaySession.STATUS_FAILURE,
186
+ };
187
+ session.completePayment(result);
188
+ if (onError) {
189
+ onError(new Error(`Failed to encode token: ${e.message}`));
190
+ }
191
+ return;
192
+ }
193
+
194
+ if (onTokenReceived) {
195
+ const result = await onTokenReceived(tokenString, {
196
+ paymentToken: tokenObject,
197
+ billingContact: paymentData.billingContact,
198
+ shippingContact: paymentData.shippingContact,
199
+ amount: amountValue, //
200
+ currency: currencyCode,
201
+ });
202
+
203
+ if (result && typeof result.then === "function") {
204
+ await result;
205
+ }
206
+
207
+ const paymentResult = {
208
+ status: window.ApplePaySession.STATUS_SUCCESS,
209
+ };
210
+ session.completePayment(paymentResult);
211
+ } else {
212
+ const paymentResult = {
213
+ status: window.ApplePaySession.STATUS_SUCCESS,
214
+ };
215
+ session.completePayment(paymentResult);
216
+ }
217
+ } catch (error) {
218
+ const result = {
219
+ status: window.ApplePaySession.STATUS_FAILURE,
220
+ };
221
+ session.completePayment(result);
222
+ if (onError) {
223
+ onError(error);
224
+ }
225
+ }
226
+ };
227
+
228
+ session.oncancel = (event) => {
229
+ // Session cancelled by user
230
+ };
231
+ };
232
+
233
+ const handleApplePayClick = () => {
234
+ if (!settings?.mid) {
235
+ const error = new Error(
236
+ "Merchant ID is not configured. Please set Merchant ID in plugin settings."
237
+ );
238
+ if (onError) {
239
+ onError(error);
240
+ }
241
+ return;
242
+ }
243
+
244
+ if (typeof window === "undefined" || !window.ApplePaySession) {
245
+ if (onError) {
246
+ onError(new Error("Apple Pay is not supported in this environment."));
247
+ }
248
+ return;
249
+ }
250
+
251
+ const amountValue = amount ? (parseFloat(amount) / 100).toFixed(2) : "0.00";
252
+ const applePayConfig = settings?.applePayConfig || {};
253
+ const supportedNetworks = applePayConfig.supportedNetworks || [
254
+ "visa",
255
+ "masterCard",
256
+ "amex",
257
+ ];
258
+ const merchantCapabilities = applePayConfig.merchantCapabilities || [
259
+ "supports3DS",
260
+ ];
261
+ const currencyCode = applePayConfig.currencyCode || "EUR";
262
+ const countryCode = applePayConfig.countryCode || "DE";
263
+
264
+ const applePayRequest = {
265
+ countryCode: countryCode,
266
+ currencyCode: currencyCode,
267
+ merchantCapabilities: merchantCapabilities,
268
+ supportedNetworks: supportedNetworks,
269
+ total: {
270
+ label: settings?.merchantName || "Total",
271
+ type: "final",
272
+ amount: amountValue,
273
+ },
274
+ };
275
+
276
+ const session = new window.ApplePaySession(3, applePayRequest);
277
+
278
+ handleEventsForApplePay(session, amountValue, currencyCode);
279
+
280
+ session.begin();
281
+ };
282
+
283
+ const mode = (settings?.mode || "test").toLowerCase();
284
+ const isLiveMode = mode === "live";
285
+
286
+ if (!settings?.mid) {
287
+ return (
288
+ <Box>
289
+ <Alert closeLabel="Close" title={t("applePayBtn.merchantIdMissingTitle", "Merchant ID Missing")} variant="warning">
290
+ <Typography variant="pi" marginTop={2}>
291
+ {t("applePayBtn.merchantIdMissing", "Merchant ID is not configured. Please set Merchant ID in plugin settings.")} {t("applePayBtn.merchantIdHint", "You can find your merchantIdentifier in PMI at: CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Payment type configuration tab.")}
292
+ </Typography>
293
+ </Alert>
294
+ </Box>
295
+ );
296
+ }
297
+
298
+ if (!isLiveMode) {
299
+ return (
300
+ <Box>
301
+ <Alert
302
+ closeLabel="Close"
303
+ title={t("applePayBtn.liveModeOnly", "Apple Pay Only Works in Live Mode")}
304
+ variant="danger"
305
+ >
306
+ <Typography variant="pi" marginTop={2}>
307
+ {t("applePayBtn.liveModeMessage", "Apple Pay is only supported in live mode. According to Payone documentation, test mode support will be available at a later time.")}
308
+ </Typography>
309
+ <Typography variant="pi" style={{ marginLeft: "8px" }}>
310
+ {t("applePayBtn.switchToLive", "Please switch to live mode in plugin settings to use Apple Pay.")}
311
+ </Typography>
312
+ </Alert>
313
+ </Box>
314
+ );
315
+ }
316
+
317
+ const buttonStyleMap = {
318
+ black: "black",
319
+ white: "white",
320
+ "white-outline": "white-outline",
321
+ };
322
+
323
+ const buttonTypeMap = {
324
+ pay: "plain",
325
+ buy: "buy",
326
+ donate: "donate",
327
+ "check-out": "check-out",
328
+ book: "book",
329
+ subscribe: "subscribe",
330
+ };
331
+
332
+ const nativeButtonStyle = buttonStyleMap[buttonStyle] || "black";
333
+ const nativeButtonType = buttonTypeMap[type] || "plain";
334
+
335
+ return (
336
+ <Box style={{ minHeight: "40px", width: "100%" }}>
337
+ <ApplePayButton
338
+ onClick={handleApplePayClick}
339
+ buttonStyle={nativeButtonStyle}
340
+ type={nativeButtonType}
341
+ style={{ width: "220px", height: "40px" }}
342
+ />
343
+ <br /> <br />
344
+ <Typography
345
+ variant="pi"
346
+ textColor="neutral600"
347
+ style={{ fontSize: "12px", marginTop: "8px", marginRight: "6px" }}
348
+ >
349
+ {t("applePayBtn.noLocalhost", "Apple Pay does NOT work on localhost. Use a production domain with HTTPS.")}
350
+ </Typography>
351
+ </Box>
352
+ );
353
+ };
354
+
355
+ export default ApplePayBtn;