This works perfectly on the command line:
curl -v https://api.sandbox.paypal.com/v1/payments/payment \
-H "Content-Type:application/json" \
-H "Authorization:Bearer <authkey>" \
-d '{"intent":"sale","redirect_urls":{"return_url":"https:\/\/devtools-paypal.com\/guide\/pay_paypal\/curl?success=true","cancel_url":"https:\/\/devtools-paypal.com\/guide\/pay_paypal\/curl?cancel=true"},"payer":{"payment_method":"paypal"},"transactions":[{"amount":{"total":"7.47","currency":"USD"},"description":"This is the payment transaction description."}]}'
and then in php I have the following
<?php
$ch = curl_init("https://api.sandbox.paypal.com/v1/payments/payment");
curl_setopt($ch, CURLOPT_ENCODING, "Content-Type:application/json");
curl_setopt($ch, CURLOPT_ENCODING, "Authorization:Bearer <authkey>");
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"intent":"sale","redirect_urls":{"return_url":"https:\/\/devtools-paypal.com\/guide\/pay_paypal\/curl?success=true","cancel_url":"https:\/\/devtools-paypal.com\/guide\/pay_paypal\/curl?cancel=true"},"payer":{"payment_method":"paypal"},"transactions":[{"amount":{"total":"7.47","currency":"USD"},"description":"This is the payment transaction description."}]}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = json_decode(curl_exec($ch));
curl_close($ch);
?>
<pre>
<?php print_r($res); ?>
</pre>
However this only prints <pre></pre>
and no response whatsoever. Why is this happening?