PHP: попробовать / поймать проверку банковского счета в Stripe?

Я использую 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

Решение

вот ваш код с обработкой ошибок:

<?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 цифр

похоже, ваш номер_карты (1100300) недействителен!

1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector