-
Notifications
You must be signed in to change notification settings - Fork 850
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 support for TaxId resource and APIs #630
Merged
+196
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 = Customer::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 Customer::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,29 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
class TaxIdTest extends TestCase | ||
{ | ||
const TEST_CUSTOMER_ID = 'cus_123'; | ||
const TEST_RESOURCE_ID = 'txi_123'; | ||
|
||
public function testHasCorrectUrl() | ||
{ | ||
$resource = \Stripe\Customer::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() | ||
); | ||
} | ||
|
||
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)); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flagging that
tax_ids
the collection is returned on the Customer object, like sources and subscriptions. Not sure anymore if that changes things