Unprocessable Entity when creating order from Billing Agreement

brianzammit
Contributor
Contributor

Hello,

I was trying to follow the following Guide to create an order and capture payment for it from a billing agreement. So far I managed to use the Billing Agreement to create payments using the deprecated `/v1/payments/payment` API, but when creating the order I am getting a 422 response with error `

NO_PAYMENT_SOURCE_PROVIDED` (see step 4 below).


Steps:
1. Create Agreement Token Request:

Spoiler
POST https://api-m.sandbox.paypal.com/v1/billing-agreements/agreement-tokens


Request Body:
{
  "description""Billing Agreement Description",
  "payer":
  {
    "payment_method""PAYPAL"
  },
  "plan":
  {
    "type""MERCHANT_INITIATED_BILLING",
    "merchant_preferences":
    {
      "return_url""https://example.com/return",
      "cancel_url""https://example.com/cancel",
      "notify_url""https://example.com/notify",
      "accepted_pymt_type""INSTANT",
      "skip_shipping_address"true
    }
  }
}

Response (201):

{
    "token_id""BA-7AC53308L08744613",
    "links": [
        {
            "rel""approval_url",
            "method""POST"
        },
        {
            "rel""self",
            "method""POST"
        }
    ]
}



 2. Agreement approved as a buyer

3. Agreement Created from Agreement Token

Spoiler
POST https://api-m.sandbox.paypal.com/v1/billing-agreements/agreements

Request Body:

{
  "token_id""BA-7AC53308L08744613"
}


Response (201):

{
    "id""B-9BS46477KS1858732",
    "state""ACTIVE",
    "description""Billing Agreement Description",
    "merchant": {
        "payee_info": {
            "email""sb-xw[Removed. Phone #s not permitted]business.example.com"
        }
    },
    "payer": {
        "payer_info": {
            "email""s[Removed. Phone #s not permitted]pan>
            "first_name""John",
            "last_name""Doe",
            "payer_id""TNBDVWE3D5AS8",
            "tenant""PAYPAL"
        }
    },
    "plan": {
        "type""MERCHANT_INITIATED_BILLING",
        "merchant_preferences": {
            "notify_url""https://example.com/notify",
            "accepted_pymt_type""INSTANT",
            "multi_factor_activation"false,
            "req_billing_address"false
        }
    },
    "create_time""2023-02-09T10:14:23.000Z",
    "update_time""2023-02-09T10:14:23.000Z",
    "links": [
        {
            "rel""cancel",
            "method""POST"
        },
        {
            "rel""self",
            "method""GET"
        }
    ]
}

4. Attempt to create order from Billing Agreement:

Spoiler
POST https://api-m.sandbox.paypal.com/v2/checkout/orders


Request Body:


{
  "intent""CAPTURE",
  "purchase_units": [
    {
      "amount": {
        "currency_code""USD",
        "value""55.00"
      }
    }
  ],
  "payment_source": {
      "token:": {
          "type""BILLING_AGREEMENT",
          "id""B-9BS46477KS1858732"
      }
  }
}



Response (422):

{
    "name""UNPROCESSABLE_ENTITY",
    "details": [
        {
            "field""/payment_source",
            "issue""NO_PAYMENT_SOURCE_PROVIDED",
            "description""NO_PAYMENT_SOURCE_PROVIDED"
        }
    ],
    "message""The requested action could not be performed, semantically incorrect, or failed business validation.",
    "debug_id""cbed6471d8f2e",
    "links": [
        {
            "rel""information_link",
            "method""GET"
        }
    ]
}

 
Your help would be greatly appreciated. Thanks.

Best regards,
Brian

Login to Me Too
5 REPLIES 5

MTS_Jennifer
Moderator
Moderator

Hello @brianzammit ,

Thank you for posting to the PayPal Community.

Here is another way you can use the billing agreement to process a payment:

https://developer.paypal.com/limited-release/reference-transactions/#link-useareferencetransactionto...

POST https://api-m.sandbox.paypal.com/v1/payments/payment
{
  "intent": "sale",
  "payer":
  {
    "payment_method": "PAYPAL",
    "funding_instruments": [
    {
      "billing":
      {
        "billing_agreement_id": "B-9BS46477KS1858732"
      }
    }]
  },
  "transactions": [
  {
    "amount":
    {
      "currency": "USD",
      "total": "55.00"
    },
    "description": "Payment transaction.",
    "custom": "Payment custom field.",
    "note_to_payee": "Note to payee field.",
    "invoice_number": "invoice777",
    "item_list":
    {
      "items": [
      {
        "sku": "skuitemNo1",
        "name": "ItemNo1",
        "description": "The item description.",
        "quantity": "1",
        "price": "55.00",
        "currency": "USD",
        "tax": "0",
        "url": "https://example.com/"
      }]
    }
  }],
  "redirect_urls":
  {
    "return_url": "https://example.com/return",
    "cancel_url": "https://example.com/cancel"
  }

 Thanks,

Jennifer

MTS

PayPal

Login to Me Too

brianzammit
Contributor
Contributor

Hello @MTS_Jennifer ,

Thank you for your reply! As indicated in my message, I have already managed to use the billing agreement to process a payment using the `v1/payments` API.
However, I was trying to work with the `v2/orders` API to avoid integrating with the deprecated `v1/payments` API. According to the documentation:

 


You pass the ID of the billing agreement in the JSON request body of a /v1/payments/payment call or a v2/orders call.


Is it possible to please clarify whether such integration should work, and maybe refer me to some additional documentation?

Thanks.
Brian



Login to Me Too

brianzammit
Contributor
Contributor

Hello @MTS_Jennifer ,

Any updates on the above please?

Thanks.
Brian

Login to Me Too

MTS_Jennifer
Moderator
Moderator

Hello @brianzammit ,

I did some testing, after you have the billing agreement id. Create an order like you normally would with orders v2 api.

 

https://api.sandbox.paypal.com/v2/checkout/orders POST with access_token
{
  "intent": "CAPTURE",
    
  "purchase_units": [
    {
        "amount": {
        "currency_code": "USD",
        "value": "100.00"
       
      },

      "shipping": {
                "name": {
                    "full_name": "John Doe"
                },
                "address": {
                    "address_line_1": "123  W Main St",
                    "admin_area_2": "San Jose",
                    "admin_area_1": "CA",
                    "postal_code": "95112",
                    "country_code": "US"
                }
            }
         }
      ],

"application_context" : {
			"return_url" : "http://www.example.com",
			"cancel_url" : "http://cancel_url.com",
            "error_url" : "http://errorurl.com",
            "shipping_preference" : "SET_PROVIDED_ADDRESS"
           
        }
		}

 

Then in the Capture Call include the billing agreement as seen in below example:

 

POST https://api.sandbox.paypal.com/v2/checkout/orders/{{order_id}}/capture
{
    "payment_source": {
        "token": {
        "id": "B-5SP65488AJ588XXXXX",
        "type": "BILLING_AGREEMENT"
        }
    }
}

 

Thanks,

Jennifer

MTS

PayPal

 

Login to Me Too

brianzammit
Contributor
Contributor

Thanks @MTS_Jennifer .

Will try it out and get back to you if I encounter any further issues.

Best regards,
Brian

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.