Details
# PayPal AI Toolkit
A plugin that integrates PayPal's APIs and MCP server into your AI coding workflow. Get AI-assisted help with PayPal payments, subscriptions, invoices, disputes, and more — in Claude Code, OpenAI Codex, Cursor, and other compatible agents.
## Features
- **Best practices Skill** — auto-injects PayPal API knowledge when you're working on payment integrations
- **Commands** — quick reference commands for common developer tasks (Claude Code and Cursor)
- **Hooks** — automatically checks PayPal best practices before writing integration code
- **MCP Server integration** — connects your agent to PayPal's sandbox MCP servers for direct API operations via natural language

## Installation
### Prerequisites
- A PayPal Developer account at https://developer.paypal.com
- A PayPal sandbox access token
- Claude Code (`claude --version`), OpenAI Codex (`codex --version`), and/or Cursor
### Claude Code
PayPal AI Toolkit is available on the official Anthropic marketplace, which Claude Code adds automatically. Install it with:
```
/plugin install paypal@claude-plugins-official
```
Then run `/reload-plugins` to activate it.
#### Local / development install
To work on the plugin itself, clone the repo and load it directly instead:
```bash
git clone https://github.com/paypal/AI-Toolkit.git
```
Then start Claude Code with the plugin loaded:
```bash
cd your-project/
claude --plugin-dir /path/to/AI-Toolkit
```
### OpenAI Codex
Add the PayPal marketplace, then install the plugin:
```bash
codex plugin marketplace add paypal/AI-Toolkit
codex plugin add paypal@paypal-ai-toolkit
```
#### Local / development install
```bash
git clone https://github.com/paypal/AI-Toolkit.git
codex plugin marketplace add /path/to/AI-Toolkit
codex plugin add paypal@paypal-ai-toolkit
```
Restart Codex after installing so skills and the sandbox MCP server load.
### Cursor
Add this repository as a marketplace, then install the plugin:
```bash
cursor-agent plugin marketplace add https://github.com/paypal/AI-Toolkit
```
Then open **Customize** (or type `/plugin`) and install `paypal` at user or project scope.
Once the plugin is listed on the Cursor marketplace, you can also install it from chat with `/add-plugin paypal`.
#### Local / development install
Load the checkout directly (no marketplace or admin setting required):
```bash
git clone https://github.com/paypal/AI-Toolkit.git
cursor-agent --plugin-dir /path/to/AI-Toolkit
```
You can also copy the repo into Cursor's local plugin folder. This requires **Allow Local Plugin Imports** (Dashboard → Settings → Security & Identity → Marketplace and Plugins), which is off by default on some teams. Symlinks that point outside this folder are skipped:
```bash
git clone https://github.com/paypal/AI-Toolkit.git ~/.cursor/plugins/local/paypal
```
`cursor-agent plugin marketplace add` only accepts a git URL (for example `https://github.com/paypal/AI-Toolkit`), not a local path.
Restart Cursor or run **Developer: Reload Window**, then confirm skills, commands, and `paypal-sandbox` in **Customize**.
### Configure your sandbox access token
1. Generate a sandbox access token:
```bash
curl -X POST https://api-m.sandbox.paypal.com/v1/oauth2/token \
-u "YOUR_SANDBOX_CLIENT_ID:YOUR_SANDBOX_CLIENT_SECRET" \
-d "grant_type=client_credentials" \
| jq -r .access_token
```
Get the client ID and secret from the [PayPal Developer Dashboard](https://developer.paypal.com/dashboard/applications/sandbox).
2. Paste the single-line value into your agent's config.
**Claude Code** — merge into the existing `"env"` block in `~/.claude/settings.json`:
```json
"env": {
"PAYPAL_SANDBOX_ACCESS_TOKEN": "A21AA…"
}
```
**OpenAI Codex** — merge into `~/.codex/config.toml`:
```toml
[shell_environment_policy.set]
PAYPAL_SANDBOX_ACCESS_TOKEN = "A21AA…"
```
**Cursor** — after installing the plugin, open **Customize → Plugins → PayPal → Configure** and paste the token. Cursor stores it and substitutes `${PAYPAL_SANDBOX_ACCESS_TOKEN}` in `.mcp.json`. A GUI-launched Cursor does not inherit `export` from `~/.zshrc`.
3. **Fully quit and reopen** the agent (close the app — not just `/clear`).
4. In Claude Code, run `/paypal:setup` to verify. In Codex or Cursor, ask the agent to list PayPal MCP tools or create a sandbox invoice.
> **Use the agent config or Cursor plugin Configure panel, not `~/.zshrc`.** GUI launches don't source `~/.zshrc`, and a line-wrapped `export` embeds a newline in the token that breaks the HTTP header.
Tokens expire in up to 8 hours depending on scope — check the `expires_in` field in the response. Run `/paypal:setup refresh` when you hit a 401.
## Commands
Slash commands are available in Claude Code and Cursor. Codex uses the same skills and MCP server through natural language.
| Command | Description |
| ------------------------------- | ------------------------------------------------- |
| `/paypal:doctor [symptom]` | Scan your codebase for PayPal integration issues |
| `/paypal:explain-error <code>` | Explain a PayPal error code with causes and fixes |
| `/paypal:sandbox [topic]` | Sandbox setup, test accounts, and testing tips |
| `/paypal:setup [mode]` | Configure the plugin, verify MCP, refresh tokens |
| `/paypal:test-accounts [topic]` | Test cards, BNPL, Venmo, webhooks, and scenarios |
### Examples
```
/paypal:explain-error INSTRUMENT_DECLINED
/paypal:explain-error 422 UNPROCESSABLE_ENTITY
/paypal:sandbox subscriptions
/paypal:sandbox webhooks
/paypal:setup
/paypal:doctor webhooks not firing
```
## MCP Server
The plugin connects to PayPal's sandbox MCP server, which exposes tools for:
- **Orders & Payments** — create orders, capture payments, process refunds
- **Invoices** — create, send, manage, and generate QR codes for invoices
- **Subscriptions** — manage billing plans and subscriptions
- **Disputes** — list and respond to buyer disputes
- **Catalog** — manage products and pricing
- **Shipment** — create and track shipments
- **Reporting** — list transactions, get merchant insights
### Transport and environments
The server uses **SSE** at the `/sse` path. `paypal-sandbox` activates once you set `PAYPAL_SANDBOX_ACCESS_TOKEN` in `~/.claude/settings.json` (Claude Code), `~/.codex/config.toml` (Codex), or **Customize → Plugins → PayPal → Configure** (Cursor).
## Skills
The `paypal-best-practices` skill is automatically invoked when your agent detects you're working on PayPal integrations. It provides:
- Recommended APIs and deprecated APIs to avoid
- Authentication and credential best practices
- Orders, Subscriptions, and Invoices API flows
- Webhook verification and security guidance
- Error handling patterns
- Sandbox testing guidance
The `paypal-routing` skill routes PayPal-related questions to the right command or reference file and is not directly user-invocable.
## Hooks
A `PreToolUse` hook checks whether a file edit touches PayPal SDK, API, or checkout code. If it does, the agent is required to consult the `paypal-best-practices` skill and the correct SDK version reference (v5 or v6) before writing the code.
## Plugin Structure
```
AI-Toolkit/
├── .agents/
│ └── plugins/
│ └── marketplace.json # Codex marketplace catalog
├── .claude-plugin/
│ ├── marketplace.json # Claude Code marketplace registry
│ └── plugin.json # Claude Code plugin manifest
├── .codex-plugin/
│ └── plugin.json # Codex plugin manifest
├── .cursor-plugin/
│ ├── marketplace.json # Cursor marketplace catalog
│ └── plugin.json # Cursor plugin manifest
├── .mcp.json # PayPal sandbox MCP server (SSE)
├── skills/
│ ├── paypal-best-practices/
│ │ ├── SKILL.md # Auto-injected best practices context
│ │ └── references/ # Topic-specific integration guides
│ └── paypal-routing/
│ └── SKILL.md # Intent routing (non-user-invocable)
├── commands/
│ ├── doctor.md # /paypal:doctor
│ ├── explain-error.md # /paypal:explain-error
│ ├── sandbox.md # /paypal:sandbox
│ ├── setup.md # /paypal:setup
│ └── test-accounts.md # /paypal:test-accounts
├── hooks/
│ └── hooks.json # Pre-write best-practices check
├── LICENSE # Apache-2.0
├── CONTRIBUTING.md # Contribution and commit guidelines
└── README.md
```
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) for how to report issues, develop locally, and submit pull requests.
Commit messages and PR titles should follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/), for example:
```
feat: allow provided config object to extend other configs
```
## Resources
- [PayPal Developer Docs](https://developer.paypal.com/docs/)
- [PayPal REST API Reference](https://developer.paypal.com/api/rest/)
- [PayPal MCP Server](https://developer.paypal.com/ai-tools/mcp-server.md)
- [PayPal Agent Toolkit](https://github.com/paypal/agent-toolkit)
- [PayPal Developer Dashboard](https://developer.paypal.com/dashboard)
## skills/paypal-best-practices/SKILL.md
---
name: paypal-best-practices
description: >-
PayPal integration guidance, code examples, and best practices.
Use for checkout, card fields, BNPL, Pay Later, Venmo, subscriptions,
invoicing, disputes, payouts, webhooks, APMs, JS SDK v5, JS SDK v6,
createInstance, payment sessions, web components, Fastlane, payment links,
donations, 3D Secure, vaulting, iDEAL, bank redirects, agentic commerce,
or any PayPal architecture decision or code generation question.
when_to_use: >-
"how do I integrate PayPal", "PayPal checkout example", "PayPal best
practices", "PayPal subscriptions guide", "PayPal webhook setup",
"PayPal error handling", "PayPal SDK code", "add Pay Later", "add Venmo",
"PayPal card fields", "PayPal disputes", "PayPal invoices",
"PayPal docs link", or any PayPal code generation request.
allowed-tools: Read, WebFetch, WebSearch
metadata:
version: "1.1.0"
category: payments-integration
tags: checkout bnpl venmo subscriptions disputes apm fastlane webhooks
---
# PayPal Best Practices
Before answering, read the relevant reference file from the table below. The reference files contain current documentation URLs, country availability, and verified code examples.
## Integration Routing
| Developer intent | Reference file |
|-----------------|----------------|
| Accept payments, add PayPal button, checkout flow, Orders API, payment link, payment links, pay link, React PayPal, @paypal/react-paypal-js, authorize vs capture, deferred capture, donate button, donations | [references/checkout.md](references/checkout.md) (v5) or [references/js-sdk-v6.md](references/js-sdk-v6.md) (v6) |
| Advanced Card Fields, Apple Pay, Google Pay, APMs, Expanded Checkout, bank redirect, iDEAL, Bancontact, BLIK, Przelewy24, Pay upon Invoice, Ratepay, domain association, regional payment methods | [references/expanded-checkout.md](references/expanded-checkout.md) (v5) or [references/js-sdk-v6.md](references/js-sdk-v6.md) (v6) |
| Add Venmo, Venmo button, Venmo eligibility, isEligible, eligibility check, Venmo app | [references/venmo.md](references/venmo.md) (v5) or [references/js-sdk-v6.md](references/js-sdk-v6.md) (v6) |
| Pay Later, installments, BNPL messaging, Pay in 4, financing, BNPL banner, Pay Later banner, Pay Later eligibility | [references/bnpl.md](references/bnpl.md) (v5) or [references/js-sdk-v6.md](references/js-sdk-v6.md) (v6) |
| Recurring billing, subscriptions, plan management, free trial, trial period, upgrade plan, downgrade plan, plan revision | [references/subscriptions.md](references/subscriptions.md) (v5) or [references/js-sdk-v6.md](references/js-sdk-v6.md) (v6) |
| Disputes, chargebacks, refunds, evidence, provide evidence, dispute lifecycle, dispute stage, INQUIRY, CLAIM | [references/disputes-refunds.md](references/disputes-refunds.md) |
| Send money, batch payouts, seller payments, Venmo payout, 1099, tax reporting, prepaid cards | [references/payouts.md](references/payouts.md) |
| Invoices, billing, send invoice, invoice reminder, partial payment, line items | [references/invoicing.md](references/invoicing.md) |
| OAuth, access tokens, credentials, idempotency, token caching, token refresh, idempotency key, PayPal-Request-Id | [references/authentication.md](references/authentication.md) |
| Webhook verification, event handling, signature check, webhook simulator, test webhooks, event types, PAYMENT.CAPTURE | [references/webhooks.md](references/webhooks.md) |
| Fastlane, accelerated guest checkout, auto-fill, prefill, single-use token, Braintree Fastlane, `braintree-web`, `BraintreeGateway`, `gateway.clientToken.generate`, `braintree.fastlane.create`, paymentMethodNonce | **Pick exactly one — three variants, do not mix.** Braintree gateway (`braintree-web`, `BraintreeGateway`, `paymentMethodNonce`): [references/fastlane-braintree.md](references/fastlane-braintree.md). PayPal-direct v5 (`paypal.Fastlane({})`, `data-sdk-client-token`): [references/fastlane.md](references/fastlane.md). PayPal-direct v6 (`sdkInstance.createFastlane()`): [references/js-sdk-v6.md](references/js-sdk-v6.md). If unclear which variant, ask before generating code. |
| 3D Secure, liability shift, SCA, PSD2, Strong Customer Authentication, enrollment status, authentication status | [references/3d-secure.md](references/3d-secure.md) |
| AI shopping agents, Store Sync, Agent Ready, agentic commerce, ChatGPT, product discovery, delegated payment token | [references/agentic-commerce.md](references/agentic-commerce.md) |
| MCP server tools, tool inventory, product catalog, merchant insights, reporting | [references/mcp-tools.md](references/mcp-tools.md) |
| JS SDK v6, v6 Web SDK, createInstance, payment sessions, web components, migrate from v5, card fields, vault, save card, save payment method, vaulting, CSP, Content Security Policy | [references/js-sdk-v6.md](references/js-sdk-v6.md) |
## Code Generation Directive
Before writing any PayPal code, detect SDK version and read the correct reference:
1. **v5** — `sdk/js?client-id=` script tag, `paypal.Buttons()`, Hosted Fields → use `checkout.md` / `expanded-checkout.md`
2. **v6** — `web-sdk/v6/core` script tag, `createInstance`, `<paypal-button>` web components → use `js-sdk-v6.md`
3. **New project** (no existing SDK) — default to v6, use `js-sdk-v6.md`
4. **Unclear** — ask the user which version they are using
## MCP Boundary
When the PayPal MCP server is connected, prefer MCP tools for live operations (creating orders, managing subscriptions, fetching disputes). Use this skill for architecture decisions, code generation, and integration guidance — not for executing API calls that MCP tools can handle directly.
## Out of Scope
This skill does NOT cover:
- PayPal Commerce Platform (multi-party marketplaces) — see [Commerce Platform docs](https://developer.paypal.com/platforms/overview.md)
- PayPal Mobile SDKs (iOS/Android native) — see [Mobile SDK docs](https://developer.paypal.com/developer-resources.md#sdks)
- Braintree direct integration (non-Agentic) — see [Braintree docs](https://developer.paypal.com/braintree/docs)
- Zettle POS / PayPal Here — see [Zettle developer docs](https://developer.zettle.com)
- Tax calculation or compliance
- PayPal Marketing Solutions
## Post-Generation Environment Check
After generating PayPal integration code, proactively scan the project to verify the environment is correctly configured for the code you just wrote.
- Identify what credentials the generated code needs (e.g. `PAYPAL_CLIENT_ID`, `PAYPAL_CLIENT_SECRET`, client token endpoint)
- Look for env files (`.env`, `.env.sample`, `.env.example`, `.env.local`) in the project root and `server/`/`client/` subdirectories
- If `.env.sample` or `.env.example` exists but no `.env` — flag it
- If `.env` exists — check the required keys are present and non-empty
- For frontend projects, read the source files to determine how `clientId` reaches the client before checking — do not assume a pattern
- Flag missing or incomplete env setup inline after the code; confirm briefly if everything looks good
- If the env setup cannot be determined, ask: "How is `PAYPAL_CLIENT_ID` configured in this project?" before flagging anything as missing
## Pre-Delivery Validation Checklist
Before presenting generated PayPal integration code, verify:
1. Credentials are not hardcoded (use env vars)
2. `PayPal-Request-Id` included on all POST requests
3. Sandbox URLs used (not production) in examples
4. Webhook signature verification is present
5. `intent` matches the use case (CAPTURE vs AUTHORIZE)
6. BNPL messaging only rendered for eligible countries/currencies
7. Venmo eligibility check before rendering Venmo button
8. Server-side order creation (not client-side `actions.order.create()`)
9. Error handling for INSTRUMENT_DECLINED (422)
10. Retry logic with exponential backoff for 429
11. `debug_id` logged from error responses
12. No deprecated or legacy APIs recommended — never use NVP/SOAP, v1/payments, Hosted Fields, or Adaptive Payments
13. Token caching implemented; Apple Pay domain verification mentioned if Apple Pay is used
## skills/paypal-routing/SKILL.md
---
name: paypal-routing
description: >-
PayPal payments, subscriptions, checkout, invoices, disputes, webhooks,
BNPL, Venmo, SDK, v5, v6, Fastlane, Braintree Fastlane, braintree-web,
accelerated guest checkout. Routes PayPal developer questions to the
right command or reference file.
when_to_use: >-
"add PayPal", "integrate checkout", "payment link", "Pay Later docs",
"explain error", "set up sandbox", "PayPal subscriptions", "webhook
verification", "migrate to v6", "migrate v5 to v6", "migrate v4 to v6",
"upgrade SDK", "migrate NVP", "migrate SOAP to REST", "PayPal invoices",
"PayPal disputes", "how do I accept payments", "PayPal docs link",
"Apple Pay", "Google Pay", "3D Secure", "iDEAL", "agentic commerce",
"agentic payments", "PayPal MCP", "add Fastlane", "Fastlane checkout",
"Braintree Fastlane", "braintree-web fastlane", "add Fastlane to my
checkout", "@braintree/fastlane", or any PayPal API question.
user-invocable: false
---
# PayPal Command Routing
When this skill activates, follow the routing table below. For reference routes, load the paypal-best-practices skill and read the specified reference file before answering — the reference files contain current URLs and verified code examples that override training knowledge.
## RulesHub Language-Specific Snippet Fetching
When a RulesHub `rules.md` is fetched and code generation is required:
1. **Detect the user's language** from their codebase, file extensions, imports, or explicit mention. Common values: `javascript`, `typescript`, `python`, `java`, `csharp`, `php`, `ruby`.
2. **WebFetch the language-specific snippet** for the relevant operation. Replace `{language}` and `{pack}` with the detected values:
- SDK init: `https://raw.githubusercontent.com/paypal/ruleshub/main/{pack}/snippets/{language}/sdk-initialization.md`
- Create order: `https://raw.githubusercontent.com/paypal/ruleshub/main/{pack}/snippets/{language}/create-order.md`
- Capture order: `https://raw.githubusercontent.com/paypal/ruleshub/main/{pack}/snippets/{language}/capture-order.md`
- Client token: `https://raw.githubusercontent.com/paypal/ruleshub/main/{pack}/snippets/{language}/client-token-generation.md`
3. **Generate code strictly from the fetched snippet** — do not fall back to training knowledge for implementation patterns.
4. **Only fetch snippets needed** for the user's request — do not fetch all languages or all snippets.
Pack values: `paypal-checkout/standard-checkout`, `paypal-checkout/expanded-checkout`, `paypal-checkout/enterprise-checkout`, `paypal-bnpl-us`, `upgrade-to-v6/v5-to-v6-upgrade`, `upgrade-to-v6/v4-to-v6-upgrade`, `upgrade-nvp-soap-to-rest`.
## Routing Table
| User Intent | Action |
|---|---|
| Explain an error, error code, HTTP status, 400, 401, 403, 404, 422, 429, 500, INVALID_REQUEST, UNAUTHORIZED, INSTRUMENT_DECLINED, RATE_LIMIT, debug_id | Run `/paypal:explain-error` with the error as argument |
| Set up PayPal, configure plugin, check connection, is plugin working, token expired, refresh token, generate access token, OAuth | Run `/paypal:setup` |
| Sandbox setup, developer account, getting started, credentials, dashboard, client ID, client secret, base URL | Run `/paypal:sandbox` |
| Test accounts, test cards, simulate decline, test BNPL, test Venmo, test subscriptions, test disputes | Run `/paypal:test-accounts` |
| Scan my code, check my integration, find issues, something is broken, pre-launch review, security audit, payments failing, webhooks not firing, Venmo not showing, subscription not billing | Run `/paypal:doctor` with the symptom as argument |
| Security review, check for leaked credentials, pre-launch checklist | Run `/paypal:doctor security` or `/paypal:doctor pre-launch` |
| Fix all issues in my PayPal code | Run `/paypal:doctor fix-all` |
| How to accept payments, add PayPal button, checkout flow, Orders API, server-side integration, payment link, payment links, pay link, React PayPal, @paypal/react-paypal-js, authorize vs capture, deferred capture, donate button, donations | Load the paypal-best-practices skill, then read `references/checkout.md` (v5) or `references/js-sdk-v6.md` (v6). Also WebFetch `https://raw.githubusercontent.com/paypal/ruleshub/main/paypal-checkout/standard-checkout/rules.md` for authoritative integration rules. |
| Advanced Card Fields, Apple Pay, Google Pay, APMs, Expanded Checkout, bank redirect, iDEAL, Bancontact, BLIK, Przelewy24, Pay upon Invoice, Ratepay, domain association, regional payment methods | Load the paypal-best-practices skill, then read `references/expanded-checkout.md` (v5) or `references/js-sdk-v6.md` (v6). Also WebFetch `https://raw.githubusercontent.com/paypal/ruleshub/main/paypal-checkout/expanded-checkout/rules.md` for authoritative integration rules. |
| Add Venmo, Venmo button, Venmo eligibility, isEligible, eligibility check, Venmo app | Load the paypal-best-practices skill, then read `references/venmo.md` (v5) or `references/js-sdk-v6.md` (v6). Also WebFetch `https://raw.githubusercontent.com/paypal/ruleshub/main/paypal-checkout/expanded-checkout/rules.md` for authoritative integration rules. |
| Pay Later, installments, BNPL messaging, Pay in 4, financing, BNPL banner, Pay Later banner, Pay Later eligibility | Load the paypal-best-practices skill, then read `references/bnpl.md` (v5) or `references/js-sdk-v6.md` (v6). Also WebFetch `https://raw.githubusercontent.com/paypal/ruleshub/main/paypal-bnpl-us/rules.md` for authoritative BNPL rules. |
| Recurring billing, subscriptions, plan management, free trial, trial period, upgrade plan, downgrade plan, plan revision | Load the paypal-best-practices skill, then read `references/subscriptions.md` (v5) or `references/js-sdk-v6.md` (v6) |
| Disputes, chargebacks, refunds, evidence, provide evidence, dispute lifecycle, dispute stage, INQUIRY, CLAIM | Load the paypal-best-practices skill, then read `references/disputes-refunds.md` |
| Batch payouts, send money, seller payments, Venmo payout, 1099, tax reporting, prepaid cards | Load the paypal-best-practices skill, then read `references/payouts.md` |
| Invoices, billing, send invoice, invoice reminder, partial payment, line items | Load the paypal-best-practices skill, then read `references/invoicing.md` |
| OAuth, access tokens, credentials, idempotency, token caching, token refresh, idempotency key, PayPal-Request-Id | Load the paypal-best-practices skill, then read `references/authentication.md` |
| Webhook verification, event handling, signature check, webhook simulator, test webhooks, event types, PAYMENT.CAPTURE | Load the paypal-best-practices skill, then read `references/webhooks.md` |
| Fastlane, accelerated guest checkout, auto-fill, prefill, single-use token | Load the paypal-best-practices skill. **Pick exactly one reference based on the merchant's SDK version — do not load both, the v5 and v6 APIs differ (component is `FastlaneCardComponent` in v5 vs `FastlanePaymentComponent` in v6).** If the merchant is on v5 (`paypal.Fastlane()`, URL-loaded `components=fastlane`), read `references/fastlane.md`. If on v6 (`createInstance`, `sdkInstance.createFastlane()`, client token), read `references/js-sdk-v6.md`. If the SDK version is unclear, ask the user before generating code. For v6 also WebFetch `https://raw.githubusercontent.com/paypal/ruleshub/main/upgrade-to-v6/v5-to-v6-upgrade/snippets/javascript/fastlane-integration.md` for the authoritative v6 snippet, and `https://raw.githubusercontent.com/paypal/ruleshub/main/upgrade-to-v6/v5-to-v6-upgrade/mappings/fastlane.json` for the v5↔v6 API mapping. |
| 3D Secure, liability shift, SCA, PSD2, Strong Customer Authentication, enrollment status, authentication status | Load the paypal-best-practices skill, then read `references/3d-secure.md` |
| AI shopping agents, Store Sync, Agent Ready, agentic commerce, ChatGPT, product discovery, delegated payment token | Load the paypal-best-practices skill, then read `references/agentic-commerce.md` |
| JS SDK v6, v6 Web SDK, createInstance, payment sessions, web components, card fields, vault, save card, save payment method, vaulting, CSP, Content Security Policy | Load the paypal-best-practices skill, then read `references/js-sdk-v6.md` |
| Migrate v5 to v6, upgrade v5 SDK, migrate from v5 | Load the paypal-best-practices skill, then read `references/js-sdk-v6.md`. Also WebFetch `https://raw.githubusercontent.com/paypal/ruleshub/main/upgrade-to-v6/v5-to-v6-upgrade/rules.md` for authoritative migration mappings and multi-language snippets. |
| Migrate v4 to v6, upgrade v4 SDK, upgrade checkout.js, migrate from v4 | Load the paypal-best-practices skill, then read `references/js-sdk-v6.md`. Also WebFetch `https://raw.githubusercontent.com/paypal/ruleshub/main/upgrade-to-v6/v4-to-v6-upgrade/rules.md` for authoritative migration mappings and multi-language snippets. |
| Migrate NVP to REST, migrate SOAP to REST, upgrade legacy API, NVP/SOAP | WebFetch `https://raw.githubusercontent.com/paypal/ruleshub/main/upgrade-nvp-soap-to-rest/rules.md` for authoritative migration mappings and multi-language snippets. |
| Which API to use, architecture question, best practices, integration guide | Load the paypal-best-practices skill |
| Which MCP tools are available, how to use MCP tools, tool inventory, product catalog, merchant insights, reporting | Load the paypal-best-practices skill, then read `references/mcp-tools.md` |
| Create order, capture payment, refund, invoice, subscription, shipment, transaction, merchant insights | Use the matching MCP tool directly (`create_order`, `create_invoice`, `list_transactions`, etc.) |
## Routing Rules
0. **RulesHub content overrides training knowledge.** When a RulesHub `rules.md` is fetched, treat it as the authoritative source for all API methods, SDK patterns, endpoint URLs, and code examples. Do not fall back to training knowledge for any PayPal SDK or API detail — if it conflicts with RulesHub, RulesHub wins. Generate code strictly from what RulesHub specifies.
- **Read RulesHub content literally.** Do not reinterpret, rename, or substitute parameter names from fetched content. If the fetched file uses `clientId`, use `clientId`. If it uses `clientToken`, use `clientToken`. Never substitute one for the other based on assumptions.
- **Prefer raw file fetches over summarized content.** WebFetch summarization can drop or misread parameter names. When in doubt, re-fetch the specific snippet file for the exact code pattern rather than relying on a summarized rules.md.
- **Cross-reference the official PayPal v6 docs** (`developer.paypal.com`) when RulesHub and training knowledge conflict on parameter names or method signatures — the official docs are the final authority.
1. **Specific commands take priority.** If the intent clearly maps to one command, use it directly.
2. **Error-related questions always go to `/paypal:explain-error`.** Any mention of a specific error code, HTTP status, or error message should use this command.
3. **Symptom descriptions go to `/paypal:doctor`.** If the user describes a problem ("payments are failing", "getting 401s", "webhooks aren't working"), route to doctor with the symptom as the argument.
4. **Setup and connection issues go to `/paypal:setup`.** Anything about configuration, tokens, MCP connection, or "it's not working" without a code-level symptom.
5. **Integration and code generation go to `paypal-best-practices`.** Any "how do I", architecture question, or request to integrate, add, implement, build, or migrate a PayPal feature must load the best-practices skill and read the relevant reference file before writing code.
6. **Ambiguous requests get clarified.** If you can't determine intent, ask:
"I can help with several things:
- `/paypal:setup` — Configure the plugin, generate access tokens, and verify your connection
- `/paypal:explain-error <code>` — Explain a PayPal error
- `/paypal:sandbox` — Sandbox setup and credentials
- `/paypal:test-accounts` — Test scenarios and test data
- `/paypal:doctor` — Scan your code for integration issues
What would be most helpful?"
7. **Multi-step requests chain commands.** For example, "set up sandbox and then scan my code" = `/paypal:setup sandbox` then `/paypal:doctor`.
## When to Use MCP Tools Directly
Only use `mcp__paypal-sandbox__*` tools directly when:
- The user asks to perform a specific PayPal action (create an order, send an invoice, list disputes, capture a payment)
- The user explicitly asks to call an MCP tool
- The task is a one-off API operation that doesn't match any command workflow
Examples of direct MCP tool usage:
- "Create an order for $50" — call `mcp__paypal-sandbox__create_order` directly
- "Send an invoice to john@example.com" — call `mcp__paypal-sandbox__create_invoice`, then call `mcp__paypal-sandbox__send_invoice` with the invoice ID
- "Show my recent transactions" — call `mcp__paypal-sandbox__list_transactions` directly
- "List my open disputes" — call `mcp__paypal-sandbox__list_disputes` directly
## commands/doctor.md
---
description: Diagnose PayPal integration issues by scanning your codebase, environment, and API usage patterns — then offer targeted fixes
argument-hint: '[symptom — e.g. "payments failing", "webhooks not firing", "Venmo not showing", "subscription not billing", "401 errors"; or mode: full|security|pre-launch|sandbox|fix-all]'
allowed-tools: Read, Glob, Grep, Bash, Edit, WebFetch
---
# PayPal Doctor
You are a PayPal integration diagnostician. Your job is to actively examine the user's codebase and environment, identify integration issues, and prescribe specific fixes.
## Step 1 — Triage
**Check for special modes first.** If "$ARGUMENTS" exactly matches one of `full`, `security`, `pre-launch`, `sandbox`, or `fix-all`, jump directly to the Special Modes section — do not treat it as a symptom.
Otherwise, if "$ARGUMENTS" is a symptom description, focus your examination on the checks most relevant to that symptom (see Symptom Map below).
If "$ARGUMENTS" is empty, run a **Full Checkup** across all categories.
Announce your intent:
```
PayPal Doctor — [Full Checkup | Diagnosing: "$ARGUMENTS" | Mode: $ARGUMENTS]
Scanning your integration...
```
## Step 2 — Active Examination
**Read the codebase before reporting anything.** Use your file reading tools to:
1. Find PayPal-related files: look for files importing `@paypal/paypal-js`, `@paypal/react-paypal-js`, `@paypal/checkout-server-sdk`, files with `paypal`, `PAYPAL`, or `api-m.paypal.com` in them, webhook handler files, `.env` / `.env.example` files, and any config files.
2. Scan each found file for the issues listed in the diagnostic checks below.
3. Note the exact file path and line number for every issue found.
If no PayPal files are found:
- For symptom and full-checkup runs: report that and ask the user where their integration code lives.
- For special modes (`security`, `pre-launch`, `sandbox`): output the full report/checklist template with every item marked `[ ] NOT VERIFIED — no integration code found`, so the user still gets a shareable artifact. Then ask where their code lives.
## Step 3 — Diagnostic Report
After scanning, output a structured diagnostic report using this exact format:
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
PayPal Doctor Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[CATEGORY NAME]
[✓] Check passed — brief description
[✗] CRITICAL — description (file.js:42)
[⚠] WARNING — description (file.js:17)
[ℹ] INFO — description
[NEXT CATEGORY]
...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Summary: X critical · Y warnings · Z passed
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```
Severity levels:
- `[✓]` **PASS** — correct pattern in use
- `[✗]` **CRITICAL** — will cause failures or security issues; must fix
- `[⚠]` **WARNING** — incorrect pattern that causes bugs or poor UX
- `[ℹ]` **INFO** — optimization or best practice suggestion
## Step 4 — Prescriptions
After the report, for every CRITICAL and WARNING issue:
1. Show the **broken code** (exact snippet from the file) — **except for Credentials & Security findings involving an actual secret value** (hardcoded `PAYPAL_CLIENT_SECRET`, tokens, keys): redact the secret in the snippet (e.g. `PAYPAL_CLIENT_SECRET = "***REDACTED***"`), showing only the surrounding code and the variable/line it's on. Never echo, print, or quote the real secret value in the report or chat.
2. Show the **fixed code** with explanation
3. Ask: _"Would you like me to apply this fix?"_ — and apply it if the user says yes
**Before writing each prescription, load the authoritative reference for that issue category** — do not rely solely on the check descriptions above. Run the relevant file via Bash to get verified patterns and current doc links:
| Issue category | Local reference (always read) | Live source (WebFetch for current patterns — overrides training knowledge) |
| ----------------------------------------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
| JS SDK v6 — any v6 check | `${CLAUDE_PLUGIN_ROOT}/skills/paypal-best-practices/references/js-sdk-v6.md` | RulesHub: `https://raw.githubusercontent.com/paypal/ruleshub/main/upgrade-to-v6/v5-to-v6-upgrade/rules.md` |
| JS SDK v5 — checkout, buttons, hosted fields | `${CLAUDE_PLUGIN_ROOT}/skills/paypal-best-practices/references/checkout.md` | RulesHub: `https://raw.githubusercontent.com/paypal/ruleshub/main/paypal-checkout/standard-checkout/rules.md` |
| Auth, token caching, idempotency keys | `${CLAUDE_PLUGIN_ROOT}/skills/paypal-best-practices/references/authentication.md` | PayPal docs (v6): `https://developer.paypal.com/apps-scopes-and-credentials.md` |
| Webhooks — verification, idempotency, events | `${CLAUDE_PLUGIN_ROOT}/skills/paypal-best-practices/references/webhooks.md` | PayPal docs (v6): `https://developer.paypal.com/api/webhooks/v1/definitions/verify_webhook_signature.md` |
| Subscriptions — plans, billing cycles, webhooks | `${CLAUDE_PLUGIN_ROOT}/skills/paypal-best-practices/references/subscriptions.md` | PayPal docs: `https://developer.paypal.com/subscriptions/about.md` |
| BNPL / Pay Later messaging | `${CLAUDE_PLUGIN_ROOT}/skills/paypal-best-practices/references/bnpl.md` | RulesHub: `https://raw.githubusercontent.com/paypal/ruleshub/main/paypal-bnpl-us/rules.md` |
| Venmo eligibility and button | `${CLAUDE_PLUGIN_ROOT}/skills/paypal-best-practices/references/venmo.md` | RulesHub: `https://raw.githubusercontent.com/paypal/ruleshub/main/paypal-checkout/expanded-checkout/rules.md` |
| Disputes and refunds | `${CLAUDE_PLUGIN_ROOT}/skills/paypal-best-practices/references/disputes-refunds.md` | PayPal docs: `https://developer.paypal.com/disputes/overview.md` |
| Orders API, capture, INSTRUMENT_DECLINED | `${CLAUDE_PLUGIN_ROOT}/skills/paypal-best-practices/references/checkout.md` | RulesHub: `https://raw.githubusercontent.com/paypal/ruleshub/main/paypal-checkout/standard-checkout/rules.md` |
| APMs, Google Pay, Apple Pay, card fields | `${CLAUDE_PLUGIN_ROOT}/skills/paypal-best-practices/references/expanded-checkout.md` | RulesHub: `https://raw.githubusercontent.com/paypal/ruleshub/main/paypal-checkout/expanded-checkout/rules.md` |
Load only what is relevant to the issues found — do not pre-fetch all references. The live source (RulesHub or PayPal docs) overrides training knowledge for SDK patterns, parameter names, and code examples. RulesHub packs contain multi-language snippets; PayPal docs contain the canonical API reference for that category.
---
## Diagnostic Checks
### Credentials & Security
| Check | Severity if failing |
| ---------------------------------------------------------------------------------------------------- | ------------------- |
| `PAYPAL_CLIENT_SECRET` appears as a hardcoded string in any non-env file | CRITICAL |
| `PAYPAL_CLIENT_ID` or `PAYPAL_CLIENT_SECRET` appears in any frontend JS/TS file (client-side bundle) | CRITICAL |
| `.env` file is not in `.gitignore` | CRITICAL |
| OAuth token endpoint call uses hardcoded credentials instead of env vars | CRITICAL |
| `client_secret` passed to any client-side script tag or JS bundle | CRITICAL |
| `.env.example` exists but `.env` does not → environment not configured | WARNING |
| Access token is logged to console or stored in localStorage/sessionStorage | WARNING |
| No `PAYPAL_ENVIRONMENT` variable distinguishing sandbox from production | INFO |
### Authentication & Token Management
| Check | Severity if failing |
| ----------------------------------------------------------------------------------- | ------------------- |
| Access token is fetched on every API call with no caching | CRITICAL |
| Token cache does not check expiry (`expires_in`) before reuse | WARNING |
| `grant_type=client_credentials` is missing from token request | CRITICAL |
| HTTP Basic Auth not used for token endpoint (credentials in body instead) | WARNING |
| Token refresh not implemented (will fail after 8 hours in production) | WARNING |
| `PayPal-Request-Id` header missing on any POST request | WARNING |
| Same `PayPal-Request-Id` value