strapi-plugin-payone-provider 1.1.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1041 -377
- package/admin/src/index.js +4 -1
- package/admin/src/pages/App/components/AppHeader.js +37 -0
- package/admin/src/pages/App/components/AppTabs.js +126 -0
- package/admin/src/pages/App/components/ConfigurationPanel.js +34 -35
- package/admin/src/pages/App/components/GooglePaybutton.js +300 -0
- package/admin/src/pages/App/components/HistoryPanel.js +25 -38
- package/admin/src/pages/App/components/PaymentActionsPanel.js +95 -280
- package/admin/src/pages/App/components/TransactionHistoryItem.js +4 -1
- package/admin/src/pages/App/components/paymentActions/AuthorizationForm.js +93 -0
- package/admin/src/pages/App/components/paymentActions/CaptureForm.js +64 -0
- package/admin/src/pages/App/components/paymentActions/PaymentMethodSelector.js +52 -0
- package/admin/src/pages/App/components/paymentActions/PaymentResult.js +85 -0
- package/admin/src/pages/App/components/paymentActions/PreauthorizationForm.js +93 -0
- package/admin/src/pages/App/components/paymentActions/RefundForm.js +89 -0
- package/admin/src/pages/App/index.js +41 -465
- package/admin/src/pages/App/styles.css +294 -0
- package/admin/src/pages/constants/paymentConstants.js +37 -0
- package/admin/src/pages/hooks/usePaymentActions.js +271 -0
- package/admin/src/pages/hooks/useSettings.js +111 -0
- package/admin/src/pages/hooks/useTransactionHistory.js +87 -0
- package/admin/src/pages/utils/api.js +10 -0
- package/admin/src/pages/utils/injectGooglePayScript.js +31 -0
- package/admin/src/pages/utils/paymentUtils.js +113 -13
- package/package.json +1 -1
- package/server/controllers/payone.js +71 -64
- package/server/routes/index.js +17 -0
- package/server/services/paymentService.js +214 -0
- package/server/services/payone.js +25 -648
- package/server/services/settingsService.js +59 -0
- package/server/services/testConnectionService.js +190 -0
- package/server/services/transactionService.js +114 -0
- package/server/utils/normalize.js +51 -0
- package/server/utils/paymentMethodParams.js +126 -0
- package/server/utils/requestBuilder.js +110 -0
- package/server/utils/responseParser.js +80 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const axios = require("axios");
|
|
4
|
+
const { normalizeReference } = require("../utils/normalize");
|
|
5
|
+
const { buildClientRequestParams, toFormData } = require("../utils/requestBuilder");
|
|
6
|
+
const { addPaymentMethodParams } = require("../utils/paymentMethodParams");
|
|
7
|
+
const { parseResponse, extractTxId, requires3DSRedirect, get3DSRedirectUrl } = require("../utils/responseParser");
|
|
8
|
+
const { getSettings, validateSettings } = require("./settingsService");
|
|
9
|
+
const { logTransaction } = require("./transactionService");
|
|
10
|
+
|
|
11
|
+
const POST_GATEWAY_URL = "https://api.pay1.de/post-gateway/";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Send request to Payone API
|
|
15
|
+
* @param {Object} strapi - Strapi instance
|
|
16
|
+
* @param {Object} params - Request parameters
|
|
17
|
+
* @returns {Promise<Object>} Response data
|
|
18
|
+
*/
|
|
19
|
+
const sendRequest = async (strapi, params) => {
|
|
20
|
+
try {
|
|
21
|
+
const settings = await getSettings(strapi);
|
|
22
|
+
|
|
23
|
+
if (!validateSettings(settings)) {
|
|
24
|
+
throw new Error("Payone settings not configured");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const reqType = params.request;
|
|
28
|
+
if (["authorization", "preauthorization", "refund"].includes(reqType)) {
|
|
29
|
+
const prefix =
|
|
30
|
+
reqType === "refund" ? "REF" : reqType === "preauthorization" ? "PRE" : "AUTH";
|
|
31
|
+
params.reference = normalizeReference(params.reference, prefix);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const requestParams = buildClientRequestParams(settings, params, strapi.log);
|
|
35
|
+
const formData = toFormData(requestParams);
|
|
36
|
+
|
|
37
|
+
const response = await axios.post(POST_GATEWAY_URL, formData, {
|
|
38
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
39
|
+
timeout: 30000
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const responseData = parseResponse(response.data, strapi.log);
|
|
43
|
+
|
|
44
|
+
if (requires3DSRedirect(responseData)) {
|
|
45
|
+
const redirectUrl = get3DSRedirectUrl(responseData);
|
|
46
|
+
responseData.requires3DSRedirect = true;
|
|
47
|
+
responseData.redirectUrl = redirectUrl;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Log transaction
|
|
51
|
+
await logTransaction(strapi, {
|
|
52
|
+
txid: extractTxId(responseData) || params.txid || null,
|
|
53
|
+
reference: params.reference || null,
|
|
54
|
+
status: responseData.status || responseData.Status || "unknown",
|
|
55
|
+
request_type: params.request,
|
|
56
|
+
amount: params.amount || null,
|
|
57
|
+
currency: params.currency || "EUR",
|
|
58
|
+
raw_request: requestParams,
|
|
59
|
+
raw_response: responseData,
|
|
60
|
+
error_code: responseData.Error?.ErrorCode || null,
|
|
61
|
+
error_message: responseData.Error?.ErrorMessage || null,
|
|
62
|
+
customer_message: responseData.Error?.CustomerMessage || null
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return responseData;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
strapi.log.error("Payone sendRequest error:", error);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Preauthorization
|
|
74
|
+
* @param {Object} strapi - Strapi instance
|
|
75
|
+
* @param {Object} params - Request parameters
|
|
76
|
+
* @returns {Promise<Object>} Response data
|
|
77
|
+
*/
|
|
78
|
+
const preauthorization = async (strapi, params) => {
|
|
79
|
+
const requiredParams = {
|
|
80
|
+
request: "preauthorization",
|
|
81
|
+
clearingtype: params.clearingtype || "cc",
|
|
82
|
+
amount: params.amount || 1000,
|
|
83
|
+
currency: params.currency || "EUR",
|
|
84
|
+
reference: params.reference || `PREAUTH-${Date.now()}`,
|
|
85
|
+
firstname: params.firstname || "Test",
|
|
86
|
+
lastname: params.lastname || "User",
|
|
87
|
+
street: params.street || "Test Street 1",
|
|
88
|
+
zip: params.zip || "12345",
|
|
89
|
+
city: params.city || "Test City",
|
|
90
|
+
country: params.country || "DE",
|
|
91
|
+
email: params.email || "test@example.com",
|
|
92
|
+
...params
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const updatedParams = addPaymentMethodParams(requiredParams, strapi.log);
|
|
96
|
+
return await sendRequest(strapi, updatedParams);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Authorization
|
|
101
|
+
* @param {Object} strapi - Strapi instance
|
|
102
|
+
* @param {Object} params - Request parameters
|
|
103
|
+
* @returns {Promise<Object>} Response data
|
|
104
|
+
*/
|
|
105
|
+
const authorization = async (strapi, params) => {
|
|
106
|
+
const requiredParams = {
|
|
107
|
+
request: "authorization",
|
|
108
|
+
clearingtype: params.clearingtype || "cc",
|
|
109
|
+
...params
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const updatedParams = addPaymentMethodParams(requiredParams, strapi.log);
|
|
113
|
+
return await sendRequest(strapi, updatedParams);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Capture
|
|
118
|
+
* @param {Object} strapi - Strapi instance
|
|
119
|
+
* @param {Object} params - Request parameters
|
|
120
|
+
* @returns {Promise<Object>} Response data
|
|
121
|
+
*/
|
|
122
|
+
const capture = async (strapi, params) => {
|
|
123
|
+
if (!params.txid) {
|
|
124
|
+
throw new Error("Transaction ID (txid) is required for capture");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const requiredParams = {
|
|
128
|
+
request: "capture",
|
|
129
|
+
txid: params.txid,
|
|
130
|
+
amount: params.amount || 1000,
|
|
131
|
+
currency: params.currency || "EUR",
|
|
132
|
+
...params
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
delete requiredParams.reference;
|
|
136
|
+
return await sendRequest(strapi, requiredParams);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Refund
|
|
141
|
+
* @param {Object} strapi - Strapi instance
|
|
142
|
+
* @param {Object} params - Request parameters
|
|
143
|
+
* @returns {Promise<Object>} Response data
|
|
144
|
+
*/
|
|
145
|
+
const refund = async (strapi, params) => {
|
|
146
|
+
if (!params.txid) {
|
|
147
|
+
throw new Error("Transaction ID (txid) is required for refund");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const requiredParams = {
|
|
151
|
+
request: "refund",
|
|
152
|
+
txid: params.txid,
|
|
153
|
+
amount: params.amount || 1000,
|
|
154
|
+
currency: params.currency || "EUR",
|
|
155
|
+
reference: params.reference || `REFUND-${Date.now()}`,
|
|
156
|
+
...params
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
return await sendRequest(strapi, requiredParams);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Handle 3D Secure callback from Payone
|
|
164
|
+
* This processes the callback after customer completes 3DS authentication
|
|
165
|
+
* @param {Object} strapi - Strapi instance
|
|
166
|
+
* @param {Object} callbackData - Callback data from Payone
|
|
167
|
+
* @returns {Promise<Object>} Processed callback result
|
|
168
|
+
*/
|
|
169
|
+
const handle3DSCallback = async (strapi, callbackData) => {
|
|
170
|
+
try {
|
|
171
|
+
const parsedData = parseResponse(callbackData, strapi.log);
|
|
172
|
+
|
|
173
|
+
// Extract transaction information
|
|
174
|
+
const txid = extractTxId(parsedData);
|
|
175
|
+
const status = parsedData.status || parsedData.Status || "unknown";
|
|
176
|
+
const reference = parsedData.reference || parsedData.Reference || null;
|
|
177
|
+
|
|
178
|
+
// Log the callback transaction
|
|
179
|
+
await logTransaction(strapi, {
|
|
180
|
+
txid: txid || null,
|
|
181
|
+
reference: reference || null,
|
|
182
|
+
status: status,
|
|
183
|
+
request_type: "3ds_callback",
|
|
184
|
+
amount: parsedData.amount || null,
|
|
185
|
+
currency: parsedData.currency || "EUR",
|
|
186
|
+
raw_request: callbackData,
|
|
187
|
+
raw_response: parsedData,
|
|
188
|
+
error_code: parsedData.Error?.ErrorCode || null,
|
|
189
|
+
error_message: parsedData.Error?.ErrorMessage || null,
|
|
190
|
+
customer_message: parsedData.Error?.CustomerMessage || null
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
return {
|
|
194
|
+
success: status.toUpperCase() === "APPROVED" || status.toUpperCase() === "REDIRECT",
|
|
195
|
+
status: status,
|
|
196
|
+
txid: txid,
|
|
197
|
+
reference: reference,
|
|
198
|
+
data: parsedData
|
|
199
|
+
};
|
|
200
|
+
} catch (error) {
|
|
201
|
+
strapi.log.error("3DS callback processing error:", error);
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
module.exports = {
|
|
207
|
+
sendRequest,
|
|
208
|
+
preauthorization,
|
|
209
|
+
authorization,
|
|
210
|
+
capture,
|
|
211
|
+
refund,
|
|
212
|
+
handle3DSCallback
|
|
213
|
+
};
|
|
214
|
+
|