From 498788ca31aa08c8e0b6d4aa6d8d14b1586f0640 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Fri, 12 Apr 2019 14:47:30 -0700 Subject: [PATCH] Add support for TaxId resource and APIs --- init.php | 1 + lib/Customer.php | 51 +++++++++++++++++++++++++ lib/TaxId.php | 71 +++++++++++++++++++++++++++++++++++ lib/Util/Util.php | 1 + tests/Stripe/CustomerTest.php | 41 ++++++++++++++++++++ tests/Stripe/TaxIdTest.php | 26 +++++++++++++ 6 files changed, 191 insertions(+) create mode 100644 lib/TaxId.php create mode 100644 tests/Stripe/TaxIdTest.php diff --git a/init.php b/init.php index 0ed7ab45d..f2649624a 100644 --- a/init.php +++ b/init.php @@ -118,6 +118,7 @@ require(dirname(__FILE__) . '/lib/SubscriptionItem.php'); require(dirname(__FILE__) . '/lib/SubscriptionSchedule.php'); require(dirname(__FILE__) . '/lib/SubscriptionScheduleRevision.php'); +require(dirname(__FILE__) . '/lib/TaxId.php'); require(dirname(__FILE__) . '/lib/Terminal/ConnectionToken.php'); require(dirname(__FILE__) . '/lib/Terminal/Location.php'); require(dirname(__FILE__) . '/lib/Terminal/Reader.php'); diff --git a/lib/Customer.php b/lib/Customer.php index 83683fe2a..4dcd95953 100644 --- a/lib/Customer.php +++ b/lib/Customer.php @@ -51,6 +51,7 @@ public static function getSavedNestedResources() } const PATH_SOURCES = '/sources'; + const PATH_TAX_IDS = '/tax_ids'; /** * @param array|null $params @@ -202,4 +203,54 @@ public static function allSources($id, $params = null, $opts = null) { return self::_allNestedResources($id, static::PATH_SOURCES, $params, $opts); } + + /** + * @param string|null $id The ID of the customer on which to create the tax id. + * @param array|null $params + * @param array|string|null $opts + * + * @return ApiResource + */ + public static function createTaxId($id, $params = null, $opts = null) + { + return self::_createNestedResource($id, static::PATH_TAX_IDS, $params, $opts); + } + + /** + * @param string|null $id The ID of the customer to which the tax id belongs. + * @param string|null $taxIdId The ID of the tax id to retrieve. + * @param array|null $params + * @param array|string|null $opts + * + * @return ApiResource + */ + public static function retrieveTaxId($id, $taxIdId, $params = null, $opts = null) + { + return self::_retrieveNestedResource($id, static::PATH_TAX_IDS, $taxIdId, $params, $opts); + } + + /** + * @param string|null $id The ID of the customer to which the tax id belongs. + * @param string|null $taxIdId The ID of the tax id to delete. + * @param array|null $params + * @param array|string|null $opts + * + * @return ApiResource + */ + public static function deleteTaxId($id, $taxIdId, $params = null, $opts = null) + { + return self::_deleteNestedResource($id, static::PATH_TAX_IDS, $taxIdId, $params, $opts); + } + + /** + * @param string|null $id The ID of the customer on which to retrieve the tax ids. + * @param array|null $params + * @param array|string|null $opts + * + * @return Collection The list of tax ids. + */ + public static function allTaxIds($id, $params = null, $opts = null) + { + return self::_allNestedResources($id, static::PATH_TAX_IDS, $params, $opts); + } } diff --git a/lib/TaxId.php b/lib/TaxId.php new file mode 100644 index 000000000..afe37e72f --- /dev/null +++ b/lib/TaxId.php @@ -0,0 +1,71 @@ +retrieveTaxId('tax_id') instead."; + throw new Error\InvalidRequest($msg, null); + } +} diff --git a/lib/Util/Util.php b/lib/Util/Util.php index 03b80ee30..e116ec9b9 100644 --- a/lib/Util/Util.php +++ b/lib/Util/Util.php @@ -131,6 +131,7 @@ public static function convertToStripeObject($resp, $opts) \Stripe\SubscriptionItem::OBJECT_NAME => 'Stripe\\SubscriptionItem', \Stripe\SubscriptionSchedule::OBJECT_NAME => 'Stripe\\SubscriptionSchedule', \Stripe\SubscriptionScheduleRevision::OBJECT_NAME => 'Stripe\\SubscriptionScheduleRevision', + \Stripe\TaxId::OBJECT_NAME => 'Stripe\\TaxId', \Stripe\ThreeDSecure::OBJECT_NAME => 'Stripe\\ThreeDSecure', \Stripe\Terminal\ConnectionToken::OBJECT_NAME => 'Stripe\\Terminal\\ConnectionToken', \Stripe\Terminal\Location::OBJECT_NAME => 'Stripe\\Terminal\\Location', diff --git a/tests/Stripe/CustomerTest.php b/tests/Stripe/CustomerTest.php index e2af6215d..3ea5b3765 100644 --- a/tests/Stripe/CustomerTest.php +++ b/tests/Stripe/CustomerTest.php @@ -6,6 +6,7 @@ class CustomerTest extends TestCase { const TEST_RESOURCE_ID = 'cus_123'; const TEST_SOURCE_ID = 'ba_123'; + const TEST_TAX_ID = 'txi_123'; public function testIsListable() { @@ -263,4 +264,44 @@ public function testSerializeSourceMap() ]; $this->assertSame($expected, $obj->serializeParameters()); } + + public function testCanCreateTaxId() + { + $this->expectsRequest( + 'post', + '/v1/customers/' . self::TEST_RESOURCE_ID . '/tax_ids' + ); + $resource = Customer::createTaxId(self::TEST_RESOURCE_ID, [ + "type" => TaxId::TYPE_EU_VAT, + "value" => "11111", + ]); + } + + public function testCanRetrieveTaxId() + { + $this->expectsRequest( + 'get', + '/v1/customers/' . self::TEST_RESOURCE_ID . '/tax_ids/' . self::TEST_TAX_ID + ); + $resource = Customer::retrieveTaxId(self::TEST_RESOURCE_ID, self::TEST_TAX_ID); + } + + public function testCanDeleteTaxId() + { + $this->expectsRequest( + 'delete', + '/v1/customers/' . self::TEST_RESOURCE_ID . '/tax_ids/' . self::TEST_TAX_ID + ); + $resource = Customer::deleteTaxId(self::TEST_RESOURCE_ID, self::TEST_TAX_ID); + } + + public function testCanListTaxIds() + { + $this->expectsRequest( + 'get', + '/v1/customers/' . self::TEST_RESOURCE_ID . '/tax_ids' + ); + $resources = Customer::allTaxIds(self::TEST_RESOURCE_ID); + $this->assertTrue(is_array($resources->data)); + } } diff --git a/tests/Stripe/TaxIdTest.php b/tests/Stripe/TaxIdTest.php new file mode 100644 index 000000000..8edf20822 --- /dev/null +++ b/tests/Stripe/TaxIdTest.php @@ -0,0 +1,26 @@ +assertSame( + "/v1/customers/" . self::TEST_CUSTOMER_ID . "/tax_ids/" . self::TEST_RESOURCE_ID, + $resource->instanceUrl() + ); + } + + /** + * @expectedException \Stripe\Error\InvalidRequest + */ + public function testIsNotDirectlyRetrievable() + { + TaxId::retrieve(self::TEST_RESOURCE_ID); + } +}