BraintreeMerchantAccountGateway

The Paid Memberships Pro Braintree MerchantAccountGateway class.

Defined (1)

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

/includes/lib/Braintree/lib/Braintree/MerchantAccountGateway.php  
  1. 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 function createForCurrency($attribs) 
  41. $response = $this->_http->post($this->_config->merchantPath() . '/merchant_accounts/create_for_currency', ['merchant_account' => $attribs]); 
  42. return $this->_verifyGatewayResponse($response); 
  43.  
  44. public function all() 
  45. $pager = [ 
  46. 'object' => $this,  
  47. 'method' => 'fetchMerchantAccounts',  
  48. ]; 
  49. return new PaginatedCollection($pager); 
  50.  
  51. public function fetchMerchantAccounts($page) 
  52. $response = $this->_http->get($this->_config->merchantPath() . '/merchant_accounts?page=' . $page); 
  53. $body = $response['merchantAccounts']; 
  54. $merchantAccounts = Util::extractattributeasarray($body, 'merchantAccount'); 
  55. $totalItems = $body['totalItems'][0]; 
  56. $pageSize = $body['pageSize'][0]; 
  57. return new PaginatedResult($totalItems, $pageSize, $merchantAccounts); 
  58.  
  59. public static function createSignature() 
  60. $addressSignature = ['streetAddress', 'postalCode', 'locality', 'region']; 
  61. $individualSignature = [ 
  62. 'firstName',  
  63. 'lastName',  
  64. 'email',  
  65. 'phone',  
  66. 'dateOfBirth',  
  67. 'ssn',  
  68. ['address' => $addressSignature] 
  69. ]; 
  70.  
  71. $businessSignature = [ 
  72. 'dbaName',  
  73. 'legalName',  
  74. 'taxId',  
  75. ['address' => $addressSignature] 
  76. ]; 
  77.  
  78. $fundingSignature = [ 
  79. 'routingNumber',  
  80. 'accountNumber',  
  81. 'destination',  
  82. 'email',  
  83. 'mobilePhone',  
  84. 'descriptor',  
  85. ]; 
  86.  
  87. return [ 
  88. 'id',  
  89. 'tosAccepted',  
  90. 'masterMerchantAccountId',  
  91. ['individual' => $individualSignature],  
  92. ['funding' => $fundingSignature],  
  93. ['business' => $businessSignature] 
  94. ]; 
  95.  
  96. public static function createDeprecatedSignature() 
  97. $applicantDetailsAddressSignature = ['streetAddress', 'postalCode', 'locality', 'region']; 
  98. $applicantDetailsSignature = [ 
  99. 'companyName',  
  100. 'firstName',  
  101. 'lastName',  
  102. 'email',  
  103. 'phone',  
  104. 'dateOfBirth',  
  105. 'ssn',  
  106. 'taxId',  
  107. 'routingNumber',  
  108. 'accountNumber',  
  109. ['address' => $applicantDetailsAddressSignature] 
  110. ]; 
  111.  
  112. return [ 
  113. ['applicantDetails' => $applicantDetailsSignature],  
  114. 'id',  
  115. 'tosAccepted',  
  116. 'masterMerchantAccountId' 
  117. ]; 
  118.  
  119. public function _doCreate($subPath, $params) 
  120. $fullPath = $this->_config->merchantPath() . $subPath; 
  121. $response = $this->_http->post($fullPath, $params); 
  122.  
  123. return $this->_verifyGatewayResponse($response); 
  124.  
  125. private function _doUpdate($subPath, $params) 
  126. $fullPath = $this->_config->merchantPath() . $subPath; 
  127. $response = $this->_http->put($fullPath, $params); 
  128.  
  129. return $this->_verifyGatewayResponse($response); 
  130.  
  131. private function _verifyGatewayResponse($response) 
  132. if (isset($response['response'])) { 
  133. $response = $response['response']; 
  134. if (isset($response['merchantAccount'])) { 
  135. // return a populated instance of merchantAccount 
  136. return new Result\Successful( 
  137. MerchantAccount::factory($response['merchantAccount']) 
  138. ); 
  139. } else if (isset($response['apiErrorResponse'])) { 
  140. return new Result\Error($response['apiErrorResponse']); 
  141. } else { 
  142. throw new Exception\Unexpected( 
  143. "Expected merchant account or apiErrorResponse" 
  144. );