Address.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace Braintree;
  3. /**
  4. * Braintree Address module
  5. * PHP Version 5
  6. * Creates and manages Braintree Addresses
  7. *
  8. * An Address belongs to a Customer. It can be associated to a
  9. * CreditCard as the billing address. It can also be used
  10. * as the shipping address when creating a Transaction.
  11. *
  12. * @package Braintree
  13. *
  14. * @property-read string $company
  15. * @property-read string $countryName
  16. * @property-read string $createdAt
  17. * @property-read string $customerId
  18. * @property-read string $extendedAddress
  19. * @property-read string $firstName
  20. * @property-read string $id
  21. * @property-read string $lastName
  22. * @property-read string $locality
  23. * @property-read string $postalCode
  24. * @property-read string $region
  25. * @property-read string $streetAddress
  26. * @property-read string $updatedAt
  27. */
  28. class Address extends Base
  29. {
  30. /**
  31. * returns false if comparing object is not a Address,
  32. * or is a Address with a different id
  33. *
  34. * @param object $other address to compare against
  35. * @return boolean
  36. */
  37. public function isEqual($other)
  38. {
  39. return !($other instanceof self) ?
  40. false :
  41. ($this->id === $other->id && $this->customerId === $other->customerId);
  42. }
  43. /**
  44. * create a printable representation of the object as:
  45. * ClassName[property=value, property=value]
  46. * @ignore
  47. * @return string
  48. */
  49. public function __toString()
  50. {
  51. return __CLASS__ . '[' .
  52. Util::attributesToString($this->_attributes) . ']';
  53. }
  54. /**
  55. * sets instance properties from an array of values
  56. *
  57. * @ignore
  58. * @access protected
  59. * @param array $addressAttribs array of address data
  60. * @return void
  61. */
  62. protected function _initialize($addressAttribs)
  63. {
  64. // set the attributes
  65. $this->_attributes = $addressAttribs;
  66. }
  67. /**
  68. * factory method: returns an instance of Address
  69. * to the requesting method, with populated properties
  70. * @ignore
  71. * @return Address
  72. */
  73. public static function factory($attributes)
  74. {
  75. $instance = new self();
  76. $instance->_initialize($attributes);
  77. return $instance;
  78. }
  79. // static methods redirecting to gateway
  80. /**
  81. *
  82. * @param array $attribs
  83. * @return Address
  84. */
  85. public static function create($attribs)
  86. {
  87. return Configuration::gateway()->address()->create($attribs);
  88. }
  89. /**
  90. *
  91. * @param array $attribs
  92. * @return Address
  93. */
  94. public static function createNoValidate($attribs)
  95. {
  96. return Configuration::gateway()->address()->createNoValidate($attribs);
  97. }
  98. /**
  99. *
  100. * @param Customer|int $customerOrId
  101. * @param int $addressId
  102. * @throws InvalidArgumentException
  103. * @return Result\Successful
  104. */
  105. public static function delete($customerOrId = null, $addressId = null)
  106. {
  107. return Configuration::gateway()->address()->delete($customerOrId, $addressId);
  108. }
  109. /**
  110. *
  111. * @param Customer|int $customerOrId
  112. * @param int $addressId
  113. * @throws Exception\NotFound
  114. * @return Address
  115. */
  116. public static function find($customerOrId, $addressId)
  117. {
  118. return Configuration::gateway()->address()->find($customerOrId, $addressId);
  119. }
  120. /**
  121. *
  122. * @param Customer|int $customerOrId
  123. * @param int $addressId
  124. * @param array $attributes
  125. * @throws Exception\Unexpected
  126. * @return Result\Successful|Result\Error
  127. */
  128. public static function update($customerOrId, $addressId, $attributes)
  129. {
  130. return Configuration::gateway()->address()->update($customerOrId, $addressId, $attributes);
  131. }
  132. public static function updateNoValidate($customerOrId, $addressId, $attributes)
  133. {
  134. return Configuration::gateway()->address()->updateNoValidate($customerOrId, $addressId, $attributes);
  135. }
  136. }
  137. class_alias('Braintree\Address', 'Braintree_Address');