Reputation: 4236
I'm using PayPal REST API to create agreement. I wonder why there is no id in the response when billing agreement is created. Only execute token is present in return_url.
When payment is created an id is returned.
Request
POST https://api.sandbox.paypal.com/v1/payments/billing-agreements HTTP/1.1
Content-Type: application/json
User-Agent: PayPalSDK/rest-sdk-dotnet 0.11.0 (core=1.6.0;lang=DOTNET;v=4.5;clr=4.0.30319.34014;bit=64;os=Microsoft Windows NT 6.2.9200.0)
Authorization: Bearer A015NObhWZJY-ZZHdSmMvYL7GFA6A-pY7pK4zV1J8wysWJE
PayPal-Request-Id: 98a56a18-2306-4301-a366-e53a5db54536
Host: api.sandbox.paypal.com
Content-Length: 246
Expect: 100-continue
{"name":"plan \"PN123\" subscription","description":"plan \"PN123\" subscription with payments every 12 months.","start_date":"2015-02-06T16:58:56z","payer":{"payment_method":"paypal"},"plan":{"id":"P-2Y404528U1543832BL7HBW6A"}}
Pretty Request Json
{
"name":"A plan \"PN123\" subscription",
"description":"plan \"PN123\" subscription with payments every 12 months.",
"start_date":"2015-02-06T16:58:56z",
"payer":{
"payment_method":"paypal"
},
"plan":{
"id":"P-2Y404528U1543832BL7HBW6A"
}
}
Response
HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbplatformapiserv3001.slc.paypal.com;threadId=374466
Paypal-Debug-Id: 739b28e849ee7
SERVER_INFO: paymentsplatformserv:v1.payments.billing-agreements&CalThreadId=501225&TopLevelTxnStartTime=14b5fce3a78&Host=slcsbpaymentsplatformserv3001.slc.paypal.com&pid=22725
Content-Language: *
Date: Fri, 06 Feb 2015 16:52:05 GMT
Content-Type: application/json
Content-Length: 1174
Pretty json from response
{
"name":"plan \"PN123\" subscription",
"description":"plan \"PN123\" subscription with payments every 12 months.",
"plan":{
"id":"P-2Y404528U1543832BL7HBW6A",
"state":"ACTIVE",
"name":"PN123",
"description":"plan \"PN123\" subscription",
"type":"INFINITE",
"payment_definitions":[
{
"id":"PD-8RD12495MY6350633L7HBW6I",
"name":"Regular Payments",
"type":"REGULAR",
"frequency":"Month",
"amount":{
"currency":"USD",
"value":"20"
},
"cycles":"0",
"charge_models":[
],
"frequency_interval":"12"
}
],
"merchant_preferences":{
"setup_fee":{
"currency":"USD",
"value":"0"
},
"max_fail_attempts":"0",
"return_url":"http://example.com/Subscription/Renew.aspx?result=ApproveAgreement",
"cancel_url":"http://example.com/Subscription/Renew.aspx?result=CancelAgreement",
"auto_bill_amount":"NO",
"initial_fail_amount_action":"CONTINUE"
}
},
"links":[
{
"href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-4R936998H4630535M",
"rel":"approval_url",
"method":"REDIRECT"
},
{
"href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/EC-4R936998H4630535M/agreement-execute",
"rel":"execute",
"method":"POST"
}
],
"start_date":"2015-02-06T16:58:56z"
}
Upvotes: 0
Views: 655
Reputation: 1489
You will get the Id when the payment gets executed, on paypal as your payment type.
You could run the samples attached with the PayPal-PHP-SDK, to try out before implementing the code yourself. Also, most of the sample code could be copy-pasted to get started easily.
Here are the screen shots from the samples:
1. Created Agreement. Use the URL pointed in dark black line
2. Executed Agreement. As you can see, it has the agreement ID.
Upvotes: 2