strapi-plugin-payone-provider 1.6.6 → 4.6.9
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/.well-known/.gitkeep +3 -0
- package/.well-known/apple-developer-merchant-id-domain-association.txt +1 -0
- package/admin/src/pages/App/components/AppTabs.jsx +37 -16
- package/admin/src/pages/App/components/ApplePayBtn.jsx +63 -28
- package/admin/src/pages/App/components/ConfigurationPanel.jsx +163 -10
- package/admin/src/pages/App/components/CustomerInfoPopover.jsx +147 -0
- package/admin/src/pages/App/components/DocsPanel.jsx +864 -194
- package/admin/src/pages/App/components/HistoryPanel.jsx +24 -237
- package/admin/src/pages/App/components/PaymentActionsPanel.jsx +8 -1
- package/admin/src/pages/App/components/RawDataPopover.jsx +113 -0
- package/admin/src/pages/App/components/StatusBadge.jsx +72 -14
- package/admin/src/pages/App/components/TransactionHistoryTable/TransactionHistoryTableFilters.jsx +113 -0
- package/admin/src/pages/App/components/TransactionHistoryTable/TransactionHistoryTablePagination.jsx +180 -0
- package/admin/src/pages/App/components/TransactionHistoryTable/index.jsx +225 -0
- package/admin/src/pages/App/components/paymentActions/ApplePayPanel.jsx +45 -1
- package/admin/src/pages/App/index.jsx +4 -0
- package/admin/src/pages/hooks/useSettings.js +26 -0
- package/admin/src/pages/hooks/useTransactionHistory.js +75 -11
- package/package.json +3 -2
- package/server/bootstrap.js +9 -3
- package/server/controllers/payone.js +8 -0
- package/server/services/applePayService.js +103 -93
- package/server/services/transactionService.js +104 -19
- package/server/utils/paymentMethodParams.js +67 -18
package/server/bootstrap.js
CHANGED
|
@@ -21,7 +21,13 @@ module.exports = async ({ strapi }) => {
|
|
|
21
21
|
merchantName: "",
|
|
22
22
|
displayName: "",
|
|
23
23
|
domainName: "",
|
|
24
|
-
merchantIdentifier: ""
|
|
24
|
+
merchantIdentifier: "",
|
|
25
|
+
enableCreditCard: true,
|
|
26
|
+
enablePayPal: true,
|
|
27
|
+
enableGooglePay: true,
|
|
28
|
+
enableApplePay: true,
|
|
29
|
+
enableSofort: true,
|
|
30
|
+
enableSepaDirectDebit: true
|
|
25
31
|
}
|
|
26
32
|
});
|
|
27
33
|
}
|
|
@@ -56,8 +62,8 @@ module.exports = async ({ strapi }) => {
|
|
|
56
62
|
|
|
57
63
|
router.get('/.well-known/apple-developer-merchantid-domain-association', async (ctx) => {
|
|
58
64
|
try {
|
|
59
|
-
const
|
|
60
|
-
const wellKnownPath = path.join(
|
|
65
|
+
const pluginRoot = path.resolve(__dirname, '..');
|
|
66
|
+
const wellKnownPath = path.join(pluginRoot, '.well-known');
|
|
61
67
|
const possiblePaths = [
|
|
62
68
|
path.join(wellKnownPath, 'apple-developer-merchantid-domain-association'),
|
|
63
69
|
path.join(wellKnownPath, 'apple-developer-merchantid-domain-association.txt'),
|
|
@@ -45,6 +45,14 @@ module.exports = ({ strapi }) => ({
|
|
|
45
45
|
portalid: settings?.portalid || null,
|
|
46
46
|
accountId: settings?.aid || null,
|
|
47
47
|
portalKey: settings?.key || null,
|
|
48
|
+
paymentMethods: {
|
|
49
|
+
creditCard: settings?.enableCreditCard,
|
|
50
|
+
paypal: settings?.enablePayPal,
|
|
51
|
+
googlePay: settings?.enableGooglePay,
|
|
52
|
+
applePay: settings?.enableApplePay,
|
|
53
|
+
sofort: settings?.enableSofort,
|
|
54
|
+
sepa: settings?.enableSepaDirectDebit,
|
|
55
|
+
},
|
|
48
56
|
}
|
|
49
57
|
};
|
|
50
58
|
} catch (error) {
|
|
@@ -8,13 +8,35 @@ const POST_GATEWAY_URL = "https://api.pay1.de/post-gateway/";
|
|
|
8
8
|
|
|
9
9
|
const parseResponse = (responseData) => {
|
|
10
10
|
if (typeof responseData === 'string') {
|
|
11
|
+
if (responseData.trim().startsWith('{')) {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(responseData);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
// Fall through to URL-encoded parsing
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
const params = new URLSearchParams(responseData);
|
|
12
20
|
const parsed = {};
|
|
13
21
|
for (const [key, value] of params.entries()) {
|
|
14
22
|
parsed[key] = value;
|
|
23
|
+
const normalizedKey = key.toLowerCase().replace(/\[/g, '_').replace(/\]/g, '');
|
|
24
|
+
if (normalizedKey !== key.toLowerCase()) {
|
|
25
|
+
parsed[normalizedKey] = value;
|
|
26
|
+
}
|
|
15
27
|
}
|
|
16
28
|
return parsed;
|
|
17
29
|
}
|
|
30
|
+
|
|
31
|
+
if (typeof responseData === 'object' && responseData !== null) {
|
|
32
|
+
const result = { ...responseData };
|
|
33
|
+
if (result['add_paydata[applepay_payment_session]']) {
|
|
34
|
+
result.add_paydata = result.add_paydata || {};
|
|
35
|
+
result.add_paydata.applepay_payment_session = result['add_paydata[applepay_payment_session]'];
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
18
40
|
return responseData;
|
|
19
41
|
};
|
|
20
42
|
|
|
@@ -45,8 +67,6 @@ const initializeApplePaySession = async (strapi, params) => {
|
|
|
45
67
|
|
|
46
68
|
const applePayConfig = settings?.applePayConfig || {};
|
|
47
69
|
const currency = params.currency || applePayConfig.currencyCode || "EUR";
|
|
48
|
-
const countryCode = params.countryCode || applePayConfig.countryCode || "DE";
|
|
49
|
-
|
|
50
70
|
const merchantName = params.displayName || settings?.merchantName || "Store";
|
|
51
71
|
const domain = params.domain || params.domainName || "localhost";
|
|
52
72
|
|
|
@@ -63,18 +83,14 @@ const initializeApplePaySession = async (strapi, params) => {
|
|
|
63
83
|
const requestParams = buildClientRequestParams(settings, baseParams, strapi.log);
|
|
64
84
|
const formData = toFormData(requestParams);
|
|
65
85
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
});
|
|
75
|
-
} catch (axiosError) {
|
|
76
|
-
throw axiosError;
|
|
77
|
-
}
|
|
86
|
+
const response = await axios.post(`${POST_GATEWAY_URL}Genericpayment`, formData, {
|
|
87
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
88
|
+
timeout: 30000,
|
|
89
|
+
validateStatus: function (status) {
|
|
90
|
+
return status >= 200 && status < 600;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
78
94
|
|
|
79
95
|
if (response.status === 403) {
|
|
80
96
|
const responseData = parseResponse(response.data);
|
|
@@ -88,12 +104,7 @@ const initializeApplePaySession = async (strapi, params) => {
|
|
|
88
104
|
|
|
89
105
|
const detailedError = new Error("403 Forbidden: Authentication failed with Payone API. " +
|
|
90
106
|
(errorCode ? `Error Code: ${errorCode}. ` : "") +
|
|
91
|
-
(errorMessage ? `Error: ${errorMessage}. ` : "")
|
|
92
|
-
"Please check: 1) Your Payone credentials (aid, portalid, mid, key) in plugin settings, " +
|
|
93
|
-
"2) Mode is set to 'live' (Apple Pay only works in live mode), " +
|
|
94
|
-
"3) Your domain is registered with Payone Merchant Services, " +
|
|
95
|
-
"4) Merchant ID (mid) matches your merchantIdentifier in PMI, " +
|
|
96
|
-
"5) Apple Pay is enabled for your portal in PMI.");
|
|
107
|
+
(errorMessage ? `Error: ${errorMessage}. ` : ""));
|
|
97
108
|
Object.assign(detailedError, { status: 403, response: response });
|
|
98
109
|
throw detailedError;
|
|
99
110
|
}
|
|
@@ -138,71 +149,7 @@ const initializeApplePaySession = async (strapi, params) => {
|
|
|
138
149
|
|
|
139
150
|
return responseData;
|
|
140
151
|
} catch (error) {
|
|
141
|
-
|
|
142
|
-
const errorResponseData = error.response?.data;
|
|
143
|
-
|
|
144
|
-
// Provide more specific error messages
|
|
145
|
-
if (errorStatus === 403 || error.message?.includes('403')) {
|
|
146
|
-
let responseData = {};
|
|
147
|
-
let errorCode = null;
|
|
148
|
-
let errorMessage = null;
|
|
149
|
-
|
|
150
|
-
if (errorResponseData) {
|
|
151
|
-
try {
|
|
152
|
-
responseData = parseResponse(errorResponseData);
|
|
153
|
-
errorCode = responseData.errorcode || responseData.ErrorCode;
|
|
154
|
-
errorMessage = responseData.errormessage || responseData.ErrorMessage || responseData.customermessage || responseData.CustomerMessage;
|
|
155
|
-
} catch (parseErr) {
|
|
156
|
-
if (typeof errorResponseData === 'string') {
|
|
157
|
-
errorMessage = errorResponseData;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (errorCode || errorMessage) {
|
|
163
|
-
strapi.log.error("[Apple Pay] 403 Forbidden from Payone:", {
|
|
164
|
-
errorcode: errorCode,
|
|
165
|
-
errormessage: errorMessage
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
let detailedMessage = "403 Forbidden: Authentication failed with Payone API. ";
|
|
170
|
-
|
|
171
|
-
if (errorCode) {
|
|
172
|
-
detailedMessage += `Error Code: ${errorCode}. `;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (errorMessage) {
|
|
176
|
-
detailedMessage += `Error: ${errorMessage}. `;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
detailedMessage += "Please check:\n" +
|
|
180
|
-
"1. Your Payone credentials (aid, portalid, mid, key) in plugin settings\n" +
|
|
181
|
-
"2. Mode is set to 'live' (Apple Pay only works in live mode according to Payone docs)\n" +
|
|
182
|
-
"3. Your domain is registered with Payone Merchant Services\n" +
|
|
183
|
-
"4. Merchant ID (mid) matches your merchantIdentifier in PMI\n" +
|
|
184
|
-
"5. Apple Pay is enabled for your portal in PMI (CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Payment type configuration tab)";
|
|
185
|
-
|
|
186
|
-
throw new Error(detailedMessage);
|
|
187
|
-
} else if (errorStatus === 401 || error.message?.includes('401')) {
|
|
188
|
-
if (errorResponseData) {
|
|
189
|
-
const responseData = parseResponse(errorResponseData);
|
|
190
|
-
strapi.log.error("[Apple Pay] 401 Unauthorized from Payone:", {
|
|
191
|
-
errorcode: responseData.errorcode || responseData.ErrorCode,
|
|
192
|
-
errormessage: responseData.errormessage || responseData.ErrorMessage
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
throw new Error("401 Unauthorized: Invalid credentials. Please verify your Payone key in plugin settings.");
|
|
196
|
-
} else if (errorStatus && errorStatus >= 500) {
|
|
197
|
-
const responseData = errorResponseData ? parseResponse(errorResponseData) : {};
|
|
198
|
-
strapi.log.error("[Apple Pay] Payone server error:", {
|
|
199
|
-
status: error.response?.status,
|
|
200
|
-
errorcode: responseData.errorcode || responseData.ErrorCode,
|
|
201
|
-
errormessage: responseData.errormessage || responseData.ErrorMessage
|
|
202
|
-
});
|
|
203
|
-
throw new Error(`Payone server error (${error.response?.status}): ${error.response?.statusText || 'Internal server error'}`);
|
|
204
|
-
}
|
|
205
|
-
|
|
152
|
+
strapi.log.error("[Apple Pay] Error:", error instanceof Error ? error.message : error);
|
|
206
153
|
throw error;
|
|
207
154
|
}
|
|
208
155
|
};
|
|
@@ -215,28 +162,89 @@ const validateApplePayMerchant = async (strapi, params) => {
|
|
|
215
162
|
throw new Error("Payone settings are not properly configured. Please check your plugin settings (aid, portalid, mid, key).");
|
|
216
163
|
}
|
|
217
164
|
|
|
218
|
-
// Get currency and country from Apple Pay config
|
|
219
165
|
const applePayConfig = settings?.applePayConfig || {};
|
|
220
|
-
const currency = params.currency || applePayConfig.currencyCode || "EUR";
|
|
221
|
-
const countryCode = params.countryCode || applePayConfig.countryCode || "DE";
|
|
222
166
|
|
|
223
|
-
// Update params with config values
|
|
224
167
|
if (!params.currency && applePayConfig.currencyCode) {
|
|
225
168
|
params.currency = applePayConfig.currencyCode;
|
|
226
169
|
}
|
|
170
|
+
|
|
227
171
|
if (!params.countryCode && applePayConfig.countryCode) {
|
|
228
172
|
params.countryCode = applePayConfig.countryCode;
|
|
229
173
|
}
|
|
230
174
|
|
|
231
175
|
const sessionResponse = await initializeApplePaySession(strapi, params);
|
|
232
176
|
|
|
233
|
-
|
|
234
|
-
|
|
177
|
+
// Extract add_paydata[applepay_payment_session] from response
|
|
178
|
+
// Payone returns this in URL-encoded format: add_paydata[applepay_payment_session]=BASE64_STRING
|
|
179
|
+
const applePaySessionBase64 =
|
|
180
|
+
sessionResponse["add_paydata[applepay_payment_session]"] ||
|
|
181
|
+
sessionResponse["add_paydata_applepay_payment_session"] ||
|
|
182
|
+
sessionResponse.add_paydata?.applepay_payment_session ||
|
|
183
|
+
(sessionResponse.add_paydata && typeof sessionResponse.add_paydata === 'object'
|
|
184
|
+
? sessionResponse.add_paydata["applepay_payment_session"]
|
|
185
|
+
: null);
|
|
186
|
+
|
|
187
|
+
strapi.log.info("[Apple Pay] Genericpayment response:", {
|
|
188
|
+
status: sessionResponse.status,
|
|
189
|
+
workorderid: sessionResponse.workorderid,
|
|
190
|
+
hasApplePaySession: !!applePaySessionBase64,
|
|
191
|
+
applePaySessionLength: applePaySessionBase64 ? applePaySessionBase64.length : 0,
|
|
192
|
+
responseKeys: Object.keys(sessionResponse),
|
|
193
|
+
hasAddPaydataKey: !!sessionResponse["add_paydata[applepay_payment_session]"],
|
|
194
|
+
hasAddPaydataObject: !!sessionResponse.add_paydata,
|
|
195
|
+
addPaydataKeys: sessionResponse.add_paydata ? Object.keys(sessionResponse.add_paydata) : null
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
if (!applePaySessionBase64) {
|
|
199
|
+
strapi.log.error("[Apple Pay] Missing applepay_payment_session in response:", {
|
|
200
|
+
status: sessionResponse.status,
|
|
201
|
+
responseKeys: Object.keys(sessionResponse),
|
|
202
|
+
responseSample: JSON.stringify(sessionResponse).substring(0, 1000),
|
|
203
|
+
addPaydataKeys: sessionResponse.add_paydata ? Object.keys(sessionResponse.add_paydata) : null
|
|
204
|
+
});
|
|
205
|
+
throw new Error("Missing applepay_payment_session in Payone response. Please check your Payone Apple Pay configuration in PMI.");
|
|
206
|
+
}
|
|
235
207
|
|
|
236
208
|
if (sessionResponse.status === "OK" && applePaySessionBase64 && applePaySessionBase64.length > 0) {
|
|
237
209
|
try {
|
|
238
|
-
|
|
239
|
-
|
|
210
|
+
strapi.log.info("[Apple Pay] Extracting merchant session from Base64:", {
|
|
211
|
+
base64Length: applePaySessionBase64.length,
|
|
212
|
+
base64Preview: applePaySessionBase64.substring(0, 100) + "...",
|
|
213
|
+
base64End: applePaySessionBase64.substring(Math.max(0, applePaySessionBase64.length - 50))
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// Decode Base64 to get merchant session JSON
|
|
217
|
+
let merchantSessionJson;
|
|
218
|
+
try {
|
|
219
|
+
merchantSessionJson = Buffer.from(applePaySessionBase64, 'base64').toString('utf-8');
|
|
220
|
+
strapi.log.info("[Apple Pay] Base64 decoded successfully, JSON length:", merchantSessionJson.length);
|
|
221
|
+
} catch (decodeError) {
|
|
222
|
+
strapi.log.error("[Apple Pay] Failed to decode Base64:", {
|
|
223
|
+
error: decodeError.message,
|
|
224
|
+
base64Length: applePaySessionBase64.length
|
|
225
|
+
});
|
|
226
|
+
throw new Error(`Failed to decode Base64 merchant session: ${decodeError.message}`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Parse JSON merchant session
|
|
230
|
+
let merchantSession;
|
|
231
|
+
try {
|
|
232
|
+
merchantSession = JSON.parse(merchantSessionJson);
|
|
233
|
+
strapi.log.info("[Apple Pay] Merchant session JSON parsed successfully");
|
|
234
|
+
} catch (parseError) {
|
|
235
|
+
strapi.log.error("[Apple Pay] Failed to parse merchant session JSON:", {
|
|
236
|
+
error: parseError.message,
|
|
237
|
+
jsonPreview: merchantSessionJson.substring(0, 500)
|
|
238
|
+
});
|
|
239
|
+
throw new Error(`Failed to parse merchant session JSON: ${parseError.message}`);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
strapi.log.info("[Apple Pay] Merchant session extracted successfully:", {
|
|
243
|
+
hasMerchantIdentifier: !!merchantSession.merchantIdentifier,
|
|
244
|
+
hasEpochTimestamp: !!merchantSession.epochTimestamp,
|
|
245
|
+
hasExpiresAt: !!merchantSession.expiresAt,
|
|
246
|
+
merchantSessionKeys: Object.keys(merchantSession)
|
|
247
|
+
});
|
|
240
248
|
|
|
241
249
|
if (merchantSession.epochTimestamp && merchantSession.epochTimestamp > 1000000000000) {
|
|
242
250
|
merchantSession.epochTimestamp = Math.floor(merchantSession.epochTimestamp / 1000);
|
|
@@ -274,7 +282,9 @@ const validateApplePayMerchant = async (strapi, params) => {
|
|
|
274
282
|
throw new Error(
|
|
275
283
|
`Payone Apple Pay initialization failed: ${errorCode ? `Error ${errorCode}` : 'Unknown error'} - ${errorMessage || 'Please check your Payone Apple Pay configuration in PMI'}`
|
|
276
284
|
);
|
|
285
|
+
|
|
277
286
|
} catch (error) {
|
|
287
|
+
strapi.log.error("[Apple Pay] Error:", error instanceof Error ? error.message : error);
|
|
278
288
|
throw error;
|
|
279
289
|
}
|
|
280
290
|
};
|
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
const { getPluginStore } = require("./settingsService");
|
|
4
4
|
|
|
5
|
+
const sanitizeRawRequest = (rawRequest) => {
|
|
6
|
+
if (!rawRequest || typeof rawRequest !== "object") return rawRequest
|
|
7
|
+
const sanitized = { ...rawRequest };
|
|
8
|
+
const sensitiveFields = ["cardpan", "cardexpiredate", "cardcvc2"];
|
|
9
|
+
|
|
10
|
+
sensitiveFields.forEach((field) => {
|
|
11
|
+
if (sanitized[field] && typeof sanitized[field] === "string") {
|
|
12
|
+
sanitized[field] = "*".repeat(sanitized[field].length);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return sanitized;
|
|
17
|
+
};
|
|
18
|
+
|
|
5
19
|
const logTransaction = async (strapi, transactionData) => {
|
|
6
20
|
const pluginStore = getPluginStore(strapi);
|
|
7
21
|
let transactionHistory =
|
|
@@ -28,17 +42,19 @@ const logTransaction = async (strapi, transactionData) => {
|
|
|
28
42
|
transactionData.customer_message ||
|
|
29
43
|
transactionData.Error?.CustomerMessage ||
|
|
30
44
|
null,
|
|
31
|
-
body: transactionData
|
|
32
|
-
raw_request: transactionData.raw_request
|
|
33
|
-
|
|
45
|
+
body: transactionData ? { ...transactionData, raw_request: sanitizeRawRequest(transactionData.raw_request) } : null,
|
|
46
|
+
raw_request: transactionData.raw_request
|
|
47
|
+
? sanitizeRawRequest(transactionData.raw_request)
|
|
48
|
+
: null,
|
|
49
|
+
raw_response: sanitizeRawRequest(transactionData.raw_response) || transactionData,
|
|
34
50
|
created_at: new Date().toISOString(),
|
|
35
51
|
updated_at: new Date().toISOString()
|
|
36
52
|
};
|
|
37
53
|
|
|
38
54
|
transactionHistory.unshift(logEntry);
|
|
39
55
|
|
|
40
|
-
if (transactionHistory.length >
|
|
41
|
-
transactionHistory = transactionHistory.slice(0,
|
|
56
|
+
if (transactionHistory.length > 5000) {
|
|
57
|
+
transactionHistory = transactionHistory.slice(0, 5000);
|
|
42
58
|
}
|
|
43
59
|
|
|
44
60
|
await pluginStore.set({
|
|
@@ -54,10 +70,19 @@ const getTransactionHistory = async (strapi, filters = {}) => {
|
|
|
54
70
|
let transactionHistory =
|
|
55
71
|
(await pluginStore.get({ key: "transactionHistory" })) || [];
|
|
56
72
|
|
|
57
|
-
if (filters.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
73
|
+
if (filters.search) {
|
|
74
|
+
const searchLower = filters.search.toLowerCase().trim();
|
|
75
|
+
transactionHistory = transactionHistory.filter((transaction) => {
|
|
76
|
+
const status = (transaction.status || "").toLowerCase();
|
|
77
|
+
const txid = (transaction.txid || "").toLowerCase();
|
|
78
|
+
const reference = (transaction.reference || "").toLowerCase();
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
status.includes(searchLower) ||
|
|
82
|
+
txid.includes(searchLower) ||
|
|
83
|
+
reference.includes(searchLower)
|
|
84
|
+
);
|
|
85
|
+
});
|
|
61
86
|
}
|
|
62
87
|
|
|
63
88
|
if (filters.request_type) {
|
|
@@ -66,16 +91,28 @@ const getTransactionHistory = async (strapi, filters = {}) => {
|
|
|
66
91
|
);
|
|
67
92
|
}
|
|
68
93
|
|
|
69
|
-
if (filters.
|
|
70
|
-
transactionHistory = transactionHistory.filter(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
94
|
+
if (filters.payment_method) {
|
|
95
|
+
transactionHistory = transactionHistory.filter((transaction) => {
|
|
96
|
+
const clearingtype = transaction.raw_request?.clearingtype || "";
|
|
97
|
+
const wallettype = transaction.raw_request?.wallettype || "";
|
|
98
|
+
|
|
99
|
+
switch (filters.payment_method) {
|
|
100
|
+
case "credit_card":
|
|
101
|
+
return clearingtype === "cc";
|
|
102
|
+
case "paypal":
|
|
103
|
+
return clearingtype === "wlt" && wallettype === "PPE";
|
|
104
|
+
case "google_pay":
|
|
105
|
+
return clearingtype === "wlt" && (wallettype === "GPY" || wallettype === "GOOGLEPAY");
|
|
106
|
+
case "apple_pay":
|
|
107
|
+
return clearingtype === "wlt" && (wallettype === "APL" || wallettype === "APPLEPAY");
|
|
108
|
+
case "sofort":
|
|
109
|
+
return clearingtype === "sb";
|
|
110
|
+
case "sepa":
|
|
111
|
+
return clearingtype === "elv";
|
|
112
|
+
default:
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
79
116
|
}
|
|
80
117
|
|
|
81
118
|
if (filters.date_from) {
|
|
@@ -92,6 +129,54 @@ const getTransactionHistory = async (strapi, filters = {}) => {
|
|
|
92
129
|
);
|
|
93
130
|
}
|
|
94
131
|
|
|
132
|
+
if (filters.status) {
|
|
133
|
+
transactionHistory = transactionHistory.filter(
|
|
134
|
+
(transaction) => transaction.status === filters.status
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Apply sorting
|
|
139
|
+
if (filters.sort_by && filters.sort_order) {
|
|
140
|
+
const sortOrder = filters.sort_order === "desc" ? -1 : 1;
|
|
141
|
+
|
|
142
|
+
transactionHistory.sort((a, b) => {
|
|
143
|
+
let aValue, bValue;
|
|
144
|
+
|
|
145
|
+
switch (filters.sort_by) {
|
|
146
|
+
case "amount":
|
|
147
|
+
aValue = a.amount || 0;
|
|
148
|
+
bValue = b.amount || 0;
|
|
149
|
+
break;
|
|
150
|
+
case "created_at":
|
|
151
|
+
aValue = new Date(a.created_at || a.timestamp || 0).getTime();
|
|
152
|
+
bValue = new Date(b.created_at || b.timestamp || 0).getTime();
|
|
153
|
+
break;
|
|
154
|
+
case "status":
|
|
155
|
+
aValue = (a.status || "").toLowerCase();
|
|
156
|
+
bValue = (b.status || "").toLowerCase();
|
|
157
|
+
break;
|
|
158
|
+
case "reference":
|
|
159
|
+
aValue = (a.reference || "").toLowerCase();
|
|
160
|
+
bValue = (b.reference || "").toLowerCase();
|
|
161
|
+
break;
|
|
162
|
+
case "method":
|
|
163
|
+
const aClearingType = a.raw_request?.clearingtype || "";
|
|
164
|
+
const bClearingType = b.raw_request?.clearingtype || "";
|
|
165
|
+
const aWalletType = a.raw_request?.wallettype || "";
|
|
166
|
+
const bWalletType = b.raw_request?.wallettype || "";
|
|
167
|
+
aValue = `${aClearingType}_${aWalletType}`.toLowerCase();
|
|
168
|
+
bValue = `${bClearingType}_${bWalletType}`.toLowerCase();
|
|
169
|
+
break;
|
|
170
|
+
default:
|
|
171
|
+
return 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (aValue < bValue) return -1 * sortOrder;
|
|
175
|
+
if (aValue > bValue) return 1 * sortOrder;
|
|
176
|
+
return 0;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
95
180
|
return transactionHistory;
|
|
96
181
|
};
|
|
97
182
|
|
|
@@ -145,15 +145,25 @@ const addPaymentMethodParams = (params, logger) => {
|
|
|
145
145
|
try {
|
|
146
146
|
const tokenString = Buffer.from(updated.applePayToken, 'base64').toString('utf-8');
|
|
147
147
|
tokenData = JSON.parse(tokenString);
|
|
148
|
+
|
|
149
|
+
if (logger) {
|
|
150
|
+
logger.info("[Apple Pay] Token decoded from Base64 successfully");
|
|
151
|
+
}
|
|
148
152
|
} catch (e) {
|
|
149
153
|
try {
|
|
150
|
-
// Try parsing as JSON string directly
|
|
151
154
|
tokenData = typeof updated.applePayToken === 'string'
|
|
152
155
|
? JSON.parse(updated.applePayToken)
|
|
153
156
|
: updated.applePayToken;
|
|
157
|
+
|
|
158
|
+
if (logger) {
|
|
159
|
+
logger.info("[Apple Pay] Token parsed as JSON string directly");
|
|
160
|
+
}
|
|
154
161
|
} catch (e2) {
|
|
155
|
-
// If already an object, use as-is
|
|
156
162
|
tokenData = updated.applePayToken;
|
|
163
|
+
|
|
164
|
+
if (logger) {
|
|
165
|
+
logger.info("[Apple Pay] Token used as-is (already an object)");
|
|
166
|
+
}
|
|
157
167
|
}
|
|
158
168
|
}
|
|
159
169
|
|
|
@@ -162,7 +172,10 @@ const addPaymentMethodParams = (params, logger) => {
|
|
|
162
172
|
|
|
163
173
|
if (!paymentData) {
|
|
164
174
|
if (logger) {
|
|
165
|
-
logger.error("[Apple Pay] Invalid token structure: missing paymentData field"
|
|
175
|
+
logger.error("[Apple Pay] Invalid token structure: missing paymentData field", {
|
|
176
|
+
tokenKeys: Object.keys(tokenData),
|
|
177
|
+
tokenStructure: JSON.stringify(tokenData).substring(0, 500)
|
|
178
|
+
});
|
|
166
179
|
}
|
|
167
180
|
delete updated.applePayToken;
|
|
168
181
|
return updated;
|
|
@@ -171,30 +184,66 @@ const addPaymentMethodParams = (params, logger) => {
|
|
|
171
184
|
const header = paymentData.header || {};
|
|
172
185
|
|
|
173
186
|
// Payone required fields according to docs
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
187
|
+
// Extract version, data, signature from paymentData
|
|
188
|
+
const tokenVersion = paymentData.version || "EC_v1";
|
|
189
|
+
const tokenDataValue = paymentData.data || "";
|
|
190
|
+
const tokenSignature = paymentData.signature || "";
|
|
191
|
+
|
|
192
|
+
// Extract from header
|
|
193
|
+
const ephemeralPublicKey = header.ephemeralPublicKey || "";
|
|
194
|
+
const publicKeyHash = header.publicKeyHash || "";
|
|
195
|
+
const transactionId = paymentData.transactionId || header.transactionId || "";
|
|
196
|
+
|
|
197
|
+
// Set Payone required fields
|
|
198
|
+
updated["add_paydata[paymentdata_token_version]"] = tokenVersion;
|
|
199
|
+
updated["add_paydata[paymentdata_token_data]"] = tokenDataValue;
|
|
200
|
+
updated["add_paydata[paymentdata_token_signature]"] = tokenSignature;
|
|
201
|
+
updated["add_paydata[paymentdata_token_ephemeral_publickey]"] = ephemeralPublicKey;
|
|
202
|
+
updated["add_paydata[paymentdata_token_publickey_hash]"] = publicKeyHash;
|
|
179
203
|
|
|
180
204
|
// Transaction ID is optional according to Payone docs
|
|
181
|
-
if (
|
|
182
|
-
updated["add_paydata[paymentdata_token_transaction_id]"] =
|
|
205
|
+
if (transactionId) {
|
|
206
|
+
updated["add_paydata[paymentdata_token_transaction_id]"] = transactionId;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (logger) {
|
|
210
|
+
logger.info("[Apple Pay] Token extracted successfully:", {
|
|
211
|
+
hasVersion: !!tokenVersion,
|
|
212
|
+
hasData: !!tokenDataValue,
|
|
213
|
+
hasSignature: !!tokenSignature,
|
|
214
|
+
hasEphemeralPublicKey: !!ephemeralPublicKey,
|
|
215
|
+
hasPublicKeyHash: !!publicKeyHash,
|
|
216
|
+
hasTransactionId: !!transactionId,
|
|
217
|
+
dataLength: tokenDataValue.length,
|
|
218
|
+
signatureLength: tokenSignature.length,
|
|
219
|
+
ephemeralPublicKeyLength: ephemeralPublicKey.length,
|
|
220
|
+
publicKeyHashLength: publicKeyHash.length
|
|
221
|
+
});
|
|
183
222
|
}
|
|
184
223
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
!
|
|
188
|
-
!
|
|
224
|
+
// Validate required fields
|
|
225
|
+
if (!tokenDataValue ||
|
|
226
|
+
!tokenSignature ||
|
|
227
|
+
!ephemeralPublicKey ||
|
|
228
|
+
!publicKeyHash) {
|
|
189
229
|
if (logger) {
|
|
190
230
|
logger.error("[Apple Pay] Missing required token fields:", {
|
|
191
|
-
hasData: !!
|
|
192
|
-
hasSignature: !!
|
|
193
|
-
hasEphemeralPublicKey: !!
|
|
194
|
-
hasPublicKeyHash: !!
|
|
231
|
+
hasData: !!tokenDataValue,
|
|
232
|
+
hasSignature: !!tokenSignature,
|
|
233
|
+
hasEphemeralPublicKey: !!ephemeralPublicKey,
|
|
234
|
+
hasPublicKeyHash: !!publicKeyHash,
|
|
235
|
+
paymentDataKeys: Object.keys(paymentData),
|
|
236
|
+
headerKeys: Object.keys(header)
|
|
195
237
|
});
|
|
196
238
|
}
|
|
197
239
|
}
|
|
240
|
+
} else {
|
|
241
|
+
if (logger) {
|
|
242
|
+
logger.error("[Apple Pay] Token is not a valid object:", {
|
|
243
|
+
tokenType: typeof tokenData,
|
|
244
|
+
tokenValue: typeof tokenData === 'string' ? tokenData.substring(0, 200) : String(tokenData).substring(0, 200)
|
|
245
|
+
});
|
|
246
|
+
}
|
|
198
247
|
}
|
|
199
248
|
|
|
200
249
|
delete updated.applePayToken;
|