@easypayment/medusa-payment-paypal 1.1.2 → 1.2.1

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 (68) hide show
  1. package/.medusa/server/src/admin/index.js +73 -73
  2. package/.medusa/server/src/admin/index.mjs +73 -73
  3. package/.medusa/server/src/api/middlewares.d.ts.map +1 -1
  4. package/.medusa/server/src/api/middlewares.js +16 -2
  5. package/.medusa/server/src/api/middlewares.js.map +1 -1
  6. package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts.map +1 -1
  7. package/.medusa/server/src/api/store/paypal/capture-order/route.js +66 -13
  8. package/.medusa/server/src/api/store/paypal/capture-order/route.js.map +1 -1
  9. package/.medusa/server/src/api/store/paypal/create-order/route.d.ts.map +1 -1
  10. package/.medusa/server/src/api/store/paypal/create-order/route.js +11 -6
  11. package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -1
  12. package/.medusa/server/src/api/utils/rate-limit.d.ts +13 -1
  13. package/.medusa/server/src/api/utils/rate-limit.d.ts.map +1 -1
  14. package/.medusa/server/src/api/utils/rate-limit.js +7 -5
  15. package/.medusa/server/src/api/utils/rate-limit.js.map +1 -1
  16. package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts.map +1 -1
  17. package/.medusa/server/src/jobs/paypal-webhook-retry.js +4 -0
  18. package/.medusa/server/src/jobs/paypal-webhook-retry.js.map +1 -1
  19. package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts +15 -0
  20. package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts.map +1 -1
  21. package/.medusa/server/src/modules/paypal/payment-provider/base-provider.js +26 -0
  22. package/.medusa/server/src/modules/paypal/payment-provider/base-provider.js.map +1 -1
  23. package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts.map +1 -1
  24. package/.medusa/server/src/modules/paypal/payment-provider/card-service.js +244 -169
  25. package/.medusa/server/src/modules/paypal/payment-provider/card-service.js.map +1 -1
  26. package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts +0 -4
  27. package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts.map +1 -1
  28. package/.medusa/server/src/modules/paypal/payment-provider/service.js +8 -25
  29. package/.medusa/server/src/modules/paypal/payment-provider/service.js.map +1 -1
  30. package/.medusa/server/src/modules/paypal/service.d.ts +2 -0
  31. package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
  32. package/.medusa/server/src/modules/paypal/service.js +54 -13
  33. package/.medusa/server/src/modules/paypal/service.js.map +1 -1
  34. package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -1
  35. package/.medusa/server/src/modules/paypal/types/config.js +13 -0
  36. package/.medusa/server/src/modules/paypal/types/config.js.map +1 -1
  37. package/.medusa/server/src/modules/paypal/utils/amounts.d.ts +1 -1
  38. package/.medusa/server/src/modules/paypal/utils/credential-resolver.d.ts.map +1 -1
  39. package/.medusa/server/src/modules/paypal/utils/credential-resolver.js +10 -34
  40. package/.medusa/server/src/modules/paypal/utils/credential-resolver.js.map +1 -1
  41. package/.medusa/server/src/modules/paypal/utils/metrics.d.ts +18 -0
  42. package/.medusa/server/src/modules/paypal/utils/metrics.d.ts.map +1 -0
  43. package/.medusa/server/src/modules/paypal/utils/metrics.js +45 -0
  44. package/.medusa/server/src/modules/paypal/utils/metrics.js.map +1 -0
  45. package/.medusa/server/src/modules/paypal/webhook-processor.d.ts +16 -0
  46. package/.medusa/server/src/modules/paypal/webhook-processor.d.ts.map +1 -1
  47. package/.medusa/server/src/modules/paypal/webhook-processor.js +85 -2
  48. package/.medusa/server/src/modules/paypal/webhook-processor.js.map +1 -1
  49. package/.medusa/server/src/subscribers/paypal-webhook-process.d.ts.map +1 -1
  50. package/.medusa/server/src/subscribers/paypal-webhook-process.js +4 -0
  51. package/.medusa/server/src/subscribers/paypal-webhook-process.js.map +1 -1
  52. package/CHANGELOG.md +208 -146
  53. package/README.md +175 -184
  54. package/package.json +91 -88
  55. package/src/api/middlewares.ts +16 -2
  56. package/src/api/store/paypal/capture-order/route.ts +83 -12
  57. package/src/api/store/paypal/create-order/route.ts +11 -7
  58. package/src/api/utils/rate-limit.ts +20 -5
  59. package/src/jobs/paypal-webhook-retry.ts +4 -0
  60. package/src/modules/paypal/payment-provider/base-provider.ts +31 -0
  61. package/src/modules/paypal/payment-provider/card-service.ts +84 -0
  62. package/src/modules/paypal/payment-provider/service.ts +12 -30
  63. package/src/modules/paypal/service.ts +1703 -1651
  64. package/src/modules/paypal/types/config.ts +16 -0
  65. package/src/modules/paypal/utils/credential-resolver.ts +9 -36
  66. package/src/modules/paypal/utils/metrics.ts +48 -0
  67. package/src/modules/paypal/webhook-processor.ts +101 -2
  68. package/src/subscribers/paypal-webhook-process.ts +4 -0
package/README.md CHANGED
@@ -1,184 +1,175 @@
1
- # PayPal for Medusa
2
-
3
- **Accept PayPal and advanced credit card payments in your Medusa v2 store — built by an official PayPal Partner.**
4
-
5
- [![npm version](https://img.shields.io/npm/v/@easypayment/medusa-payment-paypal?color=blue&label=npm)](https://www.npmjs.com/package/@easypayment/medusa-payment-paypal)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
7
- [![Medusa v2](https://img.shields.io/badge/Medusa-v2-9b59b6)](https://medusajs.com)
8
- [![PayPal PPCP](https://img.shields.io/badge/PayPal-PPCP-003087)](https://developer.paypal.com)
9
-
10
- ---
11
-
12
- ## 📋 Table of Contents
13
-
14
- - [📦 What's included](#-whats-included)
15
- - [✅ Requirements](#-requirements)
16
- - [🚀 Installation](#-installation)
17
- - [⚙️ Setup](#%EF%B8%8F-setup)
18
- - [Step 1 — Configure medusa-config.ts](#step-1--configure-medusa-configts)
19
- - [Step 2 — Run database migrations](#step-2--run-database-migrations)
20
- - [Step 3 — Connect your PayPal account](#step-3--connect-your-paypal-account)
21
- - [Step 4 — Enable providers in your region](#step-4--enable-providers-in-your-region)
22
- - [Step 5 — Configure settings](#step-5--configure-settings-optional)
23
- - [Step 6 — Add PayPal to your storefront](#step-6--add-paypal-to-your-storefront)
24
- - [📄 License](#-license)
25
-
26
- ---
27
-
28
- ## 📦 What's included
29
-
30
- | Feature | Details |
31
- |---|---|
32
- | 🔵 **PayPal Smart Buttons** | One-click wallet checkout via PayPal |
33
- | 💳 **Advanced Card Fields** | Hosted, PCI-compliant advanced credit card inputs |
34
- | 🛠 **Admin Dashboard** | Connect, configure, and switch environments from Medusa Admin |
35
- | 🌍 **Sandbox & Live** | Toggle between test and production without restarting |
36
- | ⚡ **Webhooks** | Automatically registered and verified with built-in retry support |
37
- | 🔐 **3D Secure** | Configurable SCA/3DS per transaction |
38
-
39
- ---
40
-
41
- ## ✅ Requirements
42
-
43
- - Medusa **v2**
44
- - Node.js **18+**
45
- - PostgreSQL
46
-
47
- ---
48
-
49
- ## 🚀 Installation
50
-
51
- **In your Medusa backend directory**, run:
52
-
53
- ```bash
54
- npm install @easypayment/medusa-payment-paypal
55
- ```
56
-
57
- ---
58
-
59
- ## ⚙️ Setup
60
-
61
- ### Step 1 — Configure `medusa-config.ts`
62
-
63
- Add the plugin and both payment providers to your existing `medusa-config.ts`:
64
-
65
- ```ts
66
- import { loadEnv, defineConfig } from "@medusajs/framework/utils"
67
-
68
- loadEnv(process.env.NODE_ENV || "development", process.cwd())
69
-
70
- export default defineConfig({
71
- projectConfig: {
72
- databaseUrl: process.env.DATABASE_URL,
73
- http: {
74
- storeCors: process.env.STORE_CORS!,
75
- adminCors: process.env.ADMIN_CORS!,
76
- authCors: process.env.AUTH_CORS!,
77
- jwtSecret: process.env.JWT_SECRET || "supersecret",
78
- cookieSecret: process.env.COOKIE_SECRET || "supersecret",
79
- },
80
- },
81
-
82
- plugins: [
83
- {
84
- resolve: "@easypayment/medusa-payment-paypal",
85
- options: {},
86
- },
87
- ],
88
-
89
- modules: [
90
- {
91
- resolve: "@medusajs/medusa/payment",
92
- options: {
93
- providers: [
94
- {
95
- // PayPal Smart Buttons (wallet checkout)
96
- resolve: "@easypayment/medusa-payment-paypal/providers/paypal",
97
- id: "paypal",
98
- options: {},
99
- dependencies: ["paypal_onboarding"],
100
- },
101
- {
102
- // Advanced Card Fields (hosted card inputs)
103
- resolve: "@easypayment/medusa-payment-paypal/providers/paypal_card",
104
- id: "paypal_card",
105
- options: {},
106
- dependencies: ["paypal_onboarding"],
107
- },
108
- ],
109
- },
110
- },
111
- ],
112
- })
113
- ```
114
-
115
- ---
116
-
117
- ### Step 2 — Run database migrations
118
-
119
- ```bash
120
- npx medusa db:migrate
121
- ```
122
-
123
- ---
124
-
125
- ### Step 3 — Connect your PayPal account
126
-
127
- 1. Start your Medusa server
128
- 2. Open **Medusa Admin → Settings → PayPal → PayPal Connection**
129
- 3. Choose **Sandbox** (testing) or **Live** (production)
130
- 4. Click **Connect to PayPal** and complete the onboarding flow
131
-
132
- Credentials are saved automatically. Prefer manual setup? Click **Insert credentials manually** and paste your Client ID and Secret from [developer.paypal.com](https://developer.paypal.com/dashboard/).
133
-
134
- > **🔐 Encrypt secrets at rest (recommended for production).** Set `PAYPAL_ENCRYPTION_KEY` to any strong random string. The seller client secret and PayPal app access token are then stored AES‑256‑GCM‑encrypted in the database; without it they are stored in plaintext (the previous default). Encryption is transparent — existing plaintext credentials keep working and are upgraded to ciphertext the next time they are saved/refreshed.
135
- >
136
- > Keep this key safe and backed up: **if it is lost, stored credentials cannot be decrypted** and you must reconnect PayPal. Rotating the key requires re‑saving credentials.
137
-
138
- ---
139
-
140
- ### Step 4 — Enable providers in your region
141
-
142
- 1. Go to **Medusa Admin → Settings → Regions → [your region]**
143
- 2. Under **Payment Providers**, enable:
144
-
145
- | Provider ID | Description |
146
- |---|---|
147
- | `pp_paypal_paypal` | PayPal Smart Buttons (wallet) |
148
- | `pp_paypal_card_paypal_card` | Advanced Card Fields (card) |
149
-
150
- ---
151
-
152
- ### Step 5 — Configure settings *(optional)*
153
-
154
- All settings live in **Medusa Admin → Settings → PayPal** and apply immediately — no server restart needed.
155
-
156
- | Tab | What you can configure |
157
- |---|---|
158
- | **PayPal Settings** | Enable/disable, button color, shape, label |
159
- | **Advanced Card Payments** | Enable/disable, 3D Secure mode |
160
- | **Additional Settings** | Payment action (capture / authorize), brand name, invoice prefix |
161
-
162
- ---
163
-
164
- ### Step 6 — Add PayPal to your storefront
165
-
166
- The checkout UI is shipped as a separate package — **install it inside your storefront project**, not in this backend.
167
-
168
- 📦 **[@easypayment/medusa-paypal-ui](https://www.npmjs.com/package/@easypayment/medusa-paypal-ui)** — React components, hooks, and a drop-in payment step adapter for Next.js App Router storefronts.
169
-
170
- See the [storefront integration & testing guide →](https://www.npmjs.com/package/@easypayment/medusa-paypal-ui)
171
-
172
- ---
173
-
174
- ## 📊 Observability
175
-
176
- - **Metrics** — operational counters (e.g. `create_order_success`, `capture_order_failed`, `webhook_success`, `webhook_dead_letter`) are persisted in the `paypal_metric` table.
177
- - **Audit trail** — security/lifecycle events (credential changes, environment switches, webhook registration, capture/refund failures, alerts) are emitted as structured JSON log lines tagged `"log":"paypal_audit"`. In production, ship stdout to your log aggregator and filter on that tag. Sensitive fields (secrets, tokens) are redacted before logging.
178
- - **Webhooks** — every received event is recorded in `paypal_webhook_event` with status (`processed` / `failed` / `dead_letter` / `ignored`), attempt count, and last error; failures are retried by the `paypal-webhook-retry` job.
179
-
180
- ---
181
-
182
- ## 📄 License
183
-
184
- MIT © [Easy Payment](https://www.npmjs.com/package/@easypayment/medusa-payment-paypal)
1
+ # PayPal for Medusa
2
+
3
+ **Accept PayPal and credit card payments in your Medusa v2 store — built by an official PayPal Partner.**
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@easypayment/medusa-payment-paypal?color=blue&label=npm)](https://www.npmjs.com/package/@easypayment/medusa-payment-paypal)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
7
+ [![Medusa v2](https://img.shields.io/badge/Medusa-v2-9b59b6)](https://medusajs.com)
8
+ [![PayPal PPCP](https://img.shields.io/badge/PayPal-PPCP-003087)](https://developer.paypal.com)
9
+
10
+ ---
11
+
12
+ ## ✨ What you get
13
+
14
+ | Feature | Details |
15
+ |---|---|
16
+ | 🔵 **PayPal Buttons** | One-click PayPal checkout for your customers |
17
+ | 💳 **Card Payments** | Secure credit & debit card fields, hosted by PayPal (PCI compliant) |
18
+ | 🛠 **Admin Dashboard** | Connect your PayPal account and manage everything from Medusa Admin |
19
+ | 🌍 **Test & Live modes** | Try everything safely in Sandbox before going live |
20
+ | 🔐 **3D Secure** | Extra card security, configurable in one click |
21
+ | 🔄 **Reliable by design** | Payments are verified with PayPal at every step — webhooks, retries, and safety nets are handled for you |
22
+
23
+ ---
24
+
25
+ ## ✅ Requirements
26
+
27
+ - Medusa **v2**
28
+ - Node.js **18+**
29
+ - PostgreSQL
30
+
31
+ ---
32
+
33
+ ## 🚀 Installation
34
+
35
+ In your Medusa backend folder, run:
36
+
37
+ ```bash
38
+ npm install @easypayment/medusa-payment-paypal
39
+ ```
40
+
41
+ ---
42
+
43
+ ## ⚙️ Setup — 5 steps
44
+
45
+ ### 1. Add the plugin to `medusa-config.ts`
46
+
47
+ ```ts
48
+ import { loadEnv, defineConfig } from "@medusajs/framework/utils"
49
+
50
+ loadEnv(process.env.NODE_ENV || "development", process.cwd())
51
+
52
+ export default defineConfig({
53
+ projectConfig: {
54
+ databaseUrl: process.env.DATABASE_URL,
55
+ http: {
56
+ storeCors: process.env.STORE_CORS!,
57
+ adminCors: process.env.ADMIN_CORS!,
58
+ authCors: process.env.AUTH_CORS!,
59
+ jwtSecret: process.env.JWT_SECRET || "supersecret",
60
+ cookieSecret: process.env.COOKIE_SECRET || "supersecret",
61
+ },
62
+ },
63
+
64
+ plugins: [
65
+ {
66
+ resolve: "@easypayment/medusa-payment-paypal",
67
+ options: {},
68
+ },
69
+ ],
70
+
71
+ modules: [
72
+ {
73
+ resolve: "@medusajs/medusa/payment",
74
+ options: {
75
+ providers: [
76
+ {
77
+ // PayPal Buttons
78
+ resolve: "@easypayment/medusa-payment-paypal/providers/paypal",
79
+ id: "paypal",
80
+ options: {},
81
+ dependencies: ["paypal_onboarding"],
82
+ },
83
+ {
84
+ // Card payments
85
+ resolve: "@easypayment/medusa-payment-paypal/providers/paypal_card",
86
+ id: "paypal_card",
87
+ options: {},
88
+ dependencies: ["paypal_onboarding"],
89
+ },
90
+ ],
91
+ },
92
+ },
93
+ ],
94
+ })
95
+ ```
96
+
97
+ ### 2. Run database migrations
98
+
99
+ ```bash
100
+ npx medusa db:migrate
101
+ ```
102
+
103
+ ### 3. Connect your PayPal account
104
+
105
+ 1. Start your Medusa server
106
+ 2. Open **Medusa Admin → Settings → PayPal**
107
+ 3. Choose **Sandbox** (testing) or **Live** (real payments)
108
+ 4. Click **Connect to PayPal** and follow the steps
109
+
110
+ That's it — your credentials are saved automatically. Webhooks are registered for you too.
111
+
112
+ > 💡 Prefer manual setup? Click **Insert credentials manually** and paste your Client ID and Secret from [developer.paypal.com](https://developer.paypal.com/dashboard/).
113
+
114
+ ### 4. Turn PayPal on in your region
115
+
116
+ Go to **Medusa Admin → Settings → Regions → your region** and enable:
117
+
118
+ | Payment provider | What it is |
119
+ |---|---|
120
+ | `pp_paypal_paypal` | PayPal Buttons |
121
+ | `pp_paypal_card_paypal_card` | Card payments |
122
+
123
+ ### 5. Add PayPal to your storefront
124
+
125
+ The checkout UI comes as a separate package — install it in your **storefront** project:
126
+
127
+ 📦 **[@easypayment/medusa-paypal-ui](https://www.npmjs.com/package/@easypayment/medusa-paypal-ui)** — ready-made PayPal components for Next.js storefronts, with a step-by-step guide.
128
+
129
+ ---
130
+
131
+ ## 🎨 Customize (optional)
132
+
133
+ Everything is managed in **Medusa Admin → Settings → PayPal** — changes apply instantly, no restart needed:
134
+
135
+ - **PayPal Settings** — turn PayPal on/off, button color, shape, and label
136
+ - **Advanced Card Payments** — turn card payments on/off, 3D Secure mode
137
+ - **Additional Settings** — capture vs. authorize, brand name shown at PayPal, invoice prefix
138
+
139
+ ---
140
+
141
+ ## 🔐 Going live — two things we recommend
142
+
143
+ 1. **`PAYPAL_ENCRYPTION_KEY`** — set this to any long random text in your server's environment. Your PayPal credentials are then stored encrypted in the database. Keep the key safe: if it's lost, just reconnect PayPal.
144
+ 2. **`MEDUSA_BACKEND_URL`** — set this to your backend's public address (e.g. `https://api.mystore.com`) so PayPal can reach your store for payment notifications.
145
+
146
+ <details>
147
+ <summary><b>Advanced options</b> (for developers — everything works without these)</summary>
148
+
149
+ <br>
150
+
151
+ | Variable | Default | What it does |
152
+ |---|---|---|
153
+ | `STOREFRONT_URL` | *(unset)* | Storefront address used for PayPal return/cancel pages (can also be set in Admin) |
154
+ | `PAYPAL_ENCRYPTION_STRICT` | `false` | `true` = refuse to save credentials unencrypted |
155
+ | `PAYPAL_SELLER_NONCE` | *(auto)* | Set a fixed random string when running multiple server instances |
156
+ | `PAYPAL_ADMIN_ORIGIN` | first `ADMIN_CORS` entry | Restricts the onboarding popup to your admin URL |
157
+ | `PAYPAL_WEBHOOK_COMPLETE_CART` | `true` | Safety net that finishes an order when the payment succeeded but the buyer's browser closed. `false` disables it |
158
+ | `PAYPAL_RATE_LIMIT_MAX` / `PAYPAL_RATE_LIMIT_WINDOW_MS` | *(off)* / `60000` | Optional request limit for the public checkout routes |
159
+ | `PAYPAL_WEBHOOK_RATE_LIMIT_MAX` / `PAYPAL_WEBHOOK_RATE_LIMIT_WINDOW_MS` | *(off)* / `60000` | Optional request limit for the webhook endpoint (separate from the above) |
160
+ | `PAYPAL_WEBHOOK_REPLAY_WINDOW_MINUTES` | `60` | Rejects webhook deliveries older than this |
161
+ | `PAYPAL_WEBHOOK_STALE_PROCESSING_MS` | `300000` | When the retry job re-picks-up interrupted webhook events |
162
+ | `PAYPAL_WEBHOOK_ID_LIVE` / `PAYPAL_WEBHOOK_ID_SANDBOX` | *(auto)* | Manual webhook-id override (normally automatic) |
163
+ | `PAYPAL_HTTP_TIMEOUT_MS` | `30000` | Timeout for calls to PayPal |
164
+ | `PAYPAL_CURRENCY` | `EUR` | Fallback currency if none is configured |
165
+ | `PAYPAL_ALERT_WEBHOOK_URLS` | *(unset)* | Comma-separated URLs that receive operational alert notifications |
166
+
167
+ **Monitoring:** operational counters live in the `paypal_metric` table; every webhook is recorded in `paypal_webhook_event` with automatic retries; audit events are logged as JSON lines tagged `"log":"paypal_audit"` (secrets redacted).
168
+
169
+ </details>
170
+
171
+ ---
172
+
173
+ ## 📄 License
174
+
175
+ MIT © [Easy Payment](https://www.npmjs.com/package/@easypayment/medusa-payment-paypal)
package/package.json CHANGED
@@ -1,88 +1,91 @@
1
- {
2
- "name": "@easypayment/medusa-payment-paypal",
3
- "version": "1.1.2",
4
- "description": "PayPal for Medusa v2 — Built by a PayPal Partner.",
5
- "author": "EasyPayment Plugins",
6
- "license": "MIT",
7
- "main": "./.medusa/server/src/index.js",
8
- "types": "./.medusa/server/src/index.d.ts",
9
- "files": [
10
- ".medusa/server",
11
- "src",
12
- "scripts",
13
- "package.json",
14
- "README.md",
15
- "CHANGELOG.md",
16
- "LICENSE",
17
- "tsconfig.json"
18
- ],
19
- "exports": {
20
- "./package.json": "./package.json",
21
- "./admin": "./.medusa/server/src/admin/index.mjs",
22
- "./providers/paypal": "./.medusa/server/src/providers/paypal/index.js",
23
- "./providers/paypal_card": "./.medusa/server/src/providers/paypal_card/index.js",
24
- "./modules/paypal": "./.medusa/server/src/modules/paypal/index.js",
25
- ".": "./.medusa/server/src/index.js",
26
- "./.medusa/server/src/modules/*": "./.medusa/server/src/modules/*/index.js",
27
- "./.medusa/server/src/modules/paypal": "./.medusa/server/src/modules/paypal/index.js",
28
- "./.medusa/server/src/providers/*": "./.medusa/server/src/providers/*/index.js",
29
- "./.medusa/server/src/providers/paypal": "./.medusa/server/src/providers/paypal/index.js",
30
- "./.medusa/server/src/providers/paypal_card": "./.medusa/server/src/providers/paypal_card/index.js",
31
- "./.medusa/server/src/admin": "./.medusa/server/src/admin/index.mjs",
32
- "./.medusa/server/src/*": "./.medusa/server/src/*.js",
33
- "./.medusa/*": "./.medusa/*"
34
- },
35
- "scripts": {
36
- "build": "medusa plugin:build",
37
- "develop": "medusa plugin:develop",
38
- "test": "vitest run",
39
- "test:watch": "vitest",
40
- "prepublishOnly": "npm run build"
41
- },
42
- "devDependencies": {
43
- "@medusajs/admin-sdk": "2.12.5",
44
- "@medusajs/cli": "2.12.5",
45
- "@medusajs/framework": "2.12.5",
46
- "@medusajs/icons": "2.12.5",
47
- "@medusajs/medusa": "2.12.5",
48
- "@medusajs/test-utils": "2.12.5",
49
- "@medusajs/ui": "^4.0.0",
50
- "@swc/core": "^1.5.7",
51
- "ts-node": "^10.9.2",
52
- "typescript": "^5.6.2",
53
- "vitest": "^2.0.5"
54
- },
55
- "peerDependencies": {
56
- "@medusajs/admin-sdk": "^2.12.0",
57
- "@medusajs/framework": "^2.12.0",
58
- "@medusajs/icons": "^2.12.0",
59
- "@medusajs/medusa": "^2.12.0",
60
- "@medusajs/ui": "^4.0.0"
61
- },
62
- "peerDependenciesMeta": {
63
- "@medusajs/admin-sdk": {
64
- "optional": true
65
- },
66
- "@medusajs/ui": {
67
- "optional": true
68
- },
69
- "@medusajs/icons": {
70
- "optional": true
71
- }
72
- },
73
- "publishConfig": {
74
- "access": "public"
75
- },
76
- "engines": {
77
- "node": ">=20"
78
- },
79
- "repository": {
80
- "type": "git",
81
- "url": "https://github.com/easypaymentplugins/medusa-paypal.git"
82
- },
83
- "keywords": [
84
- "medusa-v2",
85
- "medusa-plugin-integration",
86
- "medusa-plugin-payment"
87
- ]
88
- }
1
+ {
2
+ "name": "@easypayment/medusa-payment-paypal",
3
+ "version": "1.2.1",
4
+ "description": "PayPal for Medusa v2 \u2014 Built by a PayPal Partner.",
5
+ "author": "EasyPayment Plugins",
6
+ "license": "MIT",
7
+ "main": "./.medusa/server/src/index.js",
8
+ "types": "./.medusa/server/src/index.d.ts",
9
+ "files": [
10
+ ".medusa/server",
11
+ "src",
12
+ "scripts",
13
+ "package.json",
14
+ "README.md",
15
+ "CHANGELOG.md",
16
+ "LICENSE",
17
+ "tsconfig.json"
18
+ ],
19
+ "exports": {
20
+ "./package.json": "./package.json",
21
+ "./admin": "./.medusa/server/src/admin/index.mjs",
22
+ "./providers/paypal": "./.medusa/server/src/providers/paypal/index.js",
23
+ "./providers/paypal_card": "./.medusa/server/src/providers/paypal_card/index.js",
24
+ "./modules/paypal": "./.medusa/server/src/modules/paypal/index.js",
25
+ ".": "./.medusa/server/src/index.js",
26
+ "./.medusa/server/src/modules/*": "./.medusa/server/src/modules/*/index.js",
27
+ "./.medusa/server/src/modules/paypal": "./.medusa/server/src/modules/paypal/index.js",
28
+ "./.medusa/server/src/providers/*": "./.medusa/server/src/providers/*/index.js",
29
+ "./.medusa/server/src/providers/paypal": "./.medusa/server/src/providers/paypal/index.js",
30
+ "./.medusa/server/src/providers/paypal_card": "./.medusa/server/src/providers/paypal_card/index.js",
31
+ "./.medusa/server/src/admin": "./.medusa/server/src/admin/index.mjs",
32
+ "./.medusa/server/src/*": "./.medusa/server/src/*.js",
33
+ "./.medusa/*": "./.medusa/*"
34
+ },
35
+ "scripts": {
36
+ "build": "medusa plugin:build",
37
+ "develop": "medusa plugin:develop",
38
+ "test": "vitest run",
39
+ "test:watch": "vitest",
40
+ "prepublishOnly": "npm run build",
41
+ "typecheck": "tsc --noEmit"
42
+ },
43
+ "devDependencies": {
44
+ "@medusajs/admin-sdk": "2.12.5",
45
+ "@medusajs/cli": "2.12.5",
46
+ "@medusajs/framework": "2.12.5",
47
+ "@medusajs/icons": "2.12.5",
48
+ "@medusajs/medusa": "2.12.5",
49
+ "@medusajs/test-utils": "2.12.5",
50
+ "@medusajs/ui": "^4.0.0",
51
+ "@swc/core": "^1.5.7",
52
+ "@types/react": "^18.3.31",
53
+ "react": "^18.3.1",
54
+ "ts-node": "^10.9.2",
55
+ "typescript": "^5.6.2",
56
+ "vitest": "^2.0.5"
57
+ },
58
+ "peerDependencies": {
59
+ "@medusajs/admin-sdk": "^2.12.0",
60
+ "@medusajs/framework": "^2.12.0",
61
+ "@medusajs/icons": "^2.12.0",
62
+ "@medusajs/medusa": "^2.12.0",
63
+ "@medusajs/ui": "^4.0.0"
64
+ },
65
+ "peerDependenciesMeta": {
66
+ "@medusajs/admin-sdk": {
67
+ "optional": true
68
+ },
69
+ "@medusajs/ui": {
70
+ "optional": true
71
+ },
72
+ "@medusajs/icons": {
73
+ "optional": true
74
+ }
75
+ },
76
+ "publishConfig": {
77
+ "access": "public"
78
+ },
79
+ "engines": {
80
+ "node": ">=20"
81
+ },
82
+ "repository": {
83
+ "type": "git",
84
+ "url": "https://github.com/easypaymentplugins/medusa-paypal.git"
85
+ },
86
+ "keywords": [
87
+ "medusa-v2",
88
+ "medusa-plugin-integration",
89
+ "medusa-plugin-payment"
90
+ ]
91
+ }
@@ -7,10 +7,19 @@ export default defineMiddlewares({
7
7
  // Keep the exact bytes PayPal signed (`req.rawBody`) so webhook signature
8
8
  // verification hashes the original payload, not a re-serialized copy. This
9
9
  // entry must precede the "/store/paypal/:path*" catch-all below.
10
+ // Rate-limited (opt-in, like the store routes): every unauthenticated
11
+ // POST here costs a DB dedup read plus an outbound PayPal
12
+ // verify-webhook-signature call, and a flood of garbage requests could
13
+ // trip the shared circuit breaker for legitimate verifications.
10
14
  matcher: "/store/paypal/webhook",
11
15
  method: ["POST"],
12
16
  bodyParser: { preserveRawBody: true },
13
- middlewares: [],
17
+ middlewares: [
18
+ createRateLimiter("webhook", {
19
+ maxEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_MAX",
20
+ windowEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_WINDOW_MS",
21
+ }),
22
+ ],
14
23
  },
15
24
  {
16
25
  // Same raw-body requirement for the /hooks mirror of the webhook route —
@@ -19,7 +28,12 @@ export default defineMiddlewares({
19
28
  matcher: "/hooks/paypal/webhook",
20
29
  method: ["POST"],
21
30
  bodyParser: { preserveRawBody: true },
22
- middlewares: [],
31
+ middlewares: [
32
+ createRateLimiter("webhook-hooks", {
33
+ maxEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_MAX",
34
+ windowEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_WINDOW_MS",
35
+ }),
36
+ ],
23
37
  },
24
38
  {
25
39
  // Rate-limit the order-creating route: unauthenticated by necessity, so