访问https://api.sandbox.paypal.com/v1/payments/payment时获得Http响应码400

时间:2022-10-14 17:30:24

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"

我使用贝宝其他sdk / api和充电我的客户然后我打电话给多个部分时间在第一次循环然后我客户的帐户记入借方但其他客户的帐户是不能记当我试着调试我发现这个错误“Http响应代码400年访问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.

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

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

如果你需要我提供任何其他信息,请告诉我。

1 个解决方案

#1


2  

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.

如果您在try / catch块中包装任何需要$apiContext的调用并检查SDK抛出的异常,那么您将更幸运地调试您的问题。我有一个函数,它很有用。

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

#1


2  

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.

如果您在try / catch块中包装任何需要$apiContext的调用并检查SDK抛出的异常,那么您将更幸运地调试您的问题。我有一个函数,它很有用。

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