简体   繁体   English

PHP:尝试/捕获Stripe银行帐户验证?

[英]PHP: try/catch Stripe bank account verification?

I'm using Stripe API and trying to verify the bank account details. 我正在使用Stripe API,并尝试验证银行帐户详细信息。

So I tried using this: 所以我试着用这个:

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

But this doesn't really catch the errors! 但这并没有真正抓住错误!

Could someone please let me know how I can catch the bank account verification errors? 有人可以让我知道如何捕获银行帐户验证错误吗?

Thanks in advance. 提前致谢。

here's your code with the error handling: 这是您的错误处理代码:

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

when you run the code it throws an InvalidRequest exception: 当您运行代码时,它将引发InvalidRequest异常:

Invalid parameters were supplied 提供了无效的参数
Status is:400 状态是:400
Type is:invalid_request_error 类型为:invalid_request_error
Param is:bank_account[routing_number] 参数为:bank_account [routing_number]
Message is:Routing number must have 9 digits 消息是:路由号码必须有9位数字

so it looks like your routing_number (1100300) is invalid! 因此看来您的routing_number(1100300)无效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM