How to get the Agreement ID on creation of REST API

MABS-Inp
Contributor
Contributor
Hello, i'm trying to create a new billing agreement with my customers using the REST API and the PHP-SDK. Then I'll request the API to create a new agreement, passing a correct plan-ID, i'll get this response: { "name": "Base Agreement", "description": "Basic Agreement", "start_date": "2018-08-15T13:32:38+00:00", "plan": { "id": "P-1JR66297L7128100YH******", "state": "ACTIVE", "name": "Test Workflow", "description": "Test Workflow", "type": "INFINITE", "payment_definitions": [{ "id": "PD-0HN28616CR5245516H******", "name": "Monatliche Rechnung", "type": "REGULAR", "frequency": "Month", "amount": { "currency": "EUR", "value": "100" }, "cycles": "0", "charge_models": [], "state": null, "frequency_interval": "1" }], "merchant_preferences": { "setup_fee": { "currency": "EUR", "value": "0" }, "max_fail_attempts": "0", "return_url": "http://localhost/frontend/ExecuteAgreement.php?success=true", "cancel_url": "http://localhost/frontend/ExecuteAgreement.php?success=false", "notify_url": null, "id": null, "state": null, "auto_bill_amount": "NO", "initial_fail_amount_action": "CONTINUE", "accepted_payment_type": null, "char_set": null } }, "links": [{ "href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-27336791K47******", "rel": "approval_url", "method": "REDIRECT" }, { "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/EC-27336791K47******/agreement-execute", "rel": "execute", "method": "POST" }] } As you can see, the agreement is correctly created, but there is no id of the agreement. If i'll call the approval-url, it takes me correctly to the PayPal Loginpage. But also on return to my server i don't get any hint about the agreement id. How do i get it? In the Developer Docs it is mentioned, that there should be a field id, but it is not there. A bug in the API or do i make something wrong? PayPal-Debug-ID: 283eb878ec5d1
Login to Me Too
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

MTS_Justin
Moderator
Moderator
The ID when creating a billing agreement is only returned after you execute the agreement. 1. Create billing plan - https://developer.paypal.com/docs/api/payments.billing-plans/v1/#billing-plans_create 2. Activate billing plan - https://developer.paypal.com/docs/api/payments.billing-plans/v1/#billing-plans_update 3. Create billing agreement - https://developer.paypal.com/docs/api/payments.billing-agreements/v1/#billing-agreements_create 4. Redirect buyer to approve agreement (using redirect URL provided in response of 'create billing agreement' 5. Execute the agreement (passing the EC token returned after buyer approval) 6. The "ID" will be returned in the response and starts with "I-XXXXXXX", as shown in the example for 'execute a billing agreement' - https://developer.paypal.com/docs/api/payments.billing-agreements/v1/#billing-agreements_execute

Was my post helpful? If so, please give me a kudos!

View solution in original post

Login to Me Too
8 REPLIES 8
Solved

MTS_Justin
Moderator
Moderator
The ID when creating a billing agreement is only returned after you execute the agreement. 1. Create billing plan - https://developer.paypal.com/docs/api/payments.billing-plans/v1/#billing-plans_create 2. Activate billing plan - https://developer.paypal.com/docs/api/payments.billing-plans/v1/#billing-plans_update 3. Create billing agreement - https://developer.paypal.com/docs/api/payments.billing-agreements/v1/#billing-agreements_create 4. Redirect buyer to approve agreement (using redirect URL provided in response of 'create billing agreement' 5. Execute the agreement (passing the EC token returned after buyer approval) 6. The "ID" will be returned in the response and starts with "I-XXXXXXX", as shown in the example for 'execute a billing agreement' - https://developer.paypal.com/docs/api/payments.billing-agreements/v1/#billing-agreements_execute

Was my post helpful? If so, please give me a kudos!
Login to Me Too

MABS-Inp
Contributor
Contributor

Thank you Justin,

i checked your solution and finally got an ID as expected. Nevertheless i have to say, the documentation is not correct about that behaviour. Look here:
https://developer.paypal.com/docs/api/payments.billing-agreements/v1/#billing-agreements-create-resp...

There should be an explanation about this workflow. At the moment it says, that you have to create an agreement and will get an ID as response:

 

A successful request returns the HTTP 201 Created status code and a JSON response body that shows billing agreement details including a billing agreement id and redirect links to get the buyer's approval.

 

There is nowhere a hint about the need to execute the agreement before you get an ID.

Login to Me Too

MTS_Justin
Moderator
Moderator
The ID when creating a billing agreement is only returned after you execute the agreement. 1. Create billing plan - https://developer.paypal.com/docs/api/payments.billing-plans/v1/#billing-plans_create 2. Activate billing plan - https://developer.paypal.com/docs/api/payments.billing-plans/v1/#billing-plans_update 3. Create billing agreement - https://developer.paypal.com/docs/api/payments.billing-agreements/v1/#billing-agreements_create 4. Redirect buyer to approve agreement (using redirect URL provided in response of 'create billing agreement' 5. Execute the agreement (passing the EC token returned after buyer approval) 6. The "ID" will be returned in the response and starts with "I-XXXXXXX", as shown in the example for 'execute a billing agreement' - https://developer.paypal.com/docs/api/payments.billing-agreements/v1/#billing-agreements_execute

Was my post helpful? If so, please give me a kudos!
Login to Me Too

MTS_Justin
Moderator
Moderator
Apologies for the formatting - It's a system issue we're working to resolve

Was my post helpful? If so, please give me a kudos!
Login to Me Too

GlobalIPTel
New Community Member

Hi everybody,
unless I understand and use these step to create a billing-plan /agreement, there is no possibilty in this prosess to find a correlation between PlanID and AgreementID.
Thus creating an agreement assumes that a billing plan will be created and getting a PlanID as response. Creating the agreement will NOT return its ID until the Agreement is executed, response return than the AgreementID.
BUT, in the returning Agreement the Plan object is NULL, so I cannot get any correlation between my created plan/agreement and the executed Agreement.
Please fix.
Using the PayPal .NET SDK v 1.9.1
Kind regars

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.