@easypayment/medusa-payment-paypal 1.3.1 → 1.3.3

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.
@@ -1,34 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PARTNER_SELLER_NONCE = void 0;
3
4
  exports.getPayPalConfig = getPayPalConfig;
4
- const crypto_1 = require("crypto");
5
5
  const partner_1 = require("../utils/partner");
6
+ /**
7
+ * The seller nonce the hosted partner service (`partnerServiceUrl`) embeds in
8
+ * every partner-referral it creates. The onboarding token exchange sends it as
9
+ * the PKCE `code_verifier`, so it MUST equal the value the referral was minted
10
+ * with — the link request does not send a nonce, so a locally generated one
11
+ * makes every exchange fail with invalid_grant. It is not a secret: the
12
+ * single-use authCode and sharedId are what protect the exchange.
13
+ * Only override PAYPAL_SELLER_NONCE together with your own partner service.
14
+ */
15
+ exports.PARTNER_SELLER_NONCE = "a1233wtergfsdt4365tzrshgfbaewa36AGa1233wtergfsdt4365tzrshgfbaewa36AG";
6
16
  const STATIC_CFG = {
7
17
  partnerServiceUrl: "https://mbjtechnolabs.com/ppcp-seller-onboarding/seller-onboarding.php?from=medusa",
8
18
  partnerJsUrl: "https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js",
9
19
  backendUrl: "http://localhost:9000",
10
- sellerNonce: "",
20
+ sellerNonce: exports.PARTNER_SELLER_NONCE,
11
21
  bnCode: partner_1.PAYPAL_PARTNER_ATTRIBUTION_ID,
12
22
  partnerMerchantIdSandbox: "K6QLN2LPGQRHL",
13
23
  partnerMerchantIdLive: "GT5R877JNBPLL",
14
24
  alertWebhookUrls: [],
15
25
  };
16
- let warnedGeneratedNonce = false;
17
- function generateSellerNonce() {
18
- // The nonce doubles as the OAuth code_verifier for the onboarding exchange,
19
- // so every instance must agree on it. It is persisted into settings on first
20
- // boot, but two instances booting simultaneously can race to persist
21
- // different generated values — an onboarding link minted against the losing
22
- // nonce then fails its token exchange with an opaque invalid_grant. Pinning
23
- // PAYPAL_SELLER_NONCE removes the race entirely.
24
- if (!warnedGeneratedNonce) {
25
- warnedGeneratedNonce = true;
26
- console.warn("[PayPal] PAYPAL_SELLER_NONCE is not set — generating a random seller nonce. " +
27
- "For multi-instance deployments, set PAYPAL_SELLER_NONCE to a fixed random string " +
28
- "so all instances share the same onboarding code_verifier.");
29
- }
30
- return (0, crypto_1.randomBytes)(32).toString("hex");
31
- }
32
26
  /** Resolve the module configuration from the environment. */
33
27
  function getPayPalConfig() {
34
28
  const backendUrl = process.env.MEDUSA_BACKEND_URL || STATIC_CFG.backendUrl;
@@ -36,7 +30,7 @@ function getPayPalConfig() {
36
30
  ...STATIC_CFG,
37
31
  partnerServiceUrl: process.env.PAYPAL_PARTNER_SERVICE_URL || STATIC_CFG.partnerServiceUrl,
38
32
  backendUrl,
39
- sellerNonce: process.env.PAYPAL_SELLER_NONCE || generateSellerNonce(),
33
+ sellerNonce: process.env.PAYPAL_SELLER_NONCE || STATIC_CFG.sellerNonce,
40
34
  partnerMerchantIdSandbox: process.env.PAYPAL_PARTNER_MERCHANT_ID_SANDBOX ||
41
35
  STATIC_CFG.partnerMerchantIdSandbox,
42
36
  partnerMerchantIdLive: process.env.PAYPAL_PARTNER_MERCHANT_ID_LIVE ||
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../../../src/modules/paypal/types/config.ts"],"names":[],"mappings":";;AAiDA,0CAqBC;AAtED,mCAAoC;AACpC,8CAAgE;AAchE,MAAM,UAAU,GAAuB;IACrC,iBAAiB,EACf,oFAAoF;IACtF,YAAY,EACV,4EAA4E;IAC9E,UAAU,EAAE,uBAAuB;IACnC,WAAW,EAAE,EAAE;IACf,MAAM,EAAE,uCAA6B;IACrC,wBAAwB,EAAE,eAAe;IACzC,qBAAqB,EAAE,eAAe;IACtC,gBAAgB,EAAE,EAAE;CACrB,CAAA;AAED,IAAI,oBAAoB,GAAG,KAAK,CAAA;AAEhC,SAAS,mBAAmB;IAC1B,4EAA4E;IAC5E,6EAA6E;IAC7E,qEAAqE;IACrE,4EAA4E;IAC5E,4EAA4E;IAC5E,iDAAiD;IACjD,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC1B,oBAAoB,GAAG,IAAI,CAAA;QAC3B,OAAO,CAAC,IAAI,CACV,8EAA8E;YAC5E,mFAAmF;YACnF,2DAA2D,CAC9D,CAAA;IACH,CAAC;IACD,OAAO,IAAA,oBAAW,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AACxC,CAAC;AAED,6DAA6D;AAC7D,SAAgB,eAAe;IAC7B,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,UAAU,CAAC,UAAU,CAAA;IAE1E,OAAO;QACL,GAAG,UAAU;QACb,iBAAiB,EACf,OAAO,CAAC,GAAG,CAAC,0BAA0B,IAAI,UAAU,CAAC,iBAAiB;QACxE,UAAU;QACV,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,mBAAmB,EAAE;QACrE,wBAAwB,EACtB,OAAO,CAAC,GAAG,CAAC,kCAAkC;YAC9C,UAAU,CAAC,wBAAwB;QACrC,qBAAqB,EACnB,OAAO,CAAC,GAAG,CAAC,+BAA+B;YAC3C,UAAU,CAAC,qBAAqB;QAClC,gBAAgB,EACd,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,EAAE,CAAC;aAC1C,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;aACxB,MAAM,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,gBAAgB;KACpD,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../../../src/modules/paypal/types/config.ts"],"names":[],"mappings":";;;AAwCA,0CAqBC;AA7DD,8CAAgE;AAEhE;;;;;;;;GAQG;AACU,QAAA,oBAAoB,GAC/B,sEAAsE,CAAA;AAcxE,MAAM,UAAU,GAAuB;IACrC,iBAAiB,EACf,oFAAoF;IACtF,YAAY,EACV,4EAA4E;IAC9E,UAAU,EAAE,uBAAuB;IACnC,WAAW,EAAE,4BAAoB;IACjC,MAAM,EAAE,uCAA6B;IACrC,wBAAwB,EAAE,eAAe;IACzC,qBAAqB,EAAE,eAAe;IACtC,gBAAgB,EAAE,EAAE;CACrB,CAAA;AAED,6DAA6D;AAC7D,SAAgB,eAAe;IAC7B,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,UAAU,CAAC,UAAU,CAAA;IAE1E,OAAO;QACL,GAAG,UAAU;QACb,iBAAiB,EACf,OAAO,CAAC,GAAG,CAAC,0BAA0B,IAAI,UAAU,CAAC,iBAAiB;QACxE,UAAU;QACV,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,UAAU,CAAC,WAAW;QACtE,wBAAwB,EACtB,OAAO,CAAC,GAAG,CAAC,kCAAkC;YAC9C,UAAU,CAAC,wBAAwB;QACrC,qBAAqB,EACnB,OAAO,CAAC,GAAG,CAAC,+BAA+B;YAC3C,UAAU,CAAC,qBAAqB;QAClC,gBAAgB,EACd,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,EAAE,CAAC;aAC1C,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;aACxB,MAAM,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,gBAAgB;KACpD,CAAA;AACH,CAAC"}
@@ -0,0 +1,21 @@
1
+ type ResolveStorefrontUrlInput = {
2
+ /** `api_details.storefront_url` from the admin settings. */
3
+ configured?: unknown;
4
+ /** `STOREFRONT_URL` / `STORE_URL`. */
5
+ envUrl?: unknown;
6
+ /** The request's `Origin` header. */
7
+ origin?: unknown;
8
+ /** `projectConfig.http.storeCors`: a comma-separated list of origins. */
9
+ storeCors?: unknown;
10
+ };
11
+ /**
12
+ * The storefront base URL used for PayPal's return/cancel URLs: admin setting,
13
+ * then env, then the request's Origin.
14
+ *
15
+ * The Origin header is caller-controlled, and the result becomes a redirect
16
+ * target, so it only counts when it exactly matches a STORE_CORS entry. Wildcard
17
+ * and regex entries never match, which leaves the URL unset rather than trusted.
18
+ */
19
+ export declare function resolveStorefrontUrl({ configured, envUrl, origin, storeCors, }: ResolveStorefrontUrlInput): string | undefined;
20
+ export {};
21
+ //# sourceMappingURL=storefront-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storefront-url.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/paypal/utils/storefront-url.ts"],"names":[],"mappings":"AAAA,KAAK,yBAAyB,GAAG;IAC/B,4DAA4D;IAC5D,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,sCAAsC;IACtC,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,qCAAqC;IACrC,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,yEAAyE;IACzE,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAKD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,UAAU,EACV,MAAM,EACN,MAAM,EACN,SAAS,GACV,EAAE,yBAAyB,GAAG,MAAM,GAAG,SAAS,CAahD"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveStorefrontUrl = resolveStorefrontUrl;
4
+ const clean = (value) => typeof value === "string" ? value.trim().replace(/\/+$/, "") : "";
5
+ /**
6
+ * The storefront base URL used for PayPal's return/cancel URLs: admin setting,
7
+ * then env, then the request's Origin.
8
+ *
9
+ * The Origin header is caller-controlled, and the result becomes a redirect
10
+ * target, so it only counts when it exactly matches a STORE_CORS entry. Wildcard
11
+ * and regex entries never match, which leaves the URL unset rather than trusted.
12
+ */
13
+ function resolveStorefrontUrl({ configured, envUrl, origin, storeCors, }) {
14
+ const explicit = clean(configured) || clean(envUrl);
15
+ if (explicit) {
16
+ return explicit;
17
+ }
18
+ const requestOrigin = clean(origin);
19
+ if (!requestOrigin || typeof storeCors !== "string") {
20
+ return undefined;
21
+ }
22
+ const allowed = storeCors.split(",").map(clean);
23
+ return allowed.includes(requestOrigin) ? requestOrigin : undefined;
24
+ }
25
+ //# sourceMappingURL=storefront-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storefront-url.js","sourceRoot":"","sources":["../../../../../../src/modules/paypal/utils/storefront-url.ts"],"names":[],"mappings":";;AAsBA,oDAkBC;AA7BD,MAAM,KAAK,GAAG,CAAC,KAAc,EAAE,EAAE,CAC/B,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;AAEnE;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAAC,EACnC,UAAU,EACV,MAAM,EACN,MAAM,EACN,SAAS,GACiB;IAC1B,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAA;IACnD,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;IACnC,IAAI,CAAC,aAAa,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QACpD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAC/C,OAAO,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAA;AACpE,CAAC"}
package/CHANGELOG.md CHANGED
@@ -2,6 +2,37 @@
2
2
 
3
3
  All notable changes to `@easypayment/medusa-payment-paypal` are documented here.
4
4
 
5
+ ## 1.3.3 — 2026-11-05
6
+
7
+ ### Fixed
8
+ - **PayPal orders no longer drop `return_url` and `cancel_url` when no storefront
9
+ URL is configured.** With neither the admin setting nor `STOREFRONT_URL` set,
10
+ `/store/paypal/create-order` silently omitted both. It now falls back to the
11
+ request's `Origin`, only when that exactly matches a `STORE_CORS` entry
12
+ (wildcard and regex entries don't count), so a forged header can't choose the
13
+ redirect target. Set `STOREFRONT_URL` when `STORE_CORS` can't list your
14
+ storefront exactly.
15
+ - **PayPal onboarding fails on new installs.** Since 1.1.0 the seller nonce
16
+ defaulted to a random value, but the hosted partner service mints every
17
+ onboarding link with its own fixed nonce (the link request never sends one).
18
+ The final `authorization_code` exchange therefore sent a mismatched PKCE
19
+ `code_verifier` and PayPal rejected it, so the seller was never connected.
20
+ Only installs whose settings predate 1.1.0 kept working. The default is the
21
+ partner service's nonce again, and a stored random nonce is replaced on the
22
+ next settings read. `PAYPAL_SELLER_NONCE` should now only be set alongside a
23
+ custom `PAYPAL_PARTNER_SERVICE_URL`.
24
+
25
+ ## 1.3.2 — 2026-10-07
26
+
27
+ ### Changed
28
+ - **Create-order no longer uses PayPal's deprecated `application_context`.**
29
+ Wallet orders send `payment_source.paypal.experience_context` (brand_name =
30
+ merchant name, falling back to the store's own name; `landing_page: LOGIN`;
31
+ `user_action: PAY_NOW`; return/cancel URLs; shipping preference), and card
32
+ orders carry the 3DS redirect URLs in
33
+ `payment_source.card.experience_context`. Per PayPal partner integration
34
+ review (2026-10-06).
35
+
5
36
  ## 1.3.1 — 2026-10-06
6
37
 
7
38
  _(Published as 1.3.1: the 1.3.0 version number was burned by an interrupted npm publish and can't be reused.)_
package/README.md CHANGED
@@ -1,190 +1,190 @@
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
- [![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)
7
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
8
- [![Medusa v2](https://img.shields.io/badge/Medusa-v2-9b59b6)](https://medusajs.com)
9
- [![PayPal PPCP](https://img.shields.io/badge/PayPal-PPCP-003087)](https://developer.paypal.com)
10
-
11
- ---
12
-
13
- ## ✨ What you get
14
-
15
- | Feature | Details |
16
- |---|---|
17
- | 🔵 **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 |
21
- | 🔐 **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
- ---
25
-
26
- ## ✅ Requirements
27
-
28
- - Medusa **v2.12+**
29
- - Node.js **20+**
30
- - PostgreSQL
31
-
32
- ---
33
-
34
- ## 🚀 Installation
35
-
36
- In your Medusa backend folder, run:
37
-
38
- ```bash
39
- npm install @easypayment/medusa-payment-paypal
40
- ```
41
-
42
- ---
43
-
44
- ## ⚙️ Setup — 5 steps
45
-
46
- ### 1. Add the plugin to `medusa-config.ts`
47
-
48
- ```ts
49
- import { loadEnv, defineConfig } from "@medusajs/framework/utils"
50
-
51
- loadEnv(process.env.NODE_ENV || "development", process.cwd())
52
-
53
- export default defineConfig({
54
- projectConfig: {
55
- databaseUrl: process.env.DATABASE_URL,
56
- http: {
57
- storeCors: process.env.STORE_CORS!,
58
- adminCors: process.env.ADMIN_CORS!,
59
- authCors: process.env.AUTH_CORS!,
60
- jwtSecret: process.env.JWT_SECRET || "supersecret",
61
- cookieSecret: process.env.COOKIE_SECRET || "supersecret",
62
- },
63
- },
64
-
65
- plugins: [
66
- {
67
- resolve: "@easypayment/medusa-payment-paypal",
68
- options: {},
69
- },
70
- ],
71
-
72
- modules: [
73
- {
74
- resolve: "@medusajs/medusa/payment",
75
- options: {
76
- providers: [
77
- {
78
- // PayPal Buttons
79
- resolve: "@easypayment/medusa-payment-paypal/providers/paypal",
80
- id: "paypal",
81
- options: {},
82
- dependencies: ["paypal_onboarding"],
83
- },
84
- {
85
- // Card payments
86
- resolve: "@easypayment/medusa-payment-paypal/providers/paypal_card",
87
- id: "paypal_card",
88
- options: {},
89
- dependencies: ["paypal_onboarding"],
90
- },
91
- ],
92
- },
93
- },
94
- ],
95
- })
96
- ```
97
-
98
- ### 2. Run database migrations
99
-
100
- ```bash
101
- npx medusa db:migrate
102
- ```
103
-
104
- ### 3. Connect your PayPal account
105
-
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
110
-
111
- That's it — your credentials are saved automatically. Webhooks are registered for you too.
112
-
113
- > 💡 Prefer manual setup? Click **Insert credentials manually** and paste your Client ID and Secret from [developer.paypal.com](https://developer.paypal.com/dashboard/).
114
-
115
- ### 4. Turn PayPal on in your region
116
-
117
- Go to **Medusa Admin → Settings → Regions → your region** and enable:
118
-
119
- | Payment provider | What it is |
120
- |---|---|
121
- | `pp_paypal_paypal` | PayPal Buttons |
122
- | `pp_paypal_card_paypal_card` | Card payments |
123
-
124
- ### 5. Add PayPal to your storefront
125
-
126
- The checkout UI comes as a separate package — install it in your **storefront** project:
127
-
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.
129
-
130
- ---
131
-
132
- ## 🎨 Customize (optional)
133
-
134
- Everything is managed in **Medusa Admin → Settings → PayPal** — changes apply instantly, no restart needed:
135
-
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
139
-
140
- ---
141
-
142
- ## 🔐 Going live — two things we recommend
143
-
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.
146
-
147
- <details>
148
- <summary><b>Advanced options</b> (for developers — everything works without these)</summary>
149
-
150
- <br>
151
-
152
- | Variable | Default | What it does |
153
- |---|---|---|
154
- | `STOREFRONT_URL` | *(unset)* | 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` | *(auto)* | Set a fixed random string when running multiple server instances |
157
- | `PAYPAL_ADMIN_ORIGIN` | first `ADMIN_CORS` entry | Restricts the onboarding popup to your admin URL |
158
- | `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
- | `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_SEND_SHIPPING_ADDRESS` | `false` | `true` sends the cart's shipping address on PayPal orders (`SET_PROVIDED_ADDRESS`) — improves PayPal Seller Protection eligibility |
169
- | `PAYPAL_PARTNER_SERVICE_URL` | *(built-in)* | Override the partner onboarding service used by the connect flow |
170
- | `PAYPAL_PARTNER_MERCHANT_ID_SANDBOX` / `PAYPAL_PARTNER_MERCHANT_ID_LIVE` | *(built-in)* | Override the partner merchant ids used for onboarding |
171
-
172
- **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.
173
-
174
- **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).
175
-
176
- </details>
177
-
178
- ---
179
-
180
- ## 💬 Support
181
-
182
- - 🐛 **Found a bug?** [Open an issue](https://github.com/easypaymentplugins/medusa-paypal/issues)
183
- - 💡 **Questions or feature requests?** [Start a discussion](https://github.com/easypaymentplugins/medusa-paypal/discussions)
184
- - 🛍 **Storefront UI package:** [@easypayment/medusa-paypal-ui](https://www.npmjs.com/package/@easypayment/medusa-paypal-ui)
185
-
186
- ---
187
-
188
- ## 📄 License
189
-
190
- 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
+ [![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)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
8
+ [![Medusa v2](https://img.shields.io/badge/Medusa-v2-9b59b6)](https://medusajs.com)
9
+ [![PayPal PPCP](https://img.shields.io/badge/PayPal-PPCP-003087)](https://developer.paypal.com)
10
+
11
+ ---
12
+
13
+ ## ✨ What you get
14
+
15
+ | Feature | Details |
16
+ |---|---|
17
+ | 🔵 **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 |
21
+ | 🔐 **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
+ ---
25
+
26
+ ## ✅ Requirements
27
+
28
+ - Medusa **v2.12+**
29
+ - Node.js **20+**
30
+ - PostgreSQL
31
+
32
+ ---
33
+
34
+ ## 🚀 Installation
35
+
36
+ In your Medusa backend folder, run:
37
+
38
+ ```bash
39
+ npm install @easypayment/medusa-payment-paypal
40
+ ```
41
+
42
+ ---
43
+
44
+ ## ⚙️ Setup — 5 steps
45
+
46
+ ### 1. Add the plugin to `medusa-config.ts`
47
+
48
+ ```ts
49
+ import { loadEnv, defineConfig } from "@medusajs/framework/utils"
50
+
51
+ loadEnv(process.env.NODE_ENV || "development", process.cwd())
52
+
53
+ export default defineConfig({
54
+ projectConfig: {
55
+ databaseUrl: process.env.DATABASE_URL,
56
+ http: {
57
+ storeCors: process.env.STORE_CORS!,
58
+ adminCors: process.env.ADMIN_CORS!,
59
+ authCors: process.env.AUTH_CORS!,
60
+ jwtSecret: process.env.JWT_SECRET || "supersecret",
61
+ cookieSecret: process.env.COOKIE_SECRET || "supersecret",
62
+ },
63
+ },
64
+
65
+ plugins: [
66
+ {
67
+ resolve: "@easypayment/medusa-payment-paypal",
68
+ options: {},
69
+ },
70
+ ],
71
+
72
+ modules: [
73
+ {
74
+ resolve: "@medusajs/medusa/payment",
75
+ options: {
76
+ providers: [
77
+ {
78
+ // PayPal Buttons
79
+ resolve: "@easypayment/medusa-payment-paypal/providers/paypal",
80
+ id: "paypal",
81
+ options: {},
82
+ dependencies: ["paypal_onboarding"],
83
+ },
84
+ {
85
+ // Card payments
86
+ resolve: "@easypayment/medusa-payment-paypal/providers/paypal_card",
87
+ id: "paypal_card",
88
+ options: {},
89
+ dependencies: ["paypal_onboarding"],
90
+ },
91
+ ],
92
+ },
93
+ },
94
+ ],
95
+ })
96
+ ```
97
+
98
+ ### 2. Run database migrations
99
+
100
+ ```bash
101
+ npx medusa db:migrate
102
+ ```
103
+
104
+ ### 3. Connect your PayPal account
105
+
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
110
+
111
+ That's it — your credentials are saved automatically. Webhooks are registered for you too.
112
+
113
+ > 💡 Prefer manual setup? Click **Insert credentials manually** and paste your Client ID and Secret from [developer.paypal.com](https://developer.paypal.com/dashboard/).
114
+
115
+ ### 4. Turn PayPal on in your region
116
+
117
+ Go to **Medusa Admin → Settings → Regions → your region** and enable:
118
+
119
+ | Payment provider | What it is |
120
+ |---|---|
121
+ | `pp_paypal_paypal` | PayPal Buttons |
122
+ | `pp_paypal_card_paypal_card` | Card payments |
123
+
124
+ ### 5. Add PayPal to your storefront
125
+
126
+ The checkout UI comes as a separate package — install it in your **storefront** project:
127
+
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.
129
+
130
+ ---
131
+
132
+ ## 🎨 Customize (optional)
133
+
134
+ Everything is managed in **Medusa Admin → Settings → PayPal** — changes apply instantly, no restart needed:
135
+
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
139
+
140
+ ---
141
+
142
+ ## 🔐 Going live — two things we recommend
143
+
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.
146
+
147
+ <details>
148
+ <summary><b>Advanced options</b> (for developers — everything works without these)</summary>
149
+
150
+ <br>
151
+
152
+ | 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 |
158
+ | `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
+ | `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_SEND_SHIPPING_ADDRESS` | `false` | `true` sends the cart's shipping address on PayPal orders (`SET_PROVIDED_ADDRESS`) — improves PayPal Seller Protection eligibility |
169
+ | `PAYPAL_PARTNER_SERVICE_URL` | *(built-in)* | Override the partner onboarding service used by the connect flow |
170
+ | `PAYPAL_PARTNER_MERCHANT_ID_SANDBOX` / `PAYPAL_PARTNER_MERCHANT_ID_LIVE` | *(built-in)* | Override the partner merchant ids used for onboarding |
171
+
172
+ **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.
173
+
174
+ **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).
175
+
176
+ </details>
177
+
178
+ ---
179
+
180
+ ## 💬 Support
181
+
182
+ - 🐛 **Found a bug?** [Open an issue](https://github.com/easypaymentplugins/medusa-paypal/issues)
183
+ - 💡 **Questions or feature requests?** [Start a discussion](https://github.com/easypaymentplugins/medusa-paypal/discussions)
184
+ - 🛍 **Storefront UI package:** [@easypayment/medusa-paypal-ui](https://www.npmjs.com/package/@easypayment/medusa-paypal-ui)
185
+
186
+ ---
187
+
188
+ ## 📄 License
189
+
190
+ MIT © [Easy Payment](https://www.npmjs.com/package/@easypayment/medusa-payment-paypal)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easypayment/medusa-payment-paypal",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
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",