diff --git a/.travis.yml b/.travis.yml index ed52f45b2..77ba0aa05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ php: env: global: - - STRIPE_MOCK_VERSION=0.52.0 + - STRIPE_MOCK_VERSION=0.54.0 matrix: - AUTOLOAD=1 - AUTOLOAD=0 diff --git a/init.php b/init.php index a3c193aa6..7d908bf44 100644 --- a/init.php +++ b/init.php @@ -119,6 +119,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..46fa6dd0a --- /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 7b167cd64..bec1fda4d 100644 --- a/lib/Util/Util.php +++ b/lib/Util/Util.php @@ -132,6 +132,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..f482c7a10 --- /dev/null +++ b/tests/Stripe/TaxIdTest.php @@ -0,0 +1,29 @@ +assertSame( + "/v1/customers/" . self::TEST_CUSTOMER_ID . "/tax_ids/" . self::TEST_RESOURCE_ID, + $resource->instanceUrl() + ); + } + + public function testIsDeletable() + { + $resource = \Stripe\Customer::retrieveTaxId(self::TEST_CUSTOMER_ID, self::TEST_RESOURCE_ID); + $this->expectsRequest( + 'delete', + '/v1/customers/' . self::TEST_CUSTOMER_ID . '/tax_ids/' . self::TEST_RESOURCE_ID + ); + $resource->delete(); + $this->assertSame("Stripe\\TaxId", get_class($resource)); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 734c96232..958bc6e9c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/StripeMock.php'); -define("MOCK_MINIMUM_VERSION", "0.52.0"); +define("MOCK_MINIMUM_VERSION", "0.54.0"); if (\Stripe\StripeMock::start()) { register_shutdown_function('\Stripe\StripeMock::stop');