Reputation: 758
I am trying to setup a parallel payment using the paypal classic API. However, I am getting massive errors.
I have 2 test accounts setup in the sandbox as well as a classic application.
I am using PHP CURL to initiate the request. I updated the CURL code from the doc to php curl.
My PHP code as as follow:
$headers = array(
"X-PAYPAL-SECURITY-USERID: XXXXXX" ,
"X-PAYPAL-SECURITY-PASSWORD: XXXXXX",
"X-PAYPAL-SECURITY-SIGNATURE: XXXXXX" ,
"X-PAYPAL-REQUEST-DATA-FORMAT: NV",
"X-PAYPAL-RESPONSE-DATA-FORMAT: NV",
"X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T",
);
$post_array = array(
'actionType'=>'PAY',
'clientDetails.applicationId'=>'APP-80W284485P519543T',
'currencyCode'=>'USD',
'feesPayer'=>'SECONDARYRECEIVER',
'receiverList.receiver(0).amount'=>'5.00',
'receiverList.receiver(0).email'=>'[email protected]',
'receiverList.receiver(0).primary'=>'true',
'receiverList.receiver(1).amount'=>'5.00',
'receiverList.receiver(1).email'=>'[email protected] ',
'receiverList.receiver(1).primary'=>'false',
'requestEnvelope.errorLanguage'=>'en_US',
'ipnNotificationUrl'=>'http://www.yourdomain.com/ipn_myreceiver',
'returnUrl'=>'http://www.yourdomain.com/success',
'cancelUrl'=>'http://www.yourdomain.com/cancel',
);
$url = 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay';
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL,$url);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_POST, 1);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, http_build_query($post_array));
curl_setopt($curl_session, CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($curl_session, CURLOPT_TIMEOUT, 10);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_session, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($curl_session);
echo $response;
I am getting the following error response:
responseEnvelope.timestamp=2014-03-20T11%3A35%3A58.520-07%3A00&responseEnvelope.ack=Failure&responseEnvelope.correlationId=db88a73f724a0&responseEnvelope.build=10175386&error(0).errorId=580022&error(0).domain=PLATFORM&error(0).subdomain=Application&error(0).severity=Error&error(0).category=Application&error(0).message=Invalid+request+parameter%3A+email+secondaryreceiver1%40test.com++is+invalid&error(0).parameter(0)=email&error(0).parameter(1)=secondaryreceiver1%40test.com+
What is wrong?
Upvotes: 0
Views: 406
Reputation: 123
Try using http_build_query for the post fields. I usually have success with that.
so something like
$post = array('actionType' => "PAY", 'value2 => "etc etc etc );
Then in your curl options
curl_setopt($curl_session, CURLOPT_POSTFIELDS, http_build_query($post));
Upvotes: 0
Reputation: 39355
At the curl's CURLOPT_POSTFIELDS
You are doing url encoding on the whole $parameter
, which is wrong urlencode($post)
.
For http POST the url encoding is done on this way:
$param = "key1=".urlencode($value1);
$param = $param . "&" . "key2=".urlencode($value2);
$param = $param . "&" . ".email=".urlencode('[email protected]');
// and so on.
So change your POST parameters urlencoding
according to above one and then try again.
Note: if your key1, key2, etc has special character then you have to do urlencode on them as well. For example if it is xyz%32=value1
the you have to use it like urlencode('xyz%32').'=value1'
Upvotes: 1