BraintreeUsBankAccountGateway

Manages Braintree UsBankAccounts.

Defined (1)

The class is defined in the following location(s).

/includes/lib/Braintree/lib/Braintree/UsBankAccountGateway.php  
  1. class UsBankAccountGateway 
  2. private $_gateway; 
  3. private $_config; 
  4. private $_http; 
  5.  
  6. public function __construct($gateway) 
  7. $this->_gateway = $gateway; 
  8. $this->_config = $gateway->config; 
  9. $this->_config->assertHasAccessTokenOrKeys(); 
  10. $this->_http = new Http($gateway->config); 
  11.  
  12.  
  13. /** 
  14. * find a usBankAccount by token 
  15. * @access public 
  16. * @param string $token paypal accountunique id 
  17. * @return UsBankAccount 
  18. * @throws Exception\NotFound 
  19. */ 
  20. public function find($token) 
  21. try { 
  22. $path = $this->_config->merchantPath() . '/payment_methods/us_bank_account/' . $token; 
  23. $response = $this->_http->get($path); 
  24. return UsBankAccount::factory($response['usBankAccount']); 
  25. } catch (Exception\NotFound $e) { 
  26. throw new Exception\NotFound( 
  27. 'US bank account with token ' . $token . ' not found' 
  28. ); 
  29.  
  30.  
  31. /** 
  32. * create a new sale for the current UsBank account 
  33. * @param string $token 
  34. * @param array $transactionAttribs 
  35. * @return Result\Successful|Result\Error 
  36. * @see Transaction::sale() 
  37. */ 
  38. public function sale($token, $transactionAttribs) 
  39. return Transaction::sale( 
  40. array_merge( 
  41. $transactionAttribs,  
  42. ['paymentMethodToken' => $token] 
  43. ); 
  44.  
  45. /** 
  46. * generic method for validating incoming gateway responses 
  47. * creates a new UsBankAccount object and encapsulates 
  48. * it inside a Result\Successful object, or 
  49. * encapsulates a Errors object inside a Result\Error 
  50. * alternatively, throws an Unexpected exception if the response is invalid. 
  51. * @ignore 
  52. * @param array $response gateway response values 
  53. * @return Result\Successful|Result\Error 
  54. * @throws Exception\Unexpected 
  55. */ 
  56. private function _verifyGatewayResponse($response) 
  57. if (isset($response['usBankAccount'])) { 
  58. // return a populated instance of UsBankAccount 
  59. return new Result\Successful( 
  60. UsBankAccount::factory($response['usBankAccount']) 
  61. ); 
  62. } else if (isset($response['apiErrorResponse'])) { 
  63. return new Result\Error($response['apiErrorResponse']); 
  64. } else { 
  65. throw new Exception\Unexpected( 
  66. 'Expected US bank account or apiErrorResponse' 
  67. );