私はStripe PHP APIを使用しています。PHP:Stripe API単純なテキスト文字列として有用なエラーを取得していますか?
すべて正常です。しかし、私はStripe APIによって返されるエラーを簡単な読み込み可能なテキスト文字列として取得/捕捉する必要があります。私は必要なもの
これだけです -
Fatal error: Uncaught exception 'Stripe\Error\Card' with message 'Your card's security code is invalid.' in /var/www/...
:
Your card's security code is invalid.
これは私の全体のコードです:
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
require_once('stripe/init.php');
\Stripe\Stripe::setApiKey("sk_test_345345345345345345345");
$result = \Stripe\token::create(array(
"card" => array(
"name" => 'David', "number" => '4242424242424242', "exp_month" => '12', "exp_year" => '2019', "cvc" => '37674'
)
));
$token = $result['id'];
echo $token;
try {
$charge = \Stripe\Charge::create(array(
"amount" => "7000", // amount in cents, again
"currency" => "usd", "card" => $token, "description" => "[email protected]"
));
echo 'success';
} catch (\Stripe\Error\Card $e) {
// Card was declined.
$e_json = $e->getJsonBody();
$error = $e_json['error'];
echo $error;
}
?>
現在、私のコードは次のようなエラーを出力します
ご注意ください帽子これは何もしません:
catch (\Stripe\Error\Card $e) {
// Card was declined.
$e_json = $e->getJsonBody();
$error = $e_json['error'];
echo $error;
}
誰かがこれに助言していただけますか?
ありがとうございます。
EDIT:
私はすべてを試みたのだが、何もまったく機能しないことが非常にイライラさせられます。
キャッチは何もしませんし、私は私のPHPページを実行すると、それは実際にそれはそれでエラーを持っている必要があるときに常に空/ブランクで:
require_once('stripe/init.php');
\Stripe\Stripe::setApiKey("sk_test_345345345345345345345");
$result = \Stripe\token::create(array(
"card" => array(
"name" => 'David', "number" => '4242424242424242', "exp_month" => '12', "exp_year" => '2019', "cvc" => '37674'
)
));
$token = $result['id'];
echo $token;
try {
$charge = \Stripe\Charge::create(array(
"amount" => "7000", // amount in cents, again
"currency" => "usd", "card" => $token, "description" => "[email protected]"
));
echo 'success';
} catch (\Stripe\Error\Card $e) {
echo $e->getMessage();
}
への呼び出しの前に
try {
を呼び出す必要があります。 –@DavidHope、私は私の完全なストライプコードマイナス '私のサイトの関連コード'を与える私の答えを更新しました。 –
残念ながら私はストライプフォームを使用していません。すべてがサーバー側で行われています。とにかくありがとう。 –