问题
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