PayPal Payments

Use the Payments API to easily and securely accept online and mobile PayPal payments. You can enable customers to make PayPal payments with only a few clicks, depending on the country. A completed payment is known as a sale.

Integration steps

1. Required Set up your development environment.
2. Required Create PayPal payment.
3. Required Get payment approval.
4. Required Execute payment.
5. Optional Search payment details.

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 PayPal payment

After you collect the payment details from the customer, specify the payment details in a /payment call.

In the request URI, set the <Access-Token>.

In the JSON request body, set the intent to sale, the redirect URLs, the payment_method to paypal, and the transaction information in the transactions array, which contains one or more transaction objects:

curl -v -X POST https://api.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": "This is 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 color hat",
        "quantity": "5",
        "price": "3",
        "tax": "0.01",
        "sku": "1",
        "currency": "USD"
      }, {
        "name": "handbag",
        "description": "Black color hand bag",
        "quantity": "1",
        "price": "15",
        "tax": "0.02",
        "sku": "product34",
        "currency": "USD"
      }],
      "shipping_address": {
        "recipient_name": "Hello World",
        "line1": "4thFloor",
        "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",
    "cancel_url": "https://example.com"
  }
}'

A successful call returns confirmation of the transaction, with the created state and a payment ID that you can use in subsequent calls:

{
  "id": "PAY-1B56960729604235TKQQIYVY",
  "create_time": "2014-09-22T20:53:43Z",
  "update_time": "2014-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": "This is 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 color hat",
            "tax": "0.01"
          },
          {
            "name": "handbag",
            "sku": "product34",
            "price": "15.00",
            "currency": "USD",
            "quantity": "1",
            "description": "Black color handbag",
            "tax": "0.02"
          }
        ],
        "shipping_address": {
          "recipient_name": "HelloWorld",
          "line1": "4thFloor",
          "line2": "unit#34",
          "city": "SAn Jose",
          "state": "CA",
          "phone": "011862212345678",
          "postal_code": "95131",
          "country_code": "US"
        }
      }
    }
  ],
  "links": [
    {
      "href": "https://api.paypal.com/v1/payments/payment/PAY-1B56960729604235TKQQIYVY",
      "rel": "self",
      "method": "GET"
    },
    {
      "href": "https://api.paypal.com/v1/payments//cgi-bin/webscr?cmd=_express-checkout&token=EC-60385559L1062554J",
      "rel": "approval_url",
      "method": "REDIRECT"
    },
    {
      "href": "https://api.paypal.com/v1/payments/payment/PAY-1B56960729604235TKQQIYVY/execute",
      "rel": "execute",
      "method": "POST"
    }
  ]
}

Next, get approval from the customer for the payment.

Get payment approval

When you create a payment for a PayPal payment, the customer must approve the payment before you can execute the sale. To enable the customer to approve the payment, pass the id field 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.

For details, see Set up your client.

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

For NVP/SOAP API full-page redirect integrations, PayPal does a full-page redirect to the return_url that was specified when the payment was created, with PayerID and paymentId appended to the URL.

Next, execute the payment.

Execute payment

To execute the payment after the customer's approval, make a /payment/execute/ call. In the JSON request body, use the payerID value that was passed to your site. In the header, use the access token that you used when you created the payment.

curl -v -X POST https://api.sandbox.paypal.com/v1/payments/payment/PAY-34629814WL663112AKEE3AWQ/execute \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer Access-Token" \
  -d '{
  "payer_id": "RRCYJUTFJGZTA"
}'

The execute payment call returns a payment object with transaction details:

{
  "id": "PAY-4N746561P0587231SKQQK6MY",
  "create_time": "2014-09-22T23:22:27Z",
  "update_time": "2014-09-22T23:31:13Z",
  "state": "approved",
  "intent": "sale",
  "payer": {
    "payment_method": "paypal",
    "payer_info": {
      "email": "npurayil-uspr-60@paypal.com",
      "first_name": "Brian",
      "last_name": "Robinson",
      "payer_id": "JMKDKJ4D7DG7G",
      "shipping_address": {
        "line1": "4thFloor",
        "line2": "unit#34",
        "city": "SAn Jose",
        "state": "CA",
        "postal_code": "95131",
        "country_code": "US",
        "phone": "011862212345678",
        "recipient_name": "HelloWorld"
      }
    }
  },
  "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": "This is the payment transaction description.",
      "item_list": {
        "items": [
          {
            "name": "hat",
            "sku": "1",
            "price": "3.00",
            "currency": "USD",
            "quantity": "5",
            "description": "Brown color hat",
            "tax": "0.01"
          },
          {
            "name": "handbag",
            "sku": "product34",
            "price": "15.00",
            "currency": "USD",
            "quantity": "1",
            "description": "Black color handbag",
            "tax": "0.02"
          }
        ],
        "shipping_address": {
          "recipient_name": "HelloWorld",
          "line1": "4thFloor",
          "line2": "unit#34",
          "city": "SAn Jose",
          "state": "CA",
          "phone": "011862212345678",
          "postal_code": "95131",
          "country_code": "US"
        }
      },
      "related_resources": [
        {
          "sale": {
            "id": "4XP56210M0797192Y",
            "create_time": "2014-09-22T23:22:27Z",
            "update_time": "2014-09-22T23:31:13Z",
            "amount": {
              "total": "30.11",
              "currency": "USD"
            },
            "payment_mode": "INSTANT_TRANSFER",
            "state": "completed",
            "protection_eligibility": "ELIGIBLE",
            "protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE",
            "transaction_fee": {
              "value": "1.75",
              "currency": "USD"
            },
            "parent_payment": "PAY-4N746561P0587231SKQQK6MY",
            "links": [
              {
                "href": "https://api.paypal.com/v1/payments/sale/4XP56210M0797192Y",
                "rel": "self",
                "method": "GET"
              },
              {
                "href": "https://api.paypal.com/v1/payments/sale/4XP56210M0797192Y/refund",
                "rel": "refund",
                "method": "POST"
              },
              {
                "href": "https://api.paypal.com/v1/payments/payment/PAY-4N746561P0587231SKQQK6MY",
                "rel": "parent_payment",
                "method": "GET"
              }
            ]
          }
        }
      ]
    }
  ],
  "links": [
    {
      "href": "https://api.paypal.com/v1/payments/payment/PAY-4N746561P0587231SKQQK6MY",
      "rel": "self",
      "method": "GET"
    }
  ]
}

Search payment details

You can use the Payments API to list completed payments with transaction details. Then, use the transaction IDs in the response to complete other payment operations. For example, you can issue a refund for a payment, by transaction ID.

List payments with transaction details

To list payments with transaction details, enter query parameters to specify the time range of the transaction, how many payments to list, and the sort order of the payments in the response.

Note: All query parameters are optional and not passing any returns all completed payments.

Query parameters Description
start_time end_time Specify the start and end times Internet date and time format.

For example: start_time=2017-03-06T11:00:00Z and end_time=2017-03-06T16:00:00Z
start_id The ID of the starting resource in the response. When results are paged and you're making subsequent payments calls, you can use the next_id value as the start_id to continue with the next set of results.
count The number of items to list in the response. The default is 10 with a maximum of 20.
start_index The start index of the payments to list. Typically, you use the start_index to jump to a specific position in the resource history based on its cart. For example, to start at the second item in a list of results, specify ?start_index=2.
sort_by Sort payments by the payment create_time or update_time.

Request

This example request lists ten payments by create time:

curl -v -X GET https://api.sandbox.paypal.com/v1/payments/payment?count=10&start_index=0&sort_by=create_time \
-H "Content-Type: application/json" \
-H "Authorization: Bearer Access-Token"

Response

The JSON response body lists payments that match the search criteria. The count field indicates the number of payments in the response. In a subsequent list payments call, set start_id to the next_id value to list the next set of payments.

{
  "payments": [
    {
      "id": "PAY-0US81985GW1191216KOY7OXA",
      "create_time": "2017-06-30T23:48:44Z",
      "update_time": "2017-06-30T23:49:27Z",
      "state": "APPROVED",
      "intent": "order",
      "payer": {
        "payment_method": "paypal"
      },
      "transactions": [
        {
          "amount": {
            "total": "41.15",
            "currency": "USD",
            "details": {
              "subtotal": "30.00",
              "tax": "1.15",
              "shipping": "10.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": "John Doe",
              "line1": "4th Floor, One Lagoon Drive",
              "line2": "Unit #34",
              "city": "Redwood City",
              "state": "CA",
              "phone": "4084217591",
              "postal_code": "94065",
              "country_code": "US"
            }
          },
          "related_resources": [
            {
              "authorization": {
                "id": "53P09338XY5426455",
                "create_time": "2017-06-30T23:50:01Z",
                "update_time": "2017-06-30T23:50:01Z",
                "amount": {
                  "total": "41.15",
                  "currency": "USD"
                },
                "parent_payment": "PAY-0US81985GW1191216KOY7OXA",
                "valid_until": "2017-07-29T23:49:52Z",
                "links": [
                  {
                    "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-0US81985GW1191216KOY7OXA",
                    "rel": "parent_payment",
                    "method": "GET"
                  }
                ]
              }
            }
          ]
        }
      ],
      "links": [
        {
          "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-0US81985GW1191216KOY7OXA",
          "rel": "self",
          "method": "GET"
        }
      ]
    },
    {
      "id": "PAY-53485002LD6169910KOZQ25I",
      "create_time": "2017-07-01T19:35:17Z",
      "update_time": "2017-07-01T19:36:05Z",
      "state": "APPROVED",
      "intent": "order",
      "payer": {
        "payment_method": "paypal"
      },
      "transactions": [
        {
          "amount": {
            "total": "33.00",
            "currency": "USD",
            "details": {
              "subtotal": "21.00",
              "tax": "2.00",
              "shipping": "10.00"
            }
          },
          "description": "The payment transaction description.",
          "item_list": {
            "items": [
              {
                "name": "hat",
                "sku": "1",
                "price": "3.00",
                "currency": "USD",
                "quantity": "2"
              },
              {
                "name": "handbag",
                "sku": "product34",
                "price": "15.00",
                "currency": "USD",
                "quantity": "1"
              }
            ],
            "shipping_address": {
              "recipient_name": "Hannah Lu",
              "line1": "1602 Crane ct",
              "line2": "",
              "city": "San Jose",
              "state": "CA",
              "phone": "4084217591",
              "postal_code": "95052",
              "country_code": "US"
            }
          },
          "related_resources": [
            {
              "authorization": {
                "id": "91527087GH224122L",
                "create_time": "2017-07-01T19:36:22Z",
                "update_time": "2017-07-01T19:36:22Z",
                "amount": {
                  "total": "33.00",
                  "currency": "USD"
                },
                "parent_payment": "PAY-53485002LD6169910KOZQ25I",
                "valid_until": "2017-07-30T19:36:22Z",
                "links": [
                  {
                    "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-53485002LD6169910KOZQ25I",
                    "rel": "parent_payment",
                    "method": "GET"
                  }
                ]
              }
            }
          ]
        }
      ],
      "links": [
        {
          "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-53485002LD6169910KOZQ25I",
          "rel": "self",
          "method": "GET"
        }
      ]
    },
    {
      "id": "PAY-7F5790198P134484LKOZSG7Q",
      "create_time": "2017-07-01T21:09:18Z",
      "update_time": "2017-07-01T22:31:56Z",
      "state": "APPROVED",
      "intent": "order",
      "payer": {
        "payment_method": "paypal"
      },
      "transactions": [
        {
          "amount": {
            "total": "42.00",
            "currency": "USD",
            "details": {
              "subtotal": "36.00",
              "tax": "1.00",
              "shipping": "5.00"
            }
          },
          "description": "The payment transaction description.",
          "item_list": {
            "items": [
              {
                "name": "handbag",
                "sku": "product34",
                "price": "36.00",
                "currency": "USD",
                "quantity": "1"
              }
            ],
            "shipping_address": {
              "recipient_name": "Anna Joseph",
              "line1": "2525 North 1st street",
              "line2": "unit 4",
              "city": "San Jose",
              "state": "CA",
              "phone": "011862212345678",
              "postal_code": "95031",
              "country_code": "US"
            }
          },
          "related_resources": [
            {
              "capture": {
                "id": "26062838D7499294V",
                "create_time": "2017-07-01T21:16:22Z",
                "update_time": "2017-07-01T21:16:24Z",
                "amount": {
                  "total": "7.00",
                  "currency": "USD"
                },
                "state": "COMPLETED",
                "parent_payment": "PAY-7F5790198P134484LKOZSG7Q",
                "links": [
                  {
                    "href": "https://api.sandbox.paypal.com/v1/payments/capture/26062838D7499294V",
                    "rel": "self",
                    "method": "GET"
                  },
                  {
                    "href": "https://api.sandbox.paypal.com/v1/payments/capture/26062838D7499294V/refund",
                    "rel": "refund",
                    "method": "POST"
                  },
                  {
                    "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-7F5790198P134484LKOZSG7Q",
                    "rel": "parent_payment",
                    "method": "GET"
                  }
                ]
              }
            },
            {
              "capture": {
                "id": "0YU20012P1477553M",
                "create_time": "2017-07-01T22:31:54Z",
                "update_time": "2017-07-01T22:31:56Z",
                "amount": {
                  "total": "35.00",
                  "currency": "USD"
                },
                "state": "COMPLETED",
                "parent_payment": "PAY-7F5790198P134484LKOZSG7Q",
                "links": [
                  {
                    "href": "https://api.sandbox.paypal.com/v1/payments/capture/0YU20012P1477553M",
                    "rel": "self",
                    "method": "GET"
                  },
                  {
                    "href": "https://api.sandbox.paypal.com/v1/payments/capture/0YU20012P1477553M/refund",
                    "rel": "refund",
                    "method": "POST"
                  },
                  {
                    "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-7F5790198P134484LKOZSG7Q",
                    "rel": "parent_payment",
                    "method": "GET"
                  }
                ]
              }
            }
          ]
        }
      ],
      "links": [
        {
          "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-7F5790198P134484LKOZSG7Q",
          "rel": "self",
          "method": "GET"
        }
      ]
    }
  ],
  "count": 3,
  "next_id": "PAY-9X4935091L753623RKOZTRHI"
}

Show payment with transaction details

The show payment details, show sale details, and show captured payment details calls return an array of transactions that include transaction IDs. To show transaction details, call show payment details with a transaction ID.

For example, a payment request returns the following ID:

"id": "PAY-1B56960729604235TKQQIYVY"

Request

To show transaction details, specify the id in the following call:

curl -v -X GET https://api.sandbox.paypal.com/v1/payments/payment/PAY-1B56960729604235TKQQIYVY \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer Access-Token"

Response

The response lists transactions:

{
  "id": "PAY-5YK922393D847794YKER7MUI",
  "create_time": "2017-02-19T22:01:53Z",
  "update_time": "2017-02-19T22:01:55Z",
  "state": "approved",
  "intent": "sale",
  "payer": {
    "payment_method": "credit_card",
    "funding_instruments": []
  },
  "transactions": [{
    "amount": {},
    "description": "The payment transaction description.",
    "note_to_payer": "Contact us for any questions on your order.",
    "related_resources": [{
      "sale": {
        "id": "36C38912MN9658832",
        "create_time": "2017-02-19T22:01:53Z",
        "update_time": "2017-02-19T22:01:55Z",
        "state": "completed",
        "amount": {},
        "protection_eligibility": "ELIGIBLE",
        "protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE",
        "transaction_fee": {},
        "parent_payment": "PAY-5YK922393D847794YKER7MUI",
        "links": [{},
          {},
          {}
        ]
      }
    }]
  }],
  "links": []
}

Next

A sale is a completed payment. You can use the payment ID to show sale details and refund a sale.

Then, learn how to authorize and capture payments.

Additional information