PayPalAccount.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 $customerId
  19. * @property-read string $email
  20. * @property-read string $token
  21. * @property-read string $imageUrl
  22. */
  23. class PayPalAccount extends Base
  24. {
  25. /**
  26. * factory method: returns an instance of PayPalAccount
  27. * to the requesting method, with populated properties
  28. *
  29. * @ignore
  30. * @return PayPalAccount
  31. */
  32. public static function factory($attributes)
  33. {
  34. $instance = new self();
  35. $instance->_initialize($attributes);
  36. return $instance;
  37. }
  38. /* instance methods */
  39. /**
  40. * returns false if default is null or false
  41. *
  42. * @return boolean
  43. */
  44. public function isDefault()
  45. {
  46. return $this->default;
  47. }
  48. /**
  49. * sets instance properties from an array of values
  50. *
  51. * @access protected
  52. * @param array $paypalAccountAttribs array of paypalAccount data
  53. * @return void
  54. */
  55. protected function _initialize($paypalAccountAttribs)
  56. {
  57. // set the attributes
  58. $this->_attributes = $paypalAccountAttribs;
  59. $subscriptionArray = [];
  60. if (isset($paypalAccountAttribs['subscriptions'])) {
  61. foreach ($paypalAccountAttribs['subscriptions'] AS $subscription) {
  62. $subscriptionArray[] = Subscription::factory($subscription);
  63. }
  64. }
  65. $this->_set('subscriptions', $subscriptionArray);
  66. }
  67. /**
  68. * create a printable representation of the object as:
  69. * ClassName[property=value, property=value]
  70. * @return string
  71. */
  72. public function __toString()
  73. {
  74. return __CLASS__ . '[' .
  75. Util::attributesToString($this->_attributes) . ']';
  76. }
  77. // static methods redirecting to gateway
  78. public static function find($token)
  79. {
  80. return Configuration::gateway()->payPalAccount()->find($token);
  81. }
  82. public static function update($token, $attributes)
  83. {
  84. return Configuration::gateway()->payPalAccount()->update($token, $attributes);
  85. }
  86. public static function delete($token)
  87. {
  88. return Configuration::gateway()->payPalAccount()->delete($token);
  89. }
  90. public static function sale($token, $transactionAttribs)
  91. {
  92. return Configuration::gateway()->payPalAccount()->sale($token, $transactionAttribs);
  93. }
  94. }
  95. class_alias('Braintree\PayPalAccount', 'Braintree_PayPalAccount');