- Merchant onboarding — registering and connecting seller accounts as Partners
- Payment gateway — processing end-customer payments, creating orders, and managing webhooks
Configuration
| Var | Notes |
|---|---|
PAYPAL_MODE | Determines the execution environment |
PAYPAL_CLIENT_ID / PAYPAL_SECRET | Main API keys — must be kept secret |
PAYPAL_PARTNER_ID | Used for Marketplace features and seller referrals |
PAYPAL_WEBHOOK_ID | Essential for validating the signature of incoming webhooks |
Two clients
| Surface | Library | Purpose |
|---|---|---|
| Onboarding | Raw HTTP (fetch) | Token + Partner Referral management. Access tokens fetched dynamically per request |
| Payment Gateway | @paypal/checkout-server-sdk | Creating orders and financial transactions. SDK client configured for SandboxEnvironment or LiveEnvironment |
Merchant onboarding
1. Create Partner Referral
- Flow: User → Core Backend → Integration Services → PayPal API
- Internal endpoint:
POST /paypal/partner-referrals - PayPal endpoint:
POST /v2/customer/partner-referrals
onboarding_url to redirect the seller to.
2. Onboarding return (callback)
- Flow: PayPal → User redirect → Core Backend
- The Core Backend receives
merchantIdandtrackingIdin the URL and persists themerchantId.
This step does not call the Integration Service.
3. Verify merchant integration
- Internal endpoint:
GET /paypal/merchant-integrations/:merchantId
payments_receivable === true and vetting_status !== 'DENIED', the Core Backend
enables the PayPal gateway for that shop.
Payment & checkout
Create payment intent
- Internal endpoint:
POST /payment-gateway/create-intent
Webhook handling & normalization
- Flow: PayPal → Integration Services → Core Backend (
/webhook/generic)
Status mapping
| PayPal status | Core Backend action | Result |
|---|---|---|
COMPLETED | confirmPayment() | Order confirmed, inventory updated, emails sent |
REFUNDED | Update status | Order status → REFUNDED |
PENDING | Update status | Payment status → PENDING |
FAILED / DENIED | Update status | Payment status → FAILED |
CANCELLED / VOIDED | Update status | Order status → CANCELLED |
Flow diagrams
Merchant onboarding
Payment checkout
Security notes
Webhook verification
All webhooks are validated using
paypal-transmission-sig and PAYPAL_WEBHOOK_ID. The
signature includes transmissionId, timestamp, webhookId, and the CRC32 of the
request body.Token management
A new access token is obtained for each onboarding request (Client Credentials Flow).
No sensitive tokens are logged.
Troubleshooting
| Symptom | Likely cause |
|---|---|
| All webhooks rejected | PAYPAL_WEBHOOK_ID in env doesn’t match the PayPal Dashboard settings |
| Currency mismatch error | currency_code doesn’t match the seller’s PayPal account settings |
401 Unauthorized | Using sandbox keys in live (or vice versa) |