Skip to content

Commit

Permalink
Update Invoice and Subscription APIs to allow setting tax percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
downsider committed May 28, 2015
1 parent ccf00ff commit f059a71
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/Api/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
}

Expand Down
24 changes: 24 additions & 0 deletions src/Request/Customers/CreateCustomerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class CreateCustomerRequest extends AbstractCustomerRequest
*/
protected $trialEnd;

/**
* @var float
*/
protected $taxPercent;

/**
* @return string
*/
Expand Down Expand Up @@ -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;
}

}
22 changes: 22 additions & 0 deletions src/Request/Invoices/CreateInvoiceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class CreateInvoiceRequest
*/
protected $subscription;

/**
* @var float
*/
protected $taxPercent;

/**
* @param string $customer
*/
Expand Down Expand Up @@ -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;
}

}
23 changes: 23 additions & 0 deletions src/Request/Subscriptions/CreateSubscriptionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class CreateSubscriptionRequest
*/
protected $applicationFeePercent;

/**
* @var float
*/
protected $taxPercent;

/**
* @param string $plan
*/
Expand Down Expand Up @@ -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;
}


}
49 changes: 49 additions & 0 deletions src/Response/Invoices/InvoiceResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

}
25 changes: 25 additions & 0 deletions src/Response/Subscriptions/SubscriptionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ class SubscriptionResponse
*/
protected $trialStart;

/**
* @Type("float")
* @var float
*/
protected $taxPercent;

/**
* @return PlanResponse
*/
Expand Down Expand Up @@ -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;
}

}
4 changes: 3 additions & 1 deletion tests/Api/CustomersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Api/InvoicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions tests/Api/SubscriptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit f059a71

Please sign in to comment.