-
Notifications
You must be signed in to change notification settings - Fork 853
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 the Capability resource and APIs
- Loading branch information
1 parent
124fafb
commit 71b2bc0
Showing
6 changed files
with
225 additions
and
15 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,83 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
/** | ||
* Class Capability | ||
* | ||
* @package Stripe | ||
* | ||
* @property string $id | ||
* @property string $object | ||
* @property string $account | ||
* @property bool $requested | ||
* @property int $requested_at | ||
* @property mixed $requirements | ||
* @property string $status | ||
*/ | ||
class Capability extends ApiResource | ||
{ | ||
|
||
const OBJECT_NAME = "capability"; | ||
|
||
use ApiOperations\Update; | ||
|
||
/** | ||
* Possible string representations of a capability's status. | ||
* @link https://stripe.com/docs/api/capabilities/object#capability_object-status | ||
*/ | ||
const STATUS_ACTIVE = 'active'; | ||
const STATUS_INACTIVE = 'inactive'; | ||
const STATUS_PENDING = 'pending'; | ||
const STATUS_UNREQUESTED = 'unrequested'; | ||
|
||
/** | ||
* @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/capabilities/$extn"; | ||
} | ||
|
||
/** | ||
* @param array|string $_id | ||
* @param array|string|null $_opts | ||
* | ||
* @throws \Stripe\Error\InvalidRequest | ||
*/ | ||
public static function retrieve($_id, $_opts = null) | ||
{ | ||
$msg = "Capabilities cannot be accessed without an account ID. " . | ||
"Retrieve a Capability using \$account->retrieveCapability('acap_123') 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 = "Capabilities cannot be accessed without an account ID. " . | ||
"Update a Capability using \$account->updateCapability('acap_123') 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,46 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
class CapabilityTest extends TestCase | ||
{ | ||
const TEST_ACCOUNT_ID = 'acct_123'; | ||
const TEST_RESOURCE_ID = 'acap_123'; | ||
|
||
public function testHasCorrectUrl() | ||
{ | ||
$resource = \Stripe\Account::retrieveCapability(self::TEST_ACCOUNT_ID, self::TEST_RESOURCE_ID); | ||
$this->assertSame( | ||
"/v1/accounts/" . self::TEST_ACCOUNT_ID . "/capabilities/" . self::TEST_RESOURCE_ID, | ||
$resource->instanceUrl() | ||
); | ||
} | ||
|
||
/** | ||
* @expectedException \Stripe\Error\InvalidRequest | ||
*/ | ||
public function testIsNotDirectlyRetrievable() | ||
{ | ||
Capability::retrieve(self::TEST_RESOURCE_ID); | ||
} | ||
|
||
public function testIsSaveable() | ||
{ | ||
$resource = \Stripe\Account::retrieveCapability(self::TEST_ACCOUNT_ID, self::TEST_RESOURCE_ID); | ||
$resource->requested = true; | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/accounts/' . self::TEST_ACCOUNT_ID . '/capabilities/' . self::TEST_RESOURCE_ID | ||
); | ||
$resource->save(); | ||
$this->assertSame("Stripe\\Capability", get_class($resource)); | ||
} | ||
|
||
/** | ||
* @expectedException \Stripe\Error\InvalidRequest | ||
*/ | ||
public function testIsNotDirectlyUpdatable() | ||
{ | ||
Capability::update(self::TEST_RESOURCE_ID, ["requested" => true]); | ||
} | ||
} |