teamtnt / php-stripe-webhook-tester
A PHP package for testing Stripe Webhooks localy
Installs: 76 922
Dependents: 0
Suggesters: 0
Security: 0
Stars: 98
Watchers: 5
Forks: 24
Open Issues: 2
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ^6.1
Requires (Dev)
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
README
The goal of this package is to make testing stripe webhooks easy on a local machine without the use
of ngrok or other similar tunneling services. The package will simulate a post
request to a specified
endpoint with a json containing event data and make sure that your application reacts accordingly.
Install
Via Composer
$ composer require TeamTNT/php-stripe-webhook-tester
Usage
$tester = new TeamTNT\Stripe\WebhookTester(); $tester->setVersion('2018-05-21'); $tester->setEndpoint('http://local.dev/stripe/webhooks'); $response = $tester->triggerEvent('charge.succeeded');
For your convenience you can use chained methods
$tester = new TeamTNT\Stripe\WebhookTester('http://local.dev/stripe/webhooks); $response = $tester->setVersion('2014-09-08')->triggerEvent('charge.succeeded');
Laravel Integration
To implement this package with Laravel Cashier, you will need to override the eventExistsOnStripe()
method in Laravel\Cashier\WebhookController
with something like this:
protected function eventExistsOnStripe($id) { if(App::environment() == 'testing' or App::environment() == 'local') { return true; } try { return ! is_null(StripeEvent::retrieve($id, Config::get('services.stripe.secret'))); } catch (Exception $e) { return false; } }
Without the environment checks Cashier attempts to verify that the dummy event is a valid webhook with Stripe, which will obviously fail.
Available versions and events
Available versions and events can be found in the webhooks directory
Testing
$ phpunit
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.