From f059a71c24623c8ea8382ab91de32e7f79d5e492 Mon Sep 17 00:00:00 2001 From: Danny Smart Date: Thu, 28 May 2015 15:56:05 +0100 Subject: [PATCH] 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);