strapi-plugin-payone-provider 5.8.29 → 5.8.31

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.31",
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,76 @@ const ALLOWED_SORT_FIELDS = [
137
92
  "updatedAt",
138
93
  ];
139
94
 
95
+ // PayOne wallet (`clearingtype: wlt`) codes per payment method. Google Pay is
96
+ // `GGP` and Apple Pay `APL` — the values the plugin itself writes in
97
+ // `paymentMethodParams.js`; the extra aliases cover legacy rows.
98
+ const WALLET_CODES = {
99
+ paypal: ["PPE"],
100
+ google_pay: ["GGP", "GPY", "GOOGLEPAY"],
101
+ apple_pay: ["APL", "APPLEPAY"],
102
+ };
103
+
104
+ const PAYMENT_METHOD_MATCHERS = {
105
+ credit_card: (rr) => rr.clearingtype === "cc",
106
+ paypal: (rr) => rr.clearingtype === "wlt" && WALLET_CODES.paypal.includes(rr.wallettype),
107
+ google_pay: (rr) => rr.clearingtype === "wlt" && WALLET_CODES.google_pay.includes(rr.wallettype),
108
+ apple_pay: (rr) => rr.clearingtype === "wlt" && WALLET_CODES.apple_pay.includes(rr.wallettype),
109
+ sofort: (rr) => rr.clearingtype === "sb",
110
+ sepa: (rr) => rr.clearingtype === "elv",
111
+ };
112
+
113
+ /** Matches a transaction row against a payment_method filter value using its raw_request JSON. */
114
+ const matchesPaymentMethod = (row, method) => {
115
+ const matcher = PAYMENT_METHOD_MATCHERS[method];
116
+ if (!matcher) return true;
117
+ const rr = parseJsonField(row.raw_request);
118
+ const wallettype = rr.wallettype || rr["add_paydata[paymentmethod]"] || "";
119
+ return matcher({
120
+ clearingtype: String(rr.clearingtype || "").toLowerCase(),
121
+ wallettype: String(wallettype).toUpperCase(),
122
+ });
123
+ };
124
+
140
125
  const getTransactionHistory = async (
141
126
  strapi,
142
127
  { filters = {}, pagination = {}, sort_by, sort_order }
143
128
  ) => {
144
129
  const page = Math.max(1, Number(pagination.page) || 1);
145
130
  const pageSize = Math.min(100, Math.max(1, Number(pagination.pageSize) || 10));
146
- const offset = (page - 1) * pageSize;
147
131
 
148
132
  const where = buildWhereFromFilters(filters);
149
-
150
133
  const sortField =
151
134
  sort_by && ALLOWED_SORT_FIELDS.includes(sort_by) ? sort_by : "createdAt";
152
135
  const order = sort_order === "asc" ? "asc" : "desc";
153
136
 
137
+ const paymentMethod = hasFilterValue(filters.payment_method)
138
+ ? String(filters.payment_method).trim()
139
+ : "";
140
+
141
+ // payment_method can only be filtered in JS — fetch SQL-filtered rows, then
142
+ // filter and paginate by payment method here.
143
+ if (paymentMethod) {
144
+ const listOptions = { orderBy: { [sortField]: order }, limit: 10000 };
145
+ if (where !== undefined) listOptions.where = where;
146
+
147
+ const allRows = await strapi.db.query(TRANSACTION_UID).findMany(listOptions);
148
+ const filtered = allRows.filter((row) => matchesPaymentMethod(row, paymentMethod));
149
+
150
+ const total = filtered.length;
151
+ const pageCount = Math.max(1, Math.ceil(total / pageSize));
152
+ const validPage = Math.min(page, pageCount);
153
+ const start = (validPage - 1) * pageSize;
154
+
155
+ return {
156
+ data: filtered.slice(start, start + pageSize),
157
+ pagination: { page: validPage, pageSize, pageCount, total },
158
+ };
159
+ }
160
+
154
161
  const queryOptions = {
155
162
  orderBy: { [sortField]: order },
156
163
  limit: pageSize,
157
- offset,
164
+ offset: (page - 1) * pageSize,
158
165
  };
159
166
  if (where !== undefined) queryOptions.where = where;
160
167
 
@@ -167,12 +174,7 @@ const getTransactionHistory = async (
167
174
 
168
175
  return {
169
176
  data,
170
- pagination: {
171
- page: validPage,
172
- pageSize,
173
- pageCount,
174
- total,
175
- },
177
+ pagination: { page: validPage, pageSize, pageCount, total },
176
178
  };
177
179
  };
178
180
 
@@ -194,7 +196,12 @@ const getTransactionsForExport = async (
194
196
  if (where !== undefined) queryOptions.where = where;
195
197
 
196
198
  const data = await strapi.db.query(TRANSACTION_UID).findMany(queryOptions);
197
- return data;
199
+ const paymentMethod = hasFilterValue(filters.payment_method)
200
+ ? String(filters.payment_method).trim()
201
+ : "";
202
+ return paymentMethod
203
+ ? data.filter((row) => matchesPaymentMethod(row, paymentMethod))
204
+ : data;
198
205
  };
199
206
 
200
207
  const TRANSACTION_ATTRS = [