我正在使用Stripe API并尝试验证银行帐户详细信息。
所以我尝试使用它:
try {
$bank = \Stripe\Token::create(array(
"bank_account" => array(
"object" => "bank_account",
"country" => "US",
"currency" => "usd",
"account_holder_name" => 'SOme name',
"account_holder_type" => 'individual',
"routing_number" => "1100300",
"account_number" => "000123456"
)
));
$bankID = $bank['id'];
echo $bankID;
} catch (\Stripe\Error\Card $e) {
// handle errors
$error1 = $e->getMessage();
echo $error1;
}catch (Stripe_Error $e) {
// Invalid parameters were supplied to Stripe's API
$error2 = $e->getMessage();
echo $error2;
}
但这并没有真正发现错误!
有人可以告诉我如何查看银行帐户验证错误吗?
提前致谢。
答案 0 :(得分:1)
这是你的错误处理代码:
<?php
include 'vendor/autoload.php';
try {
\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
// Use Stripe's library to make requests...
$bank = \Stripe\Token::create(
array(
"bank_account" => array(
"object" => "bank_account",
"country" => "US",
"currency" => "usd",
"account_holder_name" => 'Some name',
"account_holder_type" => 'individual',
"routing_number" => "1100300",
"account_number" => "000123456"
)
)
);
} catch(\Stripe\Error\Card $e) {
// Since it's a decline, \Stripe\Error\Card will be caught
echo 'Decline' . "\n";
$body = $e->getJsonBody();
$err = $body['error'];
print('Status is:' . $e->getHttpStatus() . "\n");
print('Type is:' . $err['type'] . "\n");
print('Code is:' . $err['code'] . "\n");
// param is '' in this case
print('Param is:' . $err['param'] . "\n");
print('Message is:' . $err['message'] . "\n");
} catch (\Stripe\Error\RateLimit $e) {
// Too many requests made to the API too quickly
echo 'Too many requests' . "\n";
} catch (\Stripe\Error\InvalidRequest $e) {
// Invalid parameters were supplied to Stripe's API
echo 'Invalid parameters were supplied' . "\n";
$body = $e->getJsonBody();
$err = $body['error'];
print('Status is:' . $e->getHttpStatus() . "\n");
print('Type is:' . $err['type'] . "\n");
// param is '' in this case
print('Param is:' . $err['param'] . "\n");
print('Message is:' . $err['message'] . "\n");
} catch (\Stripe\Error\Authentication $e) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
echo 'Authentication failed' . "\n";
$message = $e->getMessage();
print('Message is:' .$message);
} catch (\Stripe\Error\ApiConnection $e) {
// Network communication with Stripe failed
echo 'Network communication failed' . "\n";
} catch (\Stripe\Error\Base $e) {
// Display a very generic error to the user, and maybe send
// yourself an email
echo 'Display a very generic error to the user' . "\n";
} catch (Exception $e) {
// Something else happened, completely unrelated to Stripe
echo 'Something else happened' . "\n";
}
当您运行代码时,它会抛出InvalidRequest异常:
提供的参数无效
现状是:400
输入为:invalid_request_error
Param是:bank_account [routing_number]
消息是:路由号码必须有9位数
所以看起来你的routing_number(1100300)无效!