strapi-plugin-payone-provider 4.6.12 → 4.6.13
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/package.json
CHANGED
package/server/config/index.js
CHANGED
|
@@ -14,7 +14,13 @@ module.exports = {
|
|
|
14
14
|
merchantName: "",
|
|
15
15
|
displayName: "",
|
|
16
16
|
domainName: "",
|
|
17
|
-
merchantIdentifier: ""
|
|
17
|
+
merchantIdentifier: "",
|
|
18
|
+
enable3DSecure: false,
|
|
19
|
+
enableCreditCard: false,
|
|
20
|
+
enablePayPal: false,
|
|
21
|
+
enableGooglePay: false,
|
|
22
|
+
enableApplePay: false,
|
|
23
|
+
enableSepaDirectDebit: false
|
|
18
24
|
}
|
|
19
25
|
},
|
|
20
26
|
validator(config) {
|
|
@@ -258,19 +258,20 @@ module.exports = ({ strapi }) => ({
|
|
|
258
258
|
|
|
259
259
|
async handleTransactionStatus(ctx) {
|
|
260
260
|
try {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
console.log(`[Payone TransactionStatus] Responded TSOK`);
|
|
261
|
+
if (!ctx.state.payoneAllowed) {
|
|
262
|
+
console.log("[Payone] Notification ignored (policy failed)");
|
|
263
|
+
} else {
|
|
264
|
+
const notificationData = ctx.request.body || {};
|
|
265
|
+
await getPayoneService(strapi).processTransactionStatus(notificationData);
|
|
266
|
+
}
|
|
268
267
|
} catch (error) {
|
|
269
|
-
console.log("[Payone TransactionStatus] Error
|
|
270
|
-
ctx.status = 200;
|
|
271
|
-
ctx.body = "TSOK";
|
|
272
|
-
ctx.type = "text/plain";
|
|
268
|
+
console.log("[Payone TransactionStatus] Error:", error);
|
|
273
269
|
}
|
|
270
|
+
|
|
271
|
+
ctx.status = 200;
|
|
272
|
+
ctx.body = "TSOK";
|
|
273
|
+
ctx.type = "text/plain";
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
+
|
|
276
277
|
});
|
|
@@ -1,30 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
module.exports = async (ctx, config, { strapi }) => {
|
|
1
|
+
module.exports = async (ctx) => {
|
|
4
2
|
const { request } = ctx;
|
|
5
|
-
const userAgent = request.header["user-agent"] || request.header["User-Agent"] || "";
|
|
6
|
-
const clientIp = request.ip || request.connection?.remoteAddress || "";
|
|
7
|
-
|
|
8
|
-
if (userAgent !== "PAYONE FinanceGate") {
|
|
9
|
-
console.log(`[Payone TransactionStatus] Invalid User-Agent: ${userAgent}, IP: ${clientIp}`);
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
3
|
|
|
4
|
+
const userAgent = request.headers["user-agent"] || "";
|
|
5
|
+
const clientIp =
|
|
6
|
+
request.headers["x-payone-client-ip"]?.trim() ||
|
|
7
|
+
request.headers["x-forwarded-for"]?.split(",")[0]?.trim() ||
|
|
8
|
+
request.ip ||
|
|
9
|
+
"";
|
|
13
10
|
|
|
14
|
-
const
|
|
15
|
-
if (ip.startsWith("185.60.20.")) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
11
|
+
const isValid = userAgent === "PAYONE FinanceGate" && (clientIp.startsWith("185.60.20.") || clientIp === "54.246.203.105");
|
|
18
12
|
|
|
19
|
-
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
23
|
-
};
|
|
13
|
+
ctx.state.payoneAllowed = isValid;
|
|
24
14
|
|
|
25
|
-
if (!
|
|
26
|
-
console.log(
|
|
27
|
-
return false;
|
|
15
|
+
if (!isValid) {
|
|
16
|
+
console.log("[Payone] Policy failed", { userAgent, clientIp });
|
|
28
17
|
}
|
|
29
18
|
|
|
30
19
|
return true;
|
|
@@ -5,48 +5,66 @@ const { sanitizeSensitive } = require("../utils/sanitize");
|
|
|
5
5
|
|
|
6
6
|
const TRANSACTION_UID = "plugin::strapi-plugin-payone-provider.transaction";
|
|
7
7
|
|
|
8
|
+
const genreateUpdateData = (notificationData, existing, safeNotification) => {
|
|
9
|
+
const amount = String(notificationData.clearing_amount) || String(Math.round(parseFloat(notificationData.price) * 100)) || existing.amount;
|
|
10
|
+
const raw_request = {
|
|
11
|
+
...existing.raw_request,
|
|
12
|
+
...notificationData,
|
|
13
|
+
mode: notificationData.mode,
|
|
14
|
+
amount,
|
|
15
|
+
clearingtype: notificationData.clearingtype || existing.clearingtype,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
status: notificationData.transaction_status || existing.status,
|
|
20
|
+
currency: notificationData.currency || existing.currency,
|
|
21
|
+
reference: notificationData.reference || existing.reference,
|
|
22
|
+
amount,
|
|
23
|
+
body: {
|
|
24
|
+
...existing.body,
|
|
25
|
+
status: notificationData.transaction_status,
|
|
26
|
+
amount,
|
|
27
|
+
raw_request: sanitizeSensitive(raw_request),
|
|
28
|
+
payone_notification_data: safeNotification,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const validateData = (notificationData, settings) => {
|
|
34
|
+
const isExist = (settings.portalid && settings.aid && settings.key) && (notificationData.portalid && notificationData.aid && notificationData.key);
|
|
35
|
+
const isMatch = notificationData.portalid === settings.portalid && notificationData.aid === settings.aid && notificationData.key === settings.key;
|
|
36
|
+
|
|
37
|
+
if (!isExist) {
|
|
38
|
+
console.log("[Payone TransactionStatus] Settings not found or payone data missing");
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!isMatch) {
|
|
43
|
+
console.log("[Payone TransactionStatus] Payone data mismatch with settings");
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return true;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
|
|
8
51
|
const processTransactionStatus = async (strapi, notificationData) => {
|
|
9
52
|
try {
|
|
10
53
|
const settings = await getSettings(strapi);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!settings || !settings.key) {
|
|
14
|
-
console.log("[Payone TransactionStatus] Settings not found or key missing");
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (notificationData.portalid !== settings.portalid || notificationData.aid !== settings.aid) {
|
|
19
|
-
console.log(`[Payone TransactionStatus] Portal ID or AID mismatch txid: ${txid}`);
|
|
54
|
+
if (!validateData(notificationData, settings)) {
|
|
20
55
|
return;
|
|
21
56
|
}
|
|
22
57
|
|
|
58
|
+
const txid = notificationData.txid;
|
|
23
59
|
const existing = await strapi.db.query(TRANSACTION_UID).findOne({ where: { txid } });
|
|
60
|
+
|
|
24
61
|
if (!existing) {
|
|
25
62
|
console.log(`[Payone TransactionStatus] Transaction ${txid} not found. Notification ignored.`);
|
|
26
63
|
return;
|
|
27
64
|
}
|
|
28
65
|
|
|
29
|
-
const amount = notificationData.clearing_amount
|
|
30
|
-
? String(notificationData.clearing_amount)
|
|
31
|
-
: notificationData.price
|
|
32
|
-
? String(Math.round(parseFloat(notificationData.price) * 100))
|
|
33
|
-
: existing.amount;
|
|
34
|
-
|
|
35
66
|
const safeNotification = sanitizeSensitive({ ...notificationData });
|
|
36
|
-
|
|
37
|
-
const data = {
|
|
38
|
-
status: notificationData.transaction_status || existing.status,
|
|
39
|
-
currency: notificationData.currency || existing.currency,
|
|
40
|
-
reference: notificationData.reference || existing.reference,
|
|
41
|
-
amount,
|
|
42
|
-
body: {
|
|
43
|
-
...existing.body,
|
|
44
|
-
status: notificationData.transaction_status,
|
|
45
|
-
amount,
|
|
46
|
-
payone_notification_data: safeNotification,
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
|
|
67
|
+
const data = genreateUpdateData(notificationData, existing, safeNotification);
|
|
50
68
|
await strapi.db.query(TRANSACTION_UID).update({
|
|
51
69
|
where: { id: existing.id },
|
|
52
70
|
data,
|