Customer.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace Stripe;
  3. /**
  4. * Class Customer
  5. *
  6. * @property string $id
  7. * @property string $object
  8. * @property int $account_balance
  9. * @property string $business_vat_id
  10. * @property string $created
  11. * @property string $currency
  12. * @property string $default_source
  13. * @property bool $delinquent
  14. * @property string $description
  15. * @property mixed $discount
  16. * @property string $email
  17. * @property bool $livemode
  18. * @property array $metadata
  19. * @property mixed $shipping
  20. * @property Collection $sources
  21. * @property Collection $subscriptions
  22. *
  23. * @package Stripe
  24. */
  25. class Customer extends ApiResource
  26. {
  27. /**
  28. * @param string $id The ID of the customer to retrieve.
  29. * @param array|string|null $opts
  30. *
  31. * @return Customer
  32. */
  33. public static function retrieve($id, $opts = null)
  34. {
  35. return self::_retrieve($id, $opts);
  36. }
  37. /**
  38. * @param array|null $params
  39. * @param array|string|null $opts
  40. *
  41. * @return Collection of Customers
  42. */
  43. public static function all($params = null, $opts = null)
  44. {
  45. return self::_all($params, $opts);
  46. }
  47. /**
  48. * @param array|null $params
  49. * @param array|string|null $opts
  50. *
  51. * @return Customer The created customer.
  52. */
  53. public static function create($params = null, $opts = null)
  54. {
  55. return self::_create($params, $opts);
  56. }
  57. /**
  58. * @param string $id The ID of the customer to update.
  59. * @param array|null $params
  60. * @param array|string|null $options
  61. *
  62. * @return Customer The updated customer.
  63. */
  64. public static function update($id, $params = null, $options = null)
  65. {
  66. return self::_update($id, $params, $options);
  67. }
  68. /**
  69. * @param array|string|null $opts
  70. *
  71. * @return Customer The saved customer.
  72. */
  73. public function save($opts = null)
  74. {
  75. return $this->_save($opts);
  76. }
  77. /**
  78. * @param array|null $params
  79. * @param array|string|null $opts
  80. *
  81. * @return Customer The deleted customer.
  82. */
  83. public function delete($params = null, $opts = null)
  84. {
  85. return $this->_delete($params, $opts);
  86. }
  87. /**
  88. * @param array|null $params
  89. *
  90. * @return InvoiceItem The resulting invoice item.
  91. */
  92. public function addInvoiceItem($params = null)
  93. {
  94. if (!$params) {
  95. $params = array();
  96. }
  97. $params['customer'] = $this->id;
  98. $ii = InvoiceItem::create($params, $this->_opts);
  99. return $ii;
  100. }
  101. /**
  102. * @param array|null $params
  103. *
  104. * @return array An array of the customer's Invoices.
  105. */
  106. public function invoices($params = null)
  107. {
  108. if (!$params) {
  109. $params = array();
  110. }
  111. $params['customer'] = $this->id;
  112. $invoices = Invoice::all($params, $this->_opts);
  113. return $invoices;
  114. }
  115. /**
  116. * @param array|null $params
  117. *
  118. * @return array An array of the customer's InvoiceItems.
  119. */
  120. public function invoiceItems($params = null)
  121. {
  122. if (!$params) {
  123. $params = array();
  124. }
  125. $params['customer'] = $this->id;
  126. $iis = InvoiceItem::all($params, $this->_opts);
  127. return $iis;
  128. }
  129. /**
  130. * @param array|null $params
  131. *
  132. * @return array An array of the customer's Charges.
  133. */
  134. public function charges($params = null)
  135. {
  136. if (!$params) {
  137. $params = array();
  138. }
  139. $params['customer'] = $this->id;
  140. $charges = Charge::all($params, $this->_opts);
  141. return $charges;
  142. }
  143. /**
  144. * @param array|null $params
  145. *
  146. * @return Subscription The updated subscription.
  147. */
  148. public function updateSubscription($params = null)
  149. {
  150. $url = $this->instanceUrl() . '/subscription';
  151. list($response, $opts) = $this->_request('post', $url, $params);
  152. $this->refreshFrom(array('subscription' => $response), $opts, true);
  153. return $this->subscription;
  154. }
  155. /**
  156. * @param array|null $params
  157. *
  158. * @return Subscription The cancelled subscription.
  159. */
  160. public function cancelSubscription($params = null)
  161. {
  162. $url = $this->instanceUrl() . '/subscription';
  163. list($response, $opts) = $this->_request('delete', $url, $params);
  164. $this->refreshFrom(array('subscription' => $response), $opts, true);
  165. return $this->subscription;
  166. }
  167. /**
  168. * @return Customer The updated customer.
  169. */
  170. public function deleteDiscount()
  171. {
  172. $url = $this->instanceUrl() . '/discount';
  173. list($response, $opts) = $this->_request('delete', $url);
  174. $this->refreshFrom(array('discount' => null), $opts, true);
  175. }
  176. }