PayPalAccount.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace Braintree;
  3. /**
  4. * Braintree PayPalAccount module
  5. *
  6. * @package Braintree
  7. * @category Resources
  8. */
  9. /**
  10. * Manages Braintree PayPalAccounts
  11. *
  12. * <b>== More information ==</b>
  13. *
  14. *
  15. * @package Braintree
  16. * @category Resources
  17. *
  18. * @property-read string $billingAgreementId
  19. * @property-read \DateTime $createdAt
  20. * @property-read string $customerId
  21. * @property-read boolean $default
  22. * @property-read string $email
  23. * @property-read string $imageUrl
  24. * @property-read string $payerId
  25. * @property-read \DateTime $revokedAt
  26. * @property-read \Braintree\Subscription[] $subscriptions
  27. * @property-read string $token
  28. * @property-read \DateTime $updatedAt
  29. */
  30. class PayPalAccount extends Base
  31. {
  32. /**
  33. * factory method: returns an instance of PayPalAccount
  34. * to the requesting method, with populated properties
  35. *
  36. * @ignore
  37. * @return PayPalAccount
  38. */
  39. public static function factory($attributes)
  40. {
  41. $instance = new self();
  42. $instance->_initialize($attributes);
  43. return $instance;
  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. * sets instance properties from an array of values
  57. *
  58. * @access protected
  59. * @param array $paypalAccountAttribs array of paypalAccount data
  60. * @return void
  61. */
  62. protected function _initialize($paypalAccountAttribs)
  63. {
  64. // set the attributes
  65. $this->_attributes = $paypalAccountAttribs;
  66. $subscriptionArray = [];
  67. if (isset($paypalAccountAttribs['subscriptions'])) {
  68. foreach ($paypalAccountAttribs['subscriptions'] AS $subscription) {
  69. $subscriptionArray[] = Subscription::factory($subscription);
  70. }
  71. }
  72. $this->_set('subscriptions', $subscriptionArray);
  73. }
  74. /**
  75. * create a printable representation of the object as:
  76. * ClassName[property=value, property=value]
  77. * @return string
  78. */
  79. public function __toString()
  80. {
  81. return __CLASS__ . '[' .
  82. Util::attributesToString($this->_attributes) . ']';
  83. }
  84. // static methods redirecting to gateway
  85. public static function find($token)
  86. {
  87. return Configuration::gateway()->payPalAccount()->find($token);
  88. }
  89. public static function update($token, $attributes)
  90. {
  91. return Configuration::gateway()->payPalAccount()->update($token, $attributes);
  92. }
  93. public static function delete($token)
  94. {
  95. return Configuration::gateway()->payPalAccount()->delete($token);
  96. }
  97. public static function sale($token, $transactionAttribs)
  98. {
  99. return Configuration::gateway()->payPalAccount()->sale($token, $transactionAttribs);
  100. }
  101. }
  102. class_alias('Braintree\PayPalAccount', 'Braintree_PayPalAccount');