strapi-plugin-payone-provider 1.6.7 → 4.6.10

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.
@@ -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 || null,
32
- raw_request: transactionData.raw_request || null,
33
- raw_response: transactionData.raw_response || transactionData,
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 > 1000) {
41
- transactionHistory = transactionHistory.slice(0, 1000);
56
+ if (transactionHistory.length > 5000) {
57
+ transactionHistory = transactionHistory.slice(0, 5000);
42
58
  }
43
59
 
44
60
  await pluginStore.set({
@@ -113,6 +129,54 @@ const getTransactionHistory = async (strapi, filters = {}) => {
113
129
  );
114
130
  }
115
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
+
116
180
  return transactionHistory;
117
181
  };
118
182