Making Paypal payment using REST API in PHP Making Paypal payment using REST API in PHP curl curl

Making Paypal payment using REST API in PHP


Try something like this, -d is the data you want to post. custom headers are set with CURLOPT_HTTPHEADER.

$data = '{  "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."    }  ]}';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 EOjEJigcsRhdOgD7_76lPfrr45UfuI43zzNzTktUk1MK",   "Content-length: ".strlen($data)));

Have a look at the options here, http://php.net/manual/en/function.curl-setopt.php Set curl_setopt($ch, CURLOPT_HEADER, false); for example if you dont need the headers returned.