Orders Integration Guide

APIDeprecatedLast updated: March 16th 2023, @ 11:23:55 am


Use the Payments REST API to create a PayPal order, which is a purchase that a customer consents to but for which funds are not placed on hold.

Overview

To complete an order, you can either:

  • Directly capture funds when you create the order. No additional authorization is required.

  • Create an authorization, which authorizes and places funds on hold for the order. Later, you can capture the funds for the order.

    For example, you can use the authorization and capture technique for orders that contain items that are not immediately available for shipment. Then, you can create subsequent basic authorizations as the items become available. These authorizations ensure that the customer still has the funds available to purchase each item.

An order is valid for 29 days. During this period, you can request from one to ten or more authorizations to ensure the availability of funds. By default, you can make up to ten basic authorizations for each order. To configure your account to enable up to 99 basic authorizations for each order, contact PayPal Customer Support.

The sum of the amounts in any open authorizations for an order cannot exceed 115% or $75, whichever is less, of the amount that you requested when you created the order.

Integration steps

1.RequiredSet up your development environment.
2.RequiredCreate an order.
3.RequiredGet customer approval.
4.RequiredExecute the order.
5.OptionalAuthorize payment for an order.
6.OptionalCapture payment for an order.

Set up your development environment

Before you can integrate Payments, you must set up your development environment. After you get a token that lets you access protected REST API resources, you create sandbox accounts to test your web and mobile apps. For details, see Get started.

Then, return to this page to integrate Payments.

Create order

When you create an order, you provide payment details just as you do when you create a PayPal payment.

In the JSON request body, set:

  • The intent to sale.
  • The payment_method to paypal. The only supported payment method for an order is a PayPal payment.
  • The redirect URLs, which are used to redirect the customer when he or she approves or cancels the order.
curl -v -X POST https://api-m.sandbox.paypal.com/v1/payments/payment \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <Access-Token>" \
-d '{
  "intent": "sale",
  "payer": {
    "payment_method": "paypal"
  },
  "transactions": [
    {
      "amount": {
        "total": "30.11",
        "currency": "USD",
        "details": {
          "subtotal": "30.00",
          "tax": "0.07",
          "shipping": "0.03",
          "handling_fee": "1.00",
          "shipping_discount": "-1.00",
          "insurance": "0.01"
        }
      },
      "description": "The payment transaction description.",
      "custom": "EBAY_EMS_90048630024435",
      "invoice_number": "48787589673",
      "payment_options": {
        "allowed_payment_method": "INSTANT_FUNDING_SOURCE"
      },
      "soft_descriptor": "ECHI5786786",
      "item_list": {
        "items": [
          {
            "name": "hat",
            "description": "Brown hat.",
            "quantity": "5",
            "price": "3",
            "tax": "0.01",
            "sku": "1",
            "currency": "USD"
          },
          {
            "name": "handbag",
            "description": "Black handbag.",
            "quantity": "1",
            "price": "15",
            "tax": "0.02",
            "sku": "product34",
            "currency": "USD"
          }
        ],
        "shipping_address": {
          "recipient_name": "Brian Robinson",
          "line1": "4th Floor",
          "line2": "Unit #34",
          "city": "San Jose",
          "country_code": "US",
          "postal_code": "95131",
          "phone": "011862212345678",
          "state": "CA"
        }
      }
    }
  ],
  "note_to_payer": "Contact us for any questions on your order.",
  "redirect_urls": {
    "return_url": "https://example.com/return",
    "cancel_url": "https://example.com/cancel"
  }
}'

A successful call returns the order details including a PayPal-generated order ID, the order state, which is created, and the date and time when the order was created.

{
  "id": "PAY-1B56960729604235TKQQIYVY",
  "create_time": "2017-09-22T20:53:43Z",
  "update_time": "2017-09-22T20:53:44Z",
  "state": "CREATED",
  "intent": "sale",
  "payer": {
    "payment_method": "paypal"
  },
  "transactions": [
    {
      "amount": {
        "total": "30.11",
        "currency": "USD",
        "details": {
          "subtotal": "30.00",
          "tax": "0.07",
          "shipping": "0.03",
          "handling_fee": "1.00",
          "insurance": "0.01",
          "shipping_discount": "-1.00"
        }
      },
      "description": "The payment transaction description.",
      "custom": "EBAY_EMS_90048630024435",
      "invoice_number": "48787589673",
      "item_list": {
        "items": [
          {
            "name": "hat",
            "sku": "1",
            "price": "3.00",
            "currency": "USD",
            "quantity": "5",
            "description": "Brown hat.",
            "tax": "0.01"
          },
          {
            "name": "handbag",
            "sku": "product34",
            "price": "15.00",
            "currency": "USD",
            "quantity": "1",
            "description": "Black handbag.",
            "tax": "0.02"
          }
        ],
        "shipping_address": {
          "recipient_name": "Brian Robinson",
          "line1": "4th Floor",
          "line2": "Unit #34",
          "city": "San Jose",
          "state": "CA",
          "phone": "011862212345678",
          "postal_code": "95131",
          "country_code": "US"
        }
      }
    }
  ],
  "links": [
    {
      "href": "https://api-m.sandbox.paypal.com/v1/payments/payment/PAY-1B56960729604235TKQQIYVY",
      "rel": "self",
      "method": "GET"
    },
    {
      "href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-60385559L1062554J",
      "rel": "approval_url",
      "method": "REDIRECT"
    },
    {
      "href": "https://api-m.sandbox.paypal.com/v1/payments/payment/PAY-1B56960729604235TKQQIYVY/execute",
      "rel": "execute",
      "method": "POST"
    }
  ]
}

Next, get customer approval for the PayPal payment for the order.

Get customer approval

When you create an order, the customer must approve the PayPal payment before you can execute the order. To enable the customer to approve the payment, pass the id value from the create order response to the payment function on your client. When the customer approves the payment, PayPal calls your client-side onAuthorize callback. PayPal passes the data.paymentID and data.payerID to your call back.

To test customer approval in sandbox:

  1. Navigate to the approval_url given in the HATEOAS links provided in your create order call.
  2. When the checkout flow popup appears, log in using the buyer account created for you when you created your sandbox account.
  3. Make the payment.
  4. Log into https://www.sandbox.paypal.com/ with your buyer account. You will see the funds transfer from the buyer side.
  5. Log into https://www.sandbox.paypal.com/ with your facilitator account (also automatically created when you created a sandbox account) and you will see the funds transfer to you from the buyer.

Note: For existing full-page-redirect integrations, redirect the customer to the approval_url from the previous response so that he or she can approve the payment.

Next, execute the order.

Execute order

To execute the order after the customer's approval, make a /payment/payment_id/execute/ call, where payment_id is the ID of the payment to execute. In the JSON request body, the payer_id is the ID of the payer that PayPal passes in the data.payerID to your call back:

curl -v -k -X POST https://api-m.sandbox.paypal.com/v1/payments/payment/PAY-9N9834337A9191208KOZOQWI/execute \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <Access-Token>' \
  -d '{
  "payer_id": "CR87QHB7JTRSC"
}'

The execute payment call returns a payment object with transaction details. The response returns HATEOAS links that you can use to complete further operations on the order:

{
  "id": "PAY-9N9834337A9191208KOZOQWI",
  "create_time": "2017-07-01T16:56:57Z",
  "update_time": "2017-07-01T17:05:41Z",
  "state": "approved",
  "intent": "order",
  "payer": {
    "payment_method": "paypal",
    "payer_info": {
      "email": "payer@example.com",
      "first_name": "Thomas",
      "last_name": "Miller",
      "payer_id": "PUP87RBJV8HPU",
      "shipping_address": {
        "line1": "4th Floor, One Lagoon Drive",
        "line2": "Unit #34",
        "city": "Redwood City",
        "state": "CA",
        "postal_code": "94065",
        "country_code": "US",
        "phone": "011862212345678",
        "recipient_name": "Thomas Miller"
      }
    }
  },
  "transactions": [
  {
    "amount": {
      "total": "41.15",
      "currency": "USD",
      "details": {
        "subtotal": "30.00",
        "tax": "0.15",
        "shipping": "11.00"
      }
    },
    "description": "The payment transaction description.",
    "item_list": {
      "items": [
      {
        "name": "hat",
        "sku": "1",
        "price": "3.00",
        "currency": "USD",
        "quantity": "5"
      },
      {
        "name": "handbag",
        "sku": "product34",
        "price": "15.00",
        "currency": "USD",
        "quantity": "1"
      }],
      "shipping_address": {
        "recipient_name": "Thomas Miller",
        "line1": "4th Floor, One Lagoon Drive",
        "line2": "Unit #34",
        "city": "Redwood City",
        "state": "CA",
        "phone": "011862212345678",
        "postal_code": "94065",
        "country_code": "US"
      }
    },
    "related_resources": [
    {
      "order": {
        "id": "O-3SP845109F051535C",
        "create_time": "2017-07-01T16:56:58Z",
        "update_time": "2017-07-01T17:05:41Z",
        "state": "pending",
        "amount": {
          "total": "41.15",
          "currency": "USD"
        },
        "parent_payment": "PAY-9N9834337A9191208KOZOQWI",
        "links": [
        {
          "href": "https://api-m.sandbox.paypal.com/v1/payments/orders/O-3SP845109F051535C",
          "rel": "self",
          "method": "GET"
        },
        {
          "href": "https://api-m.sandbox.paypal.com/v1/payments/payment/PAY-9N9834337A9191208KOZOQWI",
          "rel": "parent_payment",
          "method": "GET"
        },
        {
          "href": "https://api-m.sandbox.paypal.com/v1/payments/orders/O-3SP845109F051535C/void",
          "rel": "void",
          "method": "POST"
        },
        {
          "href": "https://api-m.sandbox.paypal.com/v1/payments/orders/O-3SP845109F051535C/authorize",
          "rel": "authorization",
          "method": "POST"
        },
        {
          "href": "https://api-m.sandbox.paypal.com/v1/payments/orders/O-3SP845109F051535C/capture",
          "rel": "capture",
          "method": "POST"
        }]
      }
    }]
  }],
  "links": [
  {
    "href": "https://api-m.sandbox.paypal.com/v1/payments/payment/PAY-9N9834337A9191208KOZOQWI",
    "rel": "self",
    "method": "GET"
  }]
}

Next, for orders for which you do not immediately capture funds, you can authorize funds and capture the funds later.

Authorize payment for an order

Authorizing an order confirms the availability of funds but does not place the funds on hold.

You can make multiple authorizations and captures against a single order.

To authorize payment for an order, pass the order ID in the URI of a POST call. The authorize order call confirms that funds are available to complete the order payment.

curl -v -X POST https://api-m.sandbox.paypal.com/v1/payments/orders/O-0NR488530V5211123/authorize \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <Access-Token>' \
  -d '{
  "amount":
  {
    "total": "7.00",
    "currency": "USD"
  }
}'

The response includes a capture link that you use to capture the payment.

{
  "status": "OK",
  "result":
  {
    "id": "0PG032325D352531H",
    "create_time": "2017-06-28T07:38:10Z",
    "update_time": "2017-06-28T07:38:12Z",
    "state": "Pending",
    "amount":
    {
      "total": "41.15",
      "currency": "USD"
    },
    "parent_payment": "O-0NR488530V5211123",
    "links": [
    {
      "href": "https://api-m.sandbox.paypal.com/v1/payments/orders/O-0NR488530V5211123",
      "rel": "self",
      "method": "GET"
    },
    {
      "href": "https://api-m.sandbox.paypal.com/v1/payments/authorization/0PG032325D352531H",
      "rel": "self",
      "method": "GET"
    },
    {
      "href": "https://api-m.sandbox.paypal.com/v1/payments/authorization/0PG032325D352531H/capture",
      "rel": "capture",
      "method": "POST"
    },
    {
      "href": "https://api-m.sandbox.paypal.com/v1/payments/payment/PAY-0AY778532K612520BKOXHAKY",
      "rel": "parent_payment",
      "method": "GET"
    }]
  }
}

Next, capture funds for an authorized order payment.

Capture payment for an order

To capture the payment for an order, use the capture link from the previous response.

Note: For a partial capture, you can provide a lower amount than the total payment. Additionally, set is_final_capture to true to explicitly indicate that the capture is the final capture, which completes the transaction and prevents future captures.

curl -v -X POST https://api-m.sandbox.paypal.com/v1/payments/orders/0PG032325D352531H/capture \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <Access-Token>" \
  -d '{
  "amount": {
    "currency": "USD",
    "total": "4.54"
  },
  "is_final_capture": true
}'

A successful call returns a capture object with details about the captured payment:

{
  "id": "51366113MA710110S",
  "create_time": "2017-07-01T17:13:45Z",
  "update_time": "2017-07-01T17:13:47Z",
  "amount": {
    "total": "4.54",
    "currency": "USD"
  },
  "is_final_capture": true,
  "state": "completed",
  "parent_payment": "PAY-9N9834337A9191208KOZOQWI",
  "links": [
  {
    "href": "https://api-m.sandbox.paypal.com/v1/payments/capture/51366113MA710110S",
    "rel": "self",
    "method": "GET"
  },
  {
    "href": "https://api-m.sandbox.paypal.com/v1/payments/capture/51366113MA710110S/refund",
    "rel": "refund",
    "method": "POST"
  },
  {
    "href": "https://api-m.sandbox.paypal.com/v1/payments/orders/O-3SP845109F051535C",
    "rel": "order",
    "method": "GET"
  },
  {
    "href": "https://api-m.sandbox.paypal.com/v1/payments/payment/PAY-9N9834337A9191208KOZOQWI",
    "rel": "parent_payment",
    "method": "GET"
  }]
}

Next

You can use the order ID to show order details or void an order. You cannot void an order if the payment has already been partially or fully captured.

Learn how to capture an authorization or refund payments.

Additional information