UsBankAccount.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace Braintree;
  3. /**
  4. * Braintree UsBankAccount module
  5. *
  6. * @package Braintree
  7. * @category Resources
  8. */
  9. /**
  10. * Manages Braintree UsBankAccounts
  11. *
  12. * <b>== More information ==</b>
  13. *
  14. *
  15. * @package Braintree
  16. * @category Resources
  17. *
  18. * @property-read string $customerId
  19. * @property-read string $email
  20. * @property-read string $token
  21. * @property-read string $imageUrl
  22. * @property-read string $routingNumber
  23. * @property-read string $accountType
  24. * @property-read string $accountHolderName
  25. * @property-read string $last4
  26. * @property-read string $bankName
  27. * @property-read string $achMandate
  28. * @property-read string $default
  29. * @property-read boolean $verified
  30. */
  31. class UsBankAccount extends Base
  32. {
  33. /**
  34. * factory method: returns an instance of UsBankAccount
  35. * to the requesting method, with populated properties
  36. *
  37. * @ignore
  38. * @return UsBankAccount
  39. */
  40. public static function factory($attributes)
  41. {
  42. $instance = new self();
  43. $instance->_initialize($attributes);
  44. return $instance;
  45. }
  46. /* instance methods */
  47. /**
  48. * sets instance properties from an array of values
  49. *
  50. * @access protected
  51. * @param array $usBankAccountAttribs array of usBankAccount data
  52. * @return void
  53. */
  54. protected function _initialize($usBankAccountAttribs)
  55. {
  56. // set the attributes
  57. $this->_attributes = $usBankAccountAttribs;
  58. $achMandate = isset($usBankAccountAttribs['achMandate']) ?
  59. AchMandate::factory($usBankAccountAttribs['achMandate']) :
  60. null;
  61. $this->_set('achMandate', $achMandate);
  62. if (isset($usBankAccountAttribs['verifications'])) {
  63. $verification_records = $usBankAccountAttribs['verifications'];
  64. $verifications = array();
  65. for ($i = 0; $i < count($verification_records); $i++) {
  66. $verifications[$i] = UsBankAccountVerification::factory($verification_records[$i]);
  67. }
  68. $this->_set('verifications', $verifications);
  69. } else {
  70. $this->_set('verifications', null);
  71. }
  72. }
  73. /**
  74. * create a printable representation of the object as:
  75. * ClassName[property=value, property=value]
  76. * @return string
  77. */
  78. public function __toString()
  79. {
  80. return __CLASS__ . '[' .
  81. Util::attributesToString($this->_attributes) . ']';
  82. }
  83. /**
  84. * returns false if default is null or false
  85. *
  86. * @return boolean
  87. */
  88. public function isDefault()
  89. {
  90. return $this->default;
  91. }
  92. // static methods redirecting to gateway
  93. public static function find($token)
  94. {
  95. return Configuration::gateway()->usBankAccount()->find($token);
  96. }
  97. public static function sale($token, $transactionAttribs)
  98. {
  99. $transactionAttribs['options'] = [
  100. 'submitForSettlement' => true
  101. ];
  102. return Configuration::gateway()->usBankAccount()->sale($token, $transactionAttribs);
  103. }
  104. }
  105. class_alias('Braintree\UsBankAccount', 'Braintree_UsBankAccount');