BraintreeMerchantAccountGateway

The PayPal for WooCommerce Braintree MerchantAccountGateway class.

Defined (1)

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

/classes/lib/Braintree/Braintree/MerchantAccountGateway.php  
  1. final class MerchantAccountGateway 
  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. public function create($attribs) 
  13. Util::verifyKeys(self::detectSignature($attribs), $attribs); 
  14. return $this->_doCreate('/merchant_accounts/create_via_api', ['merchant_account' => $attribs]); 
  15.  
  16. public function find($merchant_account_id) 
  17. try { 
  18. $path = $this->_config->merchantPath() . '/merchant_accounts/' . $merchant_account_id; 
  19. $response = $this->_http->get($path); 
  20. return MerchantAccount::factory($response['merchantAccount']); 
  21. } catch (Exception\NotFound $e) { 
  22. throw new Exception\NotFound('merchant account with id ' . $merchant_account_id . ' not found'); 
  23.  
  24. public function update($merchant_account_id, $attributes) 
  25. Util::verifyKeys(self::updateSignature(), $attributes); 
  26. return $this->_doUpdate('/merchant_accounts/' . $merchant_account_id . '/update_via_api', ['merchant_account' => $attributes]); 
  27.  
  28. public static function detectSignature($attribs) 
  29. if (isset($attribs['applicantDetails'])) { 
  30. trigger_error("DEPRECATED: Passing applicantDetails to create is deprecated. Please use individual, business, and funding", E_USER_NOTICE); 
  31. return self::createDeprecatedSignature(); 
  32. } else { 
  33. return self::createSignature(); 
  34.  
  35. public static function updateSignature() 
  36. $signature = self::createSignature(); 
  37. unset($signature['tosAccepted']); 
  38. return $signature; 
  39.  
  40. public static function createSignature() 
  41. $addressSignature = ['streetAddress', 'postalCode', 'locality', 'region']; 
  42. $individualSignature = [ 
  43. 'firstName',  
  44. 'lastName',  
  45. 'email',  
  46. 'phone',  
  47. 'dateOfBirth',  
  48. 'ssn',  
  49. ['address' => $addressSignature] 
  50. ]; 
  51.  
  52. $businessSignature = [ 
  53. 'dbaName',  
  54. 'legalName',  
  55. 'taxId',  
  56. ['address' => $addressSignature] 
  57. ]; 
  58.  
  59. $fundingSignature = [ 
  60. 'routingNumber',  
  61. 'accountNumber',  
  62. 'destination',  
  63. 'email',  
  64. 'mobilePhone',  
  65. 'descriptor',  
  66. ]; 
  67.  
  68. return [ 
  69. 'id',  
  70. 'tosAccepted',  
  71. 'masterMerchantAccountId',  
  72. ['individual' => $individualSignature],  
  73. ['funding' => $fundingSignature],  
  74. ['business' => $businessSignature] 
  75. ]; 
  76.  
  77. public static function createDeprecatedSignature() 
  78. $applicantDetailsAddressSignature = ['streetAddress', 'postalCode', 'locality', 'region']; 
  79. $applicantDetailsSignature = [ 
  80. 'companyName',  
  81. 'firstName',  
  82. 'lastName',  
  83. 'email',  
  84. 'phone',  
  85. 'dateOfBirth',  
  86. 'ssn',  
  87. 'taxId',  
  88. 'routingNumber',  
  89. 'accountNumber',  
  90. ['address' => $applicantDetailsAddressSignature] 
  91. ]; 
  92.  
  93. return [ 
  94. ['applicantDetails' => $applicantDetailsSignature],  
  95. 'id',  
  96. 'tosAccepted',  
  97. 'masterMerchantAccountId' 
  98. ]; 
  99.  
  100. public function _doCreate($subPath, $params) 
  101. $fullPath = $this->_config->merchantPath() . $subPath; 
  102. $response = $this->_http->post($fullPath, $params); 
  103.  
  104. return $this->_verifyGatewayResponse($response); 
  105.  
  106. private function _doUpdate($subPath, $params) 
  107. $fullPath = $this->_config->merchantPath() . $subPath; 
  108. $response = $this->_http->put($fullPath, $params); 
  109.  
  110. return $this->_verifyGatewayResponse($response); 
  111.  
  112. private function _verifyGatewayResponse($response) 
  113. if (isset($response['merchantAccount'])) { 
  114. // return a populated instance of merchantAccount 
  115. return new Result\Successful( 
  116. MerchantAccount::factory($response['merchantAccount']) 
  117. ); 
  118. } else if (isset($response['apiErrorResponse'])) { 
  119. return new Result\Error($response['apiErrorResponse']); 
  120. } else { 
  121. throw new Exception\Unexpected( 
  122. "Expected merchant account or apiErrorResponse" 
  123. );