As the title suggest I am trying to make a CURL call to Paypal, but I have come across an error that I believe has to do with the way I am sending my headers via CURL.
In the code example below I am declaring to two arrays with the values Paypal requires to process the request. $headers
will be used in the CURL request as the CURLOPT_HTTPHEADER
, and $URLvariable
will be concatenated with $url
and be used as the CURLOPT_URL
.
Code Example:
$headers = array(
'X-PAYPAL-SECURITY-USERID : MYSSANDBOXUSERID',
'X-PAYPAL-SECURITY-PASSWORD : MYSSANDBOXPASSWORD',
'X-PAYPAL-SECURITY-SIGNATURE : MYSSANDBOXUSERSIGNATURE',
'X-PAYPAL-REQUEST-DATA-FORMAT : JSON',
'X-PAYPAL-RESPONSE-DATA-FORMAT : JSON',
'X-PAYPAL-APPLICATION-ID : APP-80W284485P519543T'
);
$URLvariable = array (
'scope' => 'EXPRESS_CHECKOUT',
'callback' => 'http://vendorpages.info/success.html',
'requestEnvelope' => '{"errorLanguage":"en_US"}',
);
foreach ( $URLvariable as $key => $value ) {
$URLvariable .= '&' . $key . '=' . urlencode ( $value );
}
$url = "https://svcs.sandbox.paypal.com/Permissions/RequestPermissions?" . ltrim ( $URLvariable, '&' );
$curl = curl_init ();
curl_setopt ( $curl, CURLOPT_URL, $url );
curl_setopt( $curl , CURLOPT_HEADER, true);
curl_setopt( $curl , CURLOPT_HTTPHEADER, $headers);
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, false );
$result = curl_exec ( $curl );
curl_close ( $curl );
$result = urldecode ( $result );
$result = explode ( '=',$result );
print_r ($result);
*Please note I have replaced my Paypal sandbox credentials on purpose.
The output of which is:
Array ( [0] => HTTP/1.1 400 Bad Request Server: AkamaiGHost Mime-Version: 1.0 Content-Type: text/html Content-Length: 177 Expires: Sat, 08 Feb 2014 09:47:53 GMT Date: Sat, 08 Feb 2014 09:47:53 GMT Connection: close An error occurred while processing your request.
Reference #166.c60300cc.1391852873.2b18ca34 )
Any constructive help is appreciated...