@easypayment/medusa-payment-paypal 1.3.3 → 1.3.4
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/.medusa/server/src/admin/index.js +91 -7
- package/.medusa/server/src/admin/index.mjs +91 -7
- package/.medusa/server/src/api/admin/paypal/logs/route.d.ts +10 -0
- package/.medusa/server/src/api/admin/paypal/logs/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/logs/route.js +43 -0
- package/.medusa/server/src/api/admin/paypal/logs/route.js.map +1 -0
- package/.medusa/server/src/api/middlewares.d.ts.map +1 -1
- package/.medusa/server/src/api/middlewares.js +22 -4
- package/.medusa/server/src/api/middlewares.js.map +1 -1
- package/.medusa/server/src/api/utils/request-logger.d.ts +11 -0
- package/.medusa/server/src/api/utils/request-logger.d.ts.map +1 -0
- package/.medusa/server/src/api/utils/request-logger.js +69 -0
- package/.medusa/server/src/api/utils/request-logger.js.map +1 -0
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts +3 -3
- package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/service.js +9 -0
- package/.medusa/server/src/modules/paypal/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.js +1 -1
- package/.medusa/server/src/modules/paypal/types/config.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.js +10 -0
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js +39 -0
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/request-logger.d.ts +62 -0
- package/.medusa/server/src/modules/paypal/utils/request-logger.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/request-logger.js +297 -0
- package/.medusa/server/src/modules/paypal/utils/request-logger.js.map +1 -0
- package/CHANGELOG.md +7 -0
- package/README.md +4 -0
- package/package.json +1 -1
- package/src/admin/routes/settings/paypal/additional-settings/page.tsx +87 -0
- package/src/api/admin/paypal/logs/route.ts +50 -0
- package/src/api/middlewares.ts +22 -4
- package/src/api/utils/request-logger.ts +84 -0
- package/src/modules/paypal/service.ts +11 -0
- package/src/modules/paypal/types/config.ts +1 -1
- package/src/modules/paypal/utils/credential-resolver.ts +9 -0
- package/src/modules/paypal/utils/paypal-fetch.ts +42 -0
- package/src/modules/paypal/utils/request-logger.ts +358 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Opt-in request/response file logger for the PayPal integration.
|
|
4
|
+
*
|
|
5
|
+
* Purpose: produce a complete, human-readable log of the HTTP traffic between
|
|
6
|
+
* this plugin and PayPal (outbound) plus the plugin's own API routes (inbound),
|
|
7
|
+
* so it can be exported and handed to PayPal's integration-review team.
|
|
8
|
+
*
|
|
9
|
+
* Disabled by default. Turned on from the admin settings (the
|
|
10
|
+
* `additional_settings.debug_logging` flag, synced into this module via
|
|
11
|
+
* `setRequestLoggingEnabled`) or, as a convenience, by the `PAYPAL_REQUEST_LOG`
|
|
12
|
+
* env var. When off, every entry point here is a cheap no-op.
|
|
13
|
+
*
|
|
14
|
+
* The log intentionally KEEPS the `PayPal-Partner-Attribution-Id` (BN code)
|
|
15
|
+
* header — PayPal validates it during review — while redacting credentials
|
|
16
|
+
* (Authorization headers, access/refresh tokens, client secrets, raw card
|
|
17
|
+
* fields) so the exported file is safe to share.
|
|
18
|
+
*/
|
|
19
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
20
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.setRequestLoggingEnabled = setRequestLoggingEnabled;
|
|
24
|
+
exports.isRequestLoggingEnabled = isRequestLoggingEnabled;
|
|
25
|
+
exports.getCurrentLogFilePath = getCurrentLogFilePath;
|
|
26
|
+
exports.logOutbound = logOutbound;
|
|
27
|
+
exports.logInbound = logInbound;
|
|
28
|
+
exports.listLogFiles = listLogFiles;
|
|
29
|
+
exports.resolveLogFile = resolveLogFile;
|
|
30
|
+
const fs_1 = __importDefault(require("fs"));
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Enable flag
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
/**
|
|
36
|
+
* `PAYPAL_REQUEST_LOG=1|true|yes|on` forces logging on regardless of the admin
|
|
37
|
+
* setting — handy on a box where you can't reach the admin UI. The admin
|
|
38
|
+
* setting controls the process-local flag below.
|
|
39
|
+
*/
|
|
40
|
+
const ENV_FORCE_ON = /^(1|true|yes|on)$/i.test((process.env.PAYPAL_REQUEST_LOG || "").trim());
|
|
41
|
+
let settingEnabled = false;
|
|
42
|
+
/** Sync the on/off flag from the persisted `additional_settings.debug_logging`. */
|
|
43
|
+
function setRequestLoggingEnabled(enabled) {
|
|
44
|
+
settingEnabled = !!enabled;
|
|
45
|
+
}
|
|
46
|
+
/** Whether request/response logging is currently active in this process. */
|
|
47
|
+
function isRequestLoggingEnabled() {
|
|
48
|
+
return ENV_FORCE_ON || settingEnabled;
|
|
49
|
+
}
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Redaction
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// Body keys whose VALUES must never hit the exported file. Card fields are
|
|
54
|
+
// included even though they normally never reach the backend (the JS SDK sends
|
|
55
|
+
// them straight to PayPal) — defence in depth for the advanced-card flow.
|
|
56
|
+
const SENSITIVE_BODY_KEY_RE = /secret|password|client_secret|access_token|refresh_token|authorization|auth_code|code_verifier|api[_-]?key|private[_-]?key|security_code|\bcvv2?\b|card[_-]?number|(^|_)number$|expiry|exp_(month|year)/i;
|
|
57
|
+
// Request/response HEADER names to redact. The BN code header is deliberately
|
|
58
|
+
// NOT here — PayPal needs to see it in the log.
|
|
59
|
+
const SENSITIVE_HEADER_RE = /^(authorization|proxy-authorization|cookie|set-cookie|x-api-key)$/i;
|
|
60
|
+
const REDACTED = "[REDACTED]";
|
|
61
|
+
function redactBody(value, depth = 0) {
|
|
62
|
+
if (depth > 8 || value === null || typeof value !== "object") {
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
return value.slice(0, 200).map((v) => redactBody(v, depth + 1));
|
|
67
|
+
}
|
|
68
|
+
const out = {};
|
|
69
|
+
for (const [k, v] of Object.entries(value)) {
|
|
70
|
+
out[k] = SENSITIVE_BODY_KEY_RE.test(k) ? REDACTED : redactBody(v, depth + 1);
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
function redactHeaders(headers) {
|
|
75
|
+
const out = {};
|
|
76
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
77
|
+
out[k] = SENSITIVE_HEADER_RE.test(k) ? REDACTED : v;
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
/** Best-effort parse + redact of a body that may be JSON, form-encoded, or text. */
|
|
82
|
+
function redactSerializedBody(body) {
|
|
83
|
+
if (body === undefined || body === null)
|
|
84
|
+
return "";
|
|
85
|
+
// Already a plain object/array (inbound res.json payloads).
|
|
86
|
+
if (typeof body === "object" && !(body instanceof Uint8Array)) {
|
|
87
|
+
try {
|
|
88
|
+
return JSON.stringify(redactBody(body), null, 2);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return "[unserializable object]";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const text = String(body);
|
|
95
|
+
if (!text)
|
|
96
|
+
return "";
|
|
97
|
+
const trimmed = text.trim();
|
|
98
|
+
// JSON?
|
|
99
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
100
|
+
try {
|
|
101
|
+
return JSON.stringify(redactBody(JSON.parse(trimmed)), null, 2);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// fall through to form / raw handling
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Form-encoded (grant_type=...&code_verifier=...)?
|
|
108
|
+
if (/^[^=\s]+=[^&\s]*(&[^=\s]+=[^&\s]*)*$/.test(trimmed)) {
|
|
109
|
+
try {
|
|
110
|
+
const params = new URLSearchParams(trimmed);
|
|
111
|
+
const obj = {};
|
|
112
|
+
for (const [k, v] of params.entries()) {
|
|
113
|
+
obj[k] = SENSITIVE_BODY_KEY_RE.test(k) ? REDACTED : v;
|
|
114
|
+
}
|
|
115
|
+
return JSON.stringify(obj, null, 2);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// fall through
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return trimmed.slice(0, 20_000);
|
|
122
|
+
}
|
|
123
|
+
function normalizeHeaders(headers) {
|
|
124
|
+
const out = {};
|
|
125
|
+
if (!headers)
|
|
126
|
+
return out;
|
|
127
|
+
try {
|
|
128
|
+
// Fetch Headers / Response.headers
|
|
129
|
+
if (typeof headers.forEach === "function") {
|
|
130
|
+
;
|
|
131
|
+
headers.forEach((v, k) => {
|
|
132
|
+
out[k] = v;
|
|
133
|
+
});
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
if (Array.isArray(headers)) {
|
|
137
|
+
for (const pair of headers) {
|
|
138
|
+
if (pair && pair.length >= 2)
|
|
139
|
+
out[String(pair[0])] = String(pair[1]);
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
144
|
+
out[k] = Array.isArray(v) ? v.join(", ") : String(v);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
// ignore malformed header containers
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
// File sink
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
function getLogDir() {
|
|
156
|
+
const dir = (process.env.PAYPAL_LOG_DIR || "").trim();
|
|
157
|
+
return dir ? path_1.default.resolve(dir) : path_1.default.join(process.cwd(), "logs");
|
|
158
|
+
}
|
|
159
|
+
const LOG_PREFIX = "paypal-requests-";
|
|
160
|
+
function dateStamp(d = new Date()) {
|
|
161
|
+
return d.toISOString().slice(0, 10); // YYYY-MM-DD
|
|
162
|
+
}
|
|
163
|
+
/** Absolute path of the log file for the current day. */
|
|
164
|
+
function getCurrentLogFilePath() {
|
|
165
|
+
return path_1.default.join(getLogDir(), `${LOG_PREFIX}${dateStamp()}.log`);
|
|
166
|
+
}
|
|
167
|
+
let dirEnsured = false;
|
|
168
|
+
function ensureDir(dir) {
|
|
169
|
+
if (dirEnsured)
|
|
170
|
+
return true;
|
|
171
|
+
try {
|
|
172
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
173
|
+
dirEnsured = true;
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
// Only warn once; never throw into the request path.
|
|
178
|
+
console.warn("[paypal_request_log] could not create log dir", dir, e?.message);
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function write(block) {
|
|
183
|
+
try {
|
|
184
|
+
const dir = getLogDir();
|
|
185
|
+
if (!ensureDir(dir))
|
|
186
|
+
return;
|
|
187
|
+
fs_1.default.appendFileSync(getCurrentLogFilePath(), block);
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
console.warn("[paypal_request_log] write failed:", e?.message);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const DIVIDER = "=".repeat(80);
|
|
194
|
+
function renderHeaders(headers) {
|
|
195
|
+
const keys = Object.keys(headers);
|
|
196
|
+
if (keys.length === 0)
|
|
197
|
+
return " (none)";
|
|
198
|
+
return keys.map((k) => ` ${k}: ${headers[k]}`).join("\n");
|
|
199
|
+
}
|
|
200
|
+
/** Append one outbound (plugin → PayPal / onboarding service) call. */
|
|
201
|
+
function logOutbound(entry) {
|
|
202
|
+
if (!isRequestLoggingEnabled())
|
|
203
|
+
return;
|
|
204
|
+
const reqHeaders = redactHeaders(normalizeHeaders(entry.requestHeaders));
|
|
205
|
+
const resHeaders = redactHeaders(normalizeHeaders(entry.responseHeaders));
|
|
206
|
+
const outcome = entry.error
|
|
207
|
+
? `ERROR ${entry.error?.message || String(entry.error)}`
|
|
208
|
+
: `-> ${entry.status ?? "?"}${entry.statusText ? " " + entry.statusText : ""}`;
|
|
209
|
+
const duration = typeof entry.durationMs === "number" ? ` (${entry.durationMs}ms)` : "";
|
|
210
|
+
const block = [
|
|
211
|
+
DIVIDER,
|
|
212
|
+
`[${new Date().toISOString()}] OUTBOUND ${entry.method} ${entry.url} ${outcome}${duration}`,
|
|
213
|
+
"Request Headers:",
|
|
214
|
+
renderHeaders(reqHeaders),
|
|
215
|
+
"Request Body:",
|
|
216
|
+
redactSerializedBody(entry.requestBody) || " (empty)",
|
|
217
|
+
"Response Headers:",
|
|
218
|
+
renderHeaders(resHeaders),
|
|
219
|
+
"Response Body:",
|
|
220
|
+
entry.error
|
|
221
|
+
? ` ${entry.error?.stack || String(entry.error)}`
|
|
222
|
+
: redactSerializedBody(entry.responseBody) || " (empty)",
|
|
223
|
+
DIVIDER,
|
|
224
|
+
"",
|
|
225
|
+
"",
|
|
226
|
+
].join("\n");
|
|
227
|
+
write(block);
|
|
228
|
+
}
|
|
229
|
+
/** Append one inbound (client → plugin API route) request. */
|
|
230
|
+
function logInbound(entry) {
|
|
231
|
+
if (!isRequestLoggingEnabled())
|
|
232
|
+
return;
|
|
233
|
+
const reqHeaders = redactHeaders(normalizeHeaders(entry.requestHeaders));
|
|
234
|
+
const duration = typeof entry.durationMs === "number" ? ` (${entry.durationMs}ms)` : "";
|
|
235
|
+
const query = entry.query && Object.keys(entry.query).length
|
|
236
|
+
? `?${new URLSearchParams(entry.query).toString()}`
|
|
237
|
+
: "";
|
|
238
|
+
const block = [
|
|
239
|
+
DIVIDER,
|
|
240
|
+
`[${new Date().toISOString()}] INBOUND ${entry.method} ${entry.path}${query} -> ${entry.status ?? "?"}${duration}`,
|
|
241
|
+
"Request Headers:",
|
|
242
|
+
renderHeaders(reqHeaders),
|
|
243
|
+
"Request Body:",
|
|
244
|
+
redactSerializedBody(entry.requestBody) || " (empty)",
|
|
245
|
+
"Response Body:",
|
|
246
|
+
redactSerializedBody(entry.responseBody) || " (empty)",
|
|
247
|
+
DIVIDER,
|
|
248
|
+
"",
|
|
249
|
+
"",
|
|
250
|
+
].join("\n");
|
|
251
|
+
write(block);
|
|
252
|
+
}
|
|
253
|
+
/** List the available daily log files, newest first. */
|
|
254
|
+
function listLogFiles() {
|
|
255
|
+
try {
|
|
256
|
+
const dir = getLogDir();
|
|
257
|
+
if (!fs_1.default.existsSync(dir))
|
|
258
|
+
return [];
|
|
259
|
+
return fs_1.default
|
|
260
|
+
.readdirSync(dir)
|
|
261
|
+
.filter((f) => f.startsWith(LOG_PREFIX) && f.endsWith(".log"))
|
|
262
|
+
.map((name) => {
|
|
263
|
+
const stat = fs_1.default.statSync(path_1.default.join(dir, name));
|
|
264
|
+
return {
|
|
265
|
+
name,
|
|
266
|
+
size: stat.size,
|
|
267
|
+
modified: stat.mtime.toISOString(),
|
|
268
|
+
};
|
|
269
|
+
})
|
|
270
|
+
.sort((a, b) => (a.name < b.name ? 1 : -1));
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
return [];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Resolve a requested log file name to an absolute path INSIDE the log dir, or
|
|
278
|
+
* null if it escapes the dir / doesn't exist. Guards against path traversal.
|
|
279
|
+
*/
|
|
280
|
+
function resolveLogFile(name) {
|
|
281
|
+
const dir = getLogDir();
|
|
282
|
+
const target = name && name.trim() ? name.trim() : null;
|
|
283
|
+
const chosen = target
|
|
284
|
+
? path_1.default.join(dir, path_1.default.basename(target))
|
|
285
|
+
: listLogFiles()[0]
|
|
286
|
+
? path_1.default.join(dir, listLogFiles()[0].name)
|
|
287
|
+
: null;
|
|
288
|
+
if (!chosen)
|
|
289
|
+
return null;
|
|
290
|
+
// basename() already strips any directory component; verify containment.
|
|
291
|
+
if (path_1.default.dirname(chosen) !== path_1.default.resolve(dir))
|
|
292
|
+
return null;
|
|
293
|
+
if (!fs_1.default.existsSync(chosen))
|
|
294
|
+
return null;
|
|
295
|
+
return chosen;
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=request-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-logger.js","sourceRoot":"","sources":["../../../../../../src/modules/paypal/utils/request-logger.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;AAqBH,4DAEC;AAGD,0DAEC;AA6HD,sDAEC;AA2DD,kCAgCC;AAcD,gCA8BC;AAaD,oCAmBC;AAMD,wCAaC;AAnVD,4CAAmB;AACnB,gDAAuB;AAEvB,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,YAAY,GAAG,oBAAoB,CAAC,IAAI,CAC5C,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAC9C,CAAA;AAED,IAAI,cAAc,GAAG,KAAK,CAAA;AAE1B,mFAAmF;AACnF,SAAgB,wBAAwB,CAAC,OAAgB;IACvD,cAAc,GAAG,CAAC,CAAC,OAAO,CAAA;AAC5B,CAAC;AAED,4EAA4E;AAC5E,SAAgB,uBAAuB;IACrC,OAAO,YAAY,IAAI,cAAc,CAAA;AACvC,CAAC;AAED,8EAA8E;AAC9E,YAAY;AACZ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AAI,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAA;IAC3D,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAA;IACvC,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@easypayment/medusa-payment-paypal` are documented here.
|
|
4
4
|
|
|
5
|
+
## 1.3.4 — 2026-11-13
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- No code changes. Version aligned with `@easypayment/medusa-paypal-ui` 1.3.4,
|
|
10
|
+
which refreshes the storefront unsupported-currency notice.
|
|
11
|
+
|
|
5
12
|
## 1.3.3 — 2026-11-05
|
|
6
13
|
|
|
7
14
|
### Fixed
|
package/README.md
CHANGED
|
@@ -165,6 +165,8 @@ Everything is managed in **Medusa Admin → Settings → PayPal** — changes ap
|
|
|
165
165
|
| `PAYPAL_CURRENCY` | `EUR` | Fallback currency if none is configured |
|
|
166
166
|
| `PAYPAL_ALERT_WEBHOOK_URLS` | *(unset)* | Comma-separated URLs that receive operational alerts (including dead-lettered webhook events) |
|
|
167
167
|
| `PAYPAL_SETTINGS_CACHE_MS` | `15000` | In-process cache for plugin settings reads; `0` disables |
|
|
168
|
+
| `PAYPAL_REQUEST_LOG` | *(off)* | `1`/`true` force-enables the request/response log file regardless of the admin toggle (normally enabled from **Settings → PayPal → Additional Settings**) |
|
|
169
|
+
| `PAYPAL_LOG_DIR` | `./logs` | Directory for the `paypal-requests-YYYY-MM-DD.log` file written when logging is on |
|
|
168
170
|
| `PAYPAL_SEND_SHIPPING_ADDRESS` | `false` | `true` sends the cart's shipping address on PayPal orders (`SET_PROVIDED_ADDRESS`) — improves PayPal Seller Protection eligibility |
|
|
169
171
|
| `PAYPAL_PARTNER_SERVICE_URL` | *(built-in)* | Override the partner onboarding service used by the connect flow |
|
|
170
172
|
| `PAYPAL_PARTNER_MERCHANT_ID_SANDBOX` / `PAYPAL_PARTNER_MERCHANT_ID_LIVE` | *(built-in)* | Override the partner merchant ids used for onboarding |
|
|
@@ -173,6 +175,8 @@ Everything is managed in **Medusa Admin → Settings → PayPal** — changes ap
|
|
|
173
175
|
|
|
174
176
|
**Monitoring:** operational counters live in the `paypal_metric` table; every webhook is recorded in `paypal_webhook_event` with automatic retries (events that exhaust retries are dead-lettered **and pushed to `PAYPAL_ALERT_WEBHOOK_URLS`**); audit events are logged as JSON lines tagged `"log":"paypal_audit"` (secrets redacted).
|
|
175
177
|
|
|
178
|
+
**Integration log for PayPal review:** turn on **Settings → PayPal → Additional Settings → Request/response logging** (off by default) to append every PayPal API call and every plugin API request/response to `logs/paypal-requests-YYYY-MM-DD.log`. Credentials are redacted while the `PayPal-Partner-Attribution-Id` (BN code) is kept, so the file is safe to hand to PayPal's go-live review. Download it from the same settings page (**Download log**) or at `GET /admin/paypal/logs?download=1`. Turn it back off once the review is complete.
|
|
179
|
+
|
|
176
180
|
</details>
|
|
177
181
|
|
|
178
182
|
---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easypayment/medusa-payment-paypal",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"description": "PayPal & credit card payments for Medusa v2 — PayPal Buttons, hosted card fields, 3D Secure, and an admin dashboard. Built by a PayPal Partner.",
|
|
5
5
|
"author": "EasyPayment Plugins",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,6 +16,7 @@ type AdditionalSettingsForm = {
|
|
|
16
16
|
sendItemDetails: boolean
|
|
17
17
|
invoicePrefix: string
|
|
18
18
|
creditCardStatementName: string
|
|
19
|
+
debugLogging: boolean
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
const DEFAULT_FORM: AdditionalSettingsForm = {
|
|
@@ -26,6 +27,7 @@ const DEFAULT_FORM: AdditionalSettingsForm = {
|
|
|
26
27
|
sendItemDetails: true,
|
|
27
28
|
invoicePrefix: "PP-",
|
|
28
29
|
creditCardStatementName: "PayPal",
|
|
30
|
+
debugLogging: false,
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/** Overlay saved values on the defaults, ignoring `undefined` entries. */
|
|
@@ -47,11 +49,55 @@ export default function AdditionalSettingsTab() {
|
|
|
47
49
|
}))
|
|
48
50
|
const [loading, setLoading] = useState(false)
|
|
49
51
|
const [saving, setSaving] = useState(false)
|
|
52
|
+
const [downloading, setDownloading] = useState(false)
|
|
50
53
|
const [toast, setToast] = useState<ToastState>(null)
|
|
51
54
|
const didInit = useRef(false)
|
|
52
55
|
|
|
53
56
|
const dismissToast = useCallback(() => setToast(null), [])
|
|
54
57
|
|
|
58
|
+
async function onDownloadLog() {
|
|
59
|
+
try {
|
|
60
|
+
setDownloading(true)
|
|
61
|
+
setToast(null)
|
|
62
|
+
const headers: Record<string, string> = { Accept: "text/plain" }
|
|
63
|
+
if (typeof window !== "undefined") {
|
|
64
|
+
const token = (window as any).__medusa__?.token
|
|
65
|
+
if (token) headers["Authorization"] = `Bearer ${token}`
|
|
66
|
+
}
|
|
67
|
+
const res = await fetch("/admin/paypal/logs?download=1", {
|
|
68
|
+
headers,
|
|
69
|
+
credentials: "include",
|
|
70
|
+
})
|
|
71
|
+
if (!res.ok) {
|
|
72
|
+
if (res.status === 404) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
"No log file yet. Enable logging, run a test transaction, then download."
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`Download failed (${res.status})`)
|
|
78
|
+
}
|
|
79
|
+
const blob = await res.blob()
|
|
80
|
+
const dispo = res.headers.get("Content-Disposition") || ""
|
|
81
|
+
const match = dispo.match(/filename="?([^"]+)"?/)
|
|
82
|
+
const filename = match?.[1] || "paypal-requests.log"
|
|
83
|
+
const url = URL.createObjectURL(blob)
|
|
84
|
+
const a = document.createElement("a")
|
|
85
|
+
a.href = url
|
|
86
|
+
a.download = filename
|
|
87
|
+
document.body.appendChild(a)
|
|
88
|
+
a.click()
|
|
89
|
+
a.remove()
|
|
90
|
+
URL.revokeObjectURL(url)
|
|
91
|
+
} catch (e: unknown) {
|
|
92
|
+
setToast({
|
|
93
|
+
kind: "error",
|
|
94
|
+
message: e instanceof Error ? e.message : "Failed to download log",
|
|
95
|
+
})
|
|
96
|
+
} finally {
|
|
97
|
+
setDownloading(false)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
55
101
|
useEffect(() => {
|
|
56
102
|
if (didInit.current) return
|
|
57
103
|
didInit.current = true
|
|
@@ -240,6 +286,47 @@ export default function AdditionalSettingsTab() {
|
|
|
240
286
|
</FieldRow>
|
|
241
287
|
</div>
|
|
242
288
|
</SectionCard>
|
|
289
|
+
|
|
290
|
+
<SectionCard
|
|
291
|
+
title="Integration logging (PayPal review)"
|
|
292
|
+
description="Write every PayPal API request/response and plugin API request/response to a log file you can download and send to PayPal for integration approval. Credentials (auth tokens, client secrets, card fields) are redacted; the BN code is kept. Keep this OFF in normal production use."
|
|
293
|
+
right={
|
|
294
|
+
<div className="flex items-center gap-3">
|
|
295
|
+
<button
|
|
296
|
+
type="button"
|
|
297
|
+
onClick={onDownloadLog}
|
|
298
|
+
disabled={downloading}
|
|
299
|
+
className="transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none shadow-buttons-neutral text-ui-fg-base bg-ui-button-neutral after:transition-fg after:absolute after:inset-0 after:content-[''] after:button-neutral-gradient hover:bg-ui-button-neutral-hover hover:after:button-neutral-hover-gradient active:bg-ui-button-neutral-pressed active:after:button-neutral-pressed-gradient focus-visible:shadow-buttons-neutral-focus disabled:bg-ui-bg-disabled disabled:border-ui-border-base disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral disabled:after:hidden txt-compact-small-plus px-3 py-1.5"
|
|
300
|
+
>
|
|
301
|
+
{downloading ? "Preparing…" : "Download log"}
|
|
302
|
+
</button>
|
|
303
|
+
</div>
|
|
304
|
+
}
|
|
305
|
+
>
|
|
306
|
+
<div className="divide-y divide-ui-border-base">
|
|
307
|
+
<FieldRow
|
|
308
|
+
label="Request/response logging"
|
|
309
|
+
hint="When enabled, the plugin appends each request and response to logs/paypal-requests-YYYY-MM-DD.log (path configurable via PAYPAL_LOG_DIR). Remember to save after toggling."
|
|
310
|
+
>
|
|
311
|
+
<label className="inline-flex items-center gap-2">
|
|
312
|
+
<input
|
|
313
|
+
type="checkbox"
|
|
314
|
+
checked={form.debugLogging}
|
|
315
|
+
onChange={(e) =>
|
|
316
|
+
setForm((p) => ({
|
|
317
|
+
...p,
|
|
318
|
+
debugLogging: e.target.checked,
|
|
319
|
+
}))
|
|
320
|
+
}
|
|
321
|
+
className="h-4 w-4 rounded border-ui-border-base"
|
|
322
|
+
/>
|
|
323
|
+
<span className="text-sm text-ui-fg-base">
|
|
324
|
+
Enable request/response log file
|
|
325
|
+
</span>
|
|
326
|
+
</label>
|
|
327
|
+
</FieldRow>
|
|
328
|
+
</div>
|
|
329
|
+
</SectionCard>
|
|
243
330
|
</div>
|
|
244
331
|
</div>
|
|
245
332
|
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import fs from "fs"
|
|
2
|
+
import path from "path"
|
|
3
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
4
|
+
import {
|
|
5
|
+
isRequestLoggingEnabled,
|
|
6
|
+
listLogFiles,
|
|
7
|
+
resolveLogFile,
|
|
8
|
+
} from "../../../../modules/paypal/utils/request-logger"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* GET /admin/paypal/logs
|
|
12
|
+
* → { enabled, files: [{ name, size, modified }] }
|
|
13
|
+
*
|
|
14
|
+
* GET /admin/paypal/logs?file=<name>&download=1 (file optional → newest)
|
|
15
|
+
* → the raw log file as a text/plain attachment, for sending to PayPal.
|
|
16
|
+
*/
|
|
17
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
18
|
+
try {
|
|
19
|
+
const query = req.query as Record<string, string | undefined>
|
|
20
|
+
const wantsDownload =
|
|
21
|
+
query.download === "1" ||
|
|
22
|
+
query.download === "true" ||
|
|
23
|
+
typeof query.file === "string"
|
|
24
|
+
|
|
25
|
+
if (wantsDownload) {
|
|
26
|
+
const filePath = resolveLogFile(query.file)
|
|
27
|
+
if (!filePath) {
|
|
28
|
+
return res.status(404).json({ message: "Log file not found" })
|
|
29
|
+
}
|
|
30
|
+
const name = path.basename(filePath)
|
|
31
|
+
res.setHeader("Content-Type", "text/plain; charset=utf-8")
|
|
32
|
+
res.setHeader(
|
|
33
|
+
"Content-Disposition",
|
|
34
|
+
`attachment; filename="${name}"`
|
|
35
|
+
)
|
|
36
|
+
return res.send(fs.readFileSync(filePath, "utf8"))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return res.json({
|
|
40
|
+
enabled: isRequestLoggingEnabled(),
|
|
41
|
+
files: listLogFiles(),
|
|
42
|
+
})
|
|
43
|
+
} catch (e: unknown) {
|
|
44
|
+
console.error(
|
|
45
|
+
"[PayPal] logs GET failed:",
|
|
46
|
+
e instanceof Error ? e.message : e
|
|
47
|
+
)
|
|
48
|
+
return res.status(500).json({ message: "Failed to read PayPal logs" })
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/api/middlewares.ts
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
import { defineMiddlewares } from "@medusajs/framework/http"
|
|
2
2
|
import { createRateLimiter } from "./utils/rate-limit"
|
|
3
|
+
import { createInboundLogger } from "./utils/request-logger"
|
|
3
4
|
|
|
4
5
|
export default defineMiddlewares({
|
|
5
6
|
routes: [
|
|
7
|
+
// Opt-in request/response logging for the plugin's API routes. One catch-all
|
|
8
|
+
// per namespace is enough — every /store/paypal/*, /admin/paypal/* and
|
|
9
|
+
// /hooks/paypal/* request matches its namespace entry, and the logger
|
|
10
|
+
// de-dupes per request so overlapping matchers can't double-log. It is a
|
|
11
|
+
// pass-through unless logging is enabled in settings.
|
|
12
|
+
{
|
|
13
|
+
matcher: "/store/paypal/:path*",
|
|
14
|
+
middlewares: [createInboundLogger()],
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
matcher: "/store/paypal-complete",
|
|
18
|
+
middlewares: [createInboundLogger()],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
matcher: "/admin/paypal/:path*",
|
|
22
|
+
middlewares: [createInboundLogger()],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
matcher: "/hooks/paypal/:path*",
|
|
26
|
+
middlewares: [createInboundLogger()],
|
|
27
|
+
},
|
|
6
28
|
{
|
|
7
29
|
// Keep the exact bytes PayPal signed (`req.rawBody`) so webhook signature
|
|
8
30
|
// verification hashes the original payload, not a re-serialized copy. This
|
|
@@ -61,9 +83,5 @@ export default defineMiddlewares({
|
|
|
61
83
|
method: ["GET"],
|
|
62
84
|
middlewares: [createRateLimiter("config")],
|
|
63
85
|
},
|
|
64
|
-
{
|
|
65
|
-
matcher: "/store/paypal/:path*",
|
|
66
|
-
middlewares: [],
|
|
67
|
-
},
|
|
68
86
|
],
|
|
69
87
|
})
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MedusaNextFunction,
|
|
3
|
+
MedusaRequest,
|
|
4
|
+
MedusaResponse,
|
|
5
|
+
} from "@medusajs/framework/http"
|
|
6
|
+
import {
|
|
7
|
+
isRequestLoggingEnabled,
|
|
8
|
+
logInbound,
|
|
9
|
+
} from "../../modules/paypal/utils/request-logger"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Inbound request/response logger for the plugin's own API routes.
|
|
13
|
+
*
|
|
14
|
+
* Opt-in: a pass-through unless logging is enabled (admin setting or the
|
|
15
|
+
* `PAYPAL_REQUEST_LOG` env var). Captures the request body and the response
|
|
16
|
+
* payload by wrapping `res.json` / `res.send`, then appends one entry to the
|
|
17
|
+
* shared PayPal request log. Redaction of secrets happens in the logger.
|
|
18
|
+
*/
|
|
19
|
+
export function createInboundLogger() {
|
|
20
|
+
return function inboundLogger(
|
|
21
|
+
req: MedusaRequest,
|
|
22
|
+
res: MedusaResponse,
|
|
23
|
+
next: MedusaNextFunction
|
|
24
|
+
) {
|
|
25
|
+
if (!isRequestLoggingEnabled()) {
|
|
26
|
+
return next()
|
|
27
|
+
}
|
|
28
|
+
// Several route entries can match one request (e.g. the webhook raw-body
|
|
29
|
+
// entry AND the /store/paypal catch-all). Guard so we log it only once.
|
|
30
|
+
const reqAny = req as any
|
|
31
|
+
if (reqAny.__paypalLogged) {
|
|
32
|
+
return next()
|
|
33
|
+
}
|
|
34
|
+
reqAny.__paypalLogged = true
|
|
35
|
+
|
|
36
|
+
const startedAt = Date.now()
|
|
37
|
+
let responseBody: unknown
|
|
38
|
+
let captured = false
|
|
39
|
+
|
|
40
|
+
const origJson = res.json.bind(res)
|
|
41
|
+
const origSend = res.send.bind(res)
|
|
42
|
+
|
|
43
|
+
res.json = ((body: unknown) => {
|
|
44
|
+
if (!captured) {
|
|
45
|
+
responseBody = body
|
|
46
|
+
captured = true
|
|
47
|
+
}
|
|
48
|
+
return origJson(body as any)
|
|
49
|
+
}) as typeof res.json
|
|
50
|
+
|
|
51
|
+
res.send = ((body: unknown) => {
|
|
52
|
+
if (!captured) {
|
|
53
|
+
responseBody = body
|
|
54
|
+
captured = true
|
|
55
|
+
}
|
|
56
|
+
return origSend(body as any)
|
|
57
|
+
}) as typeof res.send
|
|
58
|
+
|
|
59
|
+
const flush = () => {
|
|
60
|
+
try {
|
|
61
|
+
logInbound({
|
|
62
|
+
method: req.method,
|
|
63
|
+
path: (req as any).baseUrl
|
|
64
|
+
? `${(req as any).baseUrl}${req.path || ""}`
|
|
65
|
+
: (req as any).originalUrl || req.path || req.url || "",
|
|
66
|
+
query: req.query,
|
|
67
|
+
requestHeaders: req.headers,
|
|
68
|
+
requestBody: (req as any).body,
|
|
69
|
+
status: res.statusCode,
|
|
70
|
+
responseBody,
|
|
71
|
+
durationMs: Date.now() - startedAt,
|
|
72
|
+
})
|
|
73
|
+
} catch {
|
|
74
|
+
// logging must never break the request
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// `finish` fires once the response is fully flushed, for every response
|
|
79
|
+
// path (json, send, raw end, errors) — a single reliable hook.
|
|
80
|
+
res.once("finish", flush)
|
|
81
|
+
|
|
82
|
+
return next()
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
invalidateSettingsCache,
|
|
16
16
|
setCachedSettings,
|
|
17
17
|
} from "./utils/settings-cache"
|
|
18
|
+
import { setRequestLoggingEnabled } from "./utils/request-logger"
|
|
18
19
|
|
|
19
20
|
type Environment = "sandbox" | "live"
|
|
20
21
|
|
|
@@ -1668,6 +1669,16 @@ class PayPalModuleService extends MedusaService({
|
|
|
1668
1669
|
const row = rows?.[0]
|
|
1669
1670
|
const result = { data: (row?.data || {}) as Record<string, any> }
|
|
1670
1671
|
setCachedSettings("module-settings", result)
|
|
1672
|
+
// Keep the process-local request-logging flag in step with the admin toggle.
|
|
1673
|
+
try {
|
|
1674
|
+
const addl = (result.data?.additional_settings || {}) as Record<
|
|
1675
|
+
string,
|
|
1676
|
+
unknown
|
|
1677
|
+
>
|
|
1678
|
+
setRequestLoggingEnabled(!!(addl.debugLogging ?? addl.debug_logging))
|
|
1679
|
+
} catch {
|
|
1680
|
+
// never let a logging-flag sync break settings reads
|
|
1681
|
+
}
|
|
1671
1682
|
return result
|
|
1672
1683
|
}
|
|
1673
1684
|
|