jacobbennett / stripe-test-token
Quickly create Stripe test tokens for successful and exceptional Stripe responses.
Installs: 52 461
Dependents: 0
Suggesters: 0
Security: 0
Stars: 148
Watchers: 3
Forks: 17
Open Issues: 2
Requires
- php: >=7.2|^8.0
- stripe/stripe-php: ^4.0|^5.0|^6.0|^7.0
Requires (Dev)
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-11-10 10:15:21 UTC
README
Stripe Test Tokens
Use this to quickly create Stripe test tokens for successful and exceptional responses from Stripe.
Install
composer require jacobbennett/stripe-test-token
Usage
<?php use JacobBennett\StripeTestToken; use Stripe\Charge; StripeTestToken::setApiKey('your_stripe_secret_test_key'); // Fake a Successful Charge Charge::create([ 'amount' => 500, 'currency' => 'usd', 'source' => StripeTestToken::validVisa(), ]); // Fake a Failing Charge try { Charge::create([ 'amount' => 500, 'currency' => 'usd', 'source' => StripeTestToken::cvcFail(), ]); } catch (\Stripe\Error\Card $e) { // handle errors }
Docs
Find full descriptions at original Stripe Docs Reference
Using Methods
To use any of the methods below, call the listed method as a static on the StripeTestToken
class. If you only want to return the corresponding card number, such as with Selenium or Laravel Dusk, you can call the same method on the StripeCardNumber
class.
<?php \JacobBennett\StripeCardNumber::validVisa(); // Returns the valid Visa card number 4012888888881881 \JacobBennett\StripeTestToken::validVisa(); // Attempts to generate a token against the Stripe API for a valid Visa card
Test card numbers
Genuine card information cannot be used in test mode. Instead, use any of the following test card methods to create a successful payment token:
Testing for specific responses and errors
The following methods can be used to create tokens that produce specific responses—useful for testing different scenarios and error codes. Verification checks only run when the required information is provided (e.g., for cvc_check
to fail, a CVC code must be provided).
Testing
In order to run the full test suite, you must have STRIPE_KEY
set in your environment, as the test will hit the Stripe API in order to generate a test token.
$ STRIPE_KEY=sk_test_YourTestKeyHere phpunit tests/
License
This project is open-sourced software licensed under the MIT license