Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TaxIds API #1650

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
require __DIR__ . '/lib/Service/Tax/TaxServiceFactory.php';
require __DIR__ . '/lib/Service/Tax/TransactionService.php';
require __DIR__ . '/lib/Service/TaxCodeService.php';
require __DIR__ . '/lib/Service/TaxIdService.php';
require __DIR__ . '/lib/Service/TaxRateService.php';
require __DIR__ . '/lib/Service/Terminal/ConfigurationService.php';
require __DIR__ . '/lib/Service/Terminal/ConnectionTokenService.php';
Expand Down
2 changes: 2 additions & 0 deletions lib/Service/CoreServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* @property SubscriptionScheduleService $subscriptionSchedules
* @property Tax\TaxServiceFactory $tax
* @property TaxCodeService $taxCodes
* @property TaxIdService $taxIds
* @property TaxRateService $taxRates
* @property Terminal\TerminalServiceFactory $terminal
* @property TestHelpers\TestHelpersServiceFactory $testHelpers
Expand Down Expand Up @@ -133,6 +134,7 @@ class CoreServiceFactory extends \Stripe\Service\AbstractServiceFactory
'subscriptionSchedules' => SubscriptionScheduleService::class,
'tax' => Tax\TaxServiceFactory::class,
'taxCodes' => TaxCodeService::class,
'taxIds' => TaxIdService::class,
'taxRates' => TaxRateService::class,
'terminal' => Terminal\TerminalServiceFactory::class,
'testHelpers' => TestHelpers\TestHelpersServiceFactory::class,
Expand Down
76 changes: 76 additions & 0 deletions lib/Service/TaxIdService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

// File generated from our OpenAPI spec

namespace Stripe\Service;

/**
* @phpstan-import-type RequestOptionsArray from \Stripe\Util\RequestOptions
*/
/**
* @psalm-import-type RequestOptionsArray from \Stripe\Util\RequestOptions
*/
class TaxIdService extends \Stripe\Service\AbstractService
{
/**
* Returns a list of tax IDs.
*
* @param null|array $params
* @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return \Stripe\Collection<\Stripe\TaxId>
*/
public function all($params = null, $opts = null)
{
return $this->requestCollection('get', '/v1/tax_ids', $params, $opts);
}

/**
* Creates a new account or customer <code>tax_id</code> object.
*
* @param null|array $params
* @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return \Stripe\TaxId
*/
public function create($params = null, $opts = null)
{
return $this->request('post', '/v1/tax_ids', $params, $opts);
}

/**
* Deletes an existing account or customer <code>tax_id</code> object.
*
* @param string $id
* @param null|array $params
* @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return \Stripe\TaxId
*/
public function delete($id, $params = null, $opts = null)
{
return $this->request('delete', $this->buildPath('/v1/tax_ids/%s', $id), $params, $opts);
}

/**
* Retrieves an account or customer <code>tax_id</code> object.
*
* @param string $id
* @param null|array $params
* @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return \Stripe\TaxId
*/
public function retrieve($id, $params = null, $opts = null)
{
return $this->request('get', $this->buildPath('/v1/tax_ids/%s', $id), $params, $opts);
}
}
1 change: 1 addition & 0 deletions lib/StripeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* @property \Stripe\Service\SubscriptionScheduleService $subscriptionSchedules
* @property \Stripe\Service\Tax\TaxServiceFactory $tax
* @property \Stripe\Service\TaxCodeService $taxCodes
* @property \Stripe\Service\TaxIdService $taxIds
* @property \Stripe\Service\TaxRateService $taxRates
* @property \Stripe\Service\Terminal\TerminalServiceFactory $terminal
* @property \Stripe\Service\TestHelpers\TestHelpersServiceFactory $testHelpers
Expand Down
40 changes: 3 additions & 37 deletions lib/TaxId.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class TaxId extends ApiResource
{
const OBJECT_NAME = 'tax_id';

use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Delete;
use ApiOperations\Retrieve;

const TYPE_AD_NRT = 'ad_nrt';
const TYPE_AE_TRN = 'ae_trn';
Expand Down Expand Up @@ -100,41 +103,4 @@ class TaxId extends ApiResource
const VERIFICATION_STATUS_UNAVAILABLE = 'unavailable';
const VERIFICATION_STATUS_UNVERIFIED = 'unverified';
const VERIFICATION_STATUS_VERIFIED = 'verified';

/**
* @return string the API URL for this tax id
*/
public function instanceUrl()
{
$id = $this['id'];
$customer = $this['customer'];
if (!$id) {
throw new Exception\UnexpectedValueException(
"Could not determine which URL to request: class instance has invalid ID: {$id}"
);
}
$id = Util\Util::utf8($id);
$customer = Util\Util::utf8($customer);

$base = Customer::classUrl();
$customerExtn = \urlencode($customer);
$extn = \urlencode($id);

return "{$base}/{$customerExtn}/tax_ids/{$extn}";
}

/**
* @param array|string $_id
* @param null|array|string $_opts
*
* @throws \Stripe\Exception\BadMethodCallException
*/
public static function retrieve($_id, $_opts = null)
{
$msg = 'Tax IDs cannot be retrieved without a customer ID. Retrieve ' .
"a tax ID using `Customer::retrieveTaxId('customer_id', " .
"'tax_id_id')`.";

throw new Exception\BadMethodCallException($msg);
}
}
37 changes: 31 additions & 6 deletions tests/Stripe/TaxIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,49 @@ final class TaxIdTest extends \Stripe\TestCase
{
use TestHelper;

const TEST_CUSTOMER_ID = 'cus_123';
const TEST_RESOURCE_ID = 'txi_123';

public function testHasCorrectUrl()
public function testIsListable()
{
$resource = \Stripe\Customer::retrieveTaxId(self::TEST_CUSTOMER_ID, self::TEST_RESOURCE_ID);
$this->expectsRequest(
'get',
'/v1/tax_ids'
);
$resources = TaxId::all();
static::compatAssertIsArray($resources->data);
static::assertInstanceOf(\Stripe\TaxId::class, $resources->data[0]);
}

public function testIsRetrievable()
{
$this->expectsRequest(
'get',
'/v1/tax_ids/' . self::TEST_RESOURCE_ID
);
$resource = \Stripe\TaxId::retrieve(self::TEST_RESOURCE_ID);
static::assertInstanceOf(\Stripe\TaxId::class, $resource);
static::assertSame(
'/v1/customers/' . self::TEST_CUSTOMER_ID . '/tax_ids/' . self::TEST_RESOURCE_ID,
'/v1/tax_ids/' . self::TEST_RESOURCE_ID,
$resource->instanceUrl()
);
}

public function testIsCreatable()
{
$this->expectsRequest(
'post',
'/v1/tax_ids'
);
$resource = TaxId::create(['type' => 'eu_vat', 'value' => 'DE123456789']);
static::assertInstanceOf(\Stripe\TaxId::class, $resource);
}

public function testIsDeletable()
{
$resource = \Stripe\Customer::retrieveTaxId(self::TEST_CUSTOMER_ID, self::TEST_RESOURCE_ID);
$resource = \Stripe\TaxId::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'delete',
'/v1/customers/' . self::TEST_CUSTOMER_ID . '/tax_ids/' . self::TEST_RESOURCE_ID
'/v1/tax_ids/' . self::TEST_RESOURCE_ID
);
$resource->delete();
static::assertInstanceOf(\Stripe\TaxId::class, $resource);
Expand Down
Loading