@easypayment/medusa-payment-paypal 1.3.8 → 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.
- package/.medusa/server/src/admin/index.js +175 -79
- package/.medusa/server/src/admin/index.mjs +110 -16
- package/.medusa/server/src/api/admin/paypal/merchant-status/route.d.ts +11 -0
- package/.medusa/server/src/api/admin/paypal/merchant-status/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/merchant-status/route.js +32 -0
- package/.medusa/server/src/api/admin/paypal/merchant-status/route.js.map +1 -0
- package/.medusa/server/src/api/store/paypal/create-order/route.d.ts +4 -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 +101 -102
- package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -1
- package/.medusa/server/src/modules/paypal/service.d.ts +34 -0
- package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/service.js +161 -34
- package/.medusa/server/src/modules/paypal/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.d.ts +12 -0
- package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.js +25 -1
- package/.medusa/server/src/modules/paypal/types/config.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/merchant-status.d.ts +50 -0
- package/.medusa/server/src/modules/paypal/utils/merchant-status.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/merchant-status.js +106 -0
- package/.medusa/server/src/modules/paypal/utils/merchant-status.js.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/order-context.d.ts +61 -0
- package/.medusa/server/src/modules/paypal/utils/order-context.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/order-context.js +127 -0
- package/.medusa/server/src/modules/paypal/utils/order-context.js.map +1 -0
- package/CHANGELOG.md +56 -0
- package/README.md +3 -2
- package/package.json +1 -1
- package/src/admin/routes/settings/paypal/_components/MerchantStatusNotices.tsx +116 -0
- package/src/admin/routes/settings/paypal/additional-settings/page.tsx +32 -6
- package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +2 -0
- package/src/admin/routes/settings/paypal/connection/page.tsx +7 -0
- package/src/api/admin/paypal/merchant-status/route.ts +36 -0
- package/src/api/store/paypal/create-order/route.ts +176 -157
- package/src/modules/paypal/service.ts +222 -43
- package/src/modules/paypal/types/config.ts +35 -2
- package/src/modules/paypal/utils/merchant-status.ts +185 -0
- package/src/modules/paypal/utils/order-context.ts +163 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveLandingPage = resolveLandingPage;
|
|
4
|
+
exports.buildPayPalShipping = buildPayPalShipping;
|
|
5
|
+
exports.sameShipping = sameShipping;
|
|
6
|
+
exports.shippingFingerprint = shippingFingerprint;
|
|
7
|
+
exports.isShippingAddressRejection = isShippingAddressRejection;
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
9
|
+
/**
|
|
10
|
+
* `payment_source.paypal.experience_context.landing_page` for the admin
|
|
11
|
+
* "Landing Page" setting.
|
|
12
|
+
*
|
|
13
|
+
* `LOGIN` is the default PayPal's partner review asks for. A stored
|
|
14
|
+
* "no_preference" (the admin default before 1.3.9) is treated as `LOGIN` too.
|
|
15
|
+
* "billing" selects PayPal's guest (card) checkout page, which
|
|
16
|
+
* `experience_context` calls `GUEST_CHECKOUT` — `BILLING` was its name in the
|
|
17
|
+
* deprecated `application_context`.
|
|
18
|
+
*/
|
|
19
|
+
function resolveLandingPage(setting) {
|
|
20
|
+
const value = String(setting ?? "")
|
|
21
|
+
.trim()
|
|
22
|
+
.toLowerCase();
|
|
23
|
+
return value === "billing" || value === "guest_checkout"
|
|
24
|
+
? "GUEST_CHECKOUT"
|
|
25
|
+
: "LOGIN";
|
|
26
|
+
}
|
|
27
|
+
function text(value) {
|
|
28
|
+
return String(value ?? "").trim();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Medusa stores a province either as the buyer typed it or as an ISO 3166-2
|
|
32
|
+
* code ("us-ca"). PayPal wants the subdivision without the country prefix
|
|
33
|
+
* ("CA").
|
|
34
|
+
*/
|
|
35
|
+
function normalizeProvince(province, country) {
|
|
36
|
+
const match = province.match(/^([a-z]{2})-([a-z0-9]{1,3})$/i);
|
|
37
|
+
if (match && match[1].toUpperCase() === country) {
|
|
38
|
+
return match[2].toUpperCase();
|
|
39
|
+
}
|
|
40
|
+
return province;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The cart's shipping address as a PayPal `purchase_units[].shipping` object,
|
|
44
|
+
* or null when the cart has no address PayPal would accept (it rejects an
|
|
45
|
+
* address without a street line, postal code or two-letter country).
|
|
46
|
+
*/
|
|
47
|
+
function buildPayPalShipping(addr) {
|
|
48
|
+
if (!addr)
|
|
49
|
+
return null;
|
|
50
|
+
const line1 = text(addr.address_1);
|
|
51
|
+
const postal = text(addr.postal_code);
|
|
52
|
+
const country = text(addr.country_code).toUpperCase();
|
|
53
|
+
if (!line1 || !postal || country.length !== 2)
|
|
54
|
+
return null;
|
|
55
|
+
const fullName = [addr.first_name, addr.last_name]
|
|
56
|
+
.map(text)
|
|
57
|
+
.filter(Boolean)
|
|
58
|
+
.join(" ");
|
|
59
|
+
const line2 = text(addr.address_2);
|
|
60
|
+
const city = text(addr.city);
|
|
61
|
+
const province = normalizeProvince(text(addr.province), country);
|
|
62
|
+
return {
|
|
63
|
+
...(fullName ? { name: { full_name: fullName.slice(0, 300) } } : {}),
|
|
64
|
+
address: {
|
|
65
|
+
address_line_1: line1.slice(0, 300),
|
|
66
|
+
...(line2 ? { address_line_2: line2.slice(0, 300) } : {}),
|
|
67
|
+
...(city ? { admin_area_2: city.slice(0, 120) } : {}),
|
|
68
|
+
...(province ? { admin_area_1: province.slice(0, 300) } : {}),
|
|
69
|
+
postal_code: postal.slice(0, 60),
|
|
70
|
+
country_code: country,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function comparable(shipping) {
|
|
75
|
+
const s = (shipping && typeof shipping === "object" ? shipping : {});
|
|
76
|
+
const a = (s.address && typeof s.address === "object" ? s.address : {});
|
|
77
|
+
return [
|
|
78
|
+
s.name?.full_name,
|
|
79
|
+
a.address_line_1,
|
|
80
|
+
a.address_line_2,
|
|
81
|
+
a.admin_area_2,
|
|
82
|
+
a.admin_area_1,
|
|
83
|
+
a.postal_code,
|
|
84
|
+
a.country_code,
|
|
85
|
+
]
|
|
86
|
+
.map((part) => text(part).toLowerCase().replace(/\s+/g, " "))
|
|
87
|
+
.join("|");
|
|
88
|
+
}
|
|
89
|
+
/** True when two PayPal shipping objects describe the same recipient/address. */
|
|
90
|
+
function sameShipping(a, b) {
|
|
91
|
+
return comparable(a) === comparable(b);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Short stable fingerprint of a shipping object, for the PayPal-Request-Id:
|
|
95
|
+
* PayPal replays the stored response for a repeated request id, so an order
|
|
96
|
+
* for the same cart and amount but a different address needs a different id.
|
|
97
|
+
*/
|
|
98
|
+
function shippingFingerprint(shipping) {
|
|
99
|
+
return (0, crypto_1.createHash)("sha256")
|
|
100
|
+
.update(comparable(shipping))
|
|
101
|
+
.digest("hex")
|
|
102
|
+
.slice(0, 8);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Whether PayPal rejected a Create Order request because of the shipping
|
|
106
|
+
* address we sent (so the order can be retried without it instead of failing
|
|
107
|
+
* the checkout).
|
|
108
|
+
*/
|
|
109
|
+
function isShippingAddressRejection(status, responseText) {
|
|
110
|
+
if (status !== 400 && status !== 422)
|
|
111
|
+
return false;
|
|
112
|
+
let json;
|
|
113
|
+
try {
|
|
114
|
+
json = JSON.parse(responseText);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
const details = Array.isArray(json?.details) ? json.details : [];
|
|
120
|
+
return details.some((detail) => {
|
|
121
|
+
const field = String(detail?.field || "");
|
|
122
|
+
const issue = String(detail?.issue || "");
|
|
123
|
+
return (/\/shipping(\/|$)/i.test(field) ||
|
|
124
|
+
/SHIPPING_ADDRESS|MISSING_SHIPPING/i.test(issue));
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=order-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-context.js","sourceRoot":"","sources":["../../../../../../src/modules/paypal/utils/order-context.ts"],"names":[],"mappings":";;AAoBA,gDAOC;AA+CD,kDA4BC;AAmBD,oCAEC;AAOD,kDAKC;AAOD,gEAoBC;AAlKD,mCAAmC;AAUnC;;;;;;;;;GASG;AACH,SAAgB,kBAAkB,CAAC,OAAgB;IACjD,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;SAChC,IAAI,EAAE;SACN,WAAW,EAAE,CAAA;IAChB,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,gBAAgB;QACtD,CAAC,CAAC,gBAAgB;QAClB,CAAC,CAAC,OAAO,CAAA;AACb,CAAC;AAyBD,SAAS,IAAI,CAAC,KAAc;IAC1B,OAAO,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;AACnC,CAAC;AAED;;;;GAIG;AACH,SAAS,iBAAiB,CAAC,QAAgB,EAAE,OAAe;IAC1D,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAA;IAC7D,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,OAAO,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;IAC/B,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED;;;;GA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
+
Changes requested by PayPal's partner integration review of 2026-11-17.
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- **Seller status is read with the partner's credentials.** The seller
|
|
12
|
+
onboarding status
|
|
13
|
+
(`GET /v1/customer/partners/{partner-id}/merchant-integrations/{merchant-id}`)
|
|
14
|
+
is now requested through the partner service, which calls PayPal with the
|
|
15
|
+
partner account's credentials. If the partner service cannot be reached, or
|
|
16
|
+
PayPal refuses the partner token for a seller, the plugin falls back to the
|
|
17
|
+
seller's own credentials as before. `PAYPAL_PARTNER_STATUS_URL` overrides the
|
|
18
|
+
endpoint; it is derived automatically from `PAYPAL_PARTNER_SERVICE_URL`.
|
|
19
|
+
- **Create Order: `landing_page` is `LOGIN`.** The admin "Landing Page" setting
|
|
20
|
+
defaulted to "No Preference", so stores that saved the Additional Settings
|
|
21
|
+
form sent `NO_PREFERENCE`. That option is removed and a stored
|
|
22
|
+
"no_preference" is sent as `LOGIN`. The "Billing" option is now "Guest
|
|
23
|
+
checkout (card form)" and sends `GUEST_CHECKOUT`, the value
|
|
24
|
+
`experience_context` accepts (`BILLING` belonged to the deprecated
|
|
25
|
+
`application_context`).
|
|
26
|
+
- **Create Order: the checkout shipping address is sent by default** with
|
|
27
|
+
`shipping_preference: SET_PROVIDED_ADDRESS`, so PayPal shows the address the
|
|
28
|
+
buyer entered in the storefront. Card orders carry the address too. This was
|
|
29
|
+
opt-in; turn it off with the new "Send Shipping Address" setting or
|
|
30
|
+
`PAYPAL_SEND_SHIPPING_ADDRESS=false`. Carts without a complete address (for
|
|
31
|
+
example digital goods) send none. If PayPal rejects the address, the order
|
|
32
|
+
is created without it rather than failing the checkout, and a stored order
|
|
33
|
+
is replaced when the buyer changes the address.
|
|
34
|
+
- **Create Order: `custom_id` is no longer sent at the top level of the
|
|
35
|
+
request.** It stays on the purchase unit, which is where PayPal reads it.
|
|
36
|
+
|
|
37
|
+
### Added
|
|
38
|
+
|
|
39
|
+
- **Account warnings in the admin.** The PayPal Connection page now checks the
|
|
40
|
+
seller's status and tells the merchant when their PayPal email is not
|
|
41
|
+
confirmed (`primary_email_confirmed`), when the account cannot receive
|
|
42
|
+
payments (`payments_receivable`), when PayPal payments are not enabled
|
|
43
|
+
(`PPCP_STANDARD` not `SUBSCRIBED` or `PAY_WITH_PAYPAL` not `ACTIVE`), and
|
|
44
|
+
when Advanced Card payments are not enabled (`PPCP_CUSTOM` not `SUBSCRIBED`
|
|
45
|
+
or `CUSTOM_CARD_PROCESSING` not `ACTIVE`), with wording that follows the
|
|
46
|
+
vetting status. The card warning also shows on the Advanced Card Payments
|
|
47
|
+
page. New route: `GET /admin/paypal/merchant-status`.
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
|
|
51
|
+
- **The app access token is no longer minted twice while connecting.** Saving
|
|
52
|
+
the same credentials again (to add the seller's email once it was known)
|
|
53
|
+
discarded the cached token, so a second `/v1/oauth2/token` call followed
|
|
54
|
+
within seconds. The token is now kept until it expires unless the
|
|
55
|
+
credentials actually change. Saving credentials manually no longer mints a
|
|
56
|
+
separate, uncached token for the profile lookup either.
|
|
57
|
+
- **Onboarding no longer makes a status call that always failed.** The seller
|
|
58
|
+
status was first requested with the token from the authorization-code
|
|
59
|
+
exchange, which PayPal answers with `401 AUTHORIZATION_ERROR`.
|
|
60
|
+
|
|
5
61
|
## 1.3.8 — 2026-11-17
|
|
6
62
|
|
|
7
63
|
### Changed
|
package/README.md
CHANGED
|
@@ -144,7 +144,7 @@ Everything is managed in **Medusa Admin → Settings → PayPal**. Changes apply
|
|
|
144
144
|
| --- | --- |
|
|
145
145
|
| **PayPal Settings** | Turn PayPal on or off, checkout title, button color, shape, width, height and label |
|
|
146
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, invoice prefix, card statement name |
|
|
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 |
|
|
148
148
|
|
|
149
149
|
## 🔐 Going live
|
|
150
150
|
|
|
@@ -171,7 +171,7 @@ Everything works without these. They are for developers who need to tune the plu
|
|
|
171
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
172
|
| `PAYPAL_ENCRYPTION_STRICT` | `false` | `true` refuses to save credentials unencrypted |
|
|
173
173
|
| `PAYPAL_ADMIN_ORIGIN` | First `ADMIN_CORS` entry | Restricts the onboarding popup to your admin URL |
|
|
174
|
-
| `PAYPAL_SEND_SHIPPING_ADDRESS` | `
|
|
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
175
|
| `PAYPAL_CURRENCY` | `EUR` | Fallback currency if none is configured |
|
|
176
176
|
| `PAYPAL_HTTP_TIMEOUT_MS` | `30000` | Timeout for calls to PayPal |
|
|
177
177
|
| `PAYPAL_SETTINGS_CACHE_MS` | `15000` | In-process cache for plugin settings reads. `0` disables it |
|
|
@@ -185,6 +185,7 @@ Everything works without these. They are for developers who need to tune the plu
|
|
|
185
185
|
| `PAYPAL_REQUEST_LOG` | Off | `1` or `true` forces the request/response log on, regardless of the admin toggle |
|
|
186
186
|
| `PAYPAL_LOG_DIR` | `./logs` | Directory for the `paypal-requests-YYYY-MM-DD.log` file written when logging is on |
|
|
187
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 |
|
|
188
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 |
|
|
189
190
|
| `PAYPAL_PARTNER_MERCHANT_ID_SANDBOX` / `PAYPAL_PARTNER_MERCHANT_ID_LIVE` | Built-in | Overrides the partner merchant IDs used for onboarding |
|
|
190
191
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easypayment/medusa-payment-paypal",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.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",
|
|
@@ -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 = "
|
|
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: "
|
|
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
|
-
|
|
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="
|
|
216
|
-
<option value="
|
|
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
|
|
@@ -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
|
+
}
|