This package makes it easy to handle Stripe exceptions in Laravel
How do you handle Stripe errors? Are you repeating same code again and again?
You can install the package via composer:
composer require ankurk91/laravel-stripe-exceptions
Handle Stripe charge/transfer exceptions by wrapping the API calls in try/catch like:
<?php
try {
$response = \Stripe\Charge::create([
'source' => request('source'),
'amount' => 1000,
'currency' => 'usd',
]);
} catch (\Throwable $exception) {
// send back an errored JSON response to browser
throw new \Ankurk91\StripeExceptions\ApiException($exception);
}
Handle Stripe connect exceptions:
<?php
try {
$response = \Stripe\OAuth::token([
'grant_type' => 'authorization_code',
'code' => request('code')
]);
} catch (\Throwable $exception) {
// redirect with failed error message
// `error` will be flashed in session to destination page
throw new \Ankurk91\StripeExceptions\OAuthException($exception, route('stripe.failed'));
}
You can publish the translation messages via this command
php artisan vendor:publish --provider="Ankurk91\StripeExceptions\StripeServiceProvider" --tag=translations
- Takes advantage of Laravel's inbuilt Reportable & Renderable Exceptions.
- Reports all exceptions when
APP_DEBUG
istrue
- Prevents logging of exceptions caused by user input, for example
Invalid Card
- Captures logged-in user information when an exception gets reported
If you discover any security issues, please email pro.ankurk1[at]gmail[dot]com
instead of using the issue tracker.
Please see CHANGELOG for more information what has changed recently.
The MIT License.