strapi-plugin-payone-provider 5.7.24 → 5.7.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 +506 -451
  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 +223 -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 +100 -100
  81. package/server/utils/responseParser.js +141 -141
  82. package/strapi-admin.js +4 -4
  83. package/strapi-server.js +3 -3
@@ -1,498 +1,498 @@
1
- import * as React from "react";
2
- import { useNotification } from "@strapi/strapi/admin";
3
- import {
4
- getPreauthorizationParams,
5
- getAuthorizationParams,
6
- getCaptureParams,
7
- getRefundParams,
8
- generateLagOrderNumber,
9
- getValidCardExpiryDate,
10
- } from "../utils/paymentUtils";
11
- import { DEFAULT_PAYMENT_DATA } from "../constants/paymentConstants";
12
- import usePayoneRequests from "../utils/api";
13
- import {
14
- getLanguageForCountry,
15
- getCurrencyForCountry,
16
- } from "../utils/countryLanguageUtils";
17
-
18
- const usePaymentActions = () => {
19
- const { toggleNotification } = useNotification();
20
- const { getSettings, preauthorization, authorization, capture, refund } = usePayoneRequests();
21
- const [settings, setSettings] = React.useState({ enable3DSecure: false });
22
-
23
- React.useEffect(() => {
24
- const loadSettings = async () => {
25
- try {
26
- const response = await getSettings();
27
- if (response?.data) {
28
- setSettings(response.data);
29
- }
30
- } catch (error) {
31
- console.error("Error loading settings:", error);
32
- }
33
- };
34
- loadSettings();
35
- }, []);
36
-
37
- const generateOrderReference = () => {
38
- const sequence = 1000 + Math.floor((Date.now() % 99000));
39
- return generateLagOrderNumber(sequence);
40
- };
41
-
42
- const [paymentState, setPaymentState] = React.useState({
43
- paymentAmount: "1000",
44
- preauthReference: generateOrderReference(),
45
- authReference: generateOrderReference(),
46
- captureTxid: "",
47
- refundTxid: "",
48
- refundSequenceNumber: "2",
49
- refundReference: "",
50
- paymentMethod: "cc",
51
- captureMode: "full",
52
- googlePayToken: null,
53
- applePayToken: null,
54
- cardtype: "",
55
- cardpan: "",
56
- cardexpiredate: "",
57
- cardcvc2: "",
58
- currency: "EUR",
59
- firstname: "John",
60
- lastname: "Doe",
61
- email: "test@example.com",
62
- street: "Test Street 123",
63
- zip: "12345",
64
- city: "Test City",
65
- country: "DE",
66
- telephonenumber: "01752345678",
67
- salutation: "Herr",
68
- gender: "m",
69
- ip: "127.0.0.1",
70
- language: "de",
71
- customerIsPresent: "yes",
72
- narrativeText: "",
73
- invoiceid: "",
74
- shippingFirstname: "John",
75
- shippingLastname: "Doe",
76
- shippingStreet: "Test Street 123",
77
- shippingZip: "12345",
78
- shippingCity: "Test City",
79
- shippingCountry: "DE",
80
- successurl: "",
81
- errorurl: "",
82
- backurl: "",
83
- captureSequenceNumber: "1",
84
- captureCurrency: "EUR",
85
- refundCurrency: "EUR",
86
- });
87
-
88
- const handleFieldChange = (field, value) => {
89
- setPaymentState((prev) => {
90
- const newState = { ...prev, [field]: value };
91
-
92
- if (field === "country" && value) {
93
- const languageCode = getLanguageForCountry(value);
94
- const currencyCode = getCurrencyForCountry(value);
95
- newState.language = languageCode;
96
- newState.currency = currencyCode;
97
- newState.shippingCountry = value;
98
- }
99
-
100
- if (field === "firstname" && value) {
101
- newState.shippingFirstname = value;
102
- }
103
-
104
- if (field === "lastname" && value) {
105
- newState.shippingLastname = value;
106
- }
107
-
108
- if (field === "street" && value) {
109
- newState.shippingStreet = value;
110
- }
111
-
112
- return newState;
113
- });
114
- };
115
-
116
- const [isProcessingPayment, setIsProcessingPayment] = React.useState(false);
117
- const [paymentResult, setPaymentResult] = React.useState(null);
118
- const [paymentError, setPaymentError] = React.useState(null);
119
-
120
- const handlePaymentError = (errorMessage) => {
121
- const defaultMessage = "Payment failed. Please check the error message and try again.";
122
- setPaymentError(errorMessage || defaultMessage);
123
- toggleNotification({
124
- type: "danger",
125
- message: errorMessage || defaultMessage
126
- });
127
- };
128
-
129
- const handlePaymentSuccess = (message) => {
130
- toggleNotification({
131
- type: "success",
132
- message
133
- });
134
- };
135
-
136
- const handlePreauthorization = async (tokenParam = null) => {
137
- setIsProcessingPayment(true);
138
- setPaymentError(null);
139
- setPaymentResult(null);
140
- try {
141
- const finalPreauthReference = generateOrderReference();
142
- handleFieldChange("preauthReference", finalPreauthReference);
143
-
144
- const finalCurrency = paymentState.currency || ((paymentState.paymentMethod === "cc" && paymentState.cardtype === "A") ? "USD" : "EUR");
145
- const finalInvoiceid = paymentState.invoiceid || finalPreauthReference;
146
- const finalNarrativeText = paymentState.narrativeText || ("Preauthorization for order " + finalPreauthReference);
147
-
148
- const baseParams = {
149
- amount: parseInt(paymentState.paymentAmount),
150
- currency: finalCurrency,
151
- reference: finalPreauthReference,
152
- enable3DSecure: settings.enable3DSecure !== false,
153
- invoiceid: finalInvoiceid,
154
- narrative_text: finalNarrativeText,
155
- firstname: paymentState.firstname || DEFAULT_PAYMENT_DATA.firstname,
156
- lastname: paymentState.lastname || DEFAULT_PAYMENT_DATA.lastname,
157
- email: paymentState.email || DEFAULT_PAYMENT_DATA.email,
158
- street: paymentState.street || DEFAULT_PAYMENT_DATA.street,
159
- zip: paymentState.zip || DEFAULT_PAYMENT_DATA.zip,
160
- city: paymentState.city || DEFAULT_PAYMENT_DATA.city,
161
- country: paymentState.country || DEFAULT_PAYMENT_DATA.country,
162
- telephonenumber: paymentState.telephonenumber || DEFAULT_PAYMENT_DATA.telephonenumber,
163
- salutation: paymentState.salutation || DEFAULT_PAYMENT_DATA.salutation,
164
- gender: paymentState.gender || DEFAULT_PAYMENT_DATA.gender,
165
- ip: paymentState.ip || DEFAULT_PAYMENT_DATA.ip,
166
- language: paymentState.language || DEFAULT_PAYMENT_DATA.language,
167
- customer_is_present: paymentState.customerIsPresent || DEFAULT_PAYMENT_DATA.customer_is_present,
168
- shipping_firstname: paymentState.shippingFirstname || paymentState.firstname || DEFAULT_PAYMENT_DATA.firstname,
169
- shipping_lastname: paymentState.shippingLastname || paymentState.lastname || DEFAULT_PAYMENT_DATA.lastname,
170
- shipping_street: paymentState.shippingStreet || paymentState.street || DEFAULT_PAYMENT_DATA.street,
171
- shipping_zip: paymentState.shippingZip || paymentState.zip || DEFAULT_PAYMENT_DATA.zip,
172
- shipping_city: paymentState.shippingCity || paymentState.city || DEFAULT_PAYMENT_DATA.city,
173
- shipping_country: paymentState.shippingCountry || paymentState.country || DEFAULT_PAYMENT_DATA.country,
174
- };
175
-
176
- if (paymentState.paymentMethod === "cc" && settings.enable3DSecure !== false) {
177
- if (paymentState.cardtype) baseParams.cardtype = paymentState.cardtype;
178
- if (paymentState.cardpan) baseParams.cardpan = paymentState.cardpan;
179
- baseParams.cardexpiredate = getValidCardExpiryDate(paymentState.cardexpiredate);
180
- if (paymentState.cardcvc2) baseParams.cardcvc2 = paymentState.cardcvc2;
181
- }
182
-
183
- const needsRedirectUrls =
184
- (paymentState.paymentMethod === "cc" && settings.enable3DSecure !== false) ||
185
- ["wlt", "gpp", "apl", "sb"].includes(paymentState.paymentMethod);
186
-
187
- if (needsRedirectUrls) {
188
- const baseUrl = window.location.origin;
189
- const currentPath = window.location.pathname;
190
- const isContentUI = currentPath.includes('/content-ui') || currentPath.includes('/content-manager');
191
- const basePath = isContentUI ? '/content-ui' : '/admin';
192
- const pluginPath = '/plugins/strapi-plugin-payone-provider/payment';
193
-
194
- baseParams.successurl = `${baseUrl}${basePath}${pluginPath}/success`;
195
- baseParams.errorurl = `${baseUrl}${basePath}${pluginPath}/error`;
196
- baseParams.backurl = `${baseUrl}${basePath}${pluginPath}/back`;
197
- }
198
-
199
- const tokenToUse = tokenParam || paymentState.googlePayToken || paymentState.applePayToken;
200
- if (paymentState.paymentMethod === "gpp" && tokenToUse) {
201
- baseParams.googlePayToken = tokenToUse;
202
- baseParams.settings = settings;
203
- } else if (paymentState.paymentMethod === "apl" && tokenToUse) {
204
- baseParams.applePayToken = tokenToUse;
205
- baseParams.settings = settings;
206
- }
207
-
208
- const params = getPreauthorizationParams(paymentState.paymentMethod, baseParams);
209
-
210
- const result = await preauthorization(params);
211
- const responseData = result?.data || result;
212
- const status = responseData?.Status || null;
213
- const errorCode = responseData?.errorCode || null;
214
- const errorMessage = responseData?.errorMessage || null;
215
- const requires3DSErrorCodes = ["4219", 4219];
216
- const is3DSRequiredError = requires3DSErrorCodes.includes(errorCode);
217
- const redirectUrl = responseData?.redirectUrl || null;
218
-
219
- if (is3DSRequiredError && !redirectUrl) {
220
- handlePaymentError(
221
- errorMessage + " " +
222
- (`Error code: ${errorCode || "Unknown"}`)
223
- );
224
- setPaymentResult(responseData);
225
- return { success: false, data: responseData };
226
- }
227
-
228
- if ((status === "ERROR" || status === "INVALID" || errorCode) && !is3DSRequiredError) {
229
- handlePaymentError(
230
- errorMessage + " " +
231
- (`Error code: ${errorCode || "Unknown"}`)
232
- );
233
- setPaymentResult(responseData);
234
- return { success: false, data: responseData };
235
- }
236
-
237
- const needsRedirect = responseData.requires3DSRedirect ||
238
- (status === "REDIRECT" && redirectUrl) ||
239
- (is3DSRequiredError && redirectUrl);
240
-
241
- if (needsRedirect && redirectUrl) {
242
- window.location.href = redirectUrl;
243
- return;
244
- }
245
-
246
- setPaymentResult(responseData);
247
-
248
- if (status === "APPROVED") {
249
- handlePaymentSuccess("Preauthorization completed successfully");
250
- return { success: true, data: responseData };
251
- } else {
252
- const errorMsg = errorMessage || `Unexpected status: ${status}`;
253
- handlePaymentError(
254
- errorMsg + "Preauthorization completed with status: ${status}"
255
- );
256
-
257
- return { success: false, data: responseData };
258
- }
259
- } catch (error) {
260
- const errorMessage = error.message || "Preauthorization failed";
261
- handlePaymentError(errorMessage);
262
- return { success: false, data: error };
263
- } finally {
264
- setIsProcessingPayment(false);
265
- }
266
- };
267
-
268
- const handleAuthorization = async (tokenParam = null) => {
269
- setIsProcessingPayment(true);
270
- setPaymentError(null);
271
- setPaymentResult(null);
272
-
273
- try {
274
- const finalAuthReference = generateOrderReference();
275
- handleFieldChange("authReference", finalAuthReference);
276
-
277
- const finalCurrency = paymentState.currency || ((paymentState.paymentMethod === "cc" && paymentState.cardtype === "A") ? "USD" : "EUR");
278
- const finalInvoiceid = paymentState.invoiceid || finalAuthReference;
279
- const finalNarrativeText = paymentState.narrativeText || ("Authorization for order " + finalAuthReference);
280
-
281
- const baseParams = {
282
- amount: parseInt(paymentState.paymentAmount),
283
- currency: finalCurrency,
284
- reference: finalAuthReference,
285
- enable3DSecure: settings.enable3DSecure !== false,
286
- invoiceid: finalInvoiceid,
287
- narrative_text: finalNarrativeText,
288
- firstname: paymentState.firstname || DEFAULT_PAYMENT_DATA.firstname,
289
- lastname: paymentState.lastname || DEFAULT_PAYMENT_DATA.lastname,
290
- email: paymentState.email || DEFAULT_PAYMENT_DATA.email,
291
- street: paymentState.street || DEFAULT_PAYMENT_DATA.street,
292
- zip: paymentState.zip || DEFAULT_PAYMENT_DATA.zip,
293
- city: paymentState.city || DEFAULT_PAYMENT_DATA.city,
294
- country: paymentState.country || DEFAULT_PAYMENT_DATA.country,
295
- telephonenumber: paymentState.telephonenumber || DEFAULT_PAYMENT_DATA.telephonenumber,
296
- salutation: paymentState.salutation || DEFAULT_PAYMENT_DATA.salutation,
297
- gender: paymentState.gender || DEFAULT_PAYMENT_DATA.gender,
298
- ip: paymentState.ip || DEFAULT_PAYMENT_DATA.ip,
299
- language: paymentState.language || DEFAULT_PAYMENT_DATA.language,
300
- customer_is_present: paymentState.customerIsPresent || DEFAULT_PAYMENT_DATA.customer_is_present,
301
- shipping_firstname: paymentState.shippingFirstname || paymentState.firstname || DEFAULT_PAYMENT_DATA.firstname,
302
- shipping_lastname: paymentState.shippingLastname || paymentState.lastname || DEFAULT_PAYMENT_DATA.lastname,
303
- shipping_street: paymentState.shippingStreet || paymentState.street || DEFAULT_PAYMENT_DATA.street,
304
- shipping_zip: paymentState.shippingZip || paymentState.zip || DEFAULT_PAYMENT_DATA.zip,
305
- shipping_city: paymentState.shippingCity || paymentState.city || DEFAULT_PAYMENT_DATA.city,
306
- shipping_country: paymentState.shippingCountry || paymentState.country || DEFAULT_PAYMENT_DATA.country,
307
- };
308
-
309
- if (paymentState.paymentMethod === "cc" && settings.enable3DSecure !== false) {
310
- if (paymentState.cardtype) baseParams.cardtype = paymentState.cardtype;
311
- if (paymentState.cardpan) baseParams.cardpan = paymentState.cardpan;
312
- baseParams.cardexpiredate = getValidCardExpiryDate(paymentState.cardexpiredate);
313
- if (paymentState.cardcvc2) baseParams.cardcvc2 = paymentState.cardcvc2;
314
- }
315
-
316
- const needsRedirectUrls =
317
- (paymentState.paymentMethod === "cc" && settings.enable3DSecure !== false) ||
318
- ["wlt", "gpp", "apl", "sb"].includes(paymentState.paymentMethod);
319
-
320
- if (needsRedirectUrls) {
321
- if (paymentState.successurl) {
322
- baseParams.successurl = paymentState.successurl;
323
- } else {
324
- const baseUrl = window.location.origin;
325
- const currentPath = window.location.pathname;
326
- const isContentUI = currentPath.includes('/content-ui') || currentPath.includes('/content-manager');
327
- const basePath = isContentUI ? '/content-ui' : '/admin';
328
- const pluginPath = '/plugins/strapi-plugin-payone-provider/payment';
329
- baseParams.successurl = `${baseUrl}${basePath}${pluginPath}/success`;
330
- }
331
-
332
- if (paymentState.errorurl) {
333
- baseParams.errorurl = paymentState.errorurl;
334
- } else {
335
- const baseUrl = window.location.origin;
336
- const currentPath = window.location.pathname;
337
- const isContentUI = currentPath.includes('/content-ui') || currentPath.includes('/content-manager');
338
- const basePath = isContentUI ? '/content-ui' : '/admin';
339
- const pluginPath = '/plugins/strapi-plugin-payone-provider/payment';
340
- baseParams.errorurl = `${baseUrl}${basePath}${pluginPath}/error`;
341
- }
342
-
343
- if (paymentState.backurl) {
344
- baseParams.backurl = paymentState.backurl;
345
- } else {
346
- const baseUrl = window.location.origin;
347
- const currentPath = window.location.pathname;
348
- const isContentUI = currentPath.includes('/content-ui') || currentPath.includes('/content-manager');
349
- const basePath = isContentUI ? '/content-ui' : '/admin';
350
- const pluginPath = '/plugins/strapi-plugin-payone-provider/payment';
351
- baseParams.backurl = `${baseUrl}${basePath}${pluginPath}/back`;
352
- }
353
- }
354
-
355
- const tokenToUse = tokenParam || paymentState.googlePayToken || paymentState.applePayToken;
356
- if (paymentState.paymentMethod === "gpp" && tokenToUse) {
357
- baseParams.googlePayToken = tokenToUse;
358
- baseParams.settings = settings;
359
- } else if (paymentState.paymentMethod === "apl" && tokenToUse) {
360
- baseParams.applePayToken = tokenToUse;
361
- baseParams.settings = settings;
362
- }
363
-
364
- const params = getAuthorizationParams(paymentState.paymentMethod, baseParams);
365
- const result = await authorization(params);
366
-
367
- const responseData = result?.data || result;
368
- const status = responseData?.Status || null;
369
- const errorCode = responseData?.errorCode || null;
370
- const errorMessage = responseData?.errorMessage || null;
371
- const requires3DSErrorCodes = ["4219", 4219];
372
- const is3DSRequiredError = requires3DSErrorCodes.includes(errorCode);
373
- const redirectUrl = responseData?.redirectUrl || null;
374
-
375
-
376
- if (is3DSRequiredError && !redirectUrl) {
377
- handlePaymentError(
378
- errorMessage + " " +
379
- (`Error code: ${errorCode || "Unknown"}`)
380
- );
381
- setPaymentResult(responseData);
382
- return { success: false, data: responseData };
383
- }
384
-
385
- if ((status === "ERROR" || status === "INVALID" || errorCode) && !is3DSRequiredError) {
386
- handlePaymentError(
387
- errorMessage + " " +
388
- (`Error code: ${errorCode || "Unknown"}`)
389
- );
390
- setPaymentResult(responseData);
391
- return { success: false, data: responseData };
392
- }
393
-
394
- const needsRedirect = responseData.requires3DSRedirect ||
395
- (status === "REDIRECT" && redirectUrl) ||
396
- (is3DSRequiredError && redirectUrl);
397
-
398
- if (needsRedirect && redirectUrl) {
399
- window.location.href = redirectUrl;
400
- return;
401
- }
402
-
403
- setPaymentResult(responseData);
404
-
405
- if (status === "APPROVED") {
406
- handlePaymentSuccess("Authorization completed successfully");
407
- return { success: true, data: responseData };
408
- } else {
409
- const errorMsg = errorMessage + `Unexpected status: ${status}`;
410
- handlePaymentError(
411
- errorMsg + "Authorization completed with status: ${status}"
412
- );
413
- return { success: false, data: responseData };
414
- }
415
- } catch (error) {
416
- const errorMessage = error.message || "Authorization failed";
417
- handlePaymentError(errorMessage);
418
- return { success: false, data: error };
419
- } finally {
420
- setIsProcessingPayment(false);
421
- }
422
- };
423
-
424
- const handleCapture = async () => {
425
- if (!paymentState.captureTxid.trim()) {
426
- handlePaymentError("Transaction ID is required for capture");
427
- return { success: false, data: "Transaction ID is required for capture" };
428
- }
429
- setIsProcessingPayment(true);
430
- setPaymentError(null);
431
- setPaymentResult(null);
432
- try {
433
- const params = getCaptureParams(paymentState.paymentMethod, {
434
- txid: paymentState.captureTxid,
435
- amount: parseInt(paymentState.paymentAmount),
436
- currency: paymentState.captureCurrency || "EUR",
437
- captureMode: paymentState.captureMode,
438
- sequencenumber: parseInt(paymentState.captureSequenceNumber) || 1
439
- });
440
-
441
- const result = await capture(params);
442
- setPaymentResult(result);
443
- handlePaymentSuccess("Capture completed successfully");
444
- return { success: true, data: result };
445
- } catch (error) {
446
- const errorMessage = error.message || "Capture failed";
447
- handlePaymentError(errorMessage);
448
- return { success: false, data: error };
449
- } finally {
450
- setIsProcessingPayment(false);
451
- }
452
- };
453
-
454
- const handleRefund = async () => {
455
- if (!paymentState.refundTxid.trim()) {
456
- handlePaymentError("Transaction ID is required for refund");
457
- return { success: false, data: "Transaction ID is required for refund" };
458
- }
459
- setIsProcessingPayment(true);
460
- setPaymentError(null);
461
- setPaymentResult(null);
462
- try {
463
- const params = getRefundParams(paymentState.paymentMethod, {
464
- txid: paymentState.refundTxid,
465
- sequencenumber: parseInt(paymentState.refundSequenceNumber),
466
- amount: parseInt(paymentState.paymentAmount),
467
- currency: paymentState.refundCurrency || "EUR",
468
- reference: paymentState.refundReference || `REFUND-${Date.now()}`
469
- });
470
-
471
- const result = await refund(params);
472
- setPaymentResult(result);
473
- handlePaymentSuccess("Refund completed successfully");
474
- return { success: true, data: result };
475
- } catch (error) {
476
- const errorMessage = error.message || "Refund failed";
477
- handlePaymentError(errorMessage);
478
- return { success: false, data: error };
479
- } finally {
480
- setIsProcessingPayment(false);
481
- }
482
- };
483
-
484
- return {
485
- paymentState,
486
- handleFieldChange,
487
- isProcessingPayment,
488
- paymentResult,
489
- paymentError,
490
- handlePreauthorization,
491
- handleAuthorization,
492
- handleCapture,
493
- handleRefund,
494
- };
495
- };
496
-
497
- export default usePaymentActions;
498
-
1
+ import * as React from "react";
2
+ import { useNotification } from "@strapi/strapi/admin";
3
+ import {
4
+ getPreauthorizationParams,
5
+ getAuthorizationParams,
6
+ getCaptureParams,
7
+ getRefundParams,
8
+ generateLagOrderNumber,
9
+ getValidCardExpiryDate,
10
+ } from "../utils/paymentUtils";
11
+ import { DEFAULT_PAYMENT_DATA } from "../constants/paymentConstants";
12
+ import usePayoneRequests from "../utils/api";
13
+ import {
14
+ getLanguageForCountry,
15
+ getCurrencyForCountry,
16
+ } from "../utils/countryLanguageUtils";
17
+
18
+ const usePaymentActions = () => {
19
+ const { toggleNotification } = useNotification();
20
+ const { getSettings, preauthorization, authorization, capture, refund } = usePayoneRequests();
21
+ const [settings, setSettings] = React.useState({ enable3DSecure: false });
22
+
23
+ React.useEffect(() => {
24
+ const loadSettings = async () => {
25
+ try {
26
+ const response = await getSettings();
27
+ if (response?.data) {
28
+ setSettings(response.data);
29
+ }
30
+ } catch (error) {
31
+ console.error("Error loading settings:", error);
32
+ }
33
+ };
34
+ loadSettings();
35
+ }, []);
36
+
37
+ const generateOrderReference = () => {
38
+ const sequence = 1000 + Math.floor((Date.now() % 99000));
39
+ return generateLagOrderNumber(sequence);
40
+ };
41
+
42
+ const [paymentState, setPaymentState] = React.useState({
43
+ paymentAmount: "1000",
44
+ preauthReference: generateOrderReference(),
45
+ authReference: generateOrderReference(),
46
+ captureTxid: "",
47
+ refundTxid: "",
48
+ refundSequenceNumber: "2",
49
+ refundReference: "",
50
+ paymentMethod: "cc",
51
+ captureMode: "full",
52
+ googlePayToken: null,
53
+ applePayToken: null,
54
+ cardtype: "",
55
+ cardpan: "",
56
+ cardexpiredate: "",
57
+ cardcvc2: "",
58
+ currency: "EUR",
59
+ firstname: "John",
60
+ lastname: "Doe",
61
+ email: "test@example.com",
62
+ street: "Test Street 123",
63
+ zip: "12345",
64
+ city: "Test City",
65
+ country: "DE",
66
+ telephonenumber: "01752345678",
67
+ salutation: "Herr",
68
+ gender: "m",
69
+ ip: "127.0.0.1",
70
+ language: "de",
71
+ customerIsPresent: "yes",
72
+ narrativeText: "",
73
+ invoiceid: "",
74
+ shippingFirstname: "John",
75
+ shippingLastname: "Doe",
76
+ shippingStreet: "Test Street 123",
77
+ shippingZip: "12345",
78
+ shippingCity: "Test City",
79
+ shippingCountry: "DE",
80
+ successurl: "",
81
+ errorurl: "",
82
+ backurl: "",
83
+ captureSequenceNumber: "1",
84
+ captureCurrency: "EUR",
85
+ refundCurrency: "EUR",
86
+ });
87
+
88
+ const handleFieldChange = (field, value) => {
89
+ setPaymentState((prev) => {
90
+ const newState = { ...prev, [field]: value };
91
+
92
+ if (field === "country" && value) {
93
+ const languageCode = getLanguageForCountry(value);
94
+ const currencyCode = getCurrencyForCountry(value);
95
+ newState.language = languageCode;
96
+ newState.currency = currencyCode;
97
+ newState.shippingCountry = value;
98
+ }
99
+
100
+ if (field === "firstname" && value) {
101
+ newState.shippingFirstname = value;
102
+ }
103
+
104
+ if (field === "lastname" && value) {
105
+ newState.shippingLastname = value;
106
+ }
107
+
108
+ if (field === "street" && value) {
109
+ newState.shippingStreet = value;
110
+ }
111
+
112
+ return newState;
113
+ });
114
+ };
115
+
116
+ const [isProcessingPayment, setIsProcessingPayment] = React.useState(false);
117
+ const [paymentResult, setPaymentResult] = React.useState(null);
118
+ const [paymentError, setPaymentError] = React.useState(null);
119
+
120
+ const handlePaymentError = (errorMessage) => {
121
+ const defaultMessage = "Payment failed. Please check the error message and try again.";
122
+ setPaymentError(errorMessage || defaultMessage);
123
+ toggleNotification({
124
+ type: "danger",
125
+ message: errorMessage || defaultMessage
126
+ });
127
+ };
128
+
129
+ const handlePaymentSuccess = (message) => {
130
+ toggleNotification({
131
+ type: "success",
132
+ message
133
+ });
134
+ };
135
+
136
+ const handlePreauthorization = async (tokenParam = null) => {
137
+ setIsProcessingPayment(true);
138
+ setPaymentError(null);
139
+ setPaymentResult(null);
140
+ try {
141
+ const finalPreauthReference = generateOrderReference();
142
+ handleFieldChange("preauthReference", finalPreauthReference);
143
+
144
+ const finalCurrency = paymentState.currency || ((paymentState.paymentMethod === "cc" && paymentState.cardtype === "A") ? "USD" : "EUR");
145
+ const finalInvoiceid = paymentState.invoiceid || finalPreauthReference;
146
+ const finalNarrativeText = paymentState.narrativeText || ("Preauthorization for order " + finalPreauthReference);
147
+
148
+ const baseParams = {
149
+ amount: parseInt(paymentState.paymentAmount),
150
+ currency: finalCurrency,
151
+ reference: finalPreauthReference,
152
+ enable3DSecure: settings.enable3DSecure !== false,
153
+ invoiceid: finalInvoiceid,
154
+ narrative_text: finalNarrativeText,
155
+ firstname: paymentState.firstname || DEFAULT_PAYMENT_DATA.firstname,
156
+ lastname: paymentState.lastname || DEFAULT_PAYMENT_DATA.lastname,
157
+ email: paymentState.email || DEFAULT_PAYMENT_DATA.email,
158
+ street: paymentState.street || DEFAULT_PAYMENT_DATA.street,
159
+ zip: paymentState.zip || DEFAULT_PAYMENT_DATA.zip,
160
+ city: paymentState.city || DEFAULT_PAYMENT_DATA.city,
161
+ country: paymentState.country || DEFAULT_PAYMENT_DATA.country,
162
+ telephonenumber: paymentState.telephonenumber || DEFAULT_PAYMENT_DATA.telephonenumber,
163
+ salutation: paymentState.salutation || DEFAULT_PAYMENT_DATA.salutation,
164
+ gender: paymentState.gender || DEFAULT_PAYMENT_DATA.gender,
165
+ ip: paymentState.ip || DEFAULT_PAYMENT_DATA.ip,
166
+ language: paymentState.language || DEFAULT_PAYMENT_DATA.language,
167
+ customer_is_present: paymentState.customerIsPresent || DEFAULT_PAYMENT_DATA.customer_is_present,
168
+ shipping_firstname: paymentState.shippingFirstname || paymentState.firstname || DEFAULT_PAYMENT_DATA.firstname,
169
+ shipping_lastname: paymentState.shippingLastname || paymentState.lastname || DEFAULT_PAYMENT_DATA.lastname,
170
+ shipping_street: paymentState.shippingStreet || paymentState.street || DEFAULT_PAYMENT_DATA.street,
171
+ shipping_zip: paymentState.shippingZip || paymentState.zip || DEFAULT_PAYMENT_DATA.zip,
172
+ shipping_city: paymentState.shippingCity || paymentState.city || DEFAULT_PAYMENT_DATA.city,
173
+ shipping_country: paymentState.shippingCountry || paymentState.country || DEFAULT_PAYMENT_DATA.country,
174
+ };
175
+
176
+ if (paymentState.paymentMethod === "cc" && settings.enable3DSecure !== false) {
177
+ if (paymentState.cardtype) baseParams.cardtype = paymentState.cardtype;
178
+ if (paymentState.cardpan) baseParams.cardpan = paymentState.cardpan;
179
+ baseParams.cardexpiredate = getValidCardExpiryDate(paymentState.cardexpiredate);
180
+ if (paymentState.cardcvc2) baseParams.cardcvc2 = paymentState.cardcvc2;
181
+ }
182
+
183
+ const needsRedirectUrls =
184
+ (paymentState.paymentMethod === "cc" && settings.enable3DSecure !== false) ||
185
+ ["wlt", "gpp", "apl", "sb"].includes(paymentState.paymentMethod);
186
+
187
+ if (needsRedirectUrls) {
188
+ const baseUrl = window.location.origin;
189
+ const currentPath = window.location.pathname;
190
+ const isContentUI = currentPath.includes('/content-ui') || currentPath.includes('/content-manager');
191
+ const basePath = isContentUI ? '/content-ui' : '/admin';
192
+ const pluginPath = '/plugins/strapi-plugin-payone-provider/payment';
193
+
194
+ baseParams.successurl = `${baseUrl}${basePath}${pluginPath}/success`;
195
+ baseParams.errorurl = `${baseUrl}${basePath}${pluginPath}/error`;
196
+ baseParams.backurl = `${baseUrl}${basePath}${pluginPath}/back`;
197
+ }
198
+
199
+ const tokenToUse = tokenParam || paymentState.googlePayToken || paymentState.applePayToken;
200
+ if (paymentState.paymentMethod === "gpp" && tokenToUse) {
201
+ baseParams.googlePayToken = tokenToUse;
202
+ baseParams.settings = settings;
203
+ } else if (paymentState.paymentMethod === "apl" && tokenToUse) {
204
+ baseParams.applePayToken = tokenToUse;
205
+ baseParams.settings = settings;
206
+ }
207
+
208
+ const params = getPreauthorizationParams(paymentState.paymentMethod, baseParams);
209
+
210
+ const result = await preauthorization(params);
211
+ const responseData = result?.data || result;
212
+ const status = responseData?.Status || null;
213
+ const errorCode = responseData?.errorCode || null;
214
+ const errorMessage = responseData?.errorMessage || null;
215
+ const requires3DSErrorCodes = ["4219", 4219];
216
+ const is3DSRequiredError = requires3DSErrorCodes.includes(errorCode);
217
+ const redirectUrl = responseData?.redirectUrl || null;
218
+
219
+ if (is3DSRequiredError && !redirectUrl) {
220
+ handlePaymentError(
221
+ errorMessage + " " +
222
+ (`Error code: ${errorCode || "Unknown"}`)
223
+ );
224
+ setPaymentResult(responseData);
225
+ return { success: false, data: responseData };
226
+ }
227
+
228
+ if ((status === "ERROR" || status === "INVALID" || errorCode) && !is3DSRequiredError) {
229
+ handlePaymentError(
230
+ errorMessage + " " +
231
+ (`Error code: ${errorCode || "Unknown"}`)
232
+ );
233
+ setPaymentResult(responseData);
234
+ return { success: false, data: responseData };
235
+ }
236
+
237
+ const needsRedirect = responseData.requires3DSRedirect ||
238
+ (status === "REDIRECT" && redirectUrl) ||
239
+ (is3DSRequiredError && redirectUrl);
240
+
241
+ if (needsRedirect && redirectUrl) {
242
+ window.location.href = redirectUrl;
243
+ return;
244
+ }
245
+
246
+ setPaymentResult(responseData);
247
+
248
+ if (status === "APPROVED") {
249
+ handlePaymentSuccess("Preauthorization completed successfully");
250
+ return { success: true, data: responseData };
251
+ } else {
252
+ const errorMsg = errorMessage || `Unexpected status: ${status}`;
253
+ handlePaymentError(
254
+ errorMsg + "Preauthorization completed with status: ${status}"
255
+ );
256
+
257
+ return { success: false, data: responseData };
258
+ }
259
+ } catch (error) {
260
+ const errorMessage = error.message || "Preauthorization failed";
261
+ handlePaymentError(errorMessage);
262
+ return { success: false, data: error };
263
+ } finally {
264
+ setIsProcessingPayment(false);
265
+ }
266
+ };
267
+
268
+ const handleAuthorization = async (tokenParam = null) => {
269
+ setIsProcessingPayment(true);
270
+ setPaymentError(null);
271
+ setPaymentResult(null);
272
+
273
+ try {
274
+ const finalAuthReference = generateOrderReference();
275
+ handleFieldChange("authReference", finalAuthReference);
276
+
277
+ const finalCurrency = paymentState.currency || ((paymentState.paymentMethod === "cc" && paymentState.cardtype === "A") ? "USD" : "EUR");
278
+ const finalInvoiceid = paymentState.invoiceid || finalAuthReference;
279
+ const finalNarrativeText = paymentState.narrativeText || ("Authorization for order " + finalAuthReference);
280
+
281
+ const baseParams = {
282
+ amount: parseInt(paymentState.paymentAmount),
283
+ currency: finalCurrency,
284
+ reference: finalAuthReference,
285
+ enable3DSecure: settings.enable3DSecure !== false,
286
+ invoiceid: finalInvoiceid,
287
+ narrative_text: finalNarrativeText,
288
+ firstname: paymentState.firstname || DEFAULT_PAYMENT_DATA.firstname,
289
+ lastname: paymentState.lastname || DEFAULT_PAYMENT_DATA.lastname,
290
+ email: paymentState.email || DEFAULT_PAYMENT_DATA.email,
291
+ street: paymentState.street || DEFAULT_PAYMENT_DATA.street,
292
+ zip: paymentState.zip || DEFAULT_PAYMENT_DATA.zip,
293
+ city: paymentState.city || DEFAULT_PAYMENT_DATA.city,
294
+ country: paymentState.country || DEFAULT_PAYMENT_DATA.country,
295
+ telephonenumber: paymentState.telephonenumber || DEFAULT_PAYMENT_DATA.telephonenumber,
296
+ salutation: paymentState.salutation || DEFAULT_PAYMENT_DATA.salutation,
297
+ gender: paymentState.gender || DEFAULT_PAYMENT_DATA.gender,
298
+ ip: paymentState.ip || DEFAULT_PAYMENT_DATA.ip,
299
+ language: paymentState.language || DEFAULT_PAYMENT_DATA.language,
300
+ customer_is_present: paymentState.customerIsPresent || DEFAULT_PAYMENT_DATA.customer_is_present,
301
+ shipping_firstname: paymentState.shippingFirstname || paymentState.firstname || DEFAULT_PAYMENT_DATA.firstname,
302
+ shipping_lastname: paymentState.shippingLastname || paymentState.lastname || DEFAULT_PAYMENT_DATA.lastname,
303
+ shipping_street: paymentState.shippingStreet || paymentState.street || DEFAULT_PAYMENT_DATA.street,
304
+ shipping_zip: paymentState.shippingZip || paymentState.zip || DEFAULT_PAYMENT_DATA.zip,
305
+ shipping_city: paymentState.shippingCity || paymentState.city || DEFAULT_PAYMENT_DATA.city,
306
+ shipping_country: paymentState.shippingCountry || paymentState.country || DEFAULT_PAYMENT_DATA.country,
307
+ };
308
+
309
+ if (paymentState.paymentMethod === "cc" && settings.enable3DSecure !== false) {
310
+ if (paymentState.cardtype) baseParams.cardtype = paymentState.cardtype;
311
+ if (paymentState.cardpan) baseParams.cardpan = paymentState.cardpan;
312
+ baseParams.cardexpiredate = getValidCardExpiryDate(paymentState.cardexpiredate);
313
+ if (paymentState.cardcvc2) baseParams.cardcvc2 = paymentState.cardcvc2;
314
+ }
315
+
316
+ const needsRedirectUrls =
317
+ (paymentState.paymentMethod === "cc" && settings.enable3DSecure !== false) ||
318
+ ["wlt", "gpp", "apl", "sb"].includes(paymentState.paymentMethod);
319
+
320
+ if (needsRedirectUrls) {
321
+ if (paymentState.successurl) {
322
+ baseParams.successurl = paymentState.successurl;
323
+ } else {
324
+ const baseUrl = window.location.origin;
325
+ const currentPath = window.location.pathname;
326
+ const isContentUI = currentPath.includes('/content-ui') || currentPath.includes('/content-manager');
327
+ const basePath = isContentUI ? '/content-ui' : '/admin';
328
+ const pluginPath = '/plugins/strapi-plugin-payone-provider/payment';
329
+ baseParams.successurl = `${baseUrl}${basePath}${pluginPath}/success`;
330
+ }
331
+
332
+ if (paymentState.errorurl) {
333
+ baseParams.errorurl = paymentState.errorurl;
334
+ } else {
335
+ const baseUrl = window.location.origin;
336
+ const currentPath = window.location.pathname;
337
+ const isContentUI = currentPath.includes('/content-ui') || currentPath.includes('/content-manager');
338
+ const basePath = isContentUI ? '/content-ui' : '/admin';
339
+ const pluginPath = '/plugins/strapi-plugin-payone-provider/payment';
340
+ baseParams.errorurl = `${baseUrl}${basePath}${pluginPath}/error`;
341
+ }
342
+
343
+ if (paymentState.backurl) {
344
+ baseParams.backurl = paymentState.backurl;
345
+ } else {
346
+ const baseUrl = window.location.origin;
347
+ const currentPath = window.location.pathname;
348
+ const isContentUI = currentPath.includes('/content-ui') || currentPath.includes('/content-manager');
349
+ const basePath = isContentUI ? '/content-ui' : '/admin';
350
+ const pluginPath = '/plugins/strapi-plugin-payone-provider/payment';
351
+ baseParams.backurl = `${baseUrl}${basePath}${pluginPath}/back`;
352
+ }
353
+ }
354
+
355
+ const tokenToUse = tokenParam || paymentState.googlePayToken || paymentState.applePayToken;
356
+ if (paymentState.paymentMethod === "gpp" && tokenToUse) {
357
+ baseParams.googlePayToken = tokenToUse;
358
+ baseParams.settings = settings;
359
+ } else if (paymentState.paymentMethod === "apl" && tokenToUse) {
360
+ baseParams.applePayToken = tokenToUse;
361
+ baseParams.settings = settings;
362
+ }
363
+
364
+ const params = getAuthorizationParams(paymentState.paymentMethod, baseParams);
365
+ const result = await authorization(params);
366
+
367
+ const responseData = result?.data || result;
368
+ const status = responseData?.Status || null;
369
+ const errorCode = responseData?.errorCode || null;
370
+ const errorMessage = responseData?.errorMessage || null;
371
+ const requires3DSErrorCodes = ["4219", 4219];
372
+ const is3DSRequiredError = requires3DSErrorCodes.includes(errorCode);
373
+ const redirectUrl = responseData?.redirectUrl || null;
374
+
375
+
376
+ if (is3DSRequiredError && !redirectUrl) {
377
+ handlePaymentError(
378
+ errorMessage + " " +
379
+ (`Error code: ${errorCode || "Unknown"}`)
380
+ );
381
+ setPaymentResult(responseData);
382
+ return { success: false, data: responseData };
383
+ }
384
+
385
+ if ((status === "ERROR" || status === "INVALID" || errorCode) && !is3DSRequiredError) {
386
+ handlePaymentError(
387
+ errorMessage + " " +
388
+ (`Error code: ${errorCode || "Unknown"}`)
389
+ );
390
+ setPaymentResult(responseData);
391
+ return { success: false, data: responseData };
392
+ }
393
+
394
+ const needsRedirect = responseData.requires3DSRedirect ||
395
+ (status === "REDIRECT" && redirectUrl) ||
396
+ (is3DSRequiredError && redirectUrl);
397
+
398
+ if (needsRedirect && redirectUrl) {
399
+ window.location.href = redirectUrl;
400
+ return;
401
+ }
402
+
403
+ setPaymentResult(responseData);
404
+
405
+ if (status === "APPROVED") {
406
+ handlePaymentSuccess("Authorization completed successfully");
407
+ return { success: true, data: responseData };
408
+ } else {
409
+ const errorMsg = errorMessage + `Unexpected status: ${status}`;
410
+ handlePaymentError(
411
+ errorMsg + "Authorization completed with status: ${status}"
412
+ );
413
+ return { success: false, data: responseData };
414
+ }
415
+ } catch (error) {
416
+ const errorMessage = error.message || "Authorization failed";
417
+ handlePaymentError(errorMessage);
418
+ return { success: false, data: error };
419
+ } finally {
420
+ setIsProcessingPayment(false);
421
+ }
422
+ };
423
+
424
+ const handleCapture = async () => {
425
+ if (!paymentState.captureTxid.trim()) {
426
+ handlePaymentError("Transaction ID is required for capture");
427
+ return { success: false, data: "Transaction ID is required for capture" };
428
+ }
429
+ setIsProcessingPayment(true);
430
+ setPaymentError(null);
431
+ setPaymentResult(null);
432
+ try {
433
+ const params = getCaptureParams(paymentState.paymentMethod, {
434
+ txid: paymentState.captureTxid,
435
+ amount: parseInt(paymentState.paymentAmount),
436
+ currency: paymentState.captureCurrency || "EUR",
437
+ captureMode: paymentState.captureMode,
438
+ sequencenumber: parseInt(paymentState.captureSequenceNumber) || 1
439
+ });
440
+
441
+ const result = await capture(params);
442
+ setPaymentResult(result);
443
+ handlePaymentSuccess("Capture completed successfully");
444
+ return { success: true, data: result };
445
+ } catch (error) {
446
+ const errorMessage = error.message || "Capture failed";
447
+ handlePaymentError(errorMessage);
448
+ return { success: false, data: error };
449
+ } finally {
450
+ setIsProcessingPayment(false);
451
+ }
452
+ };
453
+
454
+ const handleRefund = async () => {
455
+ if (!paymentState.refundTxid.trim()) {
456
+ handlePaymentError("Transaction ID is required for refund");
457
+ return { success: false, data: "Transaction ID is required for refund" };
458
+ }
459
+ setIsProcessingPayment(true);
460
+ setPaymentError(null);
461
+ setPaymentResult(null);
462
+ try {
463
+ const params = getRefundParams(paymentState.paymentMethod, {
464
+ txid: paymentState.refundTxid,
465
+ sequencenumber: parseInt(paymentState.refundSequenceNumber),
466
+ amount: parseInt(paymentState.paymentAmount),
467
+ currency: paymentState.refundCurrency || "EUR",
468
+ reference: paymentState.refundReference || `REFUND-${Date.now()}`
469
+ });
470
+
471
+ const result = await refund(params);
472
+ setPaymentResult(result);
473
+ handlePaymentSuccess("Refund completed successfully");
474
+ return { success: true, data: result };
475
+ } catch (error) {
476
+ const errorMessage = error.message || "Refund failed";
477
+ handlePaymentError(errorMessage);
478
+ return { success: false, data: error };
479
+ } finally {
480
+ setIsProcessingPayment(false);
481
+ }
482
+ };
483
+
484
+ return {
485
+ paymentState,
486
+ handleFieldChange,
487
+ isProcessingPayment,
488
+ paymentResult,
489
+ paymentError,
490
+ handlePreauthorization,
491
+ handleAuthorization,
492
+ handleCapture,
493
+ handleRefund,
494
+ };
495
+ };
496
+
497
+ export default usePaymentActions;
498
+