├── .gitattributes ├── .github └── workflows │ └── run-tests.yml ├── .gitignore ├── .scrutinizer.yml ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml ├── src ├── StripeCardNumber.php └── StripeTestToken.php ├── stripetesttoken-01.jpg └── tests ├── StripeCardNumberTest.php └── StripeTestTokenTest.php /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.github/workflows/run-tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | fail-fast: true 10 | matrix: 11 | os: [ubuntu-latest] 12 | php: [7.2, 7.3, 7.4, 8.0] 13 | stability: [prefer-lowest, prefer-stable] 14 | 15 | name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} 16 | 17 | steps: 18 | - name: Checkout code 19 | uses: actions/checkout@v2 20 | 21 | - name: Setup PHP 22 | uses: shivammathur/setup-php@v2 23 | with: 24 | php-version: ${{ matrix.php }} 25 | extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo 26 | coverage: none 27 | 28 | - name: Setup problem matchers 29 | run: | 30 | echo "::add-matcher::${{ runner.tool_cache }}/php.json" 31 | echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" 32 | 33 | - name: Install dependencies 34 | run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction 35 | 36 | - name: Execute tests 37 | run: vendor/bin/phpunit 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | composer.lock 3 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | build: 2 | tests: 3 | override: 4 | - 5 | command: phpunit --coverage-clover=my-coverage-file 6 | coverage: 7 | file: my-coverage-file 8 | format: php-clover 9 | 10 | checks: 11 | php: 12 | code_rating: true 13 | duplication: true 14 | 15 | tools: 16 | php_mess_detector: true 17 | php_cs_fixer: true 18 | sensiolabs_security_checker: true 19 | php_cpd: true 20 | php_loc: true 21 | php_hhvm: true 22 | php_code_sniffer: true 23 | php_sim: true 24 | php_changetracking: true 25 | php_pdepend: true 26 | php_analyzer: true 27 | 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Andrew Stilliard 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://raw.githubusercontent.com/JacobBennett/StripeTestToken/master/stripetesttoken-01.jpg) 2 | 3 | # Stripe Test Tokens 4 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/jacobbennett/stripe-test-token.svg?maxAge=2592000?style=flat-square)](https://packagist.org/packages/jacobbennett/stripe-test-token) 5 | [![Travis](https://img.shields.io/travis/JacobBennett/StripeTestToken.svg?maxAge=2592000?style=flat-square)](https://travis-ci.org/JacobBennett/StripeTestToken) 6 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) 7 | 8 | Use this to quickly create Stripe test tokens for successful and exceptional responses from Stripe. 9 | 10 | ## Install 11 | ```bash 12 | composer require jacobbennett/stripe-test-token 13 | ``` 14 | 15 | ## Usage 16 | ```php 17 | 500, 28 | 'currency' => 'usd', 29 | 'source' => StripeTestToken::validVisa(), 30 | ]); 31 | 32 | 33 | // Fake a Failing Charge 34 | 35 | try { 36 | 37 | Charge::create([ 38 | 'amount' => 500, 39 | 'currency' => 'usd', 40 | 'source' => StripeTestToken::cvcFail(), 41 | ]); 42 | 43 | } catch (\Stripe\Error\Card $e) { 44 | // handle errors 45 | } 46 | 47 | ``` 48 | 49 | ## Docs 50 | 51 | > Find full descriptions at original [Stripe Docs Reference](https://stripe.com/docs/testing#cards) 52 | 53 | ### Using Methods 54 | 55 | 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. 56 | 57 | ```php 58 | =7.2|^8.0" 21 | }, 22 | "require-dev": { 23 | "phpunit/phpunit": "^8.0" 24 | }, 25 | "scripts": { 26 | "test": "phpunit" 27 | }, 28 | "autoload": { 29 | "psr-4": { 30 | "JacobBennett\\": "src" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./tests 15 | 16 | 17 | 18 | 19 | ./src 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/StripeCardNumber.php: -------------------------------------------------------------------------------- 1 | 4012888888881881, 16 | 'validVisaDebit' => 4012888888881881, 17 | 'validMastercard' => 5555555555554444, 18 | 'validMastercardDebit' => 5200828282828210, 19 | 'validMastercardPrepaid' => 5105105105105100, 20 | 'validAmex' => 378282246310005, 21 | 'validDiscover' => 6011111111111117, 22 | 'validDinersClub' => 30569309025904, 23 | 'validJCB' => 3530111333300000, 24 | 25 | // exceptional responses 26 | 'successDirectToBalance' => 4000000000000077, 27 | 'addressZipFail' => 4000000000000010, 28 | 'addressFail' => 4000000000000028, 29 | 'zipFail' => 4000000000000036, 30 | 'addressZipUnavailable' => 4000000000000044, 31 | 'cvcFail' => 4000000000000101, 32 | 'customerChargeFail' => 4000000000000341, 33 | 'successWithReview' => 4000000000009235, 34 | 'declineCard' => 4000000000000002, 35 | 'declineFraudulentCard' => 4100000000000019, 36 | 'declineIncorrectCvc' => 4000000000000127, 37 | 'declineExpiredCard' => 4000000000000069, 38 | 'declineProcessingError' => 4000000000000119, 39 | 'declineIncorrectNumber' => 4242424242424241, 40 | 41 | // SCA 42 | 'scaAuthOneTimePayments' => 4000002500003155, 43 | 'scaAuthRequired' => 4000002760003184, 44 | 'scaAuthOnSession' => 4000003800000446, 45 | ]; 46 | 47 | public static function __callStatic($method, $args) 48 | { 49 | if (! array_key_exists($method, static::CARDS)) { 50 | throw new BadMethodCallException("The provided card type {$method} is not defined."); 51 | } 52 | 53 | return static::CARDS[$method]; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/StripeTestToken.php: -------------------------------------------------------------------------------- 1 | [ 30 | 'number' => self::getCardNumber($type), 31 | 'name' => 'Pam Beasley', 32 | 'exp_month' => 1, 33 | 'exp_year' => date("Y") + 1, 34 | 'address_line1' => '33 Zonda Lane', 35 | 'address_zip' => '44883', 36 | 'cvc' => '123', 37 | ] 38 | ])->id; 39 | } 40 | 41 | public static function getCardNumber($cardType) 42 | { 43 | return StripeCardNumber::{$cardType}(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /stripetesttoken-01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JacobBennett/StripeTestToken/87e5ad94fefafa2cff072cd9f79e9f4620c9eae8/stripetesttoken-01.jpg -------------------------------------------------------------------------------- /tests/StripeCardNumberTest.php: -------------------------------------------------------------------------------- 1 | expectException(\BadMethodCallException::class); 13 | 14 | StripeCardNumber::someInvalidCardMethod(); 15 | } 16 | 17 | /** @test */ 18 | public function it_returns_a_valid_visa_card_number() 19 | { 20 | $this->assertSame(4012888888881881, StripeCardNumber::validVisa()); 21 | } 22 | 23 | /** @test */ 24 | public function it_returns_a_valid_visa_debit_number() 25 | { 26 | $this->assertSame(4012888888881881, StripeCardNumber::validVisaDebit()); 27 | } 28 | 29 | /** @test */ 30 | public function it_returns_a_valid_mastercard_number() 31 | { 32 | $this->assertSame(5555555555554444, StripeCardNumber::validMastercard()); 33 | } 34 | 35 | /** @test */ 36 | public function it_returns_a_valid_mastercard_debit_number() 37 | { 38 | $this->assertSame(5200828282828210, StripeCardNumber::validMastercardDebit()); 39 | } 40 | 41 | /** @test */ 42 | public function it_returns_a_valid_mastercard_prepaid_number() 43 | { 44 | $this->assertSame(5105105105105100, StripeCardNumber::validMastercardPrepaid()); 45 | } 46 | 47 | /** @test */ 48 | public function it_returns_a_valid_amex_number() 49 | { 50 | $this->assertSame(378282246310005, StripeCardNumber::validAmex()); 51 | } 52 | 53 | /** @test */ 54 | public function it_returns_a_valid_discover_number() 55 | { 56 | $this->assertSame(6011111111111117, StripeCardNumber::validDiscover()); 57 | } 58 | 59 | /** @test */ 60 | public function it_returns_a_valid_diners_club_number() 61 | { 62 | $this->assertSame(30569309025904, StripeCardNumber::validDinersClub()); 63 | } 64 | 65 | /** @test */ 66 | public function it_returns_a_valid_jcb_number() 67 | { 68 | $this->assertSame(3530111333300000, StripeCardNumber::validJCB()); 69 | } 70 | 71 | /** @test */ 72 | public function it_returns_a_success_direct_to_balance_number() 73 | { 74 | $this->assertSame(4000000000000077, StripeCardNumber::successDirectToBalance()); 75 | } 76 | 77 | /** @test */ 78 | public function it_returns_an_address_zip_fail_number() 79 | { 80 | $this->assertSame(4000000000000010, StripeCardNumber::addressZipFail()); 81 | } 82 | 83 | /** @test */ 84 | public function it_returns_an_address_fail_number() 85 | { 86 | $this->assertSame(4000000000000028, StripeCardNumber::addressFail()); 87 | } 88 | 89 | /** @test */ 90 | public function it_returns_a_zip_fail_number() 91 | { 92 | $this->assertSame(4000000000000036, StripeCardNumber::zipFail()); 93 | } 94 | 95 | /** @test */ 96 | public function it_returns_an_address_zip_unavailable_number() 97 | { 98 | $this->assertSame(4000000000000044, StripeCardNumber::addressZipUnavailable()); 99 | } 100 | 101 | /** @test */ 102 | public function it_returns_a_cvc_fail_number() 103 | { 104 | $this->assertSame(4000000000000101, StripeCardNumber::cvcFail()); 105 | } 106 | 107 | /** @test */ 108 | public function it_returns_a_customer_charge_fail_number() 109 | { 110 | $this->assertSame(4000000000000341, StripeCardNumber::customerChargeFail()); 111 | } 112 | 113 | /** @test */ 114 | public function it_returns_a_success_with_review_number() 115 | { 116 | $this->assertSame(4000000000009235, StripeCardNumber::successWithReview()); 117 | } 118 | 119 | /** @test */ 120 | public function it_returns_a_declined_card_number() 121 | { 122 | $this->assertSame(4000000000000002, StripeCardNumber::declineCard()); 123 | } 124 | 125 | /** @test */ 126 | public function it_returns_a_declined_fraudulent_card_number() 127 | { 128 | $this->assertSame(4100000000000019, StripeCardNumber::declineFraudulentCard()); 129 | } 130 | 131 | /** @test */ 132 | public function it_returns_a_declined_incorrect_cvc_number() 133 | { 134 | $this->assertSame(4000000000000127, StripeCardNumber::declineIncorrectCvc()); 135 | } 136 | 137 | /** @test */ 138 | public function it_returns_a_declined_expired_card_number() 139 | { 140 | $this->assertSame(4000000000000069, StripeCardNumber::declineExpiredCard()); 141 | } 142 | 143 | /** @test */ 144 | public function it_returns_a_declined_processing_error_number() 145 | { 146 | $this->assertSame(4000000000000119, StripeCardNumber::declineProcessingError()); 147 | } 148 | 149 | /** @test */ 150 | public function it_returns_a_declined_incorrect_number() 151 | { 152 | $this->assertSame(4242424242424241, StripeCardNumber::declineIncorrectNumber()); 153 | } 154 | 155 | /** @test */ 156 | public function it_returns_a_sca_one_time_payment_number() 157 | { 158 | $this->assertSame(4000002500003155, StripeCardNumber::scaAuthOneTimePayments()); 159 | } 160 | 161 | /** @test */ 162 | public function it_returns_a_sca_auth_required_number() 163 | { 164 | $this->assertSame(4000002760003184, StripeCardNumber::scaAuthRequired()); 165 | } 166 | 167 | /** @test */ 168 | public function it_returns_a_sca_auth_on_session_required_number() 169 | { 170 | $this->assertSame(4000003800000446, StripeCardNumber::scaAuthOnSession()); 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /tests/StripeTestTokenTest.php: -------------------------------------------------------------------------------- 1 | expectException(\BadMethodCallException::class); 12 | 13 | StripeTestToken::getCardNumber('someNonExistentCardType'); 14 | } 15 | 16 | /** @test */ 17 | public function it_throws_an_exception_when_creating_a_token_with_a_non_existent_card_type_via_static_access() 18 | { 19 | $this->expectException(\BadMethodCallException::class); 20 | 21 | StripeTestToken::someNonExistentCardType(); 22 | } 23 | 24 | /** @test */ 25 | public function it_returns_a_valid_visa_card_number() 26 | { 27 | $this->assertSame(4012888888881881, StripeTestToken::getCardNumber('validVisa')); 28 | } 29 | 30 | /** @test */ 31 | public function it_returns_a_token_id_for_a_valid_visa() 32 | { 33 | if(! getenv('STRIPE_KEY')) { 34 | $this->markTestSkipped('You must set the STRIPE_KEY in your environment'); 35 | } 36 | 37 | StripeTestToken::setApiKey(getenv('STRIPE_KEY')); 38 | 39 | $this->assertTrue(is_string(StripeTestToken::create('validVisa'))); 40 | } 41 | 42 | /** @test */ 43 | public function it_returns_a_token_id_for_a_valid_mastercard_using_static_access() 44 | { 45 | if(! getenv('STRIPE_KEY')) { 46 | $this->markTestSkipped('You must set the STRIPE_KEY in your environment'); 47 | } 48 | 49 | StripeTestToken::setApiKey(getenv('STRIPE_KEY')); 50 | 51 | $this->assertTrue(is_string(StripeTestToken::validMastercard())); 52 | } 53 | } 54 | --------------------------------------------------------------------------------