SamsungPayCard.php 4.0 KB

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