strapi-plugin-payone-provider 5.8.29 → 5.8.30

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.
@@ -14,7 +14,7 @@ import { ChevronDownIcon, ChevronUpIcon } from "../icons";
14
14
  import {
15
15
  formatAmount,
16
16
  formatDate,
17
- getPaymentMethodName,
17
+ getPaymentMethodDisplay,
18
18
  } from "../../../utils/transactionTableUtils";
19
19
  import TransactionDetails from "./details/TransactionDetails";
20
20
  import FiltersPanel from "./FiltersPanel";
@@ -131,19 +131,28 @@ const TransactionTable = () => {
131
131
  {formatAmount(transaction.amount, transaction.currency)}
132
132
  </Typography>
133
133
  );
134
- case "paymentMethod":
134
+ case "paymentMethod": {
135
+ const clearingtype =
136
+ transaction.raw_request?.clearingtype ||
137
+ transaction.body?.raw_request?.clearingtype;
138
+ const wallettype =
139
+ transaction.raw_request?.wallettype ||
140
+ transaction.body?.raw_request?.wallettype;
141
+ const cardtype =
142
+ transaction.raw_request?.cardtype ||
143
+ transaction.body?.raw_request?.cardtype;
144
+ const { category, subtype } = getPaymentMethodDisplay(
145
+ clearingtype,
146
+ wallettype,
147
+ cardtype
148
+ );
135
149
  return (
136
150
  <Typography variant="pi">
137
- {getPaymentMethodName(
138
- transaction.raw_request?.clearingtype ||
139
- transaction.body?.raw_request?.clearingtype,
140
- transaction.raw_request?.wallettype ||
141
- transaction.body?.raw_request?.wallettype,
142
- transaction.raw_request?.cardtype ||
143
- transaction.body?.raw_request?.cardtype
144
- )}
151
+ {category}
152
+ {subtype ? ` / ${subtype}` : ""}
145
153
  </Typography>
146
154
  );
155
+ }
147
156
  case "type":
148
157
  return (
149
158
  <Typography variant="pi" fontWeight="semiBold">
@@ -69,3 +69,49 @@ export const getCardTypeName = (transaction) => {
69
69
  return cardtype || "Unknown";
70
70
  }
71
71
  };
72
+
73
+ const CARD_TYPE_LABELS = {
74
+ V: "Visa",
75
+ M: "Mastercard",
76
+ A: "American Express",
77
+ J: "JCB",
78
+ D: "Diners",
79
+ O: "Maestro",
80
+ };
81
+
82
+ export const getCardTypeLabel = (cardtype) =>
83
+ CARD_TYPE_LABELS[cardtype] || cardtype || null;
84
+
85
+ export const getWalletLabel = (wallettype) => {
86
+ switch (String(wallettype || "").toUpperCase()) {
87
+ case "PPE":
88
+ return "PayPal";
89
+ case "GPY":
90
+ case "GOOGLEPAY":
91
+ return "Google Pay";
92
+ case "APL":
93
+ case "APPLEPAY":
94
+ return "Apple Pay";
95
+ default:
96
+ return wallettype || null;
97
+ }
98
+ };
99
+
100
+ /**
101
+ * Resolves a transaction's payment method into a category and subtype label.
102
+ * @returns {{ category: string, subtype: string|null }}
103
+ */
104
+ export const getPaymentMethodDisplay = (clearingtype, wallettype, cardtype) => {
105
+ switch (clearingtype) {
106
+ case "cc":
107
+ return { category: "Credit Card", subtype: getCardTypeLabel(cardtype) };
108
+ case "wlt":
109
+ return { category: "Wallet", subtype: getWalletLabel(wallettype) };
110
+ case "sb":
111
+ return { category: "Online Banking", subtype: null };
112
+ case "elv":
113
+ return { category: "Direct Debit", subtype: "SEPA" };
114
+ default:
115
+ return { category: clearingtype || "Unknown", subtype: null };
116
+ }
117
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-plugin-payone-provider",
3
- "version": "5.8.29",
3
+ "version": "5.8.30",
4
4
  "description": "Strapi plugin for Payone payment gateway integration",
5
5
  "license": "MIT",
6
6
  "maintainers": [
@@ -72,55 +72,10 @@ const buildWhereFromFilters = (filters = {}) => {
72
72
  conditions.push({ createdAt: { $lte: dateTo.toISOString() } });
73
73
  }
74
74
 
75
- if (hasFilterValue(filters.payment_method)) {
76
- switch (filters.payment_method) {
77
- case "credit_card":
78
- conditions.push({ raw_request: { $containsi: '"clearingtype":"cc"' } });
79
- break;
80
- case "paypal":
81
- conditions.push({
82
- $and: [
83
- { raw_request: { $containsi: '"clearingtype":"wlt"' } },
84
- { raw_request: { $containsi: '"wallettype":"PPE"' } },
85
- ],
86
- });
87
- break;
88
- case "google_pay":
89
- conditions.push({
90
- $and: [
91
- { raw_request: { $containsi: '"clearingtype":"wlt"' } },
92
- {
93
- $or: [
94
- { raw_request: { $containsi: '"wallettype":"GPY"' } },
95
- { raw_request: { $containsi: '"wallettype":"GOOGLEPAY"' } },
96
- ],
97
- },
98
- ],
99
- });
100
- break;
101
- case "apple_pay":
102
- conditions.push({
103
- $and: [
104
- { raw_request: { $containsi: '"clearingtype":"wlt"' } },
105
- {
106
- $or: [
107
- { raw_request: { $containsi: '"wallettype":"APL"' } },
108
- { raw_request: { $containsi: '"wallettype":"APPLEPAY"' } },
109
- ],
110
- },
111
- ],
112
- });
113
- break;
114
- case "sofort":
115
- conditions.push({ raw_request: { $containsi: '"clearingtype":"sb"' } });
116
- break;
117
- case "sepa":
118
- conditions.push({ raw_request: { $containsi: '"clearingtype":"elv"' } });
119
- break;
120
- default:
121
- break;
122
- }
123
- }
75
+ // `payment_method` is NOT filtered here: the payment method lives inside the
76
+ // `raw_request` JSON column, and the query engine cannot reliably filter JSON
77
+ // columns ($containsi returns empty). It is applied in JS — see
78
+ // `matchesPaymentMethod` used by getTransactionHistory / getTransactionsForExport.
124
79
 
125
80
  if (conditions.length === 0) return undefined;
126
81
  if (conditions.length === 1) return conditions[0];
@@ -137,24 +92,66 @@ const ALLOWED_SORT_FIELDS = [
137
92
  "updatedAt",
138
93
  ];
139
94
 
95
+ const PAYMENT_METHOD_MATCHERS = {
96
+ credit_card: (rr) => rr.clearingtype === "cc",
97
+ paypal: (rr) => rr.clearingtype === "wlt" && rr.wallettype === "PPE",
98
+ google_pay: (rr) => rr.clearingtype === "wlt" && ["GPY", "GOOGLEPAY"].includes(rr.wallettype),
99
+ apple_pay: (rr) => rr.clearingtype === "wlt" && ["APL", "APPLEPAY"].includes(rr.wallettype),
100
+ sofort: (rr) => rr.clearingtype === "sb",
101
+ sepa: (rr) => rr.clearingtype === "elv",
102
+ };
103
+
104
+ /** Matches a transaction row against a payment_method filter value using its raw_request JSON. */
105
+ const matchesPaymentMethod = (row, method) => {
106
+ const matcher = PAYMENT_METHOD_MATCHERS[method];
107
+ if (!matcher) return true;
108
+ const rr = parseJsonField(row.raw_request);
109
+ return matcher({
110
+ clearingtype: String(rr.clearingtype || "").toLowerCase(),
111
+ wallettype: String(rr.wallettype || "").toUpperCase(),
112
+ });
113
+ };
114
+
140
115
  const getTransactionHistory = async (
141
116
  strapi,
142
117
  { filters = {}, pagination = {}, sort_by, sort_order }
143
118
  ) => {
144
119
  const page = Math.max(1, Number(pagination.page) || 1);
145
120
  const pageSize = Math.min(100, Math.max(1, Number(pagination.pageSize) || 10));
146
- const offset = (page - 1) * pageSize;
147
121
 
148
122
  const where = buildWhereFromFilters(filters);
149
-
150
123
  const sortField =
151
124
  sort_by && ALLOWED_SORT_FIELDS.includes(sort_by) ? sort_by : "createdAt";
152
125
  const order = sort_order === "asc" ? "asc" : "desc";
153
126
 
127
+ const paymentMethod = hasFilterValue(filters.payment_method)
128
+ ? String(filters.payment_method).trim()
129
+ : "";
130
+
131
+ // payment_method can only be filtered in JS — fetch SQL-filtered rows, then
132
+ // filter and paginate by payment method here.
133
+ if (paymentMethod) {
134
+ const listOptions = { orderBy: { [sortField]: order }, limit: 10000 };
135
+ if (where !== undefined) listOptions.where = where;
136
+
137
+ const allRows = await strapi.db.query(TRANSACTION_UID).findMany(listOptions);
138
+ const filtered = allRows.filter((row) => matchesPaymentMethod(row, paymentMethod));
139
+
140
+ const total = filtered.length;
141
+ const pageCount = Math.max(1, Math.ceil(total / pageSize));
142
+ const validPage = Math.min(page, pageCount);
143
+ const start = (validPage - 1) * pageSize;
144
+
145
+ return {
146
+ data: filtered.slice(start, start + pageSize),
147
+ pagination: { page: validPage, pageSize, pageCount, total },
148
+ };
149
+ }
150
+
154
151
  const queryOptions = {
155
152
  orderBy: { [sortField]: order },
156
153
  limit: pageSize,
157
- offset,
154
+ offset: (page - 1) * pageSize,
158
155
  };
159
156
  if (where !== undefined) queryOptions.where = where;
160
157
 
@@ -167,12 +164,7 @@ const getTransactionHistory = async (
167
164
 
168
165
  return {
169
166
  data,
170
- pagination: {
171
- page: validPage,
172
- pageSize,
173
- pageCount,
174
- total,
175
- },
167
+ pagination: { page: validPage, pageSize, pageCount, total },
176
168
  };
177
169
  };
178
170
 
@@ -194,7 +186,12 @@ const getTransactionsForExport = async (
194
186
  if (where !== undefined) queryOptions.where = where;
195
187
 
196
188
  const data = await strapi.db.query(TRANSACTION_UID).findMany(queryOptions);
197
- return data;
189
+ const paymentMethod = hasFilterValue(filters.payment_method)
190
+ ? String(filters.payment_method).trim()
191
+ : "";
192
+ return paymentMethod
193
+ ? data.filter((row) => matchesPaymentMethod(row, paymentMethod))
194
+ : data;
198
195
  };
199
196
 
200
197
  const TRANSACTION_ATTRS = [