[英]PHP: try/catch Stripe bank account verification?
我正在使用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;
}
但這並沒有真正抓住錯誤!
有人可以讓我知道如何捕獲銀行帳戶驗證錯誤嗎?
提前致謝。
這是您的錯誤處理代碼:
<?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
參數為:bank_account [routing_number]
消息是:路由號碼必須有9位數字
因此看來您的routing_number(1100300)無效!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.