Skip to content

Commit

Permalink
Test fix: Cards and card tokens require a value for CVC
Browse files Browse the repository at this point in the history
  • Loading branch information
downsider committed May 28, 2015
1 parent fa91533 commit ccf00ff
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 24 deletions.
5 changes: 3 additions & 2 deletions src/Api/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ public function getToken($tokenId)
* @param string $number
* @param string $expMonth
* @param string $expYear
* @param string $cvc
* @return CreateCardTokenRequest
*/
public function createCardTokenRequest($number, $expMonth, $expYear)
public function createCardTokenRequest($number, $expMonth, $expYear, $cvc = null)
{
return new CreateCardTokenRequest($number, $expMonth, $expYear);
return new CreateCardTokenRequest($number, $expMonth, $expYear, $cvc);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Request/Cards/CreateCardRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ class CreateCardRequest extends UpdateCardRequest
* @param string $number
* @param int $expMonth
* @param int $expYear
* @param mixed $cvc
*/
public function __construct($number, $expMonth, $expYear)
public function __construct($number, $expMonth, $expYear, $cvc = null)
{
$this->number = $number;
$this->expMonth = $expMonth;
$this->expYear = $expYear;
$this->cvc = $cvc;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Request/Tokens/CreateCardTokenRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ class CreateCardTokenRequest
* @param string $number
* @param string $expMonth
* @param string $expYear
* @param string|null $cvc
*/
public function __construct($number, $expMonth, $expYear)
public function __construct($number, $expMonth, $expYear, $cvc = null)
{
$this->number = $number;
$this->expMonth = $expMonth;
$this->expYear = $expYear;
$this->cvc = $cvc;
}

/**
Expand Down
20 changes: 10 additions & 10 deletions tests/Api/CardsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function tearDown()
public function testCreateCard()
{
$cardNumber = self::VISA_1;
$request = new CreateCardRequest($cardNumber, 1, 2020);
$request = new CreateCardRequest($cardNumber, 1, 2020, 123);
$response = $this->cards->createCard($this->customerId, $request);

$this->assertInstanceOf('Stripe\Response\Cards\CardResponse', $response);
Expand All @@ -56,7 +56,7 @@ public function testCreateCard()
// test error handling

$cardNumber = self::INCORRECT_NUMBER;
$request = new CreateCardRequest($cardNumber, 1, 2020);
$request = new CreateCardRequest($cardNumber, 1, 2020, 123);
$exceptionThrown = false;
try {
$this->cards->createCard($this->customerId, $request);
Expand All @@ -66,7 +66,7 @@ public function testCreateCard()
$this->assertTrue($exceptionThrown);

$cardNumber = self::CARD_DECLINED;
$request = new CreateCardRequest($cardNumber, 1, 2020);
$request = new CreateCardRequest($cardNumber, 1, 2020, 123);
$exceptionThrown = false;
try {
$this->cards->createCard($this->customerId, $request);
Expand All @@ -76,7 +76,7 @@ public function testCreateCard()
$this->assertTrue($exceptionThrown);

$cardNumber = self::VISA_1;
$request = new CreateCardRequest($cardNumber, 13, 2020);
$request = new CreateCardRequest($cardNumber, 13, 2020, 123);
$exceptionThrown = false;
try {
$this->cards->createCard($this->customerId, $request);
Expand All @@ -85,7 +85,7 @@ public function testCreateCard()
}
$this->assertTrue($exceptionThrown);

$request = new CreateCardRequest($cardNumber, 12, 1984);
$request = new CreateCardRequest($cardNumber, 12, 1984, 123);
$exceptionThrown = false;
try {
$this->cards->createCard($this->customerId, $request);
Expand All @@ -107,7 +107,7 @@ public function testCreateCard()

public function testUpdateCard()
{
$createResponse = $this->cards->createCard($this->customerId, new CreateCardRequest(self::VISA_1, 1, 2020));
$createResponse = $this->cards->createCard($this->customerId, new CreateCardRequest(self::VISA_1, 1, 2020, 123));
$request = new UpdateCardRequest();
$request->setExpYear(2021);
$updateResponse = $this->cards->updateCard($this->customerId, $createResponse->getId(), $request);
Expand All @@ -118,7 +118,7 @@ public function testUpdateCard()

public function testGetCard()
{
$createResponse = $this->cards->createCard($this->customerId, new CreateCardRequest(self::VISA_1, 1, 2020));
$createResponse = $this->cards->createCard($this->customerId, new CreateCardRequest(self::VISA_1, 1, 2020, 123));
$card = $this->cards->getCard($this->customerId, $createResponse->getId());

$this->assertInstanceOf('Stripe\Response\Cards\CardResponse', $card);
Expand All @@ -129,8 +129,8 @@ public function testListCards()
{
$request = new ListRequest();
$request->setLimit(1);
$this->cards->createCard($this->customerId, new CreateCardRequest(self::VISA_1, 1, 2020));
$this->cards->createCard($this->customerId, new CreateCardRequest(self::MASTERCARD_1, 2, 2020));
$this->cards->createCard($this->customerId, new CreateCardRequest(self::VISA_1, 1, 2020, 123));
$this->cards->createCard($this->customerId, new CreateCardRequest(self::MASTERCARD_1, 2, 2020, 123));
$cards = $this->cards->listCards($this->customerId, $request);

$this->assertInstanceOf(Cards::LIST_CARDS_RESPONSE_CLASS, $cards);
Expand All @@ -143,7 +143,7 @@ public function testListCards()

public function testDeleteCard()
{
$createResponse = $this->cards->createCard($this->customerId, new CreateCardRequest(self::VISA_1, 1, 2020));
$createResponse = $this->cards->createCard($this->customerId, new CreateCardRequest(self::VISA_1, 1, 2020, 123));
$deleteResponse = $this->cards->deleteCard($this->customerId, $createResponse->getId());

$this->assertTrue($deleteResponse->getDeleted());
Expand Down
12 changes: 6 additions & 6 deletions tests/Api/ChargesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function setUp()
public function testCreateCharge()
{
$request = new CreateChargeRequest(350, "usd");
$request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020));
$request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123));
$response = $this->charges->createCharge($request);

$this->assertInstanceOf(Charges::CHARGE_RESPONSE_CLASS, $response);
Expand All @@ -41,7 +41,7 @@ public function testCreateCharge()
public function testCreateChargeWithToken(){
// create a token
$tokens = new Tokens($this->client);
$tokenResponse = $tokens->createCardToken(new CreateCardTokenRequest(self::VISA_1, 1, 2020));
$tokenResponse = $tokens->createCardToken(new CreateCardTokenRequest(self::VISA_1, 1, 2020, 123));

$request = new CreateChargeRequest(350, "usd");
$request->setCard($tokenResponse->getId());
Expand All @@ -53,7 +53,7 @@ public function testCreateChargeWithToken(){
public function testGetCharge()
{
$createRequest = new CreateChargeRequest(350, "usd");
$createRequest->setCard(new CreateCardRequest(self::VISA_1, 1, 2020));
$createRequest->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123));
$createResponse = $this->charges->createCharge($createRequest);

$this->assertInstanceOf(Charges::CHARGE_RESPONSE_CLASS, $createResponse);
Expand All @@ -68,7 +68,7 @@ public function testGetCharge()
public function testUpdateCharge()
{
$createRequest = new CreateChargeRequest(350, "usd");
$createRequest->setCard(new CreateCardRequest(self::VISA_1, 1, 2020));
$createRequest->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123));
$createResponse = $this->charges->createCharge($createRequest);

$this->assertInstanceOf(Charges::CHARGE_RESPONSE_CLASS, $createResponse);
Expand All @@ -85,7 +85,7 @@ public function testUpdateCharge()
public function testRefundCharge()
{
$createRequest = new CreateChargeRequest(350, "usd");
$createRequest->setCard(new CreateCardRequest(self::VISA_1, 1, 2020));
$createRequest->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123));
$createResponse = $this->charges->createCharge($createRequest);

$this->assertInstanceOf(Charges::CHARGE_RESPONSE_CLASS, $createResponse);
Expand All @@ -99,7 +99,7 @@ public function testRefundCharge()
public function testCaptureCharge()
{
$createRequest = new CreateChargeRequest(350, "usd");
$createRequest->setCard(new CreateCardRequest(self::VISA_1, 1, 2020))
$createRequest->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123))
->setCapture(false);
$createResponse = $this->charges->createCharge($createRequest);

Expand Down
2 changes: 1 addition & 1 deletion tests/Api/DiscountsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function setUp()
$this->plans = new Plans($this->client);

$this->couponId = $this->coupons->createCoupon($this->coupons->createCouponRequest('forever')->setPercentOff(50))->getId();
$customerRequest = $this->customers->createCustomerRequest()->setCard(new CreateCardRequest(self::VISA_1, 1, 2020));
$customerRequest = $this->customers->createCustomerRequest()->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123));
$this->customerId = $this->customers->createCustomer($customerRequest)->getId();
$planRequest = $this->plans->createPlanRequest("discounts_test_plan" . rand(0, 999999), 350, 'usd', 'month', 'test plan');
$this->planId = $this->plans->createPlan($planRequest)->getId();
Expand Down
2 changes: 1 addition & 1 deletion tests/Api/InvoicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function setUp()
parent::setUp();
$this->invoices = new Invoices($this->client);
$this->customers = new Customers($this->client);
$customerRequest = $this->customers->createCustomerRequest()->setCard(new CreateCardRequest(self::VISA_1, 1, 2020));
$customerRequest = $this->customers->createCustomerRequest()->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123));
$this->customerId = $this->customers->createCustomer($customerRequest)->getId();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Api/TokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function setUp()

public function testGetToken()
{
$createRequest = $this->tokens->createCardTokenRequest(self::VISA_1, 1, 2020);
$createRequest = $this->tokens->createCardTokenRequest(self::VISA_1, 1, 2020, 123);
$createResponse = $this->tokens->createCardToken($createRequest);

$token = $this->tokens->getToken($createResponse->getId());
Expand All @@ -42,7 +42,7 @@ public function testGetToken()

public function testCreateCardToken()
{
$createRequest = $this->tokens->createCardTokenRequest(self::VISA_1, 1, 2020);
$createRequest = $this->tokens->createCardTokenRequest(self::VISA_1, 1, 2020, 123);
$createResponse = $this->tokens->createCardToken($createRequest);

$this->assertInstanceOf(Tokens::TOKEN_RESPONSE_CLASS, $createResponse);
Expand Down

0 comments on commit ccf00ff

Please sign in to comment.