ApplePayCard.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Braintree;
  3. /**
  4. * Braintree ApplePayCard module
  5. * Creates and manages Braintree Apple Pay cards
  6. *
  7. * <b>== More information ==</b>
  8. *
  9. * See {@link https://developers.braintreepayments.com/javascript+php}<br />
  10. *
  11. * @package Braintree
  12. * @category Resources
  13. *
  14. * @property-read string $bin
  15. * @property-read string $cardType
  16. * @property-read string $createdAt
  17. * @property-read string $customerId
  18. * @property-read string $expirationDate
  19. * @property-read string $expirationMonth
  20. * @property-read string $expirationYear
  21. * @property-read string $imageUrl
  22. * @property-read string $last4
  23. * @property-read string $token
  24. * @property-read string $paymentInstrumentName
  25. * @property-read string $sourceDescription
  26. * @property-read string $updatedAt
  27. */
  28. class ApplePayCard extends Base
  29. {
  30. // Card Type
  31. const AMEX = 'Apple Pay - American Express';
  32. const MASTER_CARD = 'Apple Pay - MasterCard';
  33. const VISA = 'Apple Pay - Visa';
  34. /* instance methods */
  35. /**
  36. * returns false if default is null or false
  37. *
  38. * @return boolean
  39. */
  40. public function isDefault()
  41. {
  42. return $this->default;
  43. }
  44. /**
  45. * checks whether the card is expired based on the current date
  46. *
  47. * @return boolean
  48. */
  49. public function isExpired()
  50. {
  51. return $this->expired;
  52. }
  53. /**
  54. * factory method: returns an instance of ApplePayCard
  55. * to the requesting method, with populated properties
  56. *
  57. * @ignore
  58. * @return ApplePayCard
  59. */
  60. public static function factory($attributes)
  61. {
  62. $defaultAttributes = [
  63. 'expirationMonth' => '',
  64. 'expirationYear' => '',
  65. 'last4' => '',
  66. ];
  67. $instance = new self();
  68. $instance->_initialize(array_merge($defaultAttributes, $attributes));
  69. return $instance;
  70. }
  71. /**
  72. * sets instance properties from an array of values
  73. *
  74. * @access protected
  75. * @param array $applePayCardAttribs array of Apple Pay card properties
  76. * @return void
  77. */
  78. protected function _initialize($applePayCardAttribs)
  79. {
  80. // set the attributes
  81. $this->_attributes = $applePayCardAttribs;
  82. $subscriptionArray = [];
  83. if (isset($applePayCardAttribs['subscriptions'])) {
  84. foreach ($applePayCardAttribs['subscriptions'] AS $subscription) {
  85. $subscriptionArray[] = Subscription::factory($subscription);
  86. }
  87. }
  88. $this->_set('subscriptions', $subscriptionArray);
  89. $this->_set('expirationDate', $this->expirationMonth . '/' . $this->expirationYear);
  90. }
  91. }
  92. class_alias('Braintree\ApplePayCard', 'Braintree_ApplePayCard');