Skip to content

Commit f059a71

Browse files
committed
Update Invoice and Subscription APIs to allow setting tax percentage
1 parent ccf00ff commit f059a71

File tree

9 files changed

+158
-8
lines changed

9 files changed

+158
-8
lines changed

src/Api/Invoices.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ public function getInvoice($invoiceId)
4444
* @param bool $closed
4545
* @param string $description
4646
* @param array $metadata
47+
* @param float $taxPercent
4748
* @return InvoiceResponse
4849
* @link https://stripe.com/docs/api/curl#update_plan
4950
*/
50-
public function updateInvoice($invoiceId, $applicationFee = null, $closed = null, $description = null, $metadata = null)
51+
public function updateInvoice($invoiceId, $applicationFee = null, $closed = null, $description = null, $metadata = null, $taxPercent = null)
5152
{
5253
$data = array();
5354
if (!is_null($applicationFee)) {
@@ -62,6 +63,9 @@ public function updateInvoice($invoiceId, $applicationFee = null, $closed = null
6263
if (!is_null($metadata)) {
6364
$data['metadata'] = $metadata;
6465
}
66+
if (!is_null($taxPercent)) {
67+
$data["tax_percent"] = $taxPercent;
68+
}
6569
return $this->client->post('invoices/' . $invoiceId, self::INVOICE_RESPONSE_CLASS, $data);
6670
}
6771

src/Request/Customers/CreateCustomerRequest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class CreateCustomerRequest extends AbstractCustomerRequest
2525
*/
2626
protected $trialEnd;
2727

28+
/**
29+
* @var float
30+
*/
31+
protected $taxPercent;
32+
2833
/**
2934
* @return string
3035
*/
@@ -78,4 +83,23 @@ public function setTrialEnd($trialEnd)
7883
$this->trialEnd = $trialEnd;
7984
return $this;
8085
}
86+
87+
/**
88+
* @param float $taxPercent
89+
* @return $this
90+
*/
91+
public function setTaxPercent($taxPercent)
92+
{
93+
$this->taxPercent = $taxPercent;
94+
return $this;
95+
}
96+
97+
/**
98+
* @return float
99+
*/
100+
public function getTaxPercent()
101+
{
102+
return $this->taxPercent;
103+
}
104+
81105
}

src/Request/Invoices/CreateInvoiceRequest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class CreateInvoiceRequest
3535
*/
3636
protected $subscription;
3737

38+
/**
39+
* @var float
40+
*/
41+
protected $taxPercent;
42+
3843
/**
3944
* @param string $customer
4045
*/
@@ -133,5 +138,22 @@ public function getSubscription()
133138
return $this->subscription;
134139
}
135140

141+
/**
142+
* @param float $taxPercent
143+
* @return $this
144+
*/
145+
public function setTaxPercent($taxPercent)
146+
{
147+
$this->taxPercent = $taxPercent;
148+
return $this;
149+
}
150+
151+
/**
152+
* @return float
153+
*/
154+
public function getTaxPercent()
155+
{
156+
return $this->taxPercent;
157+
}
136158

137159
}

src/Request/Subscriptions/CreateSubscriptionRequest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class CreateSubscriptionRequest
4242
*/
4343
protected $applicationFeePercent;
4444

45+
/**
46+
* @var float
47+
*/
48+
protected $taxPercent;
49+
4550
/**
4651
* @param string $plan
4752
*/
@@ -158,5 +163,23 @@ public function setTrialEnd($trialEnd)
158163
return $this;
159164
}
160165

166+
/**
167+
* @param float $taxPercent
168+
* @return $this
169+
*/
170+
public function setTaxPercent($taxPercent)
171+
{
172+
$this->taxPercent = $taxPercent;
173+
return $this;
174+
}
175+
176+
/**
177+
* @return float
178+
*/
179+
public function getTaxPercent()
180+
{
181+
return $this->taxPercent;
182+
}
183+
161184

162185
}

src/Response/Invoices/InvoiceResponse.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ class InvoiceResponse
168168
*/
169169
protected $forgiven;
170170

171+
/**
172+
* @Type("float")
173+
* @var float
174+
*/
175+
protected $taxPercent;
176+
177+
/**
178+
* @Type("integer")
179+
* @var int
180+
*/
181+
protected $tax;
182+
171183
/**
172184
* @param int $amountDue
173185
* @return $this
@@ -635,4 +647,41 @@ public function setForgiven($forgiven)
635647
$this->forgiven = $forgiven;
636648
return $this;
637649
}
650+
651+
/**
652+
* @param int $tax
653+
* @return $this
654+
*/
655+
public function setTax($tax)
656+
{
657+
$this->tax = $tax;
658+
return $this;
659+
}
660+
661+
/**
662+
* @return int
663+
*/
664+
public function getTax()
665+
{
666+
return $this->tax;
667+
}
668+
669+
/**
670+
* @param float $taxPercent
671+
* @return $this
672+
*/
673+
public function setTaxPercent($taxPercent)
674+
{
675+
$this->taxPercent = $taxPercent;
676+
return $this;
677+
}
678+
679+
/**
680+
* @return float
681+
*/
682+
public function getTaxPercent()
683+
{
684+
return $this->taxPercent;
685+
}
686+
638687
}

src/Response/Subscriptions/SubscriptionResponse.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ class SubscriptionResponse
109109
*/
110110
protected $trialStart;
111111

112+
/**
113+
* @Type("float")
114+
* @var float
115+
*/
116+
protected $taxPercent;
117+
112118
/**
113119
* @return PlanResponse
114120
*/
@@ -396,4 +402,23 @@ public function setTrialStart($trialStart)
396402
$this->trialStart = $trialStart;
397403
return $this;
398404
}
405+
406+
/**
407+
* @param float $taxPercent
408+
* @return $this
409+
*/
410+
public function setTaxPercent($taxPercent)
411+
{
412+
$this->taxPercent = $taxPercent;
413+
return $this;
414+
}
415+
416+
/**
417+
* @return float
418+
*/
419+
public function getTaxPercent()
420+
{
421+
return $this->taxPercent;
422+
}
423+
399424
}

tests/Api/CustomersTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ public function testCreateCustomer()
3131
{
3232
$balance = -500;
3333
$description = "testing";
34+
$taxRate = 12.3;
3435
$request = new CreateCustomerRequest();
35-
$request->setAccountBalance($balance)->setDescription($description);
36+
$request->setAccountBalance($balance)->setDescription($description)->setTaxPercent($taxRate);
3637
$response = $this->customers->createCustomer($request);
3738

3839
$this->assertInstanceOf(Customers::CUSTOMER_RESPONSE_CLASS, $response);
3940
$this->assertEquals($balance, $response->getAccountBalance());
4041
$this->assertEquals($description, $request->getDescription());
42+
$this->assertEquals($taxRate, $request->getTaxPercent());
4143

4244
$this->client->delete('customers/' . $response->getId());
4345
}

tests/Api/InvoicesTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@ public function testUpdateInvoice()
7676
$request = $this->invoices->createInvoiceRequest($this->customerId);
7777
$invoice = $this->invoices->createInvoice($request);
7878

79-
$updatedInvoice = $this->invoices->updateInvoice($invoice->getId(), null, false, 'Updated Description', array('updated' => 'metadata'));
79+
$updatedInvoice = $this->invoices->updateInvoice($invoice->getId(), null, false, 'Updated Description', array('updated' => 'metadata'), 0.2);
8080
$this->assertInstanceOf(Invoices::INVOICE_RESPONSE_CLASS, $updatedInvoice);
8181

8282
$this->assertEquals(null, $updatedInvoice->getApplicationFee());
8383
$this->assertEquals(false, $updatedInvoice->getClosed());
8484
$this->assertEquals('Updated Description', $updatedInvoice->getDescription());
8585
$this->assertEquals(array('updated' => 'metadata'), $updatedInvoice->getMetadata());
86+
$this->assertEquals(0.2, $updatedInvoice->getTaxPercent());
8687
}
8788

8889
public function testPayInvoice()

tests/Api/SubscriptionsTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected function tearDown()
5959
public function testCreateSubscription()
6060
{
6161
$request = new CreateSubscriptionRequest($this->planId);
62-
$request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020));
62+
$request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123));
6363
$response = $this->subscriptions->createSubscription($this->customerId, $request);
6464

6565
$this->assertInstanceOf(Subscriptions::SUBSCRIPTION_RESPONSE_CLASS, $response);
@@ -69,7 +69,7 @@ public function testCreateSubscription()
6969
public function testGetSubscription()
7070
{
7171
$request = new CreateSubscriptionRequest($this->planId);
72-
$request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020));
72+
$request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123));
7373
$createResponse = $this->subscriptions->createSubscription($this->customerId, $request);
7474

7575
$getResponse = $this->subscriptions->getSubscription($this->customerId, $createResponse->getId());
@@ -81,7 +81,7 @@ public function testGetSubscription()
8181
public function testUpdateSubscription()
8282
{
8383
$request = new CreateSubscriptionRequest($this->planId);
84-
$request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020));
84+
$request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123));
8585
$createResponse = $this->subscriptions->createSubscription($this->customerId, $request);
8686

8787
$request = new UpdateSubscriptionRequest();
@@ -95,7 +95,7 @@ public function testUpdateSubscription()
9595
public function testCancelSubscription()
9696
{
9797
$request = new CreateSubscriptionRequest($this->planId);
98-
$request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020));
98+
$request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123));
9999
$createResponse = $this->subscriptions->createSubscription($this->customerId, $request);
100100

101101
$cancelResponse = $this->subscriptions->cancelSubscription($this->customerId, $createResponse->getId(), true);
@@ -107,7 +107,7 @@ public function testCancelSubscription()
107107
public function testListSubscriptions()
108108
{
109109
$request = new CreateSubscriptionRequest($this->planId);
110-
$request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020));
110+
$request->setCard(new CreateCardRequest(self::VISA_1, 1, 2020, 123));
111111
$this->subscriptions->createSubscription($this->customerId, $request);
112112
$this->subscriptions->createSubscription($this->customerId, $request);
113113
$this->subscriptions->createSubscription($this->customerId, $request);

0 commit comments

Comments
 (0)