BraintreeCustomer

Braintree Customer module Creates and manages Customers.

Defined (1)

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

/classes/lib/Braintree/Braintree/Customer.php  
  1. class Customer extends Base 
  2. /** 
  3. * @return Customer[] 
  4. */ 
  5. public static function all() 
  6. return Configuration::gateway()->customer()->all(); 
  7.  
  8. /** 
  9. * @param string $query 
  10. * @param int[] $ids 
  11. * @return Customer|Customer[] 
  12. */ 
  13. public static function fetch($query, $ids) 
  14. return Configuration::gateway()->customer()->fetch($query, $ids); 
  15.  
  16. /** 
  17. * @param array $attribs 
  18. * @return Customer 
  19. */ 
  20. public static function create($attribs = []) 
  21. return Configuration::gateway()->customer()->create($attribs); 
  22.  
  23. /** 
  24. * @param array $attribs 
  25. * @return Customer 
  26. */ 
  27. public static function createNoValidate($attribs = []) 
  28. return Configuration::gateway()->customer()->createNoValidate($attribs); 
  29.  
  30. /** 
  31. * @deprecated since version 2.3.0 
  32. * @param string $queryString 
  33. * @return Result\Successful 
  34. */ 
  35. public static function createFromTransparentRedirect($queryString) 
  36. return Configuration::gateway()->customer()->createFromTransparentRedirect($queryString); 
  37.  
  38. /** 
  39. * @deprecated since version 2.3.0 
  40. * @return string 
  41. */ 
  42. public static function createCustomerUrl() 
  43. return Configuration::gateway()->customer()->createCustomerUrl(); 
  44.  
  45. /** 
  46. * @throws Exception\NotFound 
  47. * @param string $id customer id 
  48. * @return Customer 
  49. */ 
  50. public static function find($id) 
  51. return Configuration::gateway()->customer()->find($id); 
  52.  
  53. /** 
  54. * @param int $customerId 
  55. * @param array $transactionAttribs 
  56. * @return Result\Successful|Result\Error 
  57. */ 
  58. public static function credit($customerId, $transactionAttribs) 
  59. return Configuration::gateway()->customer()->credit($customerId, $transactionAttribs); 
  60.  
  61. /** 
  62. * @throws Exception\ValidationError 
  63. * @param type $customerId 
  64. * @param type $transactionAttribs 
  65. * @return Transaction 
  66. */ 
  67. public static function creditNoValidate($customerId, $transactionAttribs) 
  68. return Configuration::gateway()->customer()->creditNoValidate($customerId, $transactionAttribs); 
  69.  
  70. /** 
  71. * @throws Exception on invalid id or non-200 http response code 
  72. * @param int $customerId 
  73. * @return Result\Successful 
  74. */ 
  75. public static function delete($customerId) 
  76. return Configuration::gateway()->customer()->delete($customerId); 
  77.  
  78. /** 
  79. * @param int $customerId 
  80. * @param array $transactionAttribs 
  81. * @return Transaction 
  82. */ 
  83. public static function sale($customerId, $transactionAttribs) 
  84. return Configuration::gateway()->customer()->sale($customerId, $transactionAttribs); 
  85.  
  86. /** 
  87. * @param int $customerId 
  88. * @param array $transactionAttribs 
  89. * @return Transaction 
  90. */ 
  91. public static function saleNoValidate($customerId, $transactionAttribs) 
  92. return Configuration::gateway()->customer()->saleNoValidate($customerId, $transactionAttribs); 
  93.  
  94. /** 
  95. * @throws InvalidArgumentException 
  96. * @param string $query 
  97. * @return ResourceCollection 
  98. */ 
  99. public static function search($query) 
  100. return Configuration::gateway()->customer()->search($query); 
  101.  
  102. /** 
  103. * @throws Exception\Unexpected 
  104. * @param int $customerId 
  105. * @param array $attributes 
  106. * @return Result\Successful|Result\Error 
  107. */ 
  108. public static function update($customerId, $attributes) 
  109. return Configuration::gateway()->customer()->update($customerId, $attributes); 
  110.  
  111. /** 
  112. * @throws Exception\Unexpected 
  113. * @param int $customerId 
  114. * @param array $attributes 
  115. * @return CustomerGateway 
  116. */ 
  117. public static function updateNoValidate($customerId, $attributes) 
  118. return Configuration::gateway()->customer()->updateNoValidate($customerId, $attributes); 
  119.  
  120. /** 
  121. * @deprecated since version 2.3.0 
  122. * @return string 
  123. */ 
  124. public static function updateCustomerUrl() 
  125. return Configuration::gateway()->customer()->updateCustomerUrl(); 
  126.  
  127. /** 
  128. * @deprecated since version 2.3.0 
  129. * @param string $queryString 
  130. * @return Result\Successful|Result\Error 
  131. */ 
  132. public static function updateFromTransparentRedirect($queryString) 
  133. return Configuration::gateway()->customer()->updateFromTransparentRedirect($queryString); 
  134.  
  135. /** instance methods */ 
  136.  
  137. /** 
  138. * sets instance properties from an array of values 
  139. * @ignore 
  140. * @access protected 
  141. * @param array $customerAttribs array of customer data 
  142. */ 
  143. protected function _initialize($customerAttribs) 
  144. $this->_attributes = $customerAttribs; 
  145.  
  146. $addressArray = []; 
  147. if (isset($customerAttribs['addresses'])) { 
  148.  
  149. foreach ($customerAttribs['addresses'] AS $address) { 
  150. $addressArray[] = Address::factory($address); 
  151. $this->_set('addresses', $addressArray); 
  152.  
  153. $creditCardArray = []; 
  154. if (isset($customerAttribs['creditCards'])) { 
  155. foreach ($customerAttribs['creditCards'] AS $creditCard) { 
  156. $creditCardArray[] = CreditCard::factory($creditCard); 
  157. $this->_set('creditCards', $creditCardArray); 
  158.  
  159. $coinbaseAccountArray = []; 
  160. if (isset($customerAttribs['coinbaseAccounts'])) { 
  161. foreach ($customerAttribs['coinbaseAccounts'] AS $coinbaseAccount) { 
  162. $coinbaseAccountArray[] = CoinbaseAccount::factory($coinbaseAccount); 
  163. $this->_set('coinbaseAccounts', $coinbaseAccountArray); 
  164.  
  165. $paypalAccountArray = []; 
  166. if (isset($customerAttribs['paypalAccounts'])) { 
  167. foreach ($customerAttribs['paypalAccounts'] AS $paypalAccount) { 
  168. $paypalAccountArray[] = PayPalAccount::factory($paypalAccount); 
  169. $this->_set('paypalAccounts', $paypalAccountArray); 
  170.  
  171. $applePayCardArray = []; 
  172. if (isset($customerAttribs['applePayCards'])) { 
  173. foreach ($customerAttribs['applePayCards'] AS $applePayCard) { 
  174. $applePayCardArray[] = ApplePayCard::factory($applePayCard); 
  175. $this->_set('applePayCards', $applePayCardArray); 
  176.  
  177. $androidPayCardArray = []; 
  178. if (isset($customerAttribs['androidPayCards'])) { 
  179. foreach ($customerAttribs['androidPayCards'] AS $androidPayCard) { 
  180. $androidPayCardArray[] = AndroidPayCard::factory($androidPayCard); 
  181. $this->_set('androidPayCards', $androidPayCardArray); 
  182.  
  183. $amexExpressCheckoutCardArray = []; 
  184. if (isset($customerAttribs['amexExpressCheckoutCards'])) { 
  185. foreach ($customerAttribs['amexExpressCheckoutCards'] AS $amexExpressCheckoutCard) { 
  186. $amexExpressCheckoutCardArray[] = AmexExpressCheckoutCard::factory($amexExpressCheckoutCard); 
  187. $this->_set('amexExpressCheckoutCards', $amexExpressCheckoutCardArray); 
  188.  
  189. $venmoAccountArray = array(); 
  190. if (isset($customerAttribs['venmoAccounts'])) { 
  191. foreach ($customerAttribs['venmoAccounts'] AS $venmoAccount) { 
  192. $venmoAccountArray[] = VenmoAccount::factory($venmoAccount); 
  193. $this->_set('venmoAccounts', $venmoAccountArray); 
  194.  
  195. $this->_set('paymentMethods', array_merge( 
  196. $this->creditCards,  
  197. $this->paypalAccounts,  
  198. $this->applePayCards,  
  199. $this->coinbaseAccounts,  
  200. $this->androidPayCards,  
  201. $this->amexExpressCheckoutCards,  
  202. $this->venmoAccounts 
  203. )); 
  204.  
  205. /** 
  206. * returns a string representation of the customer 
  207. * @return string 
  208. */ 
  209. public function __toString() 
  210. return __CLASS__ . '[' . 
  211. Util::attributesToString($this->_attributes) .']'; 
  212.  
  213. /** 
  214. * returns false if comparing object is not a Customer,  
  215. * or is a Customer with a different id 
  216. * @param object $otherCust customer to compare against 
  217. * @return boolean 
  218. */ 
  219. public function isEqual($otherCust) 
  220. return !($otherCust instanceof Customer) ? false : $this->id === $otherCust->id; 
  221.  
  222. /** 
  223. * returns an array containt all of the customer's payment methods 
  224. * @deprecated since version 3.1.0 - use the paymentMethods property directly 
  225. * @return array 
  226. */ 
  227. public function paymentMethods() 
  228. return $this->paymentMethods; 
  229.  
  230. /** 
  231. * returns the customer's default payment method 
  232. * @return CreditCard|PayPalAccount 
  233. */ 
  234. public function defaultPaymentMethod() 
  235. $defaultPaymentMethods = array_filter($this->paymentMethods, 'Braintree\Customer::_defaultPaymentMethodFilter'); 
  236. return current($defaultPaymentMethods); 
  237.  
  238. public static function _defaultPaymentMethodFilter($paymentMethod) 
  239. return $paymentMethod->isDefault(); 
  240.  
  241. /** private class properties */ 
  242.  
  243. /** 
  244. * @access protected 
  245. * @var array registry of customer data 
  246. */ 
  247. protected $_attributes = [ 
  248. 'addresses' => '',  
  249. 'company' => '',  
  250. 'creditCards' => '',  
  251. 'email' => '',  
  252. 'fax' => '',  
  253. 'firstName' => '',  
  254. 'id' => '',  
  255. 'lastName' => '',  
  256. 'phone' => '',  
  257. 'createdAt' => '',  
  258. 'updatedAt' => '',  
  259. 'website' => '',  
  260. ]; 
  261.  
  262. /** 
  263. * factory method: returns an instance of Customer 
  264. * to the requesting method, with populated properties 
  265. * @ignore 
  266. * @param array $attributes 
  267. * @return Customer 
  268. */ 
  269. public static function factory($attributes) 
  270. $instance = new Customer(); 
  271. $instance->_initialize($attributes); 
  272. return $instance;