-
Notifications
You must be signed in to change notification settings - Fork 850
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for TaxId resource and APIs
- Loading branch information
1 parent
22f6696
commit 498788c
Showing
6 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
/** | ||
* Class TaxId | ||
* | ||
* @package Stripe | ||
* | ||
* @property string $id | ||
* @property string $object | ||
* @property string $country | ||
* @property int $created | ||
* @property string $customer | ||
* @property bool $deleted | ||
* @property bool $livemode | ||
* @property type $type | ||
* @property string $value | ||
* @property mixed $verification | ||
*/ | ||
class TaxId extends ApiResource | ||
{ | ||
|
||
const OBJECT_NAME = "tax_id"; | ||
|
||
use ApiOperations\Delete; | ||
|
||
/** | ||
* Possible string representations of a tax id's type. | ||
* @link https://stripe.com/docs/api/customers/tax_id_object#tax_id_object-type | ||
*/ | ||
const TYPE_AU_ABN = 'au_abn'; | ||
const TYPE_EU_VAT = 'eu_vat'; | ||
const TYPE_NZ_GST = 'nz_gst'; | ||
const TYPE_UNKNOWN = 'unknown'; | ||
|
||
/** | ||
* @return string The API URL for this tax id. | ||
*/ | ||
public function instanceUrl() | ||
{ | ||
$id = $this['id']; | ||
$customer = $this['customer']; | ||
if (!$id) { | ||
throw new Error\InvalidRequest( | ||
"Could not determine which URL to request: class instance has invalid ID: $id", | ||
null | ||
); | ||
} | ||
$id = Util\Util::utf8($id); | ||
$customer = Util\Util::utf8($customer); | ||
|
||
$base = Account::classUrl(); | ||
$customerExtn = urlencode($customer); | ||
$extn = urlencode($id); | ||
return "$base/$customerExtn/tax_ids/$extn"; | ||
} | ||
|
||
/** | ||
* @param array|string $_id | ||
* @param array|string|null $_opts | ||
* | ||
* @throws \Stripe\Error\InvalidRequest | ||
*/ | ||
public static function retrieve($_id, $_opts = null) | ||
{ | ||
$msg = "Tax Ids cannot be accessed without a customer ID. " . | ||
"Retrieve a Tax Id using \$account->retrieveTaxId('tax_id') instead."; | ||
throw new Error\InvalidRequest($msg, null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
class TaxIdTest extends TestCase | ||
{ | ||
const TEST_CUSTOMER_ID = 'cus_123'; | ||
const TEST_RESOURCE_ID = 'txi_123'; | ||
|
||
public function testHasCorrectUrl() | ||
{ | ||
$resource = \Stripe\Account::retrieveTaxId(self::TEST_CUSTOMER_ID, self::TEST_RESOURCE_ID); | ||
$this->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); | ||
} | ||
} |