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

北城余情 提交于 2019-12-06 08:10:32

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