curl - paypal rest api payment call returning 401 using php -
i trying add paypal site. have been following instructions @ https://developer.paypal.com/webapps/developer/docs/integration/direct/make-your-first-call/, not working. have sent request access token , gotten response. information in response stored in object called $accesstoken. problem lies when try make api call in step 3 site listed above. 401 error sent request. i'm pretty sure $url request sent function parameter correct. https://api.sandbox.paypal.com/v1/payments/payment. have been going on internet for past week , half, , haven't made progress whatsoever. appreciated. thanks!
function makepaymentapicall($accesstoken, $sale, $url, $url_success, $url_cancel){ // create curl resource $ch = curl_init(); // set url curl_setopt($ch, curlopt_url, $url); $tokentype = $accesstoken->gettokentype(); $token = $accesstoken->getaccesstoken(); $auth = "authorization:" . $tokentype . " " . $token; $saletotal = $sale->gettotal(); $header = array( 'content-type' => 'application/json', 'authorization' => $tokentype . ' ' . $token ); $dataarray = array( 'intent' => 'sale', 'redirect_urls' => array( 'return_url' => $url_success, 'cancel_url' => $url_cancel ), 'payer' => array( 'payment_method' => 'paypal' ), 'transactions' => array( 'amount' => array( 'total' => $saletotal, 'currency' => 'usd' ), 'description' => 'test payment.' ) ); curl_setopt($ch, curlopt_header, http_build_query($header)); // set data post curl_setopt($ch, curlopt_postfields, http_build_query($dataarray)); curl_setopt($ch,curlopt_returntransfer, 1); // execute curl command $output = curl_exec($ch); // info request $status = curl_getinfo($ch, curlinfo_http_code); // close curl resource free system resources curl_close($ch); return $output;
} // makepaymentapicall function
@jason247
http://php.net/manual/en/function.curl-setopt.php
i think curlopt_header requires int or bool, either 1 or true send headers.
i believe curlop_httpheader want, can pass array directly without encoding query string.
e.g.
curl_setopt($curlhandle, curlopt_header, 1); curl_setopt($curlhandle, curlopt_httpheader, $curlheaders);
Comments
Post a Comment