-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from michaeldyrynda/extract-card-numbers
📖 ✅ 🎉 Separate credit card numbers from token generation fixes #3
- Loading branch information
Showing
7 changed files
with
288 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Application Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace JacobBennett; | ||
|
||
use BadMethodCallException; | ||
|
||
/** | ||
* Provide access to varying valid and exceptional card numbers | ||
* independently of having to actually create a Stripe token. | ||
*/ | ||
class StripeCardNumber | ||
{ | ||
const CARDS = [ | ||
// valid cards | ||
'validVisa' => 4012888888881881, | ||
'validVisaDebit' => 4012888888881881, | ||
'validMastercard' => 5555555555554444, | ||
'validMastercardDebit' => 5200828282828210, | ||
'validMastercardPrepaid' => 5105105105105100, | ||
'validAmex' => 378282246310005, | ||
'validDiscover' => 6011111111111117, | ||
'validDinersClub' => 30569309025904, | ||
'validJCB' => 3530111333300000, | ||
|
||
// exceptional responses | ||
'successDirectToBalance' => 4000000000000077, | ||
'addressZipFail' => 4000000000000010, | ||
'addressFail' => 4000000000000028, | ||
'zipFail' => 4000000000000036, | ||
'addressZipUnavailable' => 4000000000000044, | ||
'cvcFail' => 4000000000000101, | ||
'customerChargeFail' => 4000000000000341, | ||
'successWithReview' => 4000000000009235, | ||
'declineCard' => 4000000000000002, | ||
'declineFraudulentCard' => 4100000000000019, | ||
'declineIncorrectCvc' => 4000000000000127, | ||
'declineExpiredCard' => 4000000000000069, | ||
'declineProcessingError' => 4000000000000119, | ||
'declineIncorrectNumber' => 4242424242424241, | ||
]; | ||
|
||
public static function __callStatic($method, $args) | ||
{ | ||
if (! array_key_exists($method, static::CARDS)) { | ||
throw new BadMethodCallException("The provided card type {$method} is not defined."); | ||
} | ||
|
||
return static::CARDS[$method]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
<?php | ||
|
||
use JacobBennett\StripeCardNumber; | ||
|
||
class StripeCardNumberTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** @test */ | ||
public function it_throws_an_exception_for_an_invalid_method() | ||
{ | ||
$this->setExpectedException(\BadMethodCallException::class); | ||
|
||
StripeCardNumber::someInvalidCardMethod(); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_valid_visa_card_number() | ||
{ | ||
$this->assertSame(4012888888881881, StripeCardNumber::validVisa()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_valid_visa_debit_number() | ||
{ | ||
$this->assertSame(4012888888881881, StripeCardNumber::validVisaDebit()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_valid_mastercard_number() | ||
{ | ||
$this->assertSame(5555555555554444, StripeCardNumber::validMastercard()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_valid_mastercard_debit_number() | ||
{ | ||
$this->assertSame(5200828282828210, StripeCardNumber::validMastercardDebit()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_valid_mastercard_prepaid_number() | ||
{ | ||
$this->assertSame(5105105105105100, StripeCardNumber::validMastercardPrepaid()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_valid_amex_number() | ||
{ | ||
$this->assertSame(378282246310005, StripeCardNumber::validAmex()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_valid_discover_number() | ||
{ | ||
$this->assertSame(6011111111111117, StripeCardNumber::validDiscover()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_valid_diners_club_number() | ||
{ | ||
$this->assertSame(30569309025904, StripeCardNumber::validDinersClub()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_valid_jcb_number() | ||
{ | ||
$this->assertSame(3530111333300000, StripeCardNumber::validJCB()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_success_direct_to_balance_number() | ||
{ | ||
$this->assertSame(4000000000000077, StripeCardNumber::successDirectToBalance()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_an_address_zip_fail_number() | ||
{ | ||
$this->assertSame(4000000000000010, StripeCardNumber::addressZipFail()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_an_address_fail_number() | ||
{ | ||
$this->assertSame(4000000000000028, StripeCardNumber::addressFail()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_zip_fail_number() | ||
{ | ||
$this->assertSame(4000000000000036, StripeCardNumber::zipFail()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_an_address_zip_unavailable_number() | ||
{ | ||
$this->assertSame(4000000000000044, StripeCardNumber::addressZipUnavailable()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_cvc_fail_number() | ||
{ | ||
$this->assertSame(4000000000000101, StripeCardNumber::cvcFail()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_customer_charge_fail_number() | ||
{ | ||
$this->assertSame(4000000000000341, StripeCardNumber::customerChargeFail()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_success_with_review_number() | ||
{ | ||
$this->assertSame(4000000000009235, StripeCardNumber::successWithReview()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_declined_card_number() | ||
{ | ||
$this->assertSame(4000000000000002, StripeCardNumber::declineCard()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_declined_fraudulent_card_number() | ||
{ | ||
$this->assertSame(4100000000000019, StripeCardNumber::declineFraudulentCard()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_declined_incorrect_cvc_number() | ||
{ | ||
$this->assertSame(4000000000000127, StripeCardNumber::declineIncorrectCvc()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_declined_expired_card_number() | ||
{ | ||
$this->assertSame(4000000000000069, StripeCardNumber::declineExpiredCard()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_declined_processing_error_number() | ||
{ | ||
$this->assertSame(4000000000000119, StripeCardNumber::declineProcessingError()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_declined_incorrect_number() | ||
{ | ||
$this->assertSame(4242424242424241, StripeCardNumber::declineIncorrectNumber()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
use JacobBennett\StripeTestToken; | ||
|
||
class StripeTestTokenTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** @test */ | ||
public function it_throws_an_exception_when_requesting_a_non_existent_card_type() | ||
{ | ||
$this->setExpectedException(\BadMethodCallException::class); | ||
|
||
StripeTestToken::getCardNumber('someNonExistentCardType'); | ||
} | ||
|
||
/** @test */ | ||
public function it_throws_an_exception_when_creating_a_token_with_a_non_existent_card_type_via_static_access() | ||
{ | ||
$this->setExpectedException(\BadMethodCallException::class); | ||
|
||
StripeTestToken::someNonExistentCardType(); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_valid_visa_card_number() | ||
{ | ||
$this->assertSame(4012888888881881, StripeTestToken::getCardNumber('validVisa')); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_token_id_for_a_valid_visa() | ||
{ | ||
$this->assertFalse(trim(getenv('STRIPE_KEY')) === '', 'You must set the STRIPE_KEY in your environment'); | ||
|
||
StripeTestToken::setApiKey(getenv('STRIPE_KEY')); | ||
|
||
$this->assertTrue(is_string(StripeTestToken::create('validVisa'))); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_token_id_for_a_valid_mastercard_using_static_access() | ||
{ | ||
$this->assertFalse(trim(getenv('STRIPE_KEY')) === '', 'You must set the STRIPE_KEY in your environment'); | ||
|
||
StripeTestToken::setApiKey(getenv('STRIPE_KEY')); | ||
|
||
$this->assertTrue(is_string(StripeTestToken::validMastercard())); | ||
} | ||
} |