@easypayment/medusa-payment-paypal 1.1.1 → 1.1.2

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.
Files changed (65) hide show
  1. package/.medusa/server/src/admin/index.js +65 -65
  2. package/.medusa/server/src/admin/index.mjs +65 -65
  3. package/.medusa/server/src/api/hooks/paypal/onboard-return/route.d.ts +16 -0
  4. package/.medusa/server/src/api/hooks/paypal/onboard-return/route.d.ts.map +1 -0
  5. package/.medusa/server/src/api/hooks/paypal/onboard-return/route.js +20 -0
  6. package/.medusa/server/src/api/hooks/paypal/onboard-return/route.js.map +1 -0
  7. package/.medusa/server/src/api/hooks/paypal/webhook/route.d.ts +18 -0
  8. package/.medusa/server/src/api/hooks/paypal/webhook/route.d.ts.map +1 -0
  9. package/.medusa/server/src/api/hooks/paypal/webhook/route.js +22 -0
  10. package/.medusa/server/src/api/hooks/paypal/webhook/route.js.map +1 -0
  11. package/.medusa/server/src/api/middlewares.d.ts.map +1 -1
  12. package/.medusa/server/src/api/middlewares.js +9 -0
  13. package/.medusa/server/src/api/middlewares.js.map +1 -1
  14. package/.medusa/server/src/api/store/paypal/config/route.d.ts.map +1 -1
  15. package/.medusa/server/src/api/store/paypal/config/route.js +8 -0
  16. package/.medusa/server/src/api/store/paypal/config/route.js.map +1 -1
  17. package/.medusa/server/src/api/store/paypal/create-order/route.d.ts.map +1 -1
  18. package/.medusa/server/src/api/store/paypal/create-order/route.js +53 -4
  19. package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -1
  20. package/.medusa/server/src/api/store/paypal-complete/route.js +1 -1
  21. package/.medusa/server/src/api/store/paypal-complete/route.js.map +1 -1
  22. package/.medusa/server/src/api/utils/rate-limit.d.ts.map +1 -1
  23. package/.medusa/server/src/api/utils/rate-limit.js +11 -2
  24. package/.medusa/server/src/api/utils/rate-limit.js.map +1 -1
  25. package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts +32 -3
  26. package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts.map +1 -1
  27. package/.medusa/server/src/modules/paypal/payment-provider/base-provider.js +47 -0
  28. package/.medusa/server/src/modules/paypal/payment-provider/base-provider.js.map +1 -1
  29. package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts.map +1 -1
  30. package/.medusa/server/src/modules/paypal/payment-provider/card-service.js +172 -117
  31. package/.medusa/server/src/modules/paypal/payment-provider/card-service.js.map +1 -1
  32. package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts.map +1 -1
  33. package/.medusa/server/src/modules/paypal/payment-provider/service.js +132 -126
  34. package/.medusa/server/src/modules/paypal/payment-provider/service.js.map +1 -1
  35. package/.medusa/server/src/modules/paypal/service.d.ts +5 -0
  36. package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
  37. package/.medusa/server/src/modules/paypal/service.js +82 -1
  38. package/.medusa/server/src/modules/paypal/service.js.map +1 -1
  39. package/.medusa/server/src/modules/paypal/utils/credential-resolver.d.ts +10 -0
  40. package/.medusa/server/src/modules/paypal/utils/credential-resolver.d.ts.map +1 -1
  41. package/.medusa/server/src/modules/paypal/utils/credential-resolver.js +39 -0
  42. package/.medusa/server/src/modules/paypal/utils/credential-resolver.js.map +1 -1
  43. package/.medusa/server/src/modules/paypal/utils/paypal-fetch.d.ts.map +1 -1
  44. package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js +45 -28
  45. package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js.map +1 -1
  46. package/.medusa/server/src/modules/paypal/webhook-processor.d.ts +11 -0
  47. package/.medusa/server/src/modules/paypal/webhook-processor.d.ts.map +1 -1
  48. package/.medusa/server/src/modules/paypal/webhook-processor.js +85 -7
  49. package/.medusa/server/src/modules/paypal/webhook-processor.js.map +1 -1
  50. package/CHANGELOG.md +73 -0
  51. package/package.json +2 -4
  52. package/src/api/hooks/paypal/onboard-return/route.ts +15 -0
  53. package/src/api/hooks/paypal/webhook/route.ts +17 -0
  54. package/src/api/middlewares.ts +9 -0
  55. package/src/api/store/paypal/config/route.ts +8 -0
  56. package/src/api/store/paypal/create-order/route.ts +64 -4
  57. package/src/api/store/paypal-complete/route.ts +1 -1
  58. package/src/api/utils/rate-limit.ts +11 -2
  59. package/src/modules/paypal/payment-provider/base-provider.ts +52 -0
  60. package/src/modules/paypal/payment-provider/card-service.ts +193 -136
  61. package/src/modules/paypal/payment-provider/service.ts +137 -156
  62. package/src/modules/paypal/service.ts +98 -1
  63. package/src/modules/paypal/utils/credential-resolver.ts +36 -0
  64. package/src/modules/paypal/utils/paypal-fetch.ts +58 -29
  65. package/src/modules/paypal/webhook-processor.ts +94 -8
@@ -7,7 +7,9 @@ exports.isRetryableError = isRetryableError;
7
7
  exports.computeNextRetryAt = computeNextRetryAt;
8
8
  exports.normalizeResource = normalizeResource;
9
9
  exports.normalizeEventVersion = normalizeEventVersion;
10
+ exports.extractCaptureIdFromLinks = extractCaptureIdFromLinks;
10
11
  exports.extractIdentifiers = extractIdentifiers;
12
+ exports.isPartialRefund = isPartialRefund;
11
13
  exports.processPayPalWebhookEvent = processPayPalWebhookEvent;
12
14
  const utils_1 = require("@medusajs/framework/utils");
13
15
  const provider_ids_1 = require("./utils/provider-ids");
@@ -89,6 +91,17 @@ function normalizeEventVersion(payload) {
89
91
  return null;
90
92
  return String(raw).trim().replace(/^v/i, "");
91
93
  }
94
+ /** Pull the capture id out of a refund resource's "up" HATEOAS link. */
95
+ function extractCaptureIdFromLinks(resource) {
96
+ const links = Array.isArray(resource?.links) ? resource.links : [];
97
+ for (const link of links) {
98
+ const href = String(link?.href || "");
99
+ const match = href.match(/\/captures\/([A-Za-z0-9-]+)/);
100
+ if (match)
101
+ return match[1];
102
+ }
103
+ return null;
104
+ }
92
105
  function extractIdentifiers(resource, eventType) {
93
106
  const related = resource?.supplementary_data?.related_ids || {};
94
107
  const isOrder = eventType.startsWith("CHECKOUT.ORDER.");
@@ -107,7 +120,21 @@ function extractIdentifiers(resource, eventType) {
107
120
  String(resource?.purchase_units?.[0]?.payments?.captures?.[0]?.id || "").trim() || null;
108
121
  }
109
122
  else if (isCapture) {
110
- captureId = String(resource?.id || "").trim() || null;
123
+ // PAYMENT.CAPTURE.REFUNDED / REVERSED carry a *refund* resource (its `id`
124
+ // is the refund id, with an "up" link to the capture) — treating that id
125
+ // as the capture id would corrupt the session's stored capture_id.
126
+ const isRefundShaped = eventType === "PAYMENT.CAPTURE.REFUNDED" ||
127
+ eventType === "PAYMENT.CAPTURE.REVERSED";
128
+ if (isRefundShaped) {
129
+ refundId = String(resource?.id || "").trim() || null;
130
+ captureId =
131
+ String(related?.capture_id || "").trim() ||
132
+ extractCaptureIdFromLinks(resource) ||
133
+ null;
134
+ }
135
+ else {
136
+ captureId = String(resource?.id || "").trim() || null;
137
+ }
111
138
  orderId = String(related?.order_id || "").trim() || null;
112
139
  cartId = String(resource?.custom_id || "").trim() || null;
113
140
  }
@@ -171,7 +198,9 @@ function mergeRefunds(existing, incoming) {
171
198
  }
172
199
  async function applyStatusToSession(container, resolved, status, patch) {
173
200
  const paymentModule = container.resolve(utils_1.Modules.PAYMENT);
174
- if (!isTransitionAllowed(resolved.sessionStatus, status)) {
201
+ // A null status means "record the data but keep the current session status"
202
+ // (e.g. a partial refund must not cancel a captured session).
203
+ if (status !== null && !isTransitionAllowed(resolved.sessionStatus, status)) {
175
204
  console.info(`[PayPal] webhook: skipping disallowed transition ${resolved.sessionStatus} → ${status} for session ${resolved.sessionId}`);
176
205
  return;
177
206
  }
@@ -185,19 +214,52 @@ async function applyStatusToSession(container, resolved, status, patch) {
185
214
  const nextRefunds = incomingRefunds
186
215
  ? mergeRefunds(existingRefunds, incomingRefunds)
187
216
  : existingRefunds;
217
+ // Drop undefined/null values from the patch so a webhook that lacks an
218
+ // identifier (e.g. a capture event with no related_ids) can never clobber
219
+ // stored fields like `order_id` with null.
220
+ const cleanPatch = {};
221
+ for (const [k, v] of Object.entries(patch)) {
222
+ if (v !== undefined && v !== null)
223
+ cleanPatch[k] = v;
224
+ }
188
225
  await paymentModule.updatePaymentSession({
189
226
  id: resolved.sessionId,
190
- status,
227
+ status: status === null ? resolved.sessionStatus : status,
191
228
  data: {
192
229
  ...resolved.sessionData,
193
230
  paypal: {
194
231
  ...existingPaypal,
195
- ...patch,
232
+ ...cleanPatch,
196
233
  refunds: nextRefunds,
197
234
  },
198
235
  },
199
236
  });
200
237
  }
238
+ /**
239
+ * True when a refund resource demonstrably covers less than the captured
240
+ * amount. Uses the refund's cumulative `total_refunded_amount` (falling back
241
+ * to the single refund amount) against the capture amount stored on the
242
+ * session (falling back to the session total). Returns false — i.e. treat as
243
+ * a full refund, matching the previous behavior — whenever the amounts can't
244
+ * be determined.
245
+ */
246
+ function isPartialRefund(resource, sessionData) {
247
+ const refundedRaw = resource?.seller_payable_breakdown?.total_refunded_amount?.value ??
248
+ resource?.amount?.value;
249
+ const refunded = Number(refundedRaw);
250
+ if (!Number.isFinite(refunded) || refunded <= 0)
251
+ return false;
252
+ const paypal = (sessionData?.paypal || {});
253
+ const capturedRaw = paypal?.capture?.amount?.value ??
254
+ paypal?.capture?.seller_receivable_breakdown?.gross_amount?.value ??
255
+ sessionData?.amount;
256
+ const captured = Number(capturedRaw);
257
+ if (!Number.isFinite(captured) || captured <= 0)
258
+ return false;
259
+ // Tolerance for floating-point noise; amounts are decimal strings from
260
+ // PayPal or the session's stored major-unit amount.
261
+ return refunded + 0.005 < captured;
262
+ }
201
263
  async function processPayPalWebhookEvent(container, input) {
202
264
  const resource = normalizeResource(input.payload);
203
265
  const { orderId, captureId, refundId, cartId: rawCartId } = extractIdentifiers(resource, input.eventType);
@@ -262,10 +324,26 @@ async function processPayPalWebhookEvent(container, input) {
262
324
  },
263
325
  ]
264
326
  : null;
265
- await applyStatusToSession(container, resolved, targetStatus, {
266
- order_id: orderId,
327
+ // A PARTIAL refund must not cancel the session: PayPal fires
328
+ // PAYMENT.CAPTURE.REFUNDED / PAYMENT.REFUND.COMPLETED for partial
329
+ // refunds too, and flipping a substantially-paid session to "canceled"
330
+ // misrepresents the payment. Record the refund but keep the status
331
+ // unless the cumulative refunded total covers the captured amount (or
332
+ // the amounts can't be determined, preserving the old full-refund
333
+ // behavior).
334
+ let effectiveStatus = targetStatus;
335
+ const isRefundEvent = input.eventType === "PAYMENT.CAPTURE.REFUNDED" ||
336
+ input.eventType === "PAYMENT.CAPTURE.REVERSED" ||
337
+ input.eventType === "PAYMENT.REFUND.COMPLETED";
338
+ if (isRefundEvent && targetStatus === "canceled") {
339
+ if (isPartialRefund(resource, resolved.sessionData)) {
340
+ effectiveStatus = null;
341
+ }
342
+ }
343
+ await applyStatusToSession(container, resolved, effectiveStatus, {
344
+ order_id: orderId ?? undefined,
267
345
  capture_id: captureId ?? resolved.sessionData.paypal?.capture_id ?? undefined,
268
- refund_id: refundId,
346
+ refund_id: refundId ?? undefined,
269
347
  refund_status: refundId ? resource?.status : undefined,
270
348
  refund_reason: refundReason,
271
349
  refund_reason_code: refundReasonCode,
@@ -1 +1 @@
1
- {"version":3,"file":"webhook-processor.js","sourceRoot":"","sources":["../../../../../src/modules/paypal/webhook-processor.ts"],"names":[],"mappings":";;;AAiCA,kDAEC;AAUD,gDAEC;AAWD,4CAKC;AAMD,gDAKC;AAGD,8CAWC;AAED,sDASC;AAUD,gDA2CC;AAuHD,8DAoHC;AAlYD,qDAAmD;AACnD,uDAA8E;AAGjE,QAAA,gBAAgB,GAGzB;IACF,yBAAyB,EAAE,YAAY;IACvC,0BAA0B,EAAE,UAAU;IACtC,2BAA2B,EAAE,UAAU;IACvC,wBAAwB,EAAE,OAAO;IACjC,yBAAyB,EAAE,YAAY;IACvC,0BAA0B,EAAE,UAAU;IACtC,0BAA0B,EAAE,UAAU;IACtC,+BAA+B,EAAE,YAAY;IAC7C,8BAA8B,EAAE,UAAU;IAC1C,8BAA8B,EAAE,OAAO;IACvC,+BAA+B,EAAE,UAAU;IAC3C,0BAA0B,EAAE,UAAU;IACtC,uBAAuB,EAAE,OAAO;CACjC,CAAA;AAGD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EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAChD,kBAAkB,EAAE,KAAK,CAAC,SAAS;gBACnC,eAAe,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aAC1C,CAAC,CAAA;YACF,cAAc,GAAG,IAAI,CAAA;QACvB,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,IAAI,CACV,wDAAwD,KAAK,CAAC,SAAS,EAAE,EACzE,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CACjC,CAAA;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;AACjE,CAAC"}
package/CHANGELOG.md CHANGED
@@ -4,6 +4,79 @@ All notable changes to `@easypayment/medusa-payment-paypal` are documented here.
4
4
 
5
5
  ## 1.1.0
6
6
 
7
+ ### Fixed (re-audit)
8
+ - **PayPal webhooks and the onboarding return bridge now work without a
9
+ publishable API key.** Medusa applies its store publishable-key middleware to
10
+ every `/store/*` route, and PayPal cannot send `x-publishable-api-key` — so
11
+ webhook deliveries and onboarding return redirects to the old `/store/paypal/*`
12
+ paths were rejected before the handlers ran. Both handlers are now also served
13
+ from `/hooks/paypal/webhook` and `/hooks/paypal/onboard-return` (no key
14
+ guard). New registrations use the `/hooks` URLs, and existing PayPal webhook
15
+ registrations pointing at the legacy path are migrated in place (best-effort,
16
+ on admin status view) via PayPal's webhook PATCH API. The legacy `/store`
17
+ routes remain for deployments that inject the key at their edge.
18
+ - **Unapproved orders can no longer be booked as authorized.** `authorizePayment`
19
+ treated a PayPal order in `CREATED`/`SAVED` status as authorized, letting a
20
+ cart complete (order placed, inventory reserved) with no payment approved at
21
+ PayPal at all. Only buyer-`APPROVED` orders now count.
22
+ - **PENDING / DECLINED captures are no longer booked as captured.** The
23
+ idempotency branches of `authorizePayment` (both providers) keyed off the mere
24
+ presence of a capture/authorization id and returned the settings-derived
25
+ status. They now derive the status from the actual PayPal resource: a
26
+ `COMPLETED` capture → captured; a `PENDING` (eCheck) capture → authorized
27
+ (order placed, funds not claimed until the `CAPTURE.COMPLETED` webhook); a
28
+ `DENIED`/`DECLINED`/`FAILED` capture → error.
29
+ - **Partial captures no longer charge the full amount.** Medusa never passes the
30
+ requested capture amount to a provider — only the Medusa capture-row id (as
31
+ `context.idempotency_key`). The providers now resolve the requested amount
32
+ from that row, so an admin capturing €40 of a €100 authorization no longer
33
+ sends a €100 capture to PayPal.
34
+ - **Stale PayPal orders are invalidated when the cart changes.** `updatePayment`
35
+ now drops the stored `paypal.order_id` when the session amount/currency
36
+ changes (before any capture/authorization), and `create-order` verifies a
37
+ stored order's amount, currency, and state against the cart before reusing it
38
+ — so a buyer who backs out of the PayPal popup and edits their cart is charged
39
+ the new total, not the stale one.
40
+ - **Card provider no longer 422s on approved capture-intent orders.** Its
41
+ `authorizePayment` called `/v2/checkout/orders/{id}/authorize` regardless of
42
+ intent, which PayPal rejects (`UNSUPPORTED_INTENT`) for `CAPTURE`-intent
43
+ orders — permanently stranding a checkout whose storefront capture call had
44
+ failed after 3-D Secure approval. Approved orders now return `authorized` and
45
+ the capture is routed by intent; `/authorize` is only called for
46
+ `AUTHORIZE`-intent orders. The impossible create-order-then-authorize
47
+ fallbacks (both providers) were replaced with clear errors.
48
+ - **Webhook processing no longer corrupts session data.** `PAYMENT.CAPTURE.REFUNDED`
49
+ / `REVERSED` events carry a *refund* resource — its id was being stored as the
50
+ session's `capture_id`. Identifiers are now extracted refund-aware (with the
51
+ capture id taken from `related_ids` or the resource's "up" link), and patches
52
+ no longer overwrite stored fields (e.g. `order_id`) with null when an event
53
+ lacks them.
54
+ - **Partial refunds no longer cancel the payment session.** Refund events now
55
+ compare the cumulative refunded total against the captured amount and keep the
56
+ session status for partial refunds (recording the refund data); only full
57
+ refunds transition the session to canceled.
58
+ - **Rate limiter can no longer be bypassed via `X-Forwarded-For`.** The client
59
+ key now uses the right-most (proxy-appended) XFF entry instead of the
60
+ left-most (client-forgeable) one.
61
+ - **`paypal-complete` no longer 500s on an empty/non-JSON body** (missing body
62
+ guard before destructuring).
63
+ - **Client-supplied idempotency keys are now cart-scoped in `create-order`**, so
64
+ a reused `Idempotency-Key` header across two carts can no longer return cart
65
+ A's cached PayPal order (and amount) for cart B.
66
+ - **Circuit breaker is now keyed per host.** Failures of a non-PayPal host (e.g.
67
+ the onboarding service) can no longer open the breaker and block live
68
+ captures/refunds against a healthy PayPal API.
69
+ - **Raw-knex reads now respect soft deletes** (`paypal_connection` /
70
+ `paypal_settings` lookups in the credential resolver filter `deleted_at`).
71
+ - **Removed the broken `./workflows` package export** (it pointed at a file that
72
+ was never built; importing it always failed).
73
+
74
+ ### Added (re-audit)
75
+ - `GET /store/paypal/config` now emits `disable_buttons` (from
76
+ `paypal_settings.disableButtons` / `disable_buttons`), which the UI package
77
+ has always read to build the SDK's `disable-funding` list.
78
+
79
+
7
80
  ### Fixed
8
81
  - **Transient capture/refund failures now retry.** The `paypalFetchWithRetry`
9
82
  wrapper (jittered backoff on 5xx/429/timeout) was implemented but never wired
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@easypayment/medusa-payment-paypal",
3
- "version": "1.1.1",
4
- "description": "PayPal integration for Medusa v2",
3
+ "version": "1.1.2",
4
+ "description": "PayPal for Medusa v2 — Built by a PayPal Partner.",
5
5
  "author": "EasyPayment Plugins",
6
6
  "license": "MIT",
7
7
  "main": "./.medusa/server/src/index.js",
@@ -19,7 +19,6 @@
19
19
  "exports": {
20
20
  "./package.json": "./package.json",
21
21
  "./admin": "./.medusa/server/src/admin/index.mjs",
22
- "./workflows": "./.medusa/server/src/workflows/index.js",
23
22
  "./providers/paypal": "./.medusa/server/src/providers/paypal/index.js",
24
23
  "./providers/paypal_card": "./.medusa/server/src/providers/paypal_card/index.js",
25
24
  "./modules/paypal": "./.medusa/server/src/modules/paypal/index.js",
@@ -30,7 +29,6 @@
30
29
  "./.medusa/server/src/providers/paypal": "./.medusa/server/src/providers/paypal/index.js",
31
30
  "./.medusa/server/src/providers/paypal_card": "./.medusa/server/src/providers/paypal_card/index.js",
32
31
  "./.medusa/server/src/admin": "./.medusa/server/src/admin/index.mjs",
33
- "./.medusa/server/src/workflows": "./.medusa/server/src/workflows/index.js",
34
32
  "./.medusa/server/src/*": "./.medusa/server/src/*.js",
35
33
  "./.medusa/*": "./.medusa/*"
36
34
  },
@@ -0,0 +1,15 @@
1
+ /**
2
+ * PayPal onboarding `return_url` under the `/hooks` namespace.
3
+ *
4
+ * PayPal redirects the onboarding popup here as a plain top-level browser
5
+ * navigation, which carries no `x-publishable-api-key` header — and Medusa's
6
+ * store publishable-key middleware rejects every `/store/*` request without
7
+ * that header before the handler runs. Hosting the return bridge under
8
+ * `/hooks` (no publishable-key guard) lets the popup complete the credential
9
+ * exchange and close itself.
10
+ *
11
+ * The legacy `/store/paypal/onboard-return` route is kept for deployments
12
+ * whose edge injects the key; both paths share this exact handler. Newly
13
+ * generated onboarding links point at `/hooks/paypal/onboard-return`.
14
+ */
15
+ export { GET } from "../../../store/paypal/onboard-return/route"
@@ -0,0 +1,17 @@
1
+ /**
2
+ * PayPal webhook endpoint under the `/hooks` namespace.
3
+ *
4
+ * Medusa applies its store publishable-key middleware to EVERY `/store/*`
5
+ * route, and PayPal's webhook delivery cannot send the
6
+ * `x-publishable-api-key` header — so the original
7
+ * `/store/paypal/webhook` endpoint is rejected with NOT_ALLOWED before the
8
+ * handler runs unless a reverse proxy injects the header. The `/hooks`
9
+ * namespace (the same one Medusa core uses for provider webhooks) has no such
10
+ * guard, so external callers can reach it directly.
11
+ *
12
+ * The `/store/paypal/webhook` route is kept for deployments that already
13
+ * inject the key at their edge; both paths share this exact handler. New
14
+ * webhook registrations (and migrated existing ones) point at
15
+ * `/hooks/paypal/webhook`.
16
+ */
17
+ export { POST } from "../../../store/paypal/webhook/route"
@@ -12,6 +12,15 @@ export default defineMiddlewares({
12
12
  bodyParser: { preserveRawBody: true },
13
13
  middlewares: [],
14
14
  },
15
+ {
16
+ // Same raw-body requirement for the /hooks mirror of the webhook route —
17
+ // the path external PayPal deliveries actually reach, since Medusa's
18
+ // publishable-key middleware blocks unauthenticated POSTs to /store/*.
19
+ matcher: "/hooks/paypal/webhook",
20
+ method: ["POST"],
21
+ bodyParser: { preserveRawBody: true },
22
+ middlewares: [],
23
+ },
15
24
  {
16
25
  // Rate-limit the order-creating route: unauthenticated by necessity, so
17
26
  // cap how fast one client can spin up PayPal orders on the merchant
@@ -100,6 +100,14 @@ export async function GET(req: MedusaRequest, res: MedusaResponse) {
100
100
  button_width: paypalSettings.buttonWidth || "responsive",
101
101
  button_height: paypalSettings.buttonHeight ?? 45,
102
102
  button_label: paypalSettings.buttonLabel || "paypal",
103
+ // Funding sources to disable in the PayPal JS SDK (e.g. ["card",
104
+ // "paylater"]). The UI package has always read this field; emit it so
105
+ // the setting actually takes effect.
106
+ disable_buttons: Array.isArray(paypalSettings.disableButtons)
107
+ ? paypalSettings.disableButtons.map((b: unknown) => String(b))
108
+ : Array.isArray(paypalSettings.disable_buttons)
109
+ ? paypalSettings.disable_buttons.map((b: unknown) => String(b))
110
+ : [],
103
111
  })
104
112
  } catch {
105
113
  return res.status(500).json({ message: "Failed to load PayPal config" })
@@ -31,6 +31,10 @@ function resolveIdempotencyKey(req: MedusaRequest, suffix: string, fallback: str
31
31
  req.headers["X-Idempotency-Key"]
32
32
  const key = Array.isArray(header) ? header[0] : header
33
33
  if (key && String(key).trim()) {
34
+ // The suffix must include the cart id (callers pass it): PayPal caches by
35
+ // PayPal-Request-Id, so a client reusing one idempotency-key header across
36
+ // two carts would otherwise get cart A's cached order (A's amount) back
37
+ // for cart B.
34
38
  return `${String(key).trim()}-${suffix}`
35
39
  }
36
40
  return fallback || `pp-${suffix}-${randomUUID()}`
@@ -102,10 +106,11 @@ export async function POST(req: MedusaRequest, res: MedusaResponse) {
102
106
  return res.status(400).json({ message: "Invalid cart_id format" })
103
107
  }
104
108
 
109
+ // A stored order id is only reused after verifying it still matches the
110
+ // cart (amount/currency/state) — see below, once the cart is loaded. Buyers
111
+ // who back out of the PayPal popup and change their cart would otherwise be
112
+ // charged the stale total.
105
113
  const existingOrderId = await getExistingPayPalOrderId(req, cartId)
106
- if (existingOrderId) {
107
- return res.json({ id: existingOrderId })
108
- }
109
114
 
110
115
  const query = req.scope.resolve("query")
111
116
 
@@ -181,6 +186,57 @@ export async function POST(req: MedusaRequest, res: MedusaResponse) {
181
186
  const totalMajor = Number(cart.total || 0)
182
187
  const value = totalMajor.toFixed(exponent)
183
188
 
189
+ // Reuse the stored PayPal order only when it still matches the cart: same
190
+ // amount, same currency, and still in a reusable (pre-terminal) state. On
191
+ // mismatch fall through and create a fresh order (which replaces the
192
+ // stored id on the session). If PayPal can't be reached for the check,
193
+ // reuse the stored id — matching the previous behavior rather than
194
+ // blocking checkout on a transient error.
195
+ if (existingOrderId) {
196
+ try {
197
+ const checkBase = getPayPalApiBase(creds.environment)
198
+ const checkToken = await paypal.getAppAccessToken()
199
+ const checkResp = await paypalFetch(
200
+ `${checkBase}/v2/checkout/orders/${encodeURIComponent(existingOrderId)}`,
201
+ {
202
+ method: "GET",
203
+ headers: {
204
+ Authorization: `Bearer ${checkToken}`,
205
+ "Content-Type": "application/json",
206
+ },
207
+ }
208
+ )
209
+ if (checkResp.ok) {
210
+ const existingOrder = await checkResp.json()
211
+ const existingAmount = existingOrder?.purchase_units?.[0]?.amount
212
+ const existingStatus = String(existingOrder?.status || "").toUpperCase()
213
+ const reusableStatus = ["CREATED", "APPROVED", "PAYER_ACTION_REQUIRED"].includes(
214
+ existingStatus
215
+ )
216
+ const amountMatches =
217
+ String(existingAmount?.value || "") === value &&
218
+ String(existingAmount?.currency_code || "").toUpperCase() === currency
219
+ if (reusableStatus && amountMatches) {
220
+ return res.json({ id: existingOrderId })
221
+ }
222
+ if (existingStatus === "COMPLETED") {
223
+ // Already paid — never mint a second order for this cart.
224
+ return res.json({ id: existingOrderId })
225
+ }
226
+ logger.info(
227
+ `[paypal] create-order: stored order ${existingOrderId} is stale (status=${existingStatus}, amount=${existingAmount?.value} ${existingAmount?.currency_code} vs cart ${value} ${currency}) — creating a fresh order (request_id=${requestId})`
228
+ )
229
+ } else if (checkResp.status !== 404) {
230
+ // Transient PayPal-side failure: reuse rather than block checkout.
231
+ return res.json({ id: existingOrderId })
232
+ }
233
+ // 404: the stored order no longer exists (e.g. environment switched) —
234
+ // fall through and create a fresh one.
235
+ } catch {
236
+ return res.json({ id: existingOrderId })
237
+ }
238
+ }
239
+
184
240
  const paymentActionRaw =
185
241
  typeof additionalSettings.paymentAction === "string"
186
242
  ? additionalSettings.paymentAction
@@ -378,7 +434,11 @@ export async function POST(req: MedusaRequest, res: MedusaResponse) {
378
434
  // Deterministic-per-cart idempotency key for the PayPal call. Kept distinct
379
435
  // from `requestId` (the log/response correlation id declared at the top of
380
436
  // POST) so the two never shadow each other.
381
- const paypalRequestId = resolveIdempotencyKey(req, "create-order", `pp-create-${cart.id}`)
437
+ const paypalRequestId = resolveIdempotencyKey(
438
+ req,
439
+ `create-order-${cart.id}`,
440
+ `pp-create-${cart.id}`
441
+ )
382
442
 
383
443
  const ppResp = await paypalFetch(`${base}/v2/checkout/orders`, {
384
444
  method: "POST",
@@ -8,7 +8,7 @@ import { runCoreWorkflow } from "../../../modules/paypal/utils/core-workflow"
8
8
  export async function POST(req: MedusaRequest, res: MedusaResponse) {
9
9
  const logger = req.scope.resolve<Logger>(ContainerRegistrationKeys.LOGGER)
10
10
  const requestId = randomUUID()
11
- const { cart_id } = req.body as { cart_id: string }
11
+ const { cart_id } = (req.body || {}) as { cart_id: string }
12
12
 
13
13
  if (!cart_id || typeof cart_id !== "string") {
14
14
  return res.status(400).json({ message: "cart_id is required" })
@@ -44,10 +44,19 @@ function readConfiguredMax(): number | null {
44
44
  }
45
45
 
46
46
  function clientKey(req: MedusaRequest): string {
47
+ // Use the RIGHT-most x-forwarded-for entry: proxies append the address they
48
+ // received the request from, so the right-most value was written by the
49
+ // merchant's own edge proxy and cannot be forged by the client. The
50
+ // left-most entry is fully client-controlled — keying on it would let an
51
+ // attacker rotate a header value to get a fresh bucket per request,
52
+ // bypassing the limiter entirely.
47
53
  const fwd = req.headers["x-forwarded-for"]
48
- const fwdIp = Array.isArray(fwd) ? fwd[0] : fwd
54
+ const fwdRaw = Array.isArray(fwd) ? fwd[fwd.length - 1] : fwd
55
+ const parts = fwdRaw
56
+ ? fwdRaw.split(",").map((s) => s.trim()).filter(Boolean)
57
+ : []
49
58
  const ip =
50
- (fwdIp ? fwdIp.split(",")[0].trim() : undefined) ||
59
+ parts[parts.length - 1] ||
51
60
  req.socket?.remoteAddress ||
52
61
  "unknown"
53
62
  return ip
@@ -135,6 +135,58 @@ export abstract class PayPalProviderBase extends AbstractPaymentProvider<Options
135
135
  return formatAmountForPayPal(amount, currencyCode || "EUR")
136
136
  }
137
137
 
138
+ /**
139
+ * Amount to send to PayPal for a capture. Medusa invokes the provider's
140
+ * capturePayment with only `{ data, context: { idempotency_key } }` — the
141
+ * admin's requested (possibly partial) capture amount is never passed in the
142
+ * input. The idempotency_key IS the Medusa `capture` row id, so resolve the
143
+ * requested amount from that row; otherwise a partial capture would silently
144
+ * charge the buyer the full session total. Falls back to the session amount
145
+ * when the row can't be resolved (preserving full-capture behavior), and
146
+ * never returns more than the session amount.
147
+ */
148
+ protected async resolveRequestedCaptureAmount(
149
+ input: { context?: { idempotency_key?: string } },
150
+ sessionAmount: number
151
+ ): Promise<number> {
152
+ const captureRowId = input?.context?.idempotency_key?.trim()
153
+ if (!captureRowId) return sessionAmount
154
+ const requested = await this.paypal.getRequestedCaptureAmount(captureRowId)
155
+ if (requested === null || !Number.isFinite(requested) || requested <= 0) {
156
+ return sessionAmount
157
+ }
158
+ return Math.min(requested, sessionAmount)
159
+ }
160
+
161
+ /**
162
+ * When the session amount or currency changes while a not-yet-approved PayPal
163
+ * order is stored on the session, drop the stored order reference so the next
164
+ * create-order call mints a fresh order at the correct total. Without this, a
165
+ * buyer who opens PayPal (order created for the old total), backs out, and
166
+ * changes the cart gets charged the stale amount. Returns a `{ paypal }`
167
+ * patch to spread into the updated session data, or `{}` when nothing needs
168
+ * invalidating. Sessions that already carry a capture/authorization are never
169
+ * touched.
170
+ */
171
+ protected invalidateStaleOrder(
172
+ input: { data?: Record<string, unknown>; amount?: unknown },
173
+ nextCurrencyCode: string
174
+ ): Record<string, unknown> {
175
+ const data = (input.data || {}) as Record<string, any>
176
+ const paypal = (data.paypal || {}) as Record<string, any>
177
+ if (!paypal.order_id) return {}
178
+ if (paypal.capture_id || paypal.authorization_id) return {}
179
+ const prevAmount = toAmountNumber(data.amount)
180
+ const nextAmount = toAmountNumber(input.amount)
181
+ const prevCurrency = String(data.currency_code || "").toUpperCase()
182
+ const amountChanged =
183
+ prevAmount > 0 && nextAmount > 0 && prevAmount !== nextAmount
184
+ const currencyChanged = !!prevCurrency && prevCurrency !== nextCurrencyCode
185
+ if (!amountChanged && !currencyChanged) return {}
186
+ const { order_id: _orderId, order: _order, ...rest } = paypal
187
+ return { paypal: rest }
188
+ }
189
+
138
190
  protected mapCaptureStatus(status?: string) {
139
191
  // Delegate to the shared, unit-tested mapping so the card and wallet
140
192
  // providers agree with each other and with the webhook processor. Notably a