@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.
- package/.medusa/server/src/admin/index.js +73 -73
- package/.medusa/server/src/admin/index.mjs +73 -73
- package/.medusa/server/src/api/middlewares.d.ts.map +1 -1
- package/.medusa/server/src/api/middlewares.js +16 -2
- package/.medusa/server/src/api/middlewares.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/capture-order/route.js +66 -13
- package/.medusa/server/src/api/store/paypal/capture-order/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/create-order/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/create-order/route.js +11 -6
- package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -1
- package/.medusa/server/src/api/utils/rate-limit.d.ts +13 -1
- package/.medusa/server/src/api/utils/rate-limit.d.ts.map +1 -1
- package/.medusa/server/src/api/utils/rate-limit.js +7 -5
- package/.medusa/server/src/api/utils/rate-limit.js.map +1 -1
- package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts.map +1 -1
- package/.medusa/server/src/jobs/paypal-webhook-retry.js +4 -0
- package/.medusa/server/src/jobs/paypal-webhook-retry.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts +15 -0
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.js +26 -0
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.js +244 -169
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts +0 -4
- package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/service.js +8 -25
- package/.medusa/server/src/modules/paypal/payment-provider/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/service.d.ts +2 -0
- package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/service.js +54 -13
- package/.medusa/server/src/modules/paypal/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.js +13 -0
- package/.medusa/server/src/modules/paypal/types/config.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/amounts.d.ts +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 -34
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/metrics.d.ts +18 -0
- package/.medusa/server/src/modules/paypal/utils/metrics.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/metrics.js +45 -0
- package/.medusa/server/src/modules/paypal/utils/metrics.js.map +1 -0
- package/.medusa/server/src/modules/paypal/webhook-processor.d.ts +16 -0
- package/.medusa/server/src/modules/paypal/webhook-processor.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/webhook-processor.js +85 -2
- package/.medusa/server/src/modules/paypal/webhook-processor.js.map +1 -1
- package/.medusa/server/src/subscribers/paypal-webhook-process.d.ts.map +1 -1
- package/.medusa/server/src/subscribers/paypal-webhook-process.js +4 -0
- package/.medusa/server/src/subscribers/paypal-webhook-process.js.map +1 -1
- package/CHANGELOG.md +208 -146
- package/README.md +175 -184
- package/package.json +91 -88
- package/src/api/middlewares.ts +16 -2
- package/src/api/store/paypal/capture-order/route.ts +83 -12
- package/src/api/store/paypal/create-order/route.ts +11 -7
- package/src/api/utils/rate-limit.ts +20 -5
- package/src/jobs/paypal-webhook-retry.ts +4 -0
- package/src/modules/paypal/payment-provider/base-provider.ts +31 -0
- package/src/modules/paypal/payment-provider/card-service.ts +84 -0
- package/src/modules/paypal/payment-provider/service.ts +12 -30
- package/src/modules/paypal/service.ts +1703 -1651
- package/src/modules/paypal/types/config.ts +16 -0
- package/src/modules/paypal/utils/credential-resolver.ts +9 -36
- package/src/modules/paypal/utils/metrics.ts +48 -0
- package/src/modules/paypal/webhook-processor.ts +101 -2
- 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
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/@easypayment/medusa-payment-paypal)
|
|
6
|
-
[](LICENSE)
|
|
7
|
-
[](https://medusajs.com)
|
|
8
|
-
[](https://developer.paypal.com)
|
|
9
|
-
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
|
157
|
-
|
|
158
|
-
|
|
|
159
|
-
|
|
|
160
|
-
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
+
[](https://www.npmjs.com/package/@easypayment/medusa-payment-paypal)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://medusajs.com)
|
|
8
|
+
[](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
|
|
4
|
-
"description": "PayPal for Medusa v2
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
"@medusajs/
|
|
45
|
-
"@medusajs/
|
|
46
|
-
"@medusajs/
|
|
47
|
-
"@medusajs/
|
|
48
|
-
"@medusajs/
|
|
49
|
-
"@medusajs/
|
|
50
|
-
"@
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"@medusajs/
|
|
60
|
-
"@medusajs/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"@medusajs/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"@medusajs/
|
|
67
|
-
"optional": true
|
|
68
|
-
},
|
|
69
|
-
"@medusajs/
|
|
70
|
-
"optional": true
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
},
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
},
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"medusa-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
+
}
|
package/src/api/middlewares.ts
CHANGED
|
@@ -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
|