BraintreeCreditCard

Braintree CreditCard module Creates and manages Braintree CreditCards.

Defined (1)

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

/includes/lib/Braintree/lib/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. const PRODUCT_ID_UNKNOWN = "Unknown"; 
  48.  
  49. /** instance methods */ 
  50. /** 
  51. * returns false if default is null or false 
  52. * @return boolean 
  53. */ 
  54. public function isDefault() 
  55. return $this->default; 
  56.  
  57. /** 
  58. * checks whether the card is expired based on the current date 
  59. * @return boolean 
  60. */ 
  61. public function isExpired() 
  62. return $this->expired; 
  63.  
  64. /** 
  65. * checks whether the card is associated with venmo sdk 
  66. * @return boolean 
  67. */ 
  68. public function isVenmoSdk() 
  69. return $this->venmoSdk; 
  70.  
  71. /** 
  72. * sets instance properties from an array of values 
  73. * @access protected 
  74. * @param array $creditCardAttribs array of creditcard data 
  75. * @return void 
  76. */ 
  77. protected function _initialize($creditCardAttribs) 
  78. // set the attributes 
  79. $this->_attributes = $creditCardAttribs; 
  80.  
  81. // map each address into its own object 
  82. $billingAddress = isset($creditCardAttribs['billingAddress']) ? 
  83. Address::factory($creditCardAttribs['billingAddress']) : 
  84. null; 
  85.  
  86. $subscriptionArray = []; 
  87. if (isset($creditCardAttribs['subscriptions'])) { 
  88. foreach ($creditCardAttribs['subscriptions'] AS $subscription) { 
  89. $subscriptionArray[] = Subscription::factory($subscription); 
  90.  
  91. $this->_set('subscriptions', $subscriptionArray); 
  92. $this->_set('billingAddress', $billingAddress); 
  93. $this->_set('expirationDate', $this->expirationMonth . '/' . $this->expirationYear); 
  94. $this->_set('maskedNumber', $this->bin . '******' . $this->last4); 
  95.  
  96. if(isset($creditCardAttribs['verifications']) && count($creditCardAttribs['verifications']) > 0) { 
  97. $verifications = $creditCardAttribs['verifications']; 
  98. usort($verifications, [$this, '_compareCreatedAtOnVerifications']); 
  99.  
  100. $this->_set('verification', CreditCardVerification::factory($verifications[0])); 
  101.  
  102. private function _compareCreatedAtOnVerifications($verificationAttrib1, $verificationAttrib2) 
  103. return ($verificationAttrib2['createdAt'] < $verificationAttrib1['createdAt']) ? -1 : 1; 
  104.  
  105. /** 
  106. * returns false if comparing object is not a CreditCard,  
  107. * or is a CreditCard with a different id 
  108. * @param object $otherCreditCard customer to compare against 
  109. * @return boolean 
  110. */ 
  111. public function isEqual($otherCreditCard) 
  112. return !($otherCreditCard instanceof self) ? false : $this->token === $otherCreditCard->token; 
  113.  
  114. /** 
  115. * create a printable representation of the object as: 
  116. * ClassName[property=value, property=value] 
  117. * @return string 
  118. */ 
  119. public function __toString() 
  120. return __CLASS__ . '[' . 
  121. Util::attributesToString($this->_attributes) .']'; 
  122.  
  123. /** 
  124. * factory method: returns an instance of CreditCard 
  125. * to the requesting method, with populated properties 
  126. * @ignore 
  127. * @return CreditCard 
  128. */ 
  129. public static function factory($attributes) 
  130. $defaultAttributes = [ 
  131. 'bin' => '',  
  132. 'expirationMonth' => '',  
  133. 'expirationYear' => '',  
  134. 'last4' => '',  
  135. ]; 
  136.  
  137. $instance = new self(); 
  138. $instance->_initialize(array_merge($defaultAttributes, $attributes)); 
  139. return $instance; 
  140.  
  141.  
  142. // static methods redirecting to gateway 
  143.  
  144. public static function create($attribs) 
  145. return Configuration::gateway()->creditCard()->create($attribs); 
  146.  
  147. public static function createNoValidate($attribs) 
  148. return Configuration::gateway()->creditCard()->createNoValidate($attribs); 
  149.  
  150. public static function createFromTransparentRedirect($queryString) 
  151. return Configuration::gateway()->creditCard()->createFromTransparentRedirect($queryString); 
  152.  
  153. public static function createCreditCardUrl() 
  154. return Configuration::gateway()->creditCard()->createCreditCardUrl(); 
  155.  
  156. public static function expired() 
  157. return Configuration::gateway()->creditCard()->expired(); 
  158.  
  159. public static function fetchExpired($ids) 
  160. return Configuration::gateway()->creditCard()->fetchExpired($ids); 
  161.  
  162. public static function expiringBetween($startDate, $endDate) 
  163. return Configuration::gateway()->creditCard()->expiringBetween($startDate, $endDate); 
  164.  
  165. public static function fetchExpiring($startDate, $endDate, $ids) 
  166. return Configuration::gateway()->creditCard()->fetchExpiring($startDate, $endDate, $ids); 
  167.  
  168. public static function find($token) 
  169. return Configuration::gateway()->creditCard()->find($token); 
  170.  
  171. public static function fromNonce($nonce) 
  172. return Configuration::gateway()->creditCard()->fromNonce($nonce); 
  173.  
  174. public static function credit($token, $transactionAttribs) 
  175. return Configuration::gateway()->creditCard()->credit($token, $transactionAttribs); 
  176.  
  177. public static function creditNoValidate($token, $transactionAttribs) 
  178. return Configuration::gateway()->creditCard()->creditNoValidate($token, $transactionAttribs); 
  179.  
  180. public static function sale($token, $transactionAttribs) 
  181. return Configuration::gateway()->creditCard()->sale($token, $transactionAttribs); 
  182.  
  183. public static function saleNoValidate($token, $transactionAttribs) 
  184. return Configuration::gateway()->creditCard()->saleNoValidate($token, $transactionAttribs); 
  185.  
  186. public static function update($token, $attributes) 
  187. return Configuration::gateway()->creditCard()->update($token, $attributes); 
  188.  
  189. public static function updateNoValidate($token, $attributes) 
  190. return Configuration::gateway()->creditCard()->updateNoValidate($token, $attributes); 
  191.  
  192. public static function updateCreditCardUrl() 
  193. return Configuration::gateway()->creditCard()->updateCreditCardUrl(); 
  194.  
  195. public static function updateFromTransparentRedirect($queryString) 
  196. return Configuration::gateway()->creditCard()->updateFromTransparentRedirect($queryString); 
  197.  
  198. public static function delete($token) 
  199. return Configuration::gateway()->creditCard()->delete($token); 
  200.  
  201. /** @return array */ 
  202. public static function allCardTypes() 
  203. return [ 
  204. CreditCard::AMEX,  
  205. CreditCard::CARTE_BLANCHE,  
  206. CreditCard::CHINA_UNION_PAY,  
  207. CreditCard::DINERS_CLUB_INTERNATIONAL,  
  208. CreditCard::DISCOVER,  
  209. CreditCard::JCB,  
  210. CreditCard::LASER,  
  211. CreditCard::MAESTRO,  
  212. CreditCard::MASTER_CARD,  
  213. CreditCard::SOLO,  
  214. CreditCard::SWITCH_TYPE,  
  215. CreditCard::VISA,  
  216. CreditCard::UNKNOWN 
  217. ];