From ccf00ff5513243eb31cd2a007b8792800053cb26 Mon Sep 17 00:00:00 2001 From: Danny Smart Date: Thu, 28 May 2015 15:19:11 +0100 Subject: [PATCH 1/2] 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); From f059a71c24623c8ea8382ab91de32e7f79d5e492 Mon Sep 17 00:00:00 2001 From: Danny Smart Date: Thu, 28 May 2015 15:56:05 +0100 Subject: [PATCH 2/2] Update Invoice and Subscription APIs to allow setting tax percentage --- src/Api/Invoices.php | 6 ++- .../Customers/CreateCustomerRequest.php | 24 +++++++++ src/Request/Invoices/CreateInvoiceRequest.php | 22 +++++++++ .../CreateSubscriptionRequest.php | 23 +++++++++ src/Response/Invoices/InvoiceResponse.php | 49 +++++++++++++++++++ .../Subscriptions/SubscriptionResponse.php | 25 ++++++++++ tests/Api/CustomersTest.php | 4 +- tests/Api/InvoicesTest.php | 3 +- tests/Api/SubscriptionsTest.php | 10 ++-- 9 files changed, 158 insertions(+), 8 deletions(-) diff --git a/src/Api/Invoices.php b/src/Api/Invoices.php index 33ac76c..91329bc 100644 --- a/src/Api/Invoices.php +++ b/src/Api/Invoices.php @@ -44,10 +44,11 @@ public function getInvoice($invoiceId) * @param bool $closed * @param string $description * @param array $metadata + * @param float $taxPercent * @return InvoiceResponse * @link https://stripe.com/docs/api/curl#update_plan */ - public function updateInvoice($invoiceId, $applicationFee = null, $closed = null, $description = null, $metadata = null) + public function updateInvoice($invoiceId, $applicationFee = null, $closed = null, $description = null, $metadata = null, $taxPercent = null) { $data = array(); if (!is_null($applicationFee)) { @@ -62,6 +63,9 @@ public function updateInvoice($invoiceId, $applicationFee = null, $closed = null if (!is_null($metadata)) { $data['metadata'] = $metadata; } + if (!is_null($taxPercent)) { + $data["tax_percent"] = $taxPercent; + } return $this->client->post('invoices/' . $invoiceId, self::INVOICE_RESPONSE_CLASS, $data); } diff --git a/src/Request/Customers/CreateCustomerRequest.php b/src/Request/Customers/CreateCustomerRequest.php index 782903b..76c545c 100644 --- a/src/Request/Customers/CreateCustomerRequest.php +++ b/src/Request/Customers/CreateCustomerRequest.php @@ -25,6 +25,11 @@ class CreateCustomerRequest extends AbstractCustomerRequest */ protected $trialEnd; + /** + * @var float + */ + protected $taxPercent; + /** * @return string */ @@ -78,4 +83,23 @@ public function setTrialEnd($trialEnd) $this->trialEnd = $trialEnd; return $this; } + + /** + * @param float $taxPercent + * @return $this + */ + public function setTaxPercent($taxPercent) + { + $this->taxPercent = $taxPercent; + return $this; + } + + /** + * @return float + */ + public function getTaxPercent() + { + return $this->taxPercent; + } + } \ No newline at end of file diff --git a/src/Request/Invoices/CreateInvoiceRequest.php b/src/Request/Invoices/CreateInvoiceRequest.php index bd98ed8..60bde98 100644 --- a/src/Request/Invoices/CreateInvoiceRequest.php +++ b/src/Request/Invoices/CreateInvoiceRequest.php @@ -35,6 +35,11 @@ class CreateInvoiceRequest */ protected $subscription; + /** + * @var float + */ + protected $taxPercent; + /** * @param string $customer */ @@ -133,5 +138,22 @@ public function getSubscription() return $this->subscription; } + /** + * @param float $taxPercent + * @return $this + */ + public function setTaxPercent($taxPercent) + { + $this->taxPercent = $taxPercent; + return $this; + } + + /** + * @return float + */ + public function getTaxPercent() + { + return $this->taxPercent; + } } diff --git a/src/Request/Subscriptions/CreateSubscriptionRequest.php b/src/Request/Subscriptions/CreateSubscriptionRequest.php index 99f2801..41fdcb2 100644 --- a/src/Request/Subscriptions/CreateSubscriptionRequest.php +++ b/src/Request/Subscriptions/CreateSubscriptionRequest.php @@ -42,6 +42,11 @@ class CreateSubscriptionRequest */ protected $applicationFeePercent; + /** + * @var float + */ + protected $taxPercent; + /** * @param string $plan */ @@ -158,5 +163,23 @@ public function setTrialEnd($trialEnd) return $this; } + /** + * @param float $taxPercent + * @return $this + */ + public function setTaxPercent($taxPercent) + { + $this->taxPercent = $taxPercent; + return $this; + } + + /** + * @return float + */ + public function getTaxPercent() + { + return $this->taxPercent; + } + } \ No newline at end of file diff --git a/src/Response/Invoices/InvoiceResponse.php b/src/Response/Invoices/InvoiceResponse.php index 7877a5f..4a3ae2a 100644 --- a/src/Response/Invoices/InvoiceResponse.php +++ b/src/Response/Invoices/InvoiceResponse.php @@ -168,6 +168,18 @@ class InvoiceResponse */ protected $forgiven; + /** + * @Type("float") + * @var float + */ + protected $taxPercent; + + /** + * @Type("integer") + * @var int + */ + protected $tax; + /** * @param int $amountDue * @return $this @@ -635,4 +647,41 @@ public function setForgiven($forgiven) $this->forgiven = $forgiven; return $this; } + + /** + * @param int $tax + * @return $this + */ + public function setTax($tax) + { + $this->tax = $tax; + return $this; + } + + /** + * @return int + */ + public function getTax() + { + return $this->tax; + } + + /** + * @param float $taxPercent + * @return $this + */ + public function setTaxPercent($taxPercent) + { + $this->taxPercent = $taxPercent; + return $this; + } + + /** + * @return float + */ + public function getTaxPercent() + { + return $this->taxPercent; + } + } diff --git a/src/Response/Subscriptions/SubscriptionResponse.php b/src/Response/Subscriptions/SubscriptionResponse.php index 8dd10ff..ad731d3 100644 --- a/src/Response/Subscriptions/SubscriptionResponse.php +++ b/src/Response/Subscriptions/SubscriptionResponse.php @@ -109,6 +109,12 @@ class SubscriptionResponse */ protected $trialStart; + /** + * @Type("float") + * @var float + */ + protected $taxPercent; + /** * @return PlanResponse */ @@ -396,4 +402,23 @@ public function setTrialStart($trialStart) $this->trialStart = $trialStart; return $this; } + + /** + * @param float $taxPercent + * @return $this + */ + public function setTaxPercent($taxPercent) + { + $this->taxPercent = $taxPercent; + return $this; + } + + /** + * @return float + */ + public function getTaxPercent() + { + return $this->taxPercent; + } + } \ No newline at end of file diff --git a/tests/Api/CustomersTest.php b/tests/Api/CustomersTest.php index a8fc53e..317d5c8 100644 --- a/tests/Api/CustomersTest.php +++ b/tests/Api/CustomersTest.php @@ -31,13 +31,15 @@ public function testCreateCustomer() { $balance = -500; $description = "testing"; + $taxRate = 12.3; $request = new CreateCustomerRequest(); - $request->setAccountBalance($balance)->setDescription($description); + $request->setAccountBalance($balance)->setDescription($description)->setTaxPercent($taxRate); $response = $this->customers->createCustomer($request); $this->assertInstanceOf(Customers::CUSTOMER_RESPONSE_CLASS, $response); $this->assertEquals($balance, $response->getAccountBalance()); $this->assertEquals($description, $request->getDescription()); + $this->assertEquals($taxRate, $request->getTaxPercent()); $this->client->delete('customers/' . $response->getId()); } diff --git a/tests/Api/InvoicesTest.php b/tests/Api/InvoicesTest.php index 6f9ab1d..c24e0e0 100644 --- a/tests/Api/InvoicesTest.php +++ b/tests/Api/InvoicesTest.php @@ -76,13 +76,14 @@ public function testUpdateInvoice() $request = $this->invoices->createInvoiceRequest($this->customerId); $invoice = $this->invoices->createInvoice($request); - $updatedInvoice = $this->invoices->updateInvoice($invoice->getId(), null, false, 'Updated Description', array('updated' => 'metadata')); + $updatedInvoice = $this->invoices->updateInvoice($invoice->getId(), null, false, 'Updated Description', array('updated' => 'metadata'), 0.2); $this->assertInstanceOf(Invoices::INVOICE_RESPONSE_CLASS, $updatedInvoice); $this->assertEquals(null, $updatedInvoice->getApplicationFee()); $this->assertEquals(false, $updatedInvoice->getClosed()); $this->assertEquals('Updated Description', $updatedInvoice->getDescription()); $this->assertEquals(array('updated' => 'metadata'), $updatedInvoice->getMetadata()); + $this->assertEquals(0.2, $updatedInvoice->getTaxPercent()); } public function testPayInvoice() diff --git a/tests/Api/SubscriptionsTest.php b/tests/Api/SubscriptionsTest.php index d2f3872..da82e63 100644 --- a/tests/Api/SubscriptionsTest.php +++ b/tests/Api/SubscriptionsTest.php @@ -59,7 +59,7 @@ protected function tearDown() public function testCreateSubscription() { $request = new CreateSubscriptionRequest($this->planId); - $request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020)); + $request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123)); $response = $this->subscriptions->createSubscription($this->customerId, $request); $this->assertInstanceOf(Subscriptions::SUBSCRIPTION_RESPONSE_CLASS, $response); @@ -69,7 +69,7 @@ public function testCreateSubscription() public function testGetSubscription() { $request = new CreateSubscriptionRequest($this->planId); - $request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020)); + $request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123)); $createResponse = $this->subscriptions->createSubscription($this->customerId, $request); $getResponse = $this->subscriptions->getSubscription($this->customerId, $createResponse->getId()); @@ -81,7 +81,7 @@ public function testGetSubscription() public function testUpdateSubscription() { $request = new CreateSubscriptionRequest($this->planId); - $request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020)); + $request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123)); $createResponse = $this->subscriptions->createSubscription($this->customerId, $request); $request = new UpdateSubscriptionRequest(); @@ -95,7 +95,7 @@ public function testUpdateSubscription() public function testCancelSubscription() { $request = new CreateSubscriptionRequest($this->planId); - $request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020)); + $request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123)); $createResponse = $this->subscriptions->createSubscription($this->customerId, $request); $cancelResponse = $this->subscriptions->cancelSubscription($this->customerId, $createResponse->getId(), true); @@ -107,7 +107,7 @@ public function testCancelSubscription() public function testListSubscriptions() { $request = new CreateSubscriptionRequest($this->planId); - $request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020)); + $request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123)); $this->subscriptions->createSubscription($this->customerId, $request); $this->subscriptions->createSubscription($this->customerId, $request); $this->subscriptions->createSubscription($this->customerId, $request);