Skip to main content

Backend Integration

Implement PayPal Checkout server-side using cURL, Python, Node.js, TypeScript, Java, .NET, Ruby, or PHP.

You’ll learn how to:

  • Set up environment credentials.
  • Authenticate your server with PayPal.
  • Create and capture orders securely from your backend.

Overview

PayPal Checkout uses a two-part integration:

  1. Client-side: Renders payment buttons and card fields.
  2. Server-side: Handles secure API calls to create and capture orders.

This guide focuses on the server-side logic using the Orders v2 API.

Integration flow

  1. Button Setup
    • Merchant server sends checkout info to webpage
    • PayPal JS SDK displays the PayPal button
  2. Order Creation
    • Buyer clicks PayPal button
    • createOrder() callback triggers
    • Merchant server calls POST /v2/checkout/orders
    • PayPal returns Order ID
  3. Buyer Approval
    • Buyer logs into PayPal
    • Selects shipping options
    • Approves payment
  4. Payment Capture
    • PayPal sends "Order Approved" notification
    • onApproved() callback triggers
    • Merchant server calls POST /v2/checkout/orders/{orderID}/capture
    • PayPal confirms payment
    • Merchant completes checkout

Prerequisites

All examples use sandbox endpoints. Swap in api.paypal.com for production.

Set these values as environment variables or securely in a config file:

PAYPAL_CLIENT_ID=your-sandbox-client-id
PAYPAL_CLIENT_SECRET=your-sandbox-client-secret
PAYPAL_API=https://api-m.sandbox.paypal.com

Code samples

The following code examples demonstrate how to implement the server-side components of PayPal Checkout integration, including authentication, order creation, and payment capture across different programming languages.

1. Get access token

curl -v -X POST https://api.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-H "Content-Type: application/x-www-form-urlencoded" \
-u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
-d "grant_type=client_credentials"

2. Create order

curl -v -X POST https://api.sandbox.paypal.com/v2/checkout/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"intent": "CAPTURE",
"purchase_units": [
{
"amount": {
"currency_code": "USD",
"value": "100.00"
}
}
],
"application_context": {
"return_url": "https://example.com/return",
"cancel_url": "https://example.com/cancel"
}
}'

3. Capture order

curl -v -X POST https://api.sandbox.paypal.com/v2/checkout/orders/ORDER_ID/capture \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{}'

Next steps

  • Validate payment status after capture.
  • Store payment details in your database.
  • Add webhook listeners to handle asynchronous events.

See also