douchong4730 2014-03-20 18:07
浏览 42
已采纳

Paypal经典API:php CURL失败

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'=>'primaryreceiver1@test.com',
    'receiverList.receiver(0).primary'=>'true',
    'receiverList.receiver(1).amount'=>'5.00',
    'receiverList.receiver(1).email'=>'secondaryreceiver1@test.com ',
    '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?

  • 写回答

2条回答 默认 最新

  • dongli2000 2014-03-20 18:19
    关注

    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('primaryreceiver1@test.com');
    // 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'

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮