Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment

☆樱花仙子☆ 提交于 2019-12-22 18:06:48

问题


I am using PayPal rest sdk/api and charging to my customers but then i am calling charge section multiple time in loop then at first time my customer's account is debited but other customer's account is not debited when i tried to debug i found this error "Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment"

As when loop calls first time the Rest sdk/api charge function then it get success but the it showing error when loop runs further.

Please let me know if you want any other information from my side.


回答1:


You'll have better luck debugging your issue if you wrap any calls which require an $apiContext in a try / catch block and examine the exceptions that the SDK throws. I have a function I've been using for this that's been helpful.

function PaypalError($e){

    $err = "";

    do {
        if (is_a($e, "PayPal\Exception\PayPalConnectionException")){
            $data = json_decode($e->getData(),true);
            $err .= $data['name'] . " - " . $data['message'] . "<br>";
            if (isset($data['details'])){
                $err .= "<ul>";
                foreach ($data['details'] as $details){
                    $err .= "<li>". $details['field'] . ": " . $details['issue'] . "</li>";
                }
                $err .= "</ul>";
            }
        }else{
            //some other type of error
            $err .= sprintf("%s:%d %s (%d) [%s]\n", $e->getFile(), $e->getLine(), $e->getMessage(), $e->getCode(), get_class($e));
        }
    } while($e = $e->getPrevious());

    return $err;
}

Used thusly:

try{
    $Payment->create($apiContext); //or any similar calls
}catch(Exception $e){
    echo PaypalError($e);
}


来源:https://stackoverflow.com/questions/29161899/got-http-response-code-400-when-accessing-https-api-sandbox-paypal-com-v1-paym

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!