Reference Transactions Integration Guide

DOCS

Last updated: Sept 23rd, 4:22pm

Use the PayPal Reference Transactions API to create and manage billing agreement tokens and billing agreements. You can use a reference transaction to make a payment.

Overview

The PayPal Reference Transactions API enables a customer and merchant to enter into a contract, or a billing agreement, based on reference transactions. A reference transaction is a financial transaction that you initiate through a billing agreement and from which you can derive subsequent payments.

The combination of billing agreements and reference transactions benefits customers, merchants, and partners:

  • Customers can make seamless on-demand or recurring payments for services or goods without needing to log in to the merchant site after agreement approval.

    For example, customers can enter into agreements to:

    • Make future payments for actual usage of utilities, such as gas or electricity.

    • Make future purchases on the merchant site without being on the merchant site.

    • Make recurring payments for a subscription service.

    • Pay a merchant in a marketplace on a regular basis.

      A customer can have multiple billing agreements. For example, the customer might establish separate agreements for different kinds of service.

  • Merchants can initiate recurring payments for varying amounts on varying schedules.

    For example, merchants can enter into agreements to:

    • Get consent to take funds from a customer's account at varying amounts and schedules.
    • Create a billing agreement that charges the customer's PayPal account for subsequent purchases.
    • Initiate a payment based on the billing agreement.
    • Leverage PayPal to protect the risks inherent in processing payments.
  • Partners can enter into an agreement with merchants on the platform to charge merchant fees on demand in varying amounts.

A billing agreement can be merchant-initiated or channel-initiated:

Billing agreement type Description
Merchant-initiated agreement (MIB)

A basic agreement between a merchant and a customer.

The merchant initiates the agreement, the customer signs the agreement with the merchant, and the same merchant processes and receives the payment.

Channel-initiated agreement (CIB)

An agreement between a customer and a channel.

The customer grants a channel permission to process third-party payments, or reference transactions. This eliminates the need for the customer to sign a separate billing agreement with each third-party merchant.

The channel decides when and by which third-party merchant payments are processed.

1. Set up your development environment

Before you can integrate Reference Transactions, 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 Reference Transactions.

2. Create billing agreement token

To create a billing agreement token, pass the agreement details including the description, payer, and billing plan in the JSON request body.

Set the payment_method parameter in the payer object to PAYPAL.

This call returns an approval URL, where the payer is redirected. The payer logs in to PayPal one time to approve the agreement and select a funding instrument. After that, the payer doesn't need to log in again. If the payer approves the agreement, they are redirected to the return URL specified during billing agreement token creation.

For example:

    1curl -v -X POST https://api-m.sandbox.paypal.com/v1/billing-agreements/agreement-tokens \
    2 -H "Content-Type: application/json" \
    3 -H "Authorization: Bearer ACCESS-TOKEN" \
    4 -d '{
    5 "description": "Billing Agreement",
    6 "shipping_address":
    7 {
    8 "line1": "123 Main St.",
    9 "line2": "Suite #4",
    10 "city": "New York",
    11 "state": "NY",
    12 "postal_code": "12345",
    13 "country_code": "US",
    14 "recipient_name": "John Doe"
    15 },
    16 "payer":
    17 {
    18 "payment_method": "PAYPAL"
    19 },
    20 "plan":
    21 {
    22 "type": "MERCHANT_INITIATED_BILLING",
    23 "merchant_preferences":
    24 {
    25 "return_url": "https://example.com/return",
    26 "cancel_url": "https://example.com/cancel",
    27 "notify_url": "https://example.com/notify",
    28 "accepted_pymt_type": "INSTANT",
    29 "skip_shipping_address": false,
    30 "immutable_shipping_address": true
    31 }
    32 }
    33}'

    If your request for a billing agreement with PayPal payment method succeeds, the API returns the HTTP 201 Created status code and a JSON response that includes an approval URL:

      1{
      2 "links": [
      3 {
      4 "href": "https://api-m.sandbox.paypal.com/agreements/approve?ba_token=BA-8A802366G0648845Y",
      5 "rel": "approval_url",
      6 "method": "POST"
      7 },
      8 {
      9 "href": "https://api-m.sandbox.paypal.com/v1/billing-agreements/BA-8A802366G0648845Y/agreements",
      10 "rel": "self",
      11 "method": "POST"
      12 }],
      13 "token_id": "BA-8A802366G0648845Y"
      14}

      Redirect the payer to the approval URL, where the payer can consent to the billing agreement and select a funding instrument. Then, redirect the payer to the return URL specified during billing agreement token creation.

      3. Create billing agreement

      After payer approval, use a billing agreement token to create the agreement.

      Include the token in the URI:

        1curl -v -X POST https://api-m.sandbox.paypal.com/v1/billing-agreements/agreements \
        2 -H "Content-Type: application/json" \
        3 -H "Authorization: Bearer ACCESS-TOKEN" \
        4 -d '{
        5 "token_id": "BA-8A802366G0648845Y"
        6}'

        A successful request returns the HTTP 201 Created status code and a JSON response body that includes the billing agreement ID, the state of the agreement, which is ACTIVE, and information about the payer:

          1{
          2 "id": "B-50V812176H0783741",
          3 "state": "ACTIVE",
          4 "description": "Billing Agreement",
          5 "payer":
          6 {
          7 "payer_info":
          8 {
          9 "email": "doe@example.com",
          10 "first_name": "John",
          11 "last_name": "Doe",
          12 "payer_id": "ZU7HZ76P4VL5U"
          13 }
          14 },
          15 "plan":
          16 {
          17 "type": "MERCHANT_INITIATED_BILLING",
          18 "merchant_preferences":
          19 {
          20 "notify_url": "https://example.com/notify",
          21 "accepted_pymt_type": "INSTANT"
          22 }
          23 },
          24 "links": [
          25 {
          26 "href": "https://api-m.sandbox.paypal.com/v1/billing-agreements/agreements/B-50V812176H0783741/cancel",
          27 "rel": "cancel",
          28 "method": "POST"
          29 },
          30 {
          31 "href": "https://api-m.sandbox.paypal.com/v1/billing-agreements/agreements/B-50V812176H0783741",
          32 "rel": "self",
          33 "method": "GET"
          34 }],
          35 "merchant":
          36 {
          37 "payee_info":
          38 {
          39 "email": "merchant@example.com"
          40 }
          41 },
          42 "create_time": "2023-08-08T07:19:28.000Z",
          43 "update_time": "2023-08-08T07:19:28.000Z"
          44}

          Save the id value, which is the billing agreement ID.

          Next, use the reference transaction to make a payment.

          4. Use a reference transaction to make a payment

          To use a reference transaction to make a payment, pass the ID of the billing agreement in the JSON request body of a /v2/checkout/orders call:

            1curl - v - X POST https: //api-m.sandbox.paypal.com/v2/checkout/orders \
            2 -H "Content-Type: application/json"\ - H "Authorization: Bearer ACCESS-TOKEN"\ - d '{
            3"intent": "CAPTURE", "purchase_units": [{
            4 "amount": {
            5 "currency_code": "EUR",
            6 "value": "0.01"
            7 }
            8}], "payment_source": {
            9 "token": {
            10 "id": "B-50V812176H0783741",
            11 "type": "BILLING_AGREEMENT"
            12 }
            13}
            14}

            A successful request returns a JSON response body that shows payment details:

              1{
              2 "id": "5AT627990P285181E",
              3 "status": "COMPLETED",
              4 "purchase_units": [{
              5 "reference_id": "default",
              6 "payments": {
              7 "authorizations": [{
              8 "status": "CREATED",
              9 "id": "6MS02512BP527144J",
              10 "amount": {
              11 "currency_code": "EUR",
              12 "value": "0.01"
              13 },
              14 "seller_protection": {
              15 "status": "ELIGIBLE",
              16 "dispute_categories": ["ITEM_NOT_RECEIVED", "UNAUTHORIZED_TRANSACTION"]
              17 },
              18 "expiration_time": "2023-09-27T20:13:54Z",
              19 "links": [{
              20 "href": "https://api-m.paypal.com/v2/payments/authorizations/6MS02512BP527144J",
              21 "rel": "self",
              22 "method": "GET"
              23 }, {
              24 "href": "https://api-m.paypal.com/v2/payments/authorizations/6MS02512BP527144J/capture",
              25 "rel": "capture",
              26 "method": "POST"
              27 }, {
              28 "href": "https://api-m.paypal.com/v2/payments/authorizations/6MS02512BP527144J/void",
              29 "rel": "void",
              30 "method": "POST"
              31 }, {
              32 "href": "https://api-m.paypal.com/v2/checkout/orders/5AT627990P285181E",
              33 "rel": "up",
              34 "method": "GET"
              35 }],
              36 "create_time": "2023-08-29T20:13:54Z",
              37 "update_time": "2023-08-29T20:13:54Z"
              38 }]
              39 }
              40 }],
              41 "payer_info": {
              42 "email": "doe@example.com",
              43 "first_name": "John",
              44 "last_name": "Doe",
              45 "payer_id": "ZU7HZ76P4VL5U",
              46 "phone": "123-456-7890",
              47 "billing_address": {
              48 "address_status": "CONFIRMED",
              49 "line1": "123 Main St.",
              50 "line2": "Suite #4",
              51 "city": "New York",
              52 "state": "NY",
              53 "postal_code": "12345",
              54 "country_code": "US"
              55 },
              56 "links": [{
              57 "href": "https://api-m.paypal.com/v2/checkout/orders/5AT627990P285181E",
              58 "rel": "self",
              59 "method": "GET"
              60 }]
              61}

              For more information about using a reference transaction to make a payment, see the Payments API Reference.

              Optional configuration

              You can add the following options to your configuration:

              Show billing agreement details

              To show details about the billing agreement that the payer approved, include the billing agreement ID in the URI:

                1curl -v -X GET https://api-m.sandbox.paypal.com/v1/billing-agreements/agreements/B-50V812176H0783741 \
                2 -H "Content-Type: application/json" \
                3 -H "Authorization: Bearer ACCESS-TOKEN"

                A successful request returns a JSON response body that shows agreement details:

                  1{
                  2 "id": "B-50V812176H0783741",
                  3 "state": "ACTIVE",
                  4 "description": "Billing Agreement",
                  5 "payer":
                  6 {
                  7 "payer_info":
                  8 {
                  9 "email": "doe@example.com",
                  10 "first_name": "John",
                  11 "last_name": "Doe",
                  12 "payer_id": "ZU7HZ76P4VL5U"
                  13 }
                  14 },
                  15 "plan":
                  16 {
                  17 "type": "MERCHANT_INITIATED_BILLING",
                  18 "merchant_preferences":
                  19 {
                  20 "notify_url": "https://example.com/notify",
                  21 "accepted_pymt_type": "INSTANT"
                  22 }
                  23 },
                  24 "links": [
                  25 {
                  26 "href": "https://api-m.sandbox.paypal.com/v1/billing-agreements/agreements/B-50V812176H0783741/cancel",
                  27 "rel": "cancel",
                  28 "method": "POST"
                  29 },
                  30 {
                  31 "href": "https://api-m.sandbox.paypal.com/v1/billing-agreements/agreements/B-50V812176H0783741",
                  32 "rel": "self",
                  33 "method": "GET"
                  34 }],
                  35 "merchant":
                  36 {
                  37 "payee_info":
                  38 {
                  39 "email": "merchant@example.com"
                  40 }
                  41 },
                  42 "create_time": "2017-08-08T07:19:28.000Z",
                  43 "update_time": "2017-08-08T07:19:28.000Z"
                  44}

                  Show token details

                  To show details for a billing agreement token, include the token in the URI:

                    1curl -v -X GET https://api-m.sandbox.paypal.com/v1/billing-agreements/agreement-tokens/BA-8A802366G0648845Y \
                    2 -H "Content-Type: application/json" \
                    3 -H "Authorization: Bearer ACCESS-TOKEN"

                    A successful request returns the HTTP 200 OK status code and a JSON response body that shows token details:

                      1{
                      2 "description": "Billing Agreement",
                      3 "token_id": "BA-8A802366G0648845Y",
                      4 "token_status": "PENDING",
                      5 "skip_shipping_address": false,
                      6 "immutable_shipping_address": true,
                      7 "redirect_urls":
                      8 {
                      9 "cancel_url": "https://example.com/cancel",
                      10 "return_url": "https://example.com/return",
                      11 "notify_url": "https://example.com/notify"
                      12 },
                      13 "plan_unit_list": [
                      14 {
                      15 "id": "BA-8A802366G0648845Y",
                      16 "billing_type": "MERCHANT_INITIATED_BILLING"
                      17 }],
                      18 "owner":
                      19 {
                      20 "merchant_id": "J6LF2WT3H97J6",
                      21 "email": "merchant@example.com"
                      22 }
                      23}

                      Show payer billing address and email

                      In some cases, you need the payer's billing address and email.

                      To return this information in the create billing agreement or show agreement details calls, select the Billing Address option in the admin dashboard. Then, the response shows the payer's billing address and email:

                        1{
                        2 "payer_info": {
                        3 "email": "doe@example.com",
                        4 "first_name": "John",
                        5 "last_name": "Doe",
                        6 "payer_id": "ZU7HZ76P4VL5U",
                        7 "phone": "123-456-7890",
                        8 "billing_address": {
                        9 "address_status": "CONFIRMED",
                        10 "line1": "123 Main St.",
                        11 "line2": "Suite #4",
                        12 "city": "New York",
                        13 "state": "NY",
                        14 "postal_code": "12345",
                        15 "country_code": "US"
                        16 }
                        17}

                        Update billing agreement

                        To update a billing agreement, specify the agreement ID in the https://api-m.sandbox.paypal.com/v1/billing-agreements/agreements/B-50V812176H0783741 URI:

                          1curl -v -X PATCH https://api-m.sandbox.paypal.com/v1/billing-agreements/agreements/B-50V812176H0783741 \
                          2 -H "Content-Type: application/json" \
                          3 -H "Authorization: Bearer ACCESS-TOKEN" \
                          4 -d '[{
                          5 "op": "replace",
                          6 "path": "/",
                          7 "value":
                          8 {
                          9 "description": "Example Billing Agreement",
                          10 "merchant_custom_data": "INV-001"
                          11 }
                          12},
                          13{
                          14 "op": "replace",
                          15 "path": "/plan/merchant_preferences/",
                          16 "value":
                          17 {
                          18 "notify_url": "https://example.com/notification"
                          19 }
                          20}]'

                          A successful request returns the HTTP 204 No Content status code with no JSON response body.

                          When you don't need to complete any more reference transactions with the billing agreement ID, you can cancel the agreement.

                          Cancel billing agreement

                          To cancel a billing agreement, specify the ID in the https://api-m.sandbox.paypal.com/v1/billing-agreements/agreements/{agreement_id}/cancel URI:

                            1curl -v -X POST https://api-m.sandbox.paypal.com/v1/billing-agreements/agreements/B-50V812176H0783741/cancel \
                            2 -H "Content-Type: application/json" \
                            3 -H "Authorization: Bearer ACCESS-TOKEN"

                            A successful request returns the HTTP 200 OK status code with no JSON response body.

                            Change the payment method

                            Set up your website to give your payers the option to change the payment method for a specific transaction.

                            Additional information

                            Reference Transactions API reference

                            We use cookies to improve your experience on our site. May we use marketing cookies to show you personalized ads? Manage all cookies