访问 https://api.sandbox.paypal.com/v1/payments/payment 时得到 Http 响应代码 400 [英] Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment

查看:84
本文介绍了访问 https://api.sandbox.paypal.com/v1/payments/payment 时得到 Http 响应代码 400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PayPal rest sdk/api 并向我的客户收费,但随后我在循环中多次调用收费部分,然后第一次我的客户帐户被扣款,但当我尝试调试时没有扣款其他客户的账户,我发现此错误访问 https://api.sandbox.paypal.com 时出现 Http 响应代码 400/v1/payments/payment"

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"

当循环第一次调用 Rest sdk/api 充电函数时,它会成功,但是当循环进一步运行时它会显示错误.

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.

推荐答案

如果您将任何需要 $apiContext 的调用包装在 try/catch 块中并检查 SDK 抛出的异常.我一直在使用一个有用的函数.

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;
}

如此使用:

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

这篇关于访问 https://api.sandbox.paypal.com/v1/payments/payment 时得到 Http 响应代码 400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆