BankAccount.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace Stripe;
  3. /**
  4. * Class BankAccount
  5. *
  6. * @property string $id
  7. * @property string $object
  8. * @property string $account
  9. * @property string $account_holder_name
  10. * @property string $account_holder_type
  11. * @property string $bank_name
  12. * @property string $country
  13. * @property string $currency
  14. * @property string $customer
  15. * @property bool $default_for_currency
  16. * @property string $fingerprint
  17. * @property string $last4
  18. * @property StripeObject $metadata
  19. * @property string $routing_number
  20. * @property string $status
  21. *
  22. * @package Stripe
  23. */
  24. class BankAccount extends ApiResource
  25. {
  26. const OBJECT_NAME = "bank_account";
  27. use ApiOperations\Delete;
  28. use ApiOperations\Update;
  29. /**
  30. * @return string The instance URL for this resource. It needs to be special
  31. * cased because it doesn't fit into the standard resource pattern.
  32. */
  33. public function instanceUrl()
  34. {
  35. if ($this['customer']) {
  36. $base = Customer::classUrl();
  37. $parent = $this['customer'];
  38. $path = 'sources';
  39. } elseif ($this['account']) {
  40. $base = Account::classUrl();
  41. $parent = $this['account'];
  42. $path = 'external_accounts';
  43. } else {
  44. $msg = "Bank accounts cannot be accessed without a customer ID or account ID.";
  45. throw new Error\InvalidRequest($msg, null);
  46. }
  47. $parentExtn = urlencode(Util\Util::utf8($parent));
  48. $extn = urlencode(Util\Util::utf8($this['id']));
  49. return "$base/$parentExtn/$path/$extn";
  50. }
  51. /**
  52. * @param array|string $_id
  53. * @param array|string|null $_opts
  54. *
  55. * @throws \Stripe\Error\InvalidRequest
  56. */
  57. public static function retrieve($_id, $_opts = null)
  58. {
  59. $msg = "Bank accounts cannot be accessed without a customer ID or account ID. " .
  60. "Retrieve a bank account using \$customer->sources->retrieve('bank_account_id') or " .
  61. "\$account->external_accounts->retrieve('bank_account_id') instead.";
  62. throw new Error\InvalidRequest($msg, null);
  63. }
  64. /**
  65. * @param string $_id
  66. * @param array|null $_params
  67. * @param array|string|null $_options
  68. *
  69. * @throws \Stripe\Error\InvalidRequest
  70. */
  71. public static function update($_id, $_params = null, $_options = null)
  72. {
  73. $msg = "Bank accounts cannot be accessed without a customer ID or account ID. " .
  74. "Call save() on \$customer->sources->retrieve('bank_account_id') or " .
  75. "\$account->external_accounts->retrieve('bank_account_id') instead.";
  76. throw new Error\InvalidRequest($msg, null);
  77. }
  78. /**
  79. * @param array|null $params
  80. * @param array|string|null $options
  81. *
  82. * @return BankAccount The verified bank account.
  83. */
  84. public function verify($params = null, $options = null)
  85. {
  86. $url = $this->instanceUrl() . '/verify';
  87. list($response, $opts) = $this->_request('post', $url, $params, $options);
  88. $this->refreshFrom($response, $opts);
  89. return $this;
  90. }
  91. }