MasterpassCard.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace Braintree;
  3. /**
  4. * Braintree MasterpassCard module
  5. * Creates and manages Braintree MasterpassCards
  6. *
  7. * <b>== More information ==</b>
  8. *
  9. * For more detailed information on CreditCard verifications, see {@link https://developers.braintreepayments.com/reference/response/credit-card-verification/php https://developers.braintreepayments.com/reference/response/credit-card-verification/php}
  10. *
  11. * @package Braintree
  12. * @category Resources
  13. *
  14. * @property-read string $billingAddress
  15. * @property-read string $bin
  16. * @property-read string $cardType
  17. * @property-read string $cardholderName
  18. * @property-read string $commercial
  19. * @property-read string $countryOfIssuance
  20. * @property-read string $createdAt
  21. * @property-read string $customerId
  22. * @property-read string $customerLocation
  23. * @property-read string $debit
  24. * @property-read string $default
  25. * @property-read string $durbinRegulated
  26. * @property-read string $expirationDate
  27. * @property-read string $expirationMonth
  28. * @property-read string $expirationYear
  29. * @property-read string $expired
  30. * @property-read string $healthcare
  31. * @property-read string $imageUrl
  32. * @property-read string $issuingBank
  33. * @property-read string $last4
  34. * @property-read string $maskedNumber
  35. * @property-read string $payroll
  36. * @property-read string $prepaid
  37. * @property-read string $productId
  38. * @property-read string $subscriptions
  39. * @property-read string $token
  40. * @property-read string $uniqueNumberIdentifier
  41. * @property-read string $updatedAt
  42. */
  43. class MasterpassCard extends Base
  44. {
  45. /* instance methods */
  46. /**
  47. * returns false if default is null or false
  48. *
  49. * @return boolean
  50. */
  51. public function isDefault()
  52. {
  53. return $this->default;
  54. }
  55. /**
  56. * checks whether the card is expired based on the current date
  57. *
  58. * @return boolean
  59. */
  60. public function isExpired()
  61. {
  62. return $this->expired;
  63. }
  64. /**
  65. * sets instance properties from an array of values
  66. *
  67. * @access protected
  68. * @param array $creditCardAttribs array of creditcard data
  69. * @return void
  70. */
  71. protected function _initialize($creditCardAttribs)
  72. {
  73. // set the attributes
  74. $this->_attributes = $creditCardAttribs;
  75. // map each address into its own object
  76. $billingAddress = isset($creditCardAttribs['billingAddress']) ?
  77. Address::factory($creditCardAttribs['billingAddress']) :
  78. null;
  79. $subscriptionArray = [];
  80. if (isset($creditCardAttribs['subscriptions'])) {
  81. foreach ($creditCardAttribs['subscriptions'] AS $subscription) {
  82. $subscriptionArray[] = Subscription::factory($subscription);
  83. }
  84. }
  85. $this->_set('subscriptions', $subscriptionArray);
  86. $this->_set('billingAddress', $billingAddress);
  87. $this->_set('expirationDate', $this->expirationMonth . '/' . $this->expirationYear);
  88. $this->_set('maskedNumber', $this->bin . '******' . $this->last4);
  89. }
  90. /**
  91. * returns false if comparing object is not a CreditCard,
  92. * or is a CreditCard with a different id
  93. *
  94. * @param object $otherCreditCard customer to compare against
  95. * @return boolean
  96. */
  97. public function isEqual($otherMasterpassCard)
  98. {
  99. return !($otherMasterpassCard instanceof self) ? false : $this->token === $otherMasterpassCard->token;
  100. }
  101. /**
  102. * create a printable representation of the object as:
  103. * ClassName[property=value, property=value]
  104. * @return string
  105. */
  106. public function __toString()
  107. {
  108. return __CLASS__ . '[' .
  109. Util::attributesToString($this->_attributes) .']';
  110. }
  111. /**
  112. * factory method: returns an instance of CreditCard
  113. * to the requesting method, with populated properties
  114. *
  115. * @ignore
  116. * @return MasterpassCard
  117. */
  118. public static function factory($attributes)
  119. {
  120. $defaultAttributes = [
  121. 'bin' => '',
  122. 'expirationMonth' => '',
  123. 'expirationYear' => '',
  124. 'last4' => '',
  125. ];
  126. $instance = new self();
  127. $instance->_initialize(array_merge($defaultAttributes, $attributes));
  128. return $instance;
  129. }
  130. }
  131. class_alias('Braintree\MasterpassCard', 'Braintree_MasterpassCard');