Skip to content

Commit

Permalink
Add support for the TaxRate resource
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Apr 23, 2019
1 parent 042acd0 commit 6fd057e
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
require(dirname(__FILE__) . '/lib/SubscriptionSchedule.php');
require(dirname(__FILE__) . '/lib/SubscriptionScheduleRevision.php');
require(dirname(__FILE__) . '/lib/TaxId.php');
require(dirname(__FILE__) . '/lib/TaxRate.php');
require(dirname(__FILE__) . '/lib/Terminal/ConnectionToken.php');
require(dirname(__FILE__) . '/lib/Terminal/Location.php');
require(dirname(__FILE__) . '/lib/Terminal/Reader.php');
Expand Down
8 changes: 8 additions & 0 deletions lib/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class Customer extends ApiResource
use ApiOperations\Retrieve;
use ApiOperations\Update;

/**
* Possible string representations of the customer's type of tax exemption.
* @link https://stripe.com/docs/api/customers/object#customer_object-tax_exempt
*/
const TAX_EXEMPT_NONE = 'none';
const TAX_EXEMPT_EXEMPT = 'exempt';
const TAX_EXEMPT_REVERSE = 'reverse';

public static function getSavedNestedResources()
{
static $savedNestedResources = null;
Expand Down
2 changes: 2 additions & 0 deletions lib/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class Event extends ApiResource
const SUBSCRIPTION_SCHEDULE_EXPIRING = 'subscription_schedule.expiring';
const SUBSCRIPTION_SCHEDULE_RELEASED = 'subscription_schedule.released';
const SUBSCRIPTION_SCHEDULE_UPDATED = 'subscription_schedule.updated';
const TAX_RATE_CREATED = 'tax_rate.created';
const TAX_RATE_UPDATED = 'tax_rate.updated';
const TOPUP_CANCELED = 'topup.canceled';
const TOPUP_CREATED = 'topup.created';
const TOPUP_FAILED = 'topup.failed';
Expand Down
31 changes: 31 additions & 0 deletions lib/TaxRate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Stripe;

/**
* Class TaxRate
*
* @property string $id
* @property string $object
* @property bool $active
* @property int $created
* @property string $description
* @property string $display_name
* @property bool $inclusive
* @property string $jurisdiction
* @property bool $livemode
* @property StripeObject $metadata
* @property float $percentage
*
* @package Stripe
*/
class TaxRate extends ApiResource
{

const OBJECT_NAME = "tax_rate";

use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Retrieve;
use ApiOperations\Update;
}
1 change: 1 addition & 0 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public static function convertToStripeObject($resp, $opts)
\Stripe\SubscriptionSchedule::OBJECT_NAME => 'Stripe\\SubscriptionSchedule',
\Stripe\SubscriptionScheduleRevision::OBJECT_NAME => 'Stripe\\SubscriptionScheduleRevision',
\Stripe\TaxId::OBJECT_NAME => 'Stripe\\TaxId',
\Stripe\TaxRate::OBJECT_NAME => 'Stripe\\TaxRate',
\Stripe\ThreeDSecure::OBJECT_NAME => 'Stripe\\ThreeDSecure',
\Stripe\Terminal\ConnectionToken::OBJECT_NAME => 'Stripe\\Terminal\\ConnectionToken',
\Stripe\Terminal\Location::OBJECT_NAME => 'Stripe\\Terminal\\Location',
Expand Down
67 changes: 67 additions & 0 deletions tests/Stripe/TaxRateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Stripe;

class TaxRateTest extends TestCase
{
const TEST_RESOURCE_ID = 'txr_123';

public function testIsListable()
{
$this->expectsRequest(
'get',
'/v1/tax_rates'
);
$resources = TaxRate::all();
$this->assertTrue(is_array($resources->data));
$this->assertInstanceOf("Stripe\\TaxRate", $resources->data[0]);
}

public function testIsRetrievable()
{
$this->expectsRequest(
'get',
'/v1/tax_rates/' . self::TEST_RESOURCE_ID
);
$resource = TaxRate::retrieve(self::TEST_RESOURCE_ID);
$this->assertInstanceOf("Stripe\\TaxRate", $resource);
}

public function testIsCreatable()
{
$this->expectsRequest(
'post',
'/v1/tax_rates'
);
$resource = TaxRate::create([
"display_name" => "name",
"inclusive" => false,
"percentage" => 10.15,
]);
$this->assertInstanceOf("Stripe\\TaxRate", $resource);
}

public function testIsSaveable()
{
$resource = TaxRate::retrieve(self::TEST_RESOURCE_ID);
$resource->metadata["key"] = "value";
$this->expectsRequest(
'post',
'/v1/tax_rates/' . self::TEST_RESOURCE_ID
);
$resource->save();
$this->assertInstanceOf("Stripe\\TaxRate", $resource);
}

public function testIsUpdatable()
{
$this->expectsRequest(
'post',
'/v1/tax_rates/' . self::TEST_RESOURCE_ID
);
$resource = TaxRate::update(self::TEST_RESOURCE_ID, [
"metadata" => ["key" => "value"],
]);
$this->assertInstanceOf("Stripe\\TaxRate", $resource);
}
}

0 comments on commit 6fd057e

Please sign in to comment.