PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/braintree/braintree_php/lib/Braintree/MerchantAccountGateway.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 152 lines | 133 code | 18 blank | 1 comment | 6 complexity | e2073aff6f8b3c5f2e64b23b210c44f7 MD5 | raw file
  1. <?php
  2. final class Braintree_MerchantAccountGateway
  3. {
  4. private $_gateway;
  5. private $_config;
  6. private $_http;
  7. public function __construct($gateway)
  8. {
  9. $this->_gateway = $gateway;
  10. $this->_config = $gateway->config;
  11. $this->_config->assertHasAccessTokenOrKeys();
  12. $this->_http = new Braintree_Http($gateway->config);
  13. }
  14. public function create($attribs)
  15. {
  16. Braintree_Util::verifyKeys(self::detectSignature($attribs), $attribs);
  17. return $this->_doCreate('/merchant_accounts/create_via_api', array('merchant_account' => $attribs));
  18. }
  19. public function find($merchant_account_id)
  20. {
  21. try {
  22. $path = $this->_config->merchantPath() . '/merchant_accounts/' . $merchant_account_id;
  23. $response = $this->_http->get($path);
  24. return Braintree_MerchantAccount::factory($response['merchantAccount']);
  25. } catch (Braintree_Exception_NotFound $e) {
  26. throw new Braintree_Exception_NotFound('merchant account with id ' . $merchant_account_id . ' not found');
  27. }
  28. }
  29. public function update($merchant_account_id, $attributes)
  30. {
  31. Braintree_Util::verifyKeys(self::updateSignature(), $attributes);
  32. return $this->_doUpdate('/merchant_accounts/' . $merchant_account_id . '/update_via_api', array('merchant_account' => $attributes));
  33. }
  34. public static function detectSignature($attribs)
  35. {
  36. if (isset($attribs['applicantDetails'])) {
  37. trigger_error("DEPRECATED: Passing applicantDetails to create is deprecated. Please use individual, business, and funding", E_USER_NOTICE);
  38. return self::createDeprecatedSignature();
  39. } else {
  40. return self::createSignature();
  41. }
  42. }
  43. public static function updateSignature()
  44. {
  45. $signature = self::createSignature();
  46. unset($signature['tosAccepted']);
  47. return $signature;
  48. }
  49. public static function createSignature()
  50. {
  51. $addressSignature = array('streetAddress', 'postalCode', 'locality', 'region');
  52. $individualSignature = array(
  53. 'firstName',
  54. 'lastName',
  55. 'email',
  56. 'phone',
  57. 'dateOfBirth',
  58. 'ssn',
  59. array('address' => $addressSignature)
  60. );
  61. $businessSignature = array(
  62. 'dbaName',
  63. 'legalName',
  64. 'taxId',
  65. array('address' => $addressSignature)
  66. );
  67. $fundingSignature = array(
  68. 'routingNumber',
  69. 'accountNumber',
  70. 'destination',
  71. 'email',
  72. 'mobilePhone',
  73. 'descriptor',
  74. );
  75. return array(
  76. 'id',
  77. 'tosAccepted',
  78. 'masterMerchantAccountId',
  79. array('individual' => $individualSignature),
  80. array('funding' => $fundingSignature),
  81. array('business' => $businessSignature)
  82. );
  83. }
  84. public static function createDeprecatedSignature()
  85. {
  86. $applicantDetailsAddressSignature = array('streetAddress', 'postalCode', 'locality', 'region');
  87. $applicantDetailsSignature = array(
  88. 'companyName',
  89. 'firstName',
  90. 'lastName',
  91. 'email',
  92. 'phone',
  93. 'dateOfBirth',
  94. 'ssn',
  95. 'taxId',
  96. 'routingNumber',
  97. 'accountNumber',
  98. array('address' => $applicantDetailsAddressSignature)
  99. );
  100. return array(
  101. array('applicantDetails' => $applicantDetailsSignature),
  102. 'id',
  103. 'tosAccepted',
  104. 'masterMerchantAccountId'
  105. );
  106. }
  107. public function _doCreate($subPath, $params)
  108. {
  109. $fullPath = $this->_config->merchantPath() . $subPath;
  110. $response = $this->_http->post($fullPath, $params);
  111. return $this->_verifyGatewayResponse($response);
  112. }
  113. private function _doUpdate($subPath, $params)
  114. {
  115. $fullPath = $this->_config->merchantPath() . $subPath;
  116. $response = $this->_http->put($fullPath, $params);
  117. return $this->_verifyGatewayResponse($response);
  118. }
  119. private function _verifyGatewayResponse($response)
  120. {
  121. if (isset($response['merchantAccount'])) {
  122. // return a populated instance of Braintree_merchantAccount
  123. return new Braintree_Result_Successful(
  124. Braintree_MerchantAccount::factory($response['merchantAccount'])
  125. );
  126. } else if (isset($response['apiErrorResponse'])) {
  127. return new Braintree_Result_Error($response['apiErrorResponse']);
  128. } else {
  129. throw new Braintree_Exception_Unexpected(
  130. "Expected merchant account or apiErrorResponse"
  131. );
  132. }
  133. }
  134. }