Rest API to create Payment not working

xicomxicom
Contributor
Contributor

 

Hi ,


I am using Paypal Rest API to create a payment from Backend.

I am using following API https://api.sandbox.paypal.com/v1/payments/payment 
and passing following value in Body:-

{
"intent":"sale",
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"30.11",
"currency":"USD"
},
"description":"The payment transaction description."
}
],
"redirect_urls": {
"return_url": "http://demo.xicom.us/MenuVenue",
"cancel_url": "http://demo.xicom.us/MenuVenue/"
}
}

and in header: Content-Type and Authorization: Bearer A21AAEsFea7tEoxxaeubbyMoLOor54HcO-LIAGj04OZwZJvKLdlNOHLbfQbG7RZW0TM6m31zroNYTFJvrU8a5AkffviTsHSbw




Now i am getting following response:-

{
"id": "PAY-4X031858JA230544GLDOKN3I",
"intent": "sale",
"state": "created",
"payer": {
"payment_method": "paypal"
},
"transactions": [
{
"amount": {
"total": "30.11",
"currency": "USD"
},
"description": "The payment transaction description.",
"related_resources": []
}
],
"create_time": "2017-03-30T06:34:21Z",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-4X031858JA230544GLDOKN3I",
"rel": "self",
"method": "GET"
},
{
"href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-5M454466X13926703",
"rel": "approval_url",
"method": "REDIRECT"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-4X031858JA230544GLDOKN3I/execute",
"rel": "execute",
"method": "POST"
}
]
}


but the PAyment not showing in the Sandbox account of buyer.

How user generate the payment can you please explain this.


Thanks & Regards
Vivek

Login to Me Too
4 REPLIES 4

MTS_Ciaran
Moderator
Moderator

hey, Welcome to the community. 

 

This API call just creates the payment attempt. In order to complete you still need to have the buyer redirect to PayPal i.e. the URL in this section of the response:

 

{
"href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-5M454466X13926703",
"rel": "approval_url",
"method": "REDIRECT"
},

 

Once the approve the payment, they will be redirected back to your previously set returnURL, where you execute the payment:

 

https://developer.paypal.com/docs/integration/direct/express-checkout/execute-payments/

Login to Me Too

xicomxicom
Contributor
Contributor

Hey,


We are using Mobile Application as frontend and then payment create from backend(PHP) using API.

We are generatting client_meta_id the from IOS APP then using this meta id we create payment.

 

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.sandbox.paypal.com/v1/payments/payment",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{ \n \"intent\":\"sale\",\n \"payer\":{ \n \"payment_method\":\"paypal\"\n },\n \"transactions\":[ \n { \n \"amount\":{ \n \"total\":\"30.11\",\n \"currency\":\"USD\"\n },\n \"description\":\"The payment transaction description.\"\n }\n ],\n \"redirect_urls\": {\n \"return_url\": \"http://demo.xicom.us/MenuVenue\",\n \"cancel_url\": \"http://demo.xicom.us/MenuVenue/\"\n }\n}\n",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer A21AAEsFea7tEoxxaeubbyMoLOor54HcO-LIAGj04OZwZJvKLdlNOHLbfQbG7RZW0TM6m31zroNYTFJvrU8a5AkffviTsHSbw",
"cache-control: no-cache",
"clientmetadataid: fe2eeffb188c4fcbaae36ef2125ce4b8",
"content-type: application/json",
"postman-token: 2dbf12f5-2fdc-bdbf-cf3c-a7fb08dd6b2d"
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $resp

}



Login to Me Too

xicomxicom
Contributor
Contributor

When we check buyer account then there is no record added.


How PAYPAL know that amount will deducted from which account? becouse if we pass without meta_id or with meta id, we are  getting same response in both cases

can you please clarify this.

Thanks

Login to Me Too

MTS_Ciaran
Moderator
Moderator

Responded on the other thread 🙂

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.