From ccf00ff5513243eb31cd2a007b8792800053cb26 Mon Sep 17 00:00:00 2001 From: Danny Smart Date: Thu, 28 May 2015 15:19:11 +0100 Subject: [PATCH] Test fix: Cards and card tokens require a value for CVC --- src/Api/Tokens.php | 5 +++-- src/Request/Cards/CreateCardRequest.php | 4 +++- src/Request/Tokens/CreateCardTokenRequest.php | 4 +++- tests/Api/CardsTest.php | 20 +++++++++---------- tests/Api/ChargesTest.php | 12 +++++------ tests/Api/DiscountsTest.php | 2 +- tests/Api/InvoicesTest.php | 2 +- tests/Api/TokensTest.php | 4 ++-- 8 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/Api/Tokens.php b/src/Api/Tokens.php index 3a8f102..acc7c56 100644 --- a/src/Api/Tokens.php +++ b/src/Api/Tokens.php @@ -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); } /** diff --git a/src/Request/Cards/CreateCardRequest.php b/src/Request/Cards/CreateCardRequest.php index 013811d..5bb2c68 100644 --- a/src/Request/Cards/CreateCardRequest.php +++ b/src/Request/Cards/CreateCardRequest.php @@ -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; } /** diff --git a/src/Request/Tokens/CreateCardTokenRequest.php b/src/Request/Tokens/CreateCardTokenRequest.php index cf4070a..37ba886 100644 --- a/src/Request/Tokens/CreateCardTokenRequest.php +++ b/src/Request/Tokens/CreateCardTokenRequest.php @@ -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; } /** diff --git a/tests/Api/CardsTest.php b/tests/Api/CardsTest.php index 17bb84c..06df27e 100644 --- a/tests/Api/CardsTest.php +++ b/tests/Api/CardsTest.php @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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()); diff --git a/tests/Api/ChargesTest.php b/tests/Api/ChargesTest.php index a13eb41..106dcbd 100644 --- a/tests/Api/ChargesTest.php +++ b/tests/Api/ChargesTest.php @@ -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); @@ -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()); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/tests/Api/DiscountsTest.php b/tests/Api/DiscountsTest.php index 7eac3ad..a4e9ac2 100644 --- a/tests/Api/DiscountsTest.php +++ b/tests/Api/DiscountsTest.php @@ -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(); diff --git a/tests/Api/InvoicesTest.php b/tests/Api/InvoicesTest.php index c60a537..6f9ab1d 100644 --- a/tests/Api/InvoicesTest.php +++ b/tests/Api/InvoicesTest.php @@ -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(); } diff --git a/tests/Api/TokensTest.php b/tests/Api/TokensTest.php index e411a0f..74d21fe 100644 --- a/tests/Api/TokensTest.php +++ b/tests/Api/TokensTest.php @@ -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()); @@ -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);