ankurk91 / laravel-stripe-exceptions
Handle Stripe exceptions gracefully in Laravel php framework.
Installs: 7 755
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.2.0
- illuminate/http: ^10.0 || ^11.0
- illuminate/support: ^10.0 || ^11.0
- illuminate/translation: ^10.0 || ^11.0
- stripe/stripe-php: ^12.0 || ^13.0 || ^14.0 || ^15.0 || ^16.0
Requires (Dev)
- mockery/mockery: ^1.4
- orchestra/testbench: ^8.0 || ^9.0
- phpunit/phpunit: ^9.5.10 || ^10.0
README
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?
Installation
You can install the package via composer:
composer require ankurk91/laravel-stripe-exceptions
Usage
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')); }
Modifying error messages
You can publish the translation messages via this command
php artisan vendor:publish --provider="Ankurk91\StripeExceptions\StripeServiceProvider" --tag=translations
Features
- 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
Security
If you discover any security issues, please email pro.ankurk1[at]gmail[dot]com
instead of using the issue tracker.
Changelog
Please see CHANGELOG for more information what has changed recently.
License
The MIT License.