Manages PayPal sandbox environment for local testing and development. Ensures transactions do not use real money and routes to the correct PayPal sandbox endpoints.
This skill ensures that all local payment testing is safely isolated in the PayPal Sandbox environment.
To enable Sandbox mode, ensure your .env.local (or server environment) has the following variables set:
# Set to SANDBOX for testing, LIVE for production
PAYPAL_ENVIRONMENT=SANDBOX
# Sandbox Credentials (from developer.paypal.com)
PAYPAL_CLIENT_ID_SANDBOX=your_sandbox_client_id
PAYPAL_CLIENT_SECRET_SANDBOX=your_sandbox_client_secret
# Optional: Override return URLs for local testing
PAYPAL_RETURN_URL_SANDBOX=http://localhost:3000
When loading environment variables in local-server.js, ALWAYS load .env.local BEFORE .env.
dotenv does not overwrite existing keys. If you load (Live) first, it will LOCK the environment to Live, ignoring your local Sandbox overrides.
.envCorrect Order:
dotenv.config({ path: resolve(__dirname, '.env.local') }); // Loads Sandbox/Overrides FIRST
dotenv.config({ path: resolve(__dirname, '.env') }); // Loads Defaults SECOND
ALWAYS use port 3000 for local development. If port 3000 is already in use, you MUST:
Kill the existing process on port 3000:
lsof -ti:3000 | xargs kill -9 2>/dev/null || true
Then start the dev server on port 3000:
npm run dev -- --port 3000
Why this matters:
localhost:3000Before testing, verify the API is hitting the sandbox endpoint:
https://api.sandbox.paypal.com (NOT api.paypal.com)Use "Personal" and "Business" sandbox accounts created at developer.paypal.com.
sandbox.paypal.com./payment/success works correctly on localhost.PAYPAL_ENVIRONMENT=LIVE in a local .env.local file.localhost:3000 is added as a valid redirect URI in your PayPal app settings if using OAuth.PayPal aggressively blocks automated browsers (used by AI agents), often resulting in a "You have been blocked" screen during testing. This does NOT mean the feature failed.
https://www.paypal.com/checkoutnow?token=... or https://www.sandbox.paypal.com/...Do not attempt to bypass the block. Instead, validate the success based on the handoff state:
paypal.com with a valid ?token=... query parameter, the Application <-> PayPal handshake was SUCCESSFUL.Example Report:
"The checkout flow is functioning correctly. The backend successfully initiated the session, and the browser redirected to PayPal with a valid token (
token=...). The 'Blocked' screen is expected when using an automated agent. Please verify the visual checkout by determining the URL in a standard browser."