I'm a bit late to the party but I found this in the PayPal docs
PayPal payments involve these 3 steps:
- Specify payment information to create a payment.
- Get payment approval.
- Execute the payment to the PayPal user's account.
1) Set the intent to sale
, and the payment_method to paypal
.
Include redirect URLs. The user is redirected to these URLs when they either approve or cancel the payment.
curl https://api.sandbox.paypal.com/v1/payments/payment \
-v \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer accessToken' \
-d '{
"intent":"sale",
"redirect_urls":{
"return_url":"http://return_URL_here",
"cancel_url":"http://cancel_URL_here"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD"
},
"description":"This is the payment transaction description."
}
]
}
Response:
{
"id":"PAY-6RV70583SB702805EKEYSZ6Y",
"create_time":"2013-03-01T22:34:35Z",
"update_time":"2013-03-01T22:34:36Z",
"state":"created",
"intent":"sale",
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD",
"details":{
"subtotal":"7.47"
}
},
"description":"This is the payment transaction description."
}
],
"links":[
{
"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RV70583SB702805EKEYSZ6Y",
"rel":"self",
"method":"GET"
},
{
"href":"https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=EC-60U79048BN7719609",
"rel":"approval_url",
"method":"REDIRECT"
},
{
"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RV70583SB702805EKEYSZ6Y/execute",
"rel":"execute",
"method":"POST"
}
]
}
2) Get payment approval
Please note the HATEOAS links in the example above. Direct the user to the approval_url
on the PayPal site, so that the user can approve the payment. The user must approve the payment before you can execute and complete the sale.
3) Execute the payment
When the user approves the payment, PayPal redirects the user to the return_url that was specified
when the payment was created. A payer Id and payment Id are appended to the return URL, as PayerID
and paymentId
:
http://return_url?paymentId=PAY-6RV70583SB702805EKEYSZ6Y&token=EC-60U79048BN7719609&PayerID=7E7MGXCWTTKK2
The token value appended to the return URL is not needed when you execute the payment.
To execute the payment after the user's approval, make a /payment/execute/
call. In the body of the request, use the payer_id
value that was appended to the return URL. In the header, use the access token that you used when you created the payment.
curl https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RV70583SB702805EKEYSZ6Y/execute/ \
-v \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer accessToken' \
-d '{ "payer_id" : "7E7MGXCWTTKK2" }'
Note: Once a payment is complete, it is referred to as a sale. You can then look up the sale and refund it.
Hope it helps!