-
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.
Merge pull request #536 from stripe/remi-add-person
Add support for the Person resource
- Loading branch information
Showing
9 changed files
with
306 additions
and
5 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
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,92 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
/** | ||
* Class Person | ||
* | ||
* @package Stripe | ||
* | ||
* @property string $id | ||
* @property string $object | ||
* @property string $account | ||
* @property mixed $address | ||
* @property mixed $address_kana | ||
* @property mixed $address_kanji | ||
* @property int $created | ||
* @property bool $deleted | ||
* @property mixed $dob | ||
* @property string $email | ||
* @property string $first_name | ||
* @property string $first_name_kana | ||
* @property string $first_name_kanji | ||
* @property string $gender | ||
* @property bool $id_number_provided | ||
* @property string $last_name | ||
* @property string $last_name_kana | ||
* @property string $last_name_kanji | ||
* @property string $maiden_name | ||
* @property StripeObject $metadata | ||
* @property string $phone | ||
* @property mixed $relationship | ||
* @property mixed $requirements | ||
* @property bool $ssn_last_4_provided | ||
* @property mixed $verification | ||
*/ | ||
class Person extends ApiResource | ||
{ | ||
const OBJECT_NAME = "person"; | ||
|
||
use ApiOperations\Delete; | ||
use ApiOperations\Update; | ||
|
||
/** | ||
* @return string The API URL for this Stripe account reversal. | ||
*/ | ||
public function instanceUrl() | ||
{ | ||
$id = $this['id']; | ||
$account = $this['account']; | ||
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); | ||
$account = Util\Util::utf8($account); | ||
|
||
$base = Account::classUrl(); | ||
$accountExtn = urlencode($account); | ||
$extn = urlencode($id); | ||
return "$base/$accountExtn/persons/$extn"; | ||
} | ||
|
||
/** | ||
* @param array|string $_id | ||
* @param array|string|null $_opts | ||
* | ||
* @throws \Stripe\Error\InvalidRequest | ||
*/ | ||
public static function retrieve($_id, $_opts = null) | ||
{ | ||
$msg = "Persons cannot be accessed without an account ID. " . | ||
"Retrieve a Person using \$account->retrievePerson('person_id') instead."; | ||
throw new Error\InvalidRequest($msg, null); | ||
} | ||
|
||
/** | ||
* @param string $_id | ||
* @param array|null $_params | ||
* @param array|string|null $_options | ||
* | ||
* @throws \Stripe\Error\InvalidRequest | ||
*/ | ||
public static function update($_id, $_params = null, $_options = null) | ||
{ | ||
$msg = "Persons cannot be accessed without an account ID. " . | ||
"Retrieve a Person using \$account->retrievePerson('person_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
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,59 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
class PersonTest extends TestCase | ||
{ | ||
const TEST_ACCOUNT_ID = 'acct_123'; | ||
const TEST_RESOURCE_ID = 'person_123'; | ||
|
||
public function testHasCorrectUrl() | ||
{ | ||
$resource = \Stripe\Account::retrievePerson(self::TEST_ACCOUNT_ID, self::TEST_RESOURCE_ID); | ||
$this->assertSame( | ||
"/v1/accounts/" . self::TEST_ACCOUNT_ID . "/persons/" . self::TEST_RESOURCE_ID, | ||
$resource->instanceUrl() | ||
); | ||
} | ||
|
||
/** | ||
* @expectedException \Stripe\Error\InvalidRequest | ||
*/ | ||
public function testIsNotDirectlyRetrievable() | ||
{ | ||
Person::retrieve(self::TEST_RESOURCE_ID); | ||
} | ||
|
||
public function testIsSaveable() | ||
{ | ||
$resource = \Stripe\Account::retrievePerson(self::TEST_ACCOUNT_ID, self::TEST_RESOURCE_ID); | ||
$resource->first_name = "value"; | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/accounts/' . self::TEST_ACCOUNT_ID . '/persons/' . self::TEST_RESOURCE_ID | ||
); | ||
$resource->save(); | ||
$this->assertSame("Stripe\\Person", get_class($resource)); | ||
} | ||
|
||
/** | ||
* @expectedException \Stripe\Error\InvalidRequest | ||
*/ | ||
public function testIsNotDirectlyUpdatable() | ||
{ | ||
Person::update(self::TEST_RESOURCE_ID, [ | ||
"first_name" => ["John"], | ||
]); | ||
} | ||
|
||
public function testIsDeletable() | ||
{ | ||
$resource = \Stripe\Account::retrievePerson(self::TEST_ACCOUNT_ID, self::TEST_RESOURCE_ID); | ||
$this->expectsRequest( | ||
'delete', | ||
'/v1/accounts/' . self::TEST_ACCOUNT_ID . '/persons/' . self::TEST_RESOURCE_ID | ||
); | ||
$resource->delete(); | ||
$this->assertSame("Stripe\\Person", get_class($resource)); | ||
} | ||
} |
Oops, something went wrong.