Reputation: 45
<?php
function pay()
{
$data = '
{
"intent":"sale",
"redirect_urls":
{
"return_url":"http://n1.lchs-is.org",
"cancel_url":"http://n1.lchs-is.org"
},
"payer":
{
"payment_method":"paypal"
},
"transactions":
[
{
"amount":
{
"total":"7.47",
"currency":"USD"
},
"description":"This is the payment transaction description."
}
]
}
';
//Start curl request
$ch = curl_init();
//Set curl options
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Bearer A101.lTxNCRX3B-vhQIN4991wdthA6SzCtPKganKXVOZta84hADs-25S5OGk4yyG-HLzR.lM-rDOIJAaEXGWhcYi2YF8yhnRy",
));
//Display results
$json = curl_exec($ch); // <------- It's displaying this array that it receives from curl right here
curl_close($ch);
}
pay();
?>
I coded this PHP code to simply create a paypal payment, and when I run it, it displays the JSON Array, even when I coded it not to. Why is this so and how can I fix this?
Also any code I typed after executing the pay()
function, is not executed. For example if I put echo "test";
that line of code is not executed.
Upvotes: 1
Views: 55
Reputation: 909
You might need to set CURLOPT_RETURNTRANSFER
For example
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // Store value in string $response below
$response = curl_exec($curl); //execute and get the results
Upvotes: 4