Customer.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe;
  4. /**
  5. * This object represents a customer of your business. It lets you create recurring
  6. * charges and track payments that belong to the same customer.
  7. *
  8. * Related guide: <a
  9. * href="https://stripe.com/docs/payments/save-during-payment">Save a card during
  10. * payment</a>.
  11. *
  12. * @property string $id Unique identifier for the object.
  13. * @property string $object String representing the object's type. Objects of the same type share the same value.
  14. * @property null|\Stripe\StripeObject $address The customer's address.
  15. * @property int $balance Current balance, if any, being stored on the customer. If negative, the customer has credit to apply to their next invoice. If positive, the customer has an amount owed that will be added to their next invoice. The balance does not refer to any unpaid invoices; it solely takes into account amounts that have yet to be successfully applied to any invoice. This balance is only taken into account as invoices are finalized.
  16. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  17. * @property null|string $currency Three-letter <a href="https://stripe.com/docs/currencies">ISO code for the currency</a> the customer can be charged in for recurring billing purposes.
  18. * @property null|string|\Stripe\Account|\Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source $default_source <p>ID of the default payment source for the customer.</p><p>If you are using payment methods created via the PaymentMethods API, see the <a href="https://stripe.com/docs/api/customers/object#customer_object-invoice_settings-default_payment_method">invoice_settings.default_payment_method</a> field instead.</p>
  19. * @property null|bool $delinquent <p>When the customer's latest invoice is billed by charging automatically, <code>delinquent</code> is <code>true</code> if the invoice's latest charge failed. When the customer's latest invoice is billed by sending an invoice, <code>delinquent</code> is <code>true</code> if the invoice isn't paid by its due date.</p><p>If an invoice is marked uncollectible by <a href="https://stripe.com/docs/billing/automatic-collection">dunning</a>, <code>delinquent</code> doesn't get reset to <code>false</code>.</p>
  20. * @property null|string $description An arbitrary string attached to the object. Often useful for displaying to users.
  21. * @property null|\Stripe\Discount $discount Describes the current discount active on the customer, if there is one.
  22. * @property null|string $email The customer's email address.
  23. * @property null|string $invoice_prefix The prefix for the customer used to generate unique invoice numbers.
  24. * @property \Stripe\StripeObject $invoice_settings
  25. * @property bool $livemode Has the value <code>true</code> if the object exists in live mode or the value <code>false</code> if the object exists in test mode.
  26. * @property \Stripe\StripeObject $metadata Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
  27. * @property null|string $name The customer's full name or business name.
  28. * @property int $next_invoice_sequence The suffix of the customer's next invoice number, e.g., 0001.
  29. * @property null|string $phone The customer's phone number.
  30. * @property null|string[] $preferred_locales The customer's preferred locales (languages), ordered by preference.
  31. * @property null|\Stripe\StripeObject $shipping Mailing and shipping address for the customer. Appears on invoices emailed to this customer.
  32. * @property \Stripe\Collection<\Stripe\Account|\Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source> $sources The customer's payment sources, if any.
  33. * @property \Stripe\Collection<\Stripe\Subscription> $subscriptions The customer's current subscriptions, if any.
  34. * @property \Stripe\StripeObject $tax
  35. * @property null|string $tax_exempt Describes the customer's tax exemption status. One of <code>none</code>, <code>exempt</code>, or <code>reverse</code>. When set to <code>reverse</code>, invoice and receipt PDFs include the text <strong>&quot;Reverse charge&quot;</strong>.
  36. * @property \Stripe\Collection<\Stripe\TaxId> $tax_ids The customer's tax IDs.
  37. * @property null|string|\Stripe\TestHelpers\TestClock $test_clock ID of the test clock this customer belongs to.
  38. */
  39. class Customer extends ApiResource
  40. {
  41. const OBJECT_NAME = 'customer';
  42. use ApiOperations\All;
  43. use ApiOperations\Create;
  44. use ApiOperations\Delete;
  45. use ApiOperations\NestedResource;
  46. use ApiOperations\Retrieve;
  47. use ApiOperations\Update;
  48. const TAX_EXEMPT_EXEMPT = 'exempt';
  49. const TAX_EXEMPT_NONE = 'none';
  50. const TAX_EXEMPT_REVERSE = 'reverse';
  51. public static function getSavedNestedResources()
  52. {
  53. static $savedNestedResources = null;
  54. if (null === $savedNestedResources) {
  55. $savedNestedResources = new Util\Set([
  56. 'source',
  57. ]);
  58. }
  59. return $savedNestedResources;
  60. }
  61. /**
  62. * @param null|array $params
  63. * @param null|array|string $opts
  64. *
  65. * @return \Stripe\Customer the updated customer
  66. */
  67. public function deleteDiscount($params = null, $opts = null)
  68. {
  69. $url = $this->instanceUrl() . '/discount';
  70. list($response, $opts) = $this->_request('delete', $url, $params, $opts);
  71. $this->refreshFrom(['discount' => null], $opts, true);
  72. return $this;
  73. }
  74. /**
  75. * @param null|array $params
  76. * @param null|array|string $opts
  77. * @param mixed $id
  78. *
  79. * @throws \Stripe\Exception\ApiErrorException if the request fails
  80. *
  81. * @return \Stripe\Collection<\Stripe\Customer> list of PaymentMethods
  82. */
  83. public static function allPaymentMethods($id, $params = null, $opts = null)
  84. {
  85. $url = static::resourceUrl($id) . '/payment_methods';
  86. list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
  87. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  88. $obj->setLastResponse($response);
  89. return $obj;
  90. }
  91. const PATH_BALANCE_TRANSACTIONS = '/balance_transactions';
  92. /**
  93. * @param string $id the ID of the customer on which to retrieve the customer balance transactions
  94. * @param null|array $params
  95. * @param null|array|string $opts
  96. *
  97. * @throws \Stripe\Exception\ApiErrorException if the request fails
  98. *
  99. * @return \Stripe\Collection<\Stripe\CustomerBalanceTransaction> the list of customer balance transactions
  100. */
  101. public static function allBalanceTransactions($id, $params = null, $opts = null)
  102. {
  103. return self::_allNestedResources($id, static::PATH_BALANCE_TRANSACTIONS, $params, $opts);
  104. }
  105. /**
  106. * @param string $id the ID of the customer on which to create the customer balance transaction
  107. * @param null|array $params
  108. * @param null|array|string $opts
  109. *
  110. * @throws \Stripe\Exception\ApiErrorException if the request fails
  111. *
  112. * @return \Stripe\CustomerBalanceTransaction
  113. */
  114. public static function createBalanceTransaction($id, $params = null, $opts = null)
  115. {
  116. return self::_createNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $params, $opts);
  117. }
  118. /**
  119. * @param string $id the ID of the customer to which the customer balance transaction belongs
  120. * @param string $balanceTransactionId the ID of the customer balance transaction to retrieve
  121. * @param null|array $params
  122. * @param null|array|string $opts
  123. *
  124. * @throws \Stripe\Exception\ApiErrorException if the request fails
  125. *
  126. * @return \Stripe\CustomerBalanceTransaction
  127. */
  128. public static function retrieveBalanceTransaction($id, $balanceTransactionId, $params = null, $opts = null)
  129. {
  130. return self::_retrieveNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $balanceTransactionId, $params, $opts);
  131. }
  132. /**
  133. * @param string $id the ID of the customer to which the customer balance transaction belongs
  134. * @param string $balanceTransactionId the ID of the customer balance transaction to update
  135. * @param null|array $params
  136. * @param null|array|string $opts
  137. *
  138. * @throws \Stripe\Exception\ApiErrorException if the request fails
  139. *
  140. * @return \Stripe\CustomerBalanceTransaction
  141. */
  142. public static function updateBalanceTransaction($id, $balanceTransactionId, $params = null, $opts = null)
  143. {
  144. return self::_updateNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $balanceTransactionId, $params, $opts);
  145. }
  146. const PATH_SOURCES = '/sources';
  147. /**
  148. * @param string $id the ID of the customer on which to retrieve the payment sources
  149. * @param null|array $params
  150. * @param null|array|string $opts
  151. *
  152. * @throws \Stripe\Exception\ApiErrorException if the request fails
  153. *
  154. * @return \Stripe\Collection<\Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source> the list of payment sources (AlipayAccount, BankAccount, BitcoinReceiver, Card or Source)
  155. */
  156. public static function allSources($id, $params = null, $opts = null)
  157. {
  158. return self::_allNestedResources($id, static::PATH_SOURCES, $params, $opts);
  159. }
  160. /**
  161. * @param string $id the ID of the customer on which to create the payment source
  162. * @param null|array $params
  163. * @param null|array|string $opts
  164. *
  165. * @throws \Stripe\Exception\ApiErrorException if the request fails
  166. *
  167. * @return \Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  168. */
  169. public static function createSource($id, $params = null, $opts = null)
  170. {
  171. return self::_createNestedResource($id, static::PATH_SOURCES, $params, $opts);
  172. }
  173. /**
  174. * @param string $id the ID of the customer to which the payment source belongs
  175. * @param string $sourceId the ID of the payment source to delete
  176. * @param null|array $params
  177. * @param null|array|string $opts
  178. *
  179. * @throws \Stripe\Exception\ApiErrorException if the request fails
  180. *
  181. * @return \Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  182. */
  183. public static function deleteSource($id, $sourceId, $params = null, $opts = null)
  184. {
  185. return self::_deleteNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
  186. }
  187. /**
  188. * @param string $id the ID of the customer to which the payment source belongs
  189. * @param string $sourceId the ID of the payment source to retrieve
  190. * @param null|array $params
  191. * @param null|array|string $opts
  192. *
  193. * @throws \Stripe\Exception\ApiErrorException if the request fails
  194. *
  195. * @return \Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  196. */
  197. public static function retrieveSource($id, $sourceId, $params = null, $opts = null)
  198. {
  199. return self::_retrieveNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
  200. }
  201. /**
  202. * @param string $id the ID of the customer to which the payment source belongs
  203. * @param string $sourceId the ID of the payment source to update
  204. * @param null|array $params
  205. * @param null|array|string $opts
  206. *
  207. * @throws \Stripe\Exception\ApiErrorException if the request fails
  208. *
  209. * @return \Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  210. */
  211. public static function updateSource($id, $sourceId, $params = null, $opts = null)
  212. {
  213. return self::_updateNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
  214. }
  215. const PATH_TAX_IDS = '/tax_ids';
  216. /**
  217. * @param string $id the ID of the customer on which to retrieve the tax ids
  218. * @param null|array $params
  219. * @param null|array|string $opts
  220. *
  221. * @throws \Stripe\Exception\ApiErrorException if the request fails
  222. *
  223. * @return \Stripe\Collection<\Stripe\TaxId> the list of tax ids
  224. */
  225. public static function allTaxIds($id, $params = null, $opts = null)
  226. {
  227. return self::_allNestedResources($id, static::PATH_TAX_IDS, $params, $opts);
  228. }
  229. /**
  230. * @param string $id the ID of the customer on which to create the tax id
  231. * @param null|array $params
  232. * @param null|array|string $opts
  233. *
  234. * @throws \Stripe\Exception\ApiErrorException if the request fails
  235. *
  236. * @return \Stripe\TaxId
  237. */
  238. public static function createTaxId($id, $params = null, $opts = null)
  239. {
  240. return self::_createNestedResource($id, static::PATH_TAX_IDS, $params, $opts);
  241. }
  242. /**
  243. * @param string $id the ID of the customer to which the tax id belongs
  244. * @param string $taxIdId the ID of the tax id to delete
  245. * @param null|array $params
  246. * @param null|array|string $opts
  247. *
  248. * @throws \Stripe\Exception\ApiErrorException if the request fails
  249. *
  250. * @return \Stripe\TaxId
  251. */
  252. public static function deleteTaxId($id, $taxIdId, $params = null, $opts = null)
  253. {
  254. return self::_deleteNestedResource($id, static::PATH_TAX_IDS, $taxIdId, $params, $opts);
  255. }
  256. /**
  257. * @param string $id the ID of the customer to which the tax id belongs
  258. * @param string $taxIdId the ID of the tax id to retrieve
  259. * @param null|array $params
  260. * @param null|array|string $opts
  261. *
  262. * @throws \Stripe\Exception\ApiErrorException if the request fails
  263. *
  264. * @return \Stripe\TaxId
  265. */
  266. public static function retrieveTaxId($id, $taxIdId, $params = null, $opts = null)
  267. {
  268. return self::_retrieveNestedResource($id, static::PATH_TAX_IDS, $taxIdId, $params, $opts);
  269. }
  270. }