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

Get rid of ExternalAccount #417

Merged
merged 1 commit into from
Jan 10, 2018
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: 0 additions & 1 deletion init.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
require(dirname(__FILE__) . '/lib/ApiRequestor.php');
require(dirname(__FILE__) . '/lib/ApiResource.php');
require(dirname(__FILE__) . '/lib/SingletonApiResource.php');
require(dirname(__FILE__) . '/lib/ExternalAccount.php');

// Stripe API Resources
require(dirname(__FILE__) . '/lib/Account.php');
Expand Down
10 changes: 5 additions & 5 deletions lib/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function deauthorize($clientId = null, $opts = null)
* @param array|null $params
* @param array|string|null $opts
*
* @return ExternalAccount
* @return BankAccount|Card
*/
public static function createExternalAccount($id, $params = null, $opts = null)
{
Expand All @@ -133,7 +133,7 @@ public static function createExternalAccount($id, $params = null, $opts = null)
* @param array|null $params
* @param array|string|null $opts
*
* @return ExternalAccount
* @return BankAccount|Card
*/
public static function retrieveExternalAccount($id, $externalAccountId, $params = null, $opts = null)
{
Expand All @@ -146,7 +146,7 @@ public static function retrieveExternalAccount($id, $externalAccountId, $params
* @param array|null $params
* @param array|string|null $opts
*
* @return ExternalAccount
* @return BankAccount|Card
*/
public static function updateExternalAccount($id, $externalAccountId, $params = null, $opts = null)
{
Expand All @@ -159,7 +159,7 @@ public static function updateExternalAccount($id, $externalAccountId, $params =
* @param array|null $params
* @param array|string|null $opts
*
* @return ExternalAccount
* @return BankAccount|Card
*/
public static function deleteExternalAccount($id, $externalAccountId, $params = null, $opts = null)
{
Expand All @@ -171,7 +171,7 @@ public static function deleteExternalAccount($id, $externalAccountId, $params =
* @param array|null $params
* @param array|string|null $opts
*
* @return ExternalAccount
* @return BankAccount|Card
*/
public static function allExternalAccounts($id, $params = null, $opts = null)
{
Expand Down
58 changes: 57 additions & 1 deletion lib/AlipayAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,64 @@
* Class AlipayAccount
*
* @package Stripe
*
* @deprecated Alipay accounts are deprecated. Please use the sources API instead.
* @link https://stripe.com/docs/sources/alipay
*/
class AlipayAccount extends ExternalAccount
class AlipayAccount extends ApiResource
{
use ApiOperations\Delete;
use ApiOperations\Update;

/**
* @return string The instance URL for this resource. It needs to be special
* cased because it doesn't fit into the standard resource pattern.
*/
public function instanceUrl()
{
if ($this['customer']) {
$base = Customer::classUrl();
$parent = $this['customer'];
$path = 'sources';
} else {
$msg = "Alipay accounts cannot be accessed without a customer ID.";
throw new Error\InvalidRequest($msg, null);
}
$parentExtn = urlencode(Util\Util::utf8($parent));
$extn = urlencode(Util\Util::utf8($this['id']));
return "$base/$parentExtn/$path/$extn";
}

/**
* @param array|string $_id
* @param array|string|null $_opts
*
* @throws \Stripe\Error\InvalidRequest
*
* @deprecated Alipay accounts are deprecated. Please use the sources API instead.
* @link https://stripe.com/docs/sources/alipay
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Alipay accounts cannot be accessed without a customer ID. " .
"Retrieve an Alipay account using \$customer->sources->retrieve('alipay_account_id') instead.";
throw new Error\InvalidRequest($msg, null);
}

/**
* @param string $_id
* @param array|null $_params
* @param array|string|null $_options
*
* @throws \Stripe\Error\InvalidRequest
*
* @deprecated Alipay accounts are deprecated. Please use the sources API instead.
* @link https://stripe.com/docs/sources/alipay
*/
public static function update($_id, $_params = null, $_options = null)
{
$msg = "Alipay accounts cannot be accessed without a customer ID. " .
"Call save() on \$customer->sources->retrieve('alipay_account_id') instead.";
throw new Error\InvalidRequest($msg, null);
}
}
57 changes: 56 additions & 1 deletion lib/BankAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,64 @@
*
* @package Stripe
*/
class BankAccount extends ExternalAccount
class BankAccount extends ApiResource
{
use ApiOperations\Delete;
use ApiOperations\Update;

/**
* @return string The instance URL for this resource. It needs to be special
* cased because it doesn't fit into the standard resource pattern.
*/
public function instanceUrl()
{
if ($this['customer']) {
$base = Customer::classUrl();
$parent = $this['customer'];
$path = 'sources';
} elseif ($this['account']) {
$base = Account::classUrl();
$parent = $this['account'];
$path = 'external_accounts';
} else {
$msg = "Bank accounts cannot be accessed without a customer ID or account ID.";
throw new Error\InvalidRequest($msg, null);
}
$parentExtn = urlencode(Util\Util::utf8($parent));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels weird to encode so much knowledge about the URL structure in this object, but this is similar to, stripe-ruby, for example:

https://github.com/stripe/stripe-ruby/blob/master/lib/stripe/bank_account.rb

On the one hand, this leads to duplicated logic; on the other hand, it simplifies this object's dependencies and leads to more explicit tests.

$extn = urlencode(Util\Util::utf8($this['id']));
return "$base/$parentExtn/$path/$extn";
}

/**
* @param array|string $_id
* @param array|string|null $_opts
*
* @throws \Stripe\Error\InvalidRequest
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Bank accounts cannot be accessed without a customer ID or account ID. " .
"Retrieve a bank account using \$customer->sources->retrieve('bank_account_id') or " .
"\$account->external_accounts->retrieve('bank_account_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 = "Bank accounts cannot be accessed without a customer ID or account ID. " .
"Call save() on \$customer->sources->retrieve('bank_account_id') or " .
"\$account->external_accounts->retrieve('bank_account_id') instead.";
throw new Error\InvalidRequest($msg, null);
}

/**
* @param array|null $params
* @param array|string|null $options
*
Expand Down
44 changes: 14 additions & 30 deletions lib/BitcoinReceiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

/**
* Class BitcoinReceiver

* @deprecated Please use sources instead.
*
* @package Stripe
*
* @deprecated Bitcoin receivers are deprecated. Please use the sources API instead.
* @link https://stripe.com/docs/sources/bitcoin
*/
class BitcoinReceiver extends ExternalAccount
class BitcoinReceiver extends ApiResource
{
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Retrieve;

/**
* @return string The class URL for this resource. It needs to be special
* cased because it doesn't fit into the standard resource pattern.
*
* @deprecated Please use sources instead.
*/
public static function classUrl()
{
Expand All @@ -27,36 +27,20 @@ public static function classUrl()
/**
* @return string The instance URL for this resource. It needs to be special
* cased because it doesn't fit into the standard resource pattern.
*
* @deprecated Please use sources instead.
*/
public function instanceUrl()
{
$result = parent::instanceUrl();
if ($result) {
return $result;
if ($this['customer']) {
$base = Customer::classUrl();
$parent = $this['customer'];
$path = 'sources';
$parentExtn = urlencode(Util\Util::utf8($parent));
$extn = urlencode(Util\Util::utf8($this['id']));
return "$base/$parentExtn/$path/$extn";
} else {
$id = $this['id'];
$id = Util\Util::utf8($id);
$extn = urlencode($id);
$base = BitcoinReceiver::classUrl();
$extn = urlencode(Util\Util::utf8($this['id']));
return "$base/$extn";
}
}

/**
* @param array|null $params
* @param array|string|null $options
*
* @return BitcoinReceiver The refunded Bitcoin Receiver item.
*
* @deprecated Please use sources instead.
*/
public function refund($params = null, $options = null)
{
$url = $this->instanceUrl() . '/refund';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom($response, $opts);
return $this;
}
}
64 changes: 62 additions & 2 deletions lib/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @property string $country
* @property string $customer
* @property string $cvc_check
* @property string $dynamic_last4": null,
* @property string $dynamic_last4
* @property int $exp_month
* @property int $exp_year
* @property string $fingerprint
Expand All @@ -31,7 +31,67 @@
*
* @package Stripe
*/
class Card extends ExternalAccount
class Card extends ApiResource
{
use ApiOperations\Delete;
use ApiOperations\Update;

/**
* @return string The instance URL for this resource. It needs to be special
* cased because cards are nested resources that may belong to different
* top-level resources.
*/
public function instanceUrl()
{
if ($this['customer']) {
$base = Customer::classUrl();
$parent = $this['customer'];
$path = 'sources';
} elseif ($this['account']) {
$base = Account::classUrl();
$parent = $this['account'];
$path = 'external_accounts';
} elseif ($this['recipient']) {
$base = Recipient::classUrl();
$parent = $this['recipient'];
$path = 'cards';
} else {
$msg = "Cards cannot be accessed without a customer ID, account ID or recipient ID.";
throw new Error\InvalidRequest($msg, null);
}
$parentExtn = urlencode(Util\Util::utf8($parent));
$extn = urlencode(Util\Util::utf8($this['id']));
return "$base/$parentExtn/$path/$extn";
}

/**
* @param array|string $_id
* @param array|string|null $_opts
*
* @throws \Stripe\Error\InvalidRequest
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Cards cannot be accessed without a customer, recipient or account ID. " .
"Retrieve a card using \$customer->sources->retrieve('card_id'), " .
"\$recipient->cards->retrieve('card_id'), or";
"\$account->external_accounts->retrieve('card_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 = "Cards cannot be accessed without a customer, recipient or account ID. " .
"Call save() on \$customer->sources->retrieve('card_id'), " .
"\$recipient->cards->retrieve('card_id'), or";
"\$account->external_accounts->retrieve('card_id') instead.";
throw new Error\InvalidRequest($msg, null);
}
}
10 changes: 5 additions & 5 deletions lib/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function deleteDiscount()
* @param array|null $params
* @param array|string|null $opts
*
* @return ExternalAccount
* @return ApiResource
*/
public static function createSource($id, $params = null, $opts = null)
{
Expand All @@ -152,7 +152,7 @@ public static function createSource($id, $params = null, $opts = null)
* @param array|null $params
* @param array|string|null $opts
*
* @return ExternalAccount
* @return ApiResource
*/
public static function retrieveSource($id, $sourceId, $params = null, $opts = null)
{
Expand All @@ -165,7 +165,7 @@ public static function retrieveSource($id, $sourceId, $params = null, $opts = nu
* @param array|null $params
* @param array|string|null $opts
*
* @return ExternalAccount
* @return ApiResource
*/
public static function updateSource($id, $sourceId, $params = null, $opts = null)
{
Expand All @@ -178,7 +178,7 @@ public static function updateSource($id, $sourceId, $params = null, $opts = null
* @param array|null $params
* @param array|string|null $opts
*
* @return ExternalAccount
* @return ApiResource
*/
public static function deleteSource($id, $sourceId, $params = null, $opts = null)
{
Expand All @@ -190,7 +190,7 @@ public static function deleteSource($id, $sourceId, $params = null, $opts = null
* @param array|null $params
* @param array|string|null $opts
*
* @return ExternalAccount
* @return ApiResource
*/
public static function allSources($id, $params = null, $opts = null)
{
Expand Down
Loading