PayPal
Integrate with PayPal, built by an official PayPal Partner.
PayPal for Medusa
Accept PayPal and credit card payments in your Medusa v2 store. Built by an official PayPal Partner.
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.
β¨ What you get
- π΅ PayPal Buttons: one-click PayPal checkout for your customers
- π³ Card payments: secure credit and debit card fields, hosted by PayPal (PCI compliant)
- π§ Admin dashboard: connect your PayPal account and manage everything from Medusa Admin
- π Test and Live modes: try everything safely in Sandbox before going live
- π° Capture or authorize: charge at checkout, or authorize first and capture from the order later
- π 3D Secure: extra card security, configurable in one click
- π Reliable by design: payments are verified with PayPal at every step. Webhooks, retries and safety nets are handled for you
β Requirements
- Medusa v2.12+
- Node.js 20+
- PostgreSQL
π Installation
In your Medusa backend folder, run:
1npm install @easypayment/medusa-payment-paypal
π§© Setup in 5 steps
1. Add the plugin to Copy to clipboardmedusa-config.ts
Add the Copy to clipboardplugins entry and the two payment providers:
1234567891011121314151617181920import { loadEnv, defineConfig } from "@medusajs/framework/utils"loadEnv(process.env.NODE_ENV || "development", process.cwd())export default defineConfig({projectConfig: {databaseUrl: process.env.DATABASE_URL,http: {storeCors: process.env.STORE_CORS!,adminCors: process.env.ADMIN_CORS!,authCors: process.env.AUTH_CORS!,jwtSecret: process.env.JWT_SECRET || "supersecret",cookieSecret: process.env.COOKIE_SECRET || "supersecret",},},plugins: [{resolve: "@easypayment/medusa-payment-paypal",options: {},
2. Run database migrations
1npx medusa db:migrate
3. Connect your PayPal account
- Start your Medusa server.
- Open Medusa Admin β Settings β PayPal β PayPal Connection.
- Choose Sandbox (testing) or Live (real payments).
- Click Connect to PayPal and follow the steps in the PayPal window.
Your credentials are saved automatically, and webhooks are registered for you.
π‘ Prefer manual setup? Click Click here to insert credentials manually and paste your Client ID and Secret from developer.paypal.com.
4. Turn PayPal on in your region
Go to Medusa Admin β Settings β Regions β your region and enable:
- Copy to clipboard
pp_paypal_paypal: PayPal Buttons - Copy to clipboard
pp_paypal_card_paypal_card: Card payments
5. Add PayPal to your storefront
The checkout UI is a separate package. Install it in your storefront project and follow its step-by-step guide:
π¦ @easypayment/medusa-paypal-ui: ready-made PayPal components for Next.js storefronts.
π¨ Customize
Everything is managed in Medusa Admin β Settings β PayPal. Changes apply right away, with no restart.
- PayPal Settings: turn PayPal on or off, checkout title, button color, shape, width, height and label
- Advanced Card Payments: turn card payments on or off, checkout title, 3D Secure mode
- 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
π Going live
Set these two environment variables on your server before taking real payments:
- Copy to clipboard
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. - Copy to clipboard
MEDUSA_BACKEND_URL: your backend's public address, for example Copy to clipboardhttps://api.mystore.com, so PayPal can reach your store with payment notifications.
Then switch the environment to Live in Settings β PayPal β PayPal Connection and connect your live PayPal account.
π§° Advanced options
Everything works without these. They are for developers who need to tune the plugin.
Environment variables
- Copy to clipboard
STOREFRONT_URL(or Copy to clipboardSTORE_URL): Storefront address used for PayPal return and cancel pages. Can also be set in Admin. Default: Request origin, if listed in Copy to clipboardSTORE_CORS. - Copy to clipboard
PAYPAL_ENCRYPTION_STRICT: Copy to clipboardtruerefuses to save credentials unencrypted. Default: Copy to clipboardfalse. - Copy to clipboard
PAYPAL_ADMIN_ORIGIN: Restricts the onboarding popup to your admin URL. Default: First Copy to clipboardADMIN_CORSentry. - Copy to clipboard
PAYPAL_SEND_SHIPPING_ADDRESS: The shipping address the buyer entered at checkout is sent on PayPal orders (Copy to clipboardSET_PROVIDED_ADDRESS), which PayPal Seller Protection needs. Set Copy to clipboardfalseto let buyers pick an address in PayPal instead. Also an admin setting. Default: Copy to clipboardtrue. - Copy to clipboard
PAYPAL_CURRENCY: Fallback currency, used only when a cart has no currency of its own. PayPal otherwise charges in each cart's currency, so stores with several regions and currencies work out of the box. Default: Copy to clipboardEUR. - Copy to clipboard
PAYPAL_RESTRICT_CURRENCY: Copy to clipboardtruelimits PayPal to the single Copy to clipboardPAYPAL_CURRENCY; carts in any other currency are rejected. Default: Copy to clipboardfalse. - Copy to clipboard
PAYPAL_HTTP_TIMEOUT_MS: Timeout for calls to PayPal. Default: Copy to clipboard30000. - Copy to clipboard
PAYPAL_SETTINGS_CACHE_MS: In-process cache for plugin settings reads. Copy to clipboard0disables it. Default: Copy to clipboard15000. - Copy to clipboard
PAYPAL_WEBHOOK_COMPLETE_CART: Safety net that finishes an order when the payment succeeded but the buyer's browser closed. Copy to clipboardfalsedisables it. Default: Copy to clipboardtrue. - Copy to clipboard
PAYPAL_WEBHOOK_REPLAY_WINDOW_MINUTES: Rejects webhook deliveries older than this. Default: Copy to clipboard60. - Copy to clipboard
PAYPAL_WEBHOOK_STALE_PROCESSING_MS: When the retry job picks up interrupted webhook events again. Default: Copy to clipboard300000. - Copy to clipboard
PAYPAL_WEBHOOK_ID_LIVE/ Copy to clipboardPAYPAL_WEBHOOK_ID_SANDBOX: Manual webhook ID override. Default: Automatic. - Copy to clipboard
PAYPAL_RATE_LIMIT_MAX/ Copy to clipboardPAYPAL_RATE_LIMIT_WINDOW_MS: Optional request limit for the public checkout routes. Default: Off / Copy to clipboard60000. - Copy to clipboard
PAYPAL_WEBHOOK_RATE_LIMIT_MAX/ Copy to clipboardPAYPAL_WEBHOOK_RATE_LIMIT_WINDOW_MS: Optional request limit for the webhook endpoint, separate from the one above. Default: Off / Copy to clipboard60000. - Copy to clipboard
PAYPAL_ALERT_WEBHOOK_URLS: Comma-separated URLs that receive operational alerts, including dead-lettered webhook events. Default: Unset. - Copy to clipboard
PAYPAL_REQUEST_LOG: Copy to clipboard1or Copy to clipboardtrueforces the request/response log on, regardless of the admin toggle. Default: Off. - Copy to clipboard
PAYPAL_LOG_DIR: Directory for the Copy to clipboardpaypal-requests-YYYY-MM-DD.logfile written when logging is on. Keep it outside the folders Copy to clipboardmedusa developwatches, or every logged request restarts the dev server. Default: Copy to clipboard.medusa/paypal-logsin the project. - Copy to clipboard
PAYPAL_PARTNER_SERVICE_URL: Overrides the partner onboarding service used by the connect flow. Default: Built-in. - Copy to clipboard
PAYPAL_SELLER_NONCE: Only change this if you also run your own Copy to clipboardPAYPAL_PARTNER_SERVICE_URL. It must match the nonce that service puts in its onboarding links. Default: Partner service nonce. - Copy to clipboard
PAYPAL_PARTNER_MERCHANT_ID_SANDBOX/ Copy to clipboardPAYPAL_PARTNER_MERCHANT_ID_LIVE: Overrides the partner merchant IDs used for onboarding. Default: Built-in.
Declined cards
When PayPal declines a capture, Copy to clipboard/store/paypal/capture-order responds Copy to clipboard402 with a buyer-friendly Copy to clipboardmessage and a structured Copy to clipboarddecline object:
1{ code, message, retryable, avs_code?, cvv_code? }
Storefronts can use it to show a message such as "insufficient funds, try another card" and to decide whether to offer a retry.
Monitoring
- Operational counters live in the Copy to clipboard
paypal_metrictable. - Every webhook is recorded in Copy to clipboard
paypal_webhook_eventand retried automatically. Events that exhaust their retries are dead-lettered and pushed to Copy to clipboardPAYPAL_ALERT_WEBHOOK_URLS. - Audit events are logged as JSON lines tagged Copy to clipboard
"log":"paypal_audit", with secrets redacted.
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 and response, to Copy to clipboard.medusa/paypal-logs/paypal-requests-YYYY-MM-DD.log.
- Credentials are redacted. The Copy to clipboard
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 with Download log, or at Copy to clipboard
GET /admin/paypal/logs?download=1. - Turn logging off again once the review is complete.
π¬ Support
- π Found a bug, or have a question or feature request? Open an issue
- π Storefront UI package: @easypayment/medusa-paypal-ui
- π Release notes: see CHANGELOG.md
π License
MIT Β© Easy Payment

