@easypayment/medusa-payment-paypal 1.3.7 → 1.3.9

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 (42) hide show
  1. package/.medusa/server/src/admin/index.js +172 -76
  2. package/.medusa/server/src/admin/index.mjs +107 -13
  3. package/.medusa/server/src/api/admin/paypal/logs/route.d.ts.map +1 -1
  4. package/.medusa/server/src/api/admin/paypal/logs/route.js.map +1 -1
  5. package/.medusa/server/src/api/admin/paypal/merchant-status/route.d.ts +11 -0
  6. package/.medusa/server/src/api/admin/paypal/merchant-status/route.d.ts.map +1 -0
  7. package/.medusa/server/src/api/admin/paypal/merchant-status/route.js +32 -0
  8. package/.medusa/server/src/api/admin/paypal/merchant-status/route.js.map +1 -0
  9. package/.medusa/server/src/api/store/paypal/create-order/route.d.ts +4 -1
  10. package/.medusa/server/src/api/store/paypal/create-order/route.d.ts.map +1 -1
  11. package/.medusa/server/src/api/store/paypal/create-order/route.js +101 -102
  12. package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -1
  13. package/.medusa/server/src/modules/paypal/service.d.ts +34 -0
  14. package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
  15. package/.medusa/server/src/modules/paypal/service.js +161 -34
  16. package/.medusa/server/src/modules/paypal/service.js.map +1 -1
  17. package/.medusa/server/src/modules/paypal/types/config.d.ts +12 -0
  18. package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -1
  19. package/.medusa/server/src/modules/paypal/types/config.js +25 -1
  20. package/.medusa/server/src/modules/paypal/types/config.js.map +1 -1
  21. package/.medusa/server/src/modules/paypal/utils/merchant-status.d.ts +50 -0
  22. package/.medusa/server/src/modules/paypal/utils/merchant-status.d.ts.map +1 -0
  23. package/.medusa/server/src/modules/paypal/utils/merchant-status.js +106 -0
  24. package/.medusa/server/src/modules/paypal/utils/merchant-status.js.map +1 -0
  25. package/.medusa/server/src/modules/paypal/utils/order-context.d.ts +61 -0
  26. package/.medusa/server/src/modules/paypal/utils/order-context.d.ts.map +1 -0
  27. package/.medusa/server/src/modules/paypal/utils/order-context.js +127 -0
  28. package/.medusa/server/src/modules/paypal/utils/order-context.js.map +1 -0
  29. package/CHANGELOG.md +78 -0
  30. package/README.md +108 -61
  31. package/package.json +2 -2
  32. package/src/admin/routes/settings/paypal/_components/MerchantStatusNotices.tsx +116 -0
  33. package/src/admin/routes/settings/paypal/additional-settings/page.tsx +32 -6
  34. package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +2 -0
  35. package/src/admin/routes/settings/paypal/connection/page.tsx +7 -0
  36. package/src/api/admin/paypal/logs/route.ts +1 -4
  37. package/src/api/admin/paypal/merchant-status/route.ts +36 -0
  38. package/src/api/store/paypal/create-order/route.ts +176 -157
  39. package/src/modules/paypal/service.ts +222 -43
  40. package/src/modules/paypal/types/config.ts +35 -2
  41. package/src/modules/paypal/utils/merchant-status.ts +185 -0
  42. package/src/modules/paypal/utils/order-context.ts +163 -0
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # PayPal for Medusa
2
2
 
3
- **Accept PayPal and credit card payments in your Medusa v2 store — built by an official PayPal Partner.**
3
+ **Accept PayPal and credit card payments in your Medusa v2 store. Built by an official PayPal Partner.**
4
4
 
5
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
6
  [![npm downloads](https://img.shields.io/npm/dm/@easypayment/medusa-payment-paypal?color=blue&label=downloads)](https://www.npmjs.com/package/@easypayment/medusa-payment-paypal)
@@ -8,20 +8,31 @@
8
8
  [![Medusa v2](https://img.shields.io/badge/Medusa-v2-9b59b6)](https://medusajs.com)
9
9
  [![PayPal PPCP](https://img.shields.io/badge/PayPal-PPCP-003087)](https://developer.paypal.com)
10
10
 
11
- ---
11
+ This is the **backend plugin**. It adds PayPal to your Medusa server and Medusa Admin. The checkout components for your storefront are in the companion package, [@easypayment/medusa-paypal-ui](https://www.npmjs.com/package/@easypayment/medusa-paypal-ui).
12
+
13
+ ## Contents
14
+
15
+ - [What you get](#-what-you-get)
16
+ - [Requirements](#-requirements)
17
+ - [Installation](#-installation)
18
+ - [Setup in 5 steps](#-setup-in-5-steps)
19
+ - [Customize](#-customize)
20
+ - [Going live](#-going-live)
21
+ - [Advanced options](#-advanced-options)
22
+ - [Support](#-support)
23
+ - [License](#-license)
12
24
 
13
25
  ## ✨ What you get
14
26
 
15
27
  | Feature | Details |
16
- |---|---|
28
+ | --- | --- |
17
29
  | 🔵 **PayPal Buttons** | One-click PayPal checkout for your customers |
18
- | 💳 **Card Payments** | Secure credit & debit card fields, hosted by PayPal (PCI compliant) |
19
- | 🛠 **Admin Dashboard** | Connect your PayPal account and manage everything from Medusa Admin |
20
- | 🌍 **Test & Live modes** | Try everything safely in Sandbox before going live |
30
+ | 💳 **Card payments** | Secure credit and debit card fields, hosted by PayPal (PCI compliant) |
31
+ | 🔧 **Admin dashboard** | Connect your PayPal account and manage everything from Medusa Admin |
32
+ | 🌍 **Test and Live modes** | Try everything safely in Sandbox before going live |
33
+ | 💰 **Capture or authorize** | Charge at checkout, or authorize first and capture from the order later |
21
34
  | 🔐 **3D Secure** | Extra card security, configurable in one click |
22
- | 🔄 **Reliable by design** | Payments are verified with PayPal at every step — webhooks, retries, and safety nets are handled for you |
23
-
24
- ---
35
+ | 🔄 **Reliable by design** | Payments are verified with PayPal at every step. Webhooks, retries and safety nets are handled for you |
25
36
 
26
37
  ## ✅ Requirements
27
38
 
@@ -29,8 +40,6 @@
29
40
  - Node.js **20+**
30
41
  - PostgreSQL
31
42
 
32
- ---
33
-
34
43
  ## 🚀 Installation
35
44
 
36
45
  In your Medusa backend folder, run:
@@ -39,12 +48,12 @@ In your Medusa backend folder, run:
39
48
  npm install @easypayment/medusa-payment-paypal
40
49
  ```
41
50
 
42
- ---
43
-
44
- ## ⚙️ Setup — 5 steps
51
+ ## 🧩 Setup in 5 steps
45
52
 
46
53
  ### 1. Add the plugin to `medusa-config.ts`
47
54
 
55
+ Add the `plugins` entry and the two payment providers:
56
+
48
57
  ```ts
49
58
  import { loadEnv, defineConfig } from "@medusajs/framework/utils"
50
59
 
@@ -103,92 +112,130 @@ npx medusa db:migrate
103
112
 
104
113
  ### 3. Connect your PayPal account
105
114
 
106
- 1. Start your Medusa server
107
- 2. Open **Medusa Admin → Settings → PayPal**
108
- 3. Choose **Sandbox** (testing) or **Live** (real payments)
109
- 4. Click **Connect to PayPal** and follow the steps
115
+ 1. Start your Medusa server.
116
+ 2. Open **Medusa Admin → Settings → PayPal → PayPal Connection**.
117
+ 3. Choose **Sandbox** (testing) or **Live** (real payments).
118
+ 4. Click **Connect to PayPal** and follow the steps in the PayPal window.
110
119
 
111
- That's it — your credentials are saved automatically. Webhooks are registered for you too.
120
+ Your credentials are saved automatically, and webhooks are registered for you.
112
121
 
113
- > 💡 Prefer manual setup? Click **Insert credentials manually** and paste your Client ID and Secret from [developer.paypal.com](https://developer.paypal.com/dashboard/).
122
+ > 💡 Prefer manual setup? Click **Click here to insert credentials manually** and paste your Client ID and Secret from [developer.paypal.com](https://developer.paypal.com/dashboard/).
114
123
 
115
124
  ### 4. Turn PayPal on in your region
116
125
 
117
126
  Go to **Medusa Admin → Settings → Regions → your region** and enable:
118
127
 
119
128
  | Payment provider | What it is |
120
- |---|---|
129
+ | --- | --- |
121
130
  | `pp_paypal_paypal` | PayPal Buttons |
122
131
  | `pp_paypal_card_paypal_card` | Card payments |
123
132
 
124
133
  ### 5. Add PayPal to your storefront
125
134
 
126
- The checkout UI comes as a separate package — install it in your **storefront** project:
135
+ The checkout UI is a separate package. Install it in your **storefront** project and follow its step-by-step guide:
136
+
137
+ 📦 **[@easypayment/medusa-paypal-ui](https://www.npmjs.com/package/@easypayment/medusa-paypal-ui)**: ready-made PayPal components for Next.js storefronts.
127
138
 
128
- 📦 **[@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.
139
+ ## 🎨 Customize
129
140
 
130
- ---
141
+ Everything is managed in **Medusa Admin → Settings → PayPal**. Changes apply right away, with no restart.
131
142
 
132
- ## 🎨 Customize (optional)
143
+ | Tab | What you can change |
144
+ | --- | --- |
145
+ | **PayPal Settings** | Turn PayPal on or off, checkout title, button color, shape, width, height and label |
146
+ | **Advanced Card Payments** | Turn card payments on or off, checkout title, 3D Secure mode |
147
+ | **Additional Settings** | Payment action (capture or authorize), brand name shown at PayPal, landing page, instant payments, item details, shipping address, invoice prefix, card statement name |
133
148
 
134
- Everything is managed in **Medusa Admin → Settings → PayPal** — changes apply instantly, no restart needed:
149
+ ## 🔐 Going live
135
150
 
136
- - **PayPal Settings** — turn PayPal on/off, button color, shape, and label
137
- - **Advanced Card Payments** — turn card payments on/off, 3D Secure mode
138
- - **Additional Settings** — capture vs. authorize, brand name shown at PayPal, invoice prefix
151
+ Set these two environment variables on your server before taking real payments:
139
152
 
140
- ---
153
+ | Variable | Why |
154
+ | --- | --- |
155
+ | `PAYPAL_ENCRYPTION_KEY` | Any long random text. Your PayPal credentials are then stored encrypted in the database. Keep the key safe: if it is lost, reconnect PayPal |
156
+ | `MEDUSA_BACKEND_URL` | Your backend's public address, for example `https://api.mystore.com`, so PayPal can reach your store with payment notifications |
141
157
 
142
- ## 🔐 Going live — two things we recommend
158
+ Then switch the environment to **Live** in **Settings → PayPal → PayPal Connection** and connect your live PayPal account.
143
159
 
144
- 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.
145
- 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.
160
+ ## 🧰 Advanced options
161
+
162
+ Everything works without these. They are for developers who need to tune the plugin.
146
163
 
147
164
  <details>
148
- <summary><b>Advanced options</b> (for developers — everything works without these)</summary>
165
+ <summary><b>Environment variables</b></summary>
149
166
 
150
167
  <br>
151
168
 
152
169
  | Variable | Default | What it does |
153
- |---|---|---|
154
- | `STOREFRONT_URL` | *(request origin, if listed in `STORE_CORS`)* | Storefront address used for PayPal return/cancel pages (can also be set in Admin) |
155
- | `PAYPAL_ENCRYPTION_STRICT` | `false` | `true` = refuse to save credentials unencrypted |
156
- | `PAYPAL_SELLER_NONCE` | *(partner service nonce)* | Only change this if you also run your own `PAYPAL_PARTNER_SERVICE_URL`; it must match the nonce that service puts in its onboarding links |
157
- | `PAYPAL_ADMIN_ORIGIN` | first `ADMIN_CORS` entry | Restricts the onboarding popup to your admin URL |
170
+ | --- | --- | --- |
171
+ | `STOREFRONT_URL` (or `STORE_URL`) | Request origin, if listed in `STORE_CORS` | Storefront address used for PayPal return and cancel pages. Can also be set in Admin |
172
+ | `PAYPAL_ENCRYPTION_STRICT` | `false` | `true` refuses to save credentials unencrypted |
173
+ | `PAYPAL_ADMIN_ORIGIN` | First `ADMIN_CORS` entry | Restricts the onboarding popup to your admin URL |
174
+ | `PAYPAL_SEND_SHIPPING_ADDRESS` | `true` | The shipping address the buyer entered at checkout is sent on PayPal orders (`SET_PROVIDED_ADDRESS`), which PayPal Seller Protection needs. Set `false` to let buyers pick an address in PayPal instead. Also an admin setting |
175
+ | `PAYPAL_CURRENCY` | `EUR` | Fallback currency if none is configured |
176
+ | `PAYPAL_HTTP_TIMEOUT_MS` | `30000` | Timeout for calls to PayPal |
177
+ | `PAYPAL_SETTINGS_CACHE_MS` | `15000` | In-process cache for plugin settings reads. `0` disables it |
158
178
  | `PAYPAL_WEBHOOK_COMPLETE_CART` | `true` | Safety net that finishes an order when the payment succeeded but the buyer's browser closed. `false` disables it |
159
- | `PAYPAL_RATE_LIMIT_MAX` / `PAYPAL_RATE_LIMIT_WINDOW_MS` | *(off)* / `60000` | Optional request limit for the public checkout routes |
160
- | `PAYPAL_WEBHOOK_RATE_LIMIT_MAX` / `PAYPAL_WEBHOOK_RATE_LIMIT_WINDOW_MS` | *(off)* / `60000` | Optional request limit for the webhook endpoint (separate from the above) |
161
179
  | `PAYPAL_WEBHOOK_REPLAY_WINDOW_MINUTES` | `60` | Rejects webhook deliveries older than this |
162
- | `PAYPAL_WEBHOOK_STALE_PROCESSING_MS` | `300000` | When the retry job re-picks-up interrupted webhook events |
163
- | `PAYPAL_WEBHOOK_ID_LIVE` / `PAYPAL_WEBHOOK_ID_SANDBOX` | *(auto)* | Manual webhook-id override (normally automatic) |
164
- | `PAYPAL_HTTP_TIMEOUT_MS` | `30000` | Timeout for calls to PayPal |
165
- | `PAYPAL_CURRENCY` | `EUR` | Fallback currency if none is configured |
166
- | `PAYPAL_ALERT_WEBHOOK_URLS` | *(unset)* | Comma-separated URLs that receive operational alerts (including dead-lettered webhook events) |
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**) |
180
+ | `PAYPAL_WEBHOOK_STALE_PROCESSING_MS` | `300000` | When the retry job picks up interrupted webhook events again |
181
+ | `PAYPAL_WEBHOOK_ID_LIVE` / `PAYPAL_WEBHOOK_ID_SANDBOX` | Automatic | Manual webhook ID override |
182
+ | `PAYPAL_RATE_LIMIT_MAX` / `PAYPAL_RATE_LIMIT_WINDOW_MS` | Off / `60000` | Optional request limit for the public checkout routes |
183
+ | `PAYPAL_WEBHOOK_RATE_LIMIT_MAX` / `PAYPAL_WEBHOOK_RATE_LIMIT_WINDOW_MS` | Off / `60000` | Optional request limit for the webhook endpoint, separate from the one above |
184
+ | `PAYPAL_ALERT_WEBHOOK_URLS` | Unset | Comma-separated URLs that receive operational alerts, including dead-lettered webhook events |
185
+ | `PAYPAL_REQUEST_LOG` | Off | `1` or `true` forces the request/response log on, regardless of the admin toggle |
169
186
  | `PAYPAL_LOG_DIR` | `./logs` | Directory for the `paypal-requests-YYYY-MM-DD.log` file written when logging is on |
170
- | `PAYPAL_SEND_SHIPPING_ADDRESS` | `false` | `true` sends the cart's shipping address on PayPal orders (`SET_PROVIDED_ADDRESS`) — improves PayPal Seller Protection eligibility |
171
- | `PAYPAL_PARTNER_SERVICE_URL` | *(built-in)* | Override the partner onboarding service used by the connect flow |
172
- | `PAYPAL_PARTNER_MERCHANT_ID_SANDBOX` / `PAYPAL_PARTNER_MERCHANT_ID_LIVE` | *(built-in)* | Override the partner merchant ids used for onboarding |
187
+ | `PAYPAL_PARTNER_SERVICE_URL` | Built-in | Overrides the partner onboarding service used by the connect flow |
188
+ | `PAYPAL_PARTNER_STATUS_URL` | Derived from the service URL | Overrides the partner service endpoint that reads the seller's onboarding status |
189
+ | `PAYPAL_SELLER_NONCE` | Partner service nonce | Only change this if you also run your own `PAYPAL_PARTNER_SERVICE_URL`. It must match the nonce that service puts in its onboarding links |
190
+ | `PAYPAL_PARTNER_MERCHANT_ID_SANDBOX` / `PAYPAL_PARTNER_MERCHANT_ID_LIVE` | Built-in | Overrides the partner merchant IDs used for onboarding |
173
191
 
174
- **Declined cards:** when PayPal declines a capture, `/store/paypal/capture-order` responds `402` with a buyer-friendly `message` plus a structured `decline` object — `{ code, message, retryable, avs_code?, cvv_code? }` — so storefronts can show "insufficient funds, try another card" and decide whether to offer a retry.
192
+ </details>
175
193
 
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).
194
+ <details>
195
+ <summary><b>Declined cards</b></summary>
177
196
 
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.
197
+ <br>
198
+
199
+ When PayPal declines a capture, `/store/paypal/capture-order` responds `402` with a buyer-friendly `message` and a structured `decline` object:
200
+
201
+ ```ts
202
+ { code, message, retryable, avs_code?, cvv_code? }
203
+ ```
204
+
205
+ Storefronts can use it to show a message such as "insufficient funds, try another card" and to decide whether to offer a retry.
179
206
 
180
207
  </details>
181
208
 
182
- ---
209
+ <details>
210
+ <summary><b>Monitoring</b></summary>
183
211
 
184
- ## 💬 Support
212
+ <br>
185
213
 
186
- - 🐛 **Found a bug?** [Open an issue](https://github.com/easypaymentplugins/medusa-paypal/issues)
187
- - 💡 **Questions or feature requests?** [Start a discussion](https://github.com/easypaymentplugins/medusa-paypal/discussions)
188
- - 🛍 **Storefront UI package:** [@easypayment/medusa-paypal-ui](https://www.npmjs.com/package/@easypayment/medusa-paypal-ui)
214
+ - Operational counters live in the `paypal_metric` table.
215
+ - Every webhook is recorded in `paypal_webhook_event` and retried automatically. Events that exhaust their retries are dead-lettered and pushed to `PAYPAL_ALERT_WEBHOOK_URLS`.
216
+ - Audit events are logged as JSON lines tagged `"log":"paypal_audit"`, with secrets redacted.
217
+
218
+ </details>
219
+
220
+ <details>
221
+ <summary><b>Integration log for PayPal review</b></summary>
222
+
223
+ <br>
224
+
225
+ Turn on **Settings → PayPal → Additional Settings → Request/response logging** (off by default) to append every PayPal API call, and every plugin API request and response, to `logs/paypal-requests-YYYY-MM-DD.log`.
226
+
227
+ - Credentials are redacted. The `PayPal-Partner-Attribution-Id` (BN code) is kept, so the file is safe to hand to PayPal's go-live review.
228
+ - Download it from the same settings page with **Download log**, or at `GET /admin/paypal/logs?download=1`.
229
+ - Turn logging off again once the review is complete.
230
+
231
+ </details>
232
+
233
+ ## 💬 Support
189
234
 
190
- ---
235
+ - 🐛 **Found a bug, or have a question or feature request?** [Open an issue](https://github.com/easypaymentplugins/medusa-paypal/issues)
236
+ - 🛒 **Storefront UI package:** [@easypayment/medusa-paypal-ui](https://www.npmjs.com/package/@easypayment/medusa-paypal-ui)
237
+ - 📝 **Release notes:** see [CHANGELOG.md](CHANGELOG.md)
191
238
 
192
239
  ## 📄 License
193
240
 
194
- MIT © [Easy Payment](https://www.npmjs.com/package/@easypayment/medusa-payment-paypal)
241
+ [MIT](LICENSE) © Easy Payment
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easypayment/medusa-payment-paypal",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
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",
@@ -87,7 +87,7 @@
87
87
  },
88
88
  "repository": {
89
89
  "type": "git",
90
- "url": "https://github.com/easypaymentplugins/medusa-paypal.git"
90
+ "url": "git+https://github.com/easypaymentplugins/medusa-paypal.git"
91
91
  },
92
92
  "homepage": "https://github.com/easypaymentplugins/medusa-paypal#readme",
93
93
  "bugs": {
@@ -0,0 +1,116 @@
1
+ import React, { useEffect, useState } from "react"
2
+ import { adminFetch } from "../_utils/adminFetch"
3
+
4
+ type Notice = {
5
+ code: string
6
+ level: "error" | "warning"
7
+ message: string
8
+ }
9
+
10
+ type MerchantStatusResponse = {
11
+ available?: boolean
12
+ notices?: Notice[]
13
+ }
14
+
15
+ const URL_RE = /(https?:\/\/[^\s]+[^\s.,!?])/g
16
+
17
+ /** Render a notice, turning the PayPal URLs in it into links. */
18
+ function NoticeText({ message }: { message: string }) {
19
+ const parts = message.split(URL_RE)
20
+ return (
21
+ <>
22
+ {parts.map((part, i) =>
23
+ /^https?:\/\//.test(part) ? (
24
+ <a
25
+ key={i}
26
+ href={part}
27
+ target="_blank"
28
+ rel="noopener noreferrer"
29
+ className="underline"
30
+ >
31
+ {part}
32
+ </a>
33
+ ) : (
34
+ <React.Fragment key={i}>{part}</React.Fragment>
35
+ )
36
+ )}
37
+ </>
38
+ )
39
+ }
40
+
41
+ /**
42
+ * Warnings about the connected PayPal account, from PayPal's seller onboarding
43
+ * status: unconfirmed email, payments not receivable, PayPal payments or
44
+ * Advanced Card payments not enabled. Renders nothing while loading, when the
45
+ * seller is not connected, when the status cannot be read, and when every
46
+ * check passes.
47
+ *
48
+ * `only` narrows the notices to the ones a page cares about; `reloadKey`
49
+ * re-fetches when it changes (e.g. after connecting).
50
+ */
51
+ export default function MerchantStatusNotices({
52
+ environment,
53
+ only,
54
+ reloadKey,
55
+ }: {
56
+ environment?: "sandbox" | "live"
57
+ only?: string[]
58
+ reloadKey?: string | number
59
+ }) {
60
+ const [notices, setNotices] = useState<Notice[]>([])
61
+
62
+ useEffect(() => {
63
+ let cancelled = false
64
+ setNotices([])
65
+ ;(async () => {
66
+ try {
67
+ const json = await adminFetch<MerchantStatusResponse>(
68
+ "/admin/paypal/merchant-status",
69
+ environment ? { query: { environment } } : {}
70
+ )
71
+ if (cancelled) return
72
+ setNotices(Array.isArray(json?.notices) ? json.notices : [])
73
+ } catch {
74
+ // The warnings are advisory: never break the page over them.
75
+ }
76
+ })()
77
+ return () => {
78
+ cancelled = true
79
+ }
80
+ }, [environment, reloadKey])
81
+
82
+ const visible = only
83
+ ? notices.filter((notice) => only.includes(notice.code))
84
+ : notices
85
+ if (visible.length === 0) return null
86
+
87
+ return (
88
+ <div className="flex flex-col gap-2" data-testid="paypal-merchant-notices">
89
+ {visible.map((notice) => (
90
+ <div
91
+ key={notice.code}
92
+ role="alert"
93
+ className="rounded border p-3 text-sm"
94
+ // Colors are inline: the admin's stylesheet only carries the utility
95
+ // classes Medusa itself uses, so an amber/red palette class may not
96
+ // exist there.
97
+ style={
98
+ notice.level === "error"
99
+ ? {
100
+ background: "#fef2f2",
101
+ borderColor: "#fecaca",
102
+ color: "#b91c1c",
103
+ }
104
+ : {
105
+ background: "#fffbeb",
106
+ borderColor: "#fde68a",
107
+ color: "#92400e",
108
+ }
109
+ }
110
+ >
111
+ <NoticeText message={notice.message} />
112
+ </div>
113
+ ))}
114
+ </div>
115
+ )
116
+ }
@@ -6,7 +6,7 @@ import Toast, { ToastState } from "../_components/Toast"
6
6
  import { adminFetch } from "../_utils/adminFetch"
7
7
 
8
8
  type PaymentAction = "capture" | "authorize"
9
- type LandingPage = "no_preference" | "login" | "billing"
9
+ type LandingPage = "login" | "billing"
10
10
 
11
11
  type AdditionalSettingsForm = {
12
12
  paymentAction: PaymentAction
@@ -14,6 +14,7 @@ type AdditionalSettingsForm = {
14
14
  landingPage: LandingPage
15
15
  requireInstantPayment: boolean
16
16
  sendItemDetails: boolean
17
+ sendShippingAddress: boolean
17
18
  invoicePrefix: string
18
19
  creditCardStatementName: string
19
20
  debugLogging: boolean
@@ -22,9 +23,10 @@ type AdditionalSettingsForm = {
22
23
  const DEFAULT_FORM: AdditionalSettingsForm = {
23
24
  paymentAction: "capture",
24
25
  brandName: "PayPal",
25
- landingPage: "no_preference",
26
+ landingPage: "login",
26
27
  requireInstantPayment: false,
27
28
  sendItemDetails: true,
29
+ sendShippingAddress: true,
28
30
  invoicePrefix: "PP-",
29
31
  creditCardStatementName: "PayPal",
30
32
  debugLogging: false,
@@ -36,10 +38,14 @@ function mergeWithDefaults(saved?: Partial<AdditionalSettingsForm> | null) {
36
38
  const entries = Object.entries(saved).filter(
37
39
  ([, value]) => value !== undefined
38
40
  )
39
- return {
41
+ const merged = {
40
42
  ...DEFAULT_FORM,
41
43
  ...(Object.fromEntries(entries) as Partial<AdditionalSettingsForm>),
42
44
  }
45
+ // "No Preference" was removed in 1.3.9 (PayPal asks for the login page);
46
+ // stores that saved it are shown, and sent, "Login".
47
+ if (merged.landingPage !== "billing") merged.landingPage = "login"
48
+ return merged
43
49
  }
44
50
 
45
51
  /** Settings → PayPal → Additional Settings (checkout behaviour + invoice options). */
@@ -212,9 +218,8 @@ export default function AdditionalSettingsTab() {
212
218
  }
213
219
  className="w-full rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base outline-none focus:ring-2 focus:ring-ui-border-interactive"
214
220
  >
215
- <option value="no_preference">No Preference</option>
216
- <option value="login">Login</option>
217
- <option value="billing">Billing</option>
221
+ <option value="login">Login (PayPal account)</option>
222
+ <option value="billing">Guest checkout (card form)</option>
218
223
  </select>
219
224
  </FieldRow>
220
225
  <FieldRow label="Instant Payments">
@@ -256,6 +261,27 @@ export default function AdditionalSettingsTab() {
256
261
  </span>
257
262
  </label>
258
263
  </FieldRow>
264
+ <FieldRow
265
+ label="Send Shipping Address"
266
+ hint="Send the shipping address the customer entered at checkout to PayPal, so PayPal shows that address instead of the ones saved on the customer's PayPal account. Needed for PayPal Seller Protection."
267
+ >
268
+ <label className="inline-flex items-center gap-2">
269
+ <input
270
+ type="checkbox"
271
+ checked={form.sendShippingAddress}
272
+ onChange={(e) =>
273
+ setForm((p) => ({
274
+ ...p,
275
+ sendShippingAddress: e.target.checked,
276
+ }))
277
+ }
278
+ className="h-4 w-4 rounded border-ui-border-base"
279
+ />
280
+ <span className="text-sm text-ui-fg-base">
281
+ Send the checkout shipping address to PayPal
282
+ </span>
283
+ </label>
284
+ </FieldRow>
259
285
  <FieldRow label="Invoice prefix" htmlFor="as-invoice-prefix">
260
286
  <input
261
287
  id="as-invoice-prefix"
@@ -3,6 +3,7 @@ import PayPalTabs from "../_components/Tabs"
3
3
  import SectionCard from "../_components/SectionCard"
4
4
  import FieldRow from "../_components/FieldRow"
5
5
  import Toast, { ToastState } from "../_components/Toast"
6
+ import MerchantStatusNotices from "../_components/MerchantStatusNotices"
6
7
  import { adminFetch } from "../_utils/adminFetch"
7
8
 
8
9
  type ThreeDSContingency = "sli" | "when_required" | "always"
@@ -120,6 +121,7 @@ export default function AdvancedCardPaymentsTab() {
120
121
  </div>
121
122
  <PayPalTabs />
122
123
  <Toast toast={toast} onClose={dismissToast} />
124
+ <MerchantStatusNotices only={["card_payments_not_enabled"]} />
123
125
  <SectionCard
124
126
  title="Advanced Card Payments"
125
127
  description="Control card checkout settings and 3D Secure behavior."
@@ -8,6 +8,7 @@ import React, {
8
8
  } from "react"
9
9
  import { defineRouteConfig } from "@medusajs/admin-sdk"
10
10
  import PayPalTabs from "../_components/Tabs"
11
+ import MerchantStatusNotices from "../_components/MerchantStatusNotices"
11
12
 
12
13
  export const config = defineRouteConfig({
13
14
  label: "PayPal Connection",
@@ -808,6 +809,12 @@ export default function PayPalConnectionPage() {
808
809
  PayPal
809
810
  </a>
810
811
  </div>
812
+ <div className="mt-3">
813
+ <MerchantStatusNotices
814
+ environment={env}
815
+ reloadKey={statusInfo?.seller_client_id_masked || ""}
816
+ />
817
+ </div>
811
818
  <div className="mt-3 rounded-md border border-ui-border-base bg-ui-bg-subtle p-3 text-xs text-ui-fg-subtle">
812
819
  <div className="font-medium text-ui-fg-base">
813
820
  Connected PayPal account
@@ -29,10 +29,7 @@ export async function GET(req: MedusaRequest, res: MedusaResponse) {
29
29
  }
30
30
  const name = path.basename(filePath)
31
31
  res.setHeader("Content-Type", "text/plain; charset=utf-8")
32
- res.setHeader(
33
- "Content-Disposition",
34
- `attachment; filename="${name}"`
35
- )
32
+ res.setHeader("Content-Disposition", `attachment; filename="${name}"`)
36
33
  return res.send(fs.readFileSync(filePath, "utf8"))
37
34
  }
38
35
 
@@ -0,0 +1,36 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../modules/paypal/service"
3
+
4
+ /**
5
+ * GET /admin/paypal/merchant-status[?environment=sandbox|live][&refresh=1]
6
+ *
7
+ * Whether the connected seller can receive payments, per PayPal's seller
8
+ * onboarding status: confirmed email, payments receivable, PayPal payments and
9
+ * Advanced Card payments — plus the notices to show the merchant when a check
10
+ * fails. Cached for a few minutes; `refresh=1` forces a new lookup.
11
+ */
12
+ export async function GET(req: MedusaRequest, res: MedusaResponse) {
13
+ try {
14
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
15
+
16
+ const q = (req.query || {}) as Record<string, any>
17
+ const envParam = (q.environment || q.env) as string | undefined
18
+ const env =
19
+ envParam === "live"
20
+ ? "live"
21
+ : envParam === "sandbox"
22
+ ? "sandbox"
23
+ : undefined
24
+ const refresh = q.refresh === "1" || q.refresh === "true"
25
+
26
+ return res.json(await paypal.getMerchantStatus(env, { refresh }))
27
+ } catch (e: unknown) {
28
+ console.error(
29
+ "[PayPal] merchant-status GET failed:",
30
+ e instanceof Error ? e.message : e
31
+ )
32
+ return res
33
+ .status(500)
34
+ .json({ message: "Failed to retrieve PayPal seller status" })
35
+ }
36
+ }