Braintree_CreditCard

Creates and manages Braintree CreditCards.

Defined (1)

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

/classes/lib/Braintree/Braintree/CreditCard.php  
  1. class CreditCard extends Base 
  2. // Card Type 
  3. const AMEX = 'American Express'; 
  4. const CARTE_BLANCHE = 'Carte Blanche'; 
  5. const CHINA_UNION_PAY = 'China UnionPay'; 
  6. const DINERS_CLUB_INTERNATIONAL = 'Diners Club'; 
  7. const DISCOVER = 'Discover'; 
  8. const JCB = 'JCB'; 
  9. const LASER = 'Laser'; 
  10. const MAESTRO = 'Maestro'; 
  11. const MASTER_CARD = 'MasterCard'; 
  12. const SOLO = 'Solo'; 
  13. const SWITCH_TYPE = 'Switch'; 
  14. const VISA = 'Visa'; 
  15. const UNKNOWN = 'Unknown'; 
  16.  
  17. // Credit card origination location 
  18. const INTERNATIONAL = "international"; 
  19. const US = "us"; 
  20.  
  21. const PREPAID_YES = 'Yes'; 
  22. const PREPAID_NO = 'No'; 
  23. const PREPAID_UNKNOWN = 'Unknown'; 
  24.  
  25. const PAYROLL_YES = 'Yes'; 
  26. const PAYROLL_NO = 'No'; 
  27. const PAYROLL_UNKNOWN = 'Unknown'; 
  28.  
  29. const HEALTHCARE_YES = 'Yes'; 
  30. const HEALTHCARE_NO = 'No'; 
  31. const HEALTHCARE_UNKNOWN = 'Unknown'; 
  32.  
  33. const DURBIN_REGULATED_YES = 'Yes'; 
  34. const DURBIN_REGULATED_NO = 'No'; 
  35. const DURBIN_REGULATED_UNKNOWN = 'Unknown'; 
  36.  
  37. const DEBIT_YES = 'Yes'; 
  38. const DEBIT_NO = 'No'; 
  39. const DEBIT_UNKNOWN = 'Unknown'; 
  40.  
  41. const COMMERCIAL_YES = 'Yes'; 
  42. const COMMERCIAL_NO = 'No'; 
  43. const COMMERCIAL_UNKNOWN = 'Unknown'; 
  44.  
  45. const COUNTRY_OF_ISSUANCE_UNKNOWN = "Unknown"; 
  46. const ISSUING_BANK_UNKNOWN = "Unknown"; 
  47.  
  48. /** instance methods */ 
  49. /** 
  50. * returns false if default is null or false 
  51. * @return boolean 
  52. */ 
  53. public function isDefault() 
  54. return $this->default; 
  55.  
  56. /** 
  57. * checks whether the card is expired based on the current date 
  58. * @return boolean 
  59. */ 
  60. public function isExpired() 
  61. return $this->expired; 
  62.  
  63. /** 
  64. * checks whether the card is associated with venmo sdk 
  65. * @return boolean 
  66. */ 
  67. public function isVenmoSdk() 
  68. return $this->venmoSdk; 
  69.  
  70. /** 
  71. * sets instance properties from an array of values 
  72. * @access protected 
  73. * @param array $creditCardAttribs array of creditcard data 
  74. * @return void 
  75. */ 
  76. protected function _initialize($creditCardAttribs) 
  77. // set the attributes 
  78. $this->_attributes = $creditCardAttribs; 
  79.  
  80. // map each address into its own object 
  81. $billingAddress = isset($creditCardAttribs['billingAddress']) ? 
  82. Address::factory($creditCardAttribs['billingAddress']) : 
  83. null; 
  84.  
  85. $subscriptionArray = []; 
  86. if (isset($creditCardAttribs['subscriptions'])) { 
  87. foreach ($creditCardAttribs['subscriptions'] AS $subscription) { 
  88. $subscriptionArray[] = Subscription::factory($subscription); 
  89.  
  90. $this->_set('subscriptions', $subscriptionArray); 
  91. $this->_set('billingAddress', $billingAddress); 
  92. $this->_set('expirationDate', $this->expirationMonth . '/' . $this->expirationYear); 
  93. $this->_set('maskedNumber', $this->bin . '******' . $this->last4); 
  94.  
  95. if(isset($creditCardAttribs['verifications']) && count($creditCardAttribs['verifications']) > 0) { 
  96. $verifications = $creditCardAttribs['verifications']; 
  97. usort($verifications, [$this, '_compareCreatedAtOnVerifications']); 
  98.  
  99. $this->_set('verification', CreditCardVerification::factory($verifications[0])); 
  100.  
  101. private function _compareCreatedAtOnVerifications($verificationAttrib1, $verificationAttrib2) 
  102. return ($verificationAttrib2['createdAt'] < $verificationAttrib1['createdAt']) ? -1 : 1; 
  103.  
  104. /** 
  105. * returns false if comparing object is not a CreditCard,  
  106. * or is a CreditCard with a different id 
  107. * @param object $otherCreditCard customer to compare against 
  108. * @return boolean 
  109. */ 
  110. public function isEqual($otherCreditCard) 
  111. return !($otherCreditCard instanceof self) ? false : $this->token === $otherCreditCard->token; 
  112.  
  113. /** 
  114. * create a printable representation of the object as: 
  115. * ClassName[property=value, property=value] 
  116. * @return string 
  117. */ 
  118. public function __toString() 
  119. return __CLASS__ . '[' . 
  120. Util::attributesToString($this->_attributes) .']'; 
  121.  
  122. /** 
  123. * factory method: returns an instance of CreditCard 
  124. * to the requesting method, with populated properties 
  125. * @ignore 
  126. * @return CreditCard 
  127. */ 
  128. public static function factory($attributes) 
  129. $defaultAttributes = [ 
  130. 'bin' => '',  
  131. 'expirationMonth' => '',  
  132. 'expirationYear' => '',  
  133. 'last4' => '',  
  134. ]; 
  135.  
  136. $instance = new self(); 
  137. $instance->_initialize(array_merge($defaultAttributes, $attributes)); 
  138. return $instance; 
  139.  
  140.  
  141. // static methods redirecting to gateway 
  142.  
  143. public static function create($attribs) 
  144. return Configuration::gateway()->creditCard()->create($attribs); 
  145.  
  146. public static function createNoValidate($attribs) 
  147. return Configuration::gateway()->creditCard()->createNoValidate($attribs); 
  148.  
  149. public static function createFromTransparentRedirect($queryString) 
  150. return Configuration::gateway()->creditCard()->createFromTransparentRedirect($queryString); 
  151.  
  152. public static function createCreditCardUrl() 
  153. return Configuration::gateway()->creditCard()->createCreditCardUrl(); 
  154.  
  155. public static function expired() 
  156. return Configuration::gateway()->creditCard()->expired(); 
  157.  
  158. public static function fetchExpired($ids) 
  159. return Configuration::gateway()->creditCard()->fetchExpired($ids); 
  160.  
  161. public static function expiringBetween($startDate, $endDate) 
  162. return Configuration::gateway()->creditCard()->expiringBetween($startDate, $endDate); 
  163.  
  164. public static function fetchExpiring($startDate, $endDate, $ids) 
  165. return Configuration::gateway()->creditCard()->fetchExpiring($startDate, $endDate, $ids); 
  166.  
  167. public static function find($token) 
  168. return Configuration::gateway()->creditCard()->find($token); 
  169.  
  170. public static function fromNonce($nonce) 
  171. return Configuration::gateway()->creditCard()->fromNonce($nonce); 
  172.  
  173. public static function credit($token, $transactionAttribs) 
  174. return Configuration::gateway()->creditCard()->credit($token, $transactionAttribs); 
  175.  
  176. public static function creditNoValidate($token, $transactionAttribs) 
  177. return Configuration::gateway()->creditCard()->creditNoValidate($token, $transactionAttribs); 
  178.  
  179. public static function sale($token, $transactionAttribs) 
  180. return Configuration::gateway()->creditCard()->sale($token, $transactionAttribs); 
  181.  
  182. public static function saleNoValidate($token, $transactionAttribs) 
  183. return Configuration::gateway()->creditCard()->saleNoValidate($token, $transactionAttribs); 
  184.  
  185. public static function update($token, $attributes) 
  186. return Configuration::gateway()->creditCard()->update($token, $attributes); 
  187.  
  188. public static function updateNoValidate($token, $attributes) 
  189. return Configuration::gateway()->creditCard()->updateNoValidate($token, $attributes); 
  190.  
  191. public static function updateCreditCardUrl() 
  192. return Configuration::gateway()->creditCard()->updateCreditCardUrl(); 
  193.  
  194. public static function updateFromTransparentRedirect($queryString) 
  195. return Configuration::gateway()->creditCard()->updateFromTransparentRedirect($queryString); 
  196.  
  197. public static function delete($token) 
  198. return Configuration::gateway()->creditCard()->delete($token); 
  199.  
  200. /** @return array */ 
  201. public static function allCardTypes() 
  202. return [ 
  203. CreditCard::AMEX,  
  204. CreditCard::CARTE_BLANCHE,  
  205. CreditCard::CHINA_UNION_PAY,  
  206. CreditCard::DINERS_CLUB_INTERNATIONAL,  
  207. CreditCard::DISCOVER,  
  208. CreditCard::JCB,  
  209. CreditCard::LASER,  
  210. CreditCard::MAESTRO,  
  211. CreditCard::MASTER_CARD,  
  212. CreditCard::SOLO,  
  213. CreditCard::SWITCH_TYPE,  
  214. CreditCard::VISA,  
  215. CreditCard::UNKNOWN 
  216. ];