Customer.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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 null|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 null|\Stripe\CashBalance $cash_balance The current funds being held by Stripe on behalf of the customer. These funds can be applied towards payment intents with source &quot;cash_balance&quot;. The settings[reconciliation_mode] field describes whether these funds are applied to such payment intents manually or automatically.
  17. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  18. * @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.
  19. * @property null|string|\Stripe\Account|\Stripe\BankAccount|\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>
  20. * @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>
  21. * @property null|string $description An arbitrary string attached to the object. Often useful for displaying to users.
  22. * @property null|\Stripe\Discount $discount Describes the current discount active on the customer, if there is one.
  23. * @property null|string $email The customer's email address.
  24. * @property null|\Stripe\StripeObject $invoice_credit_balance The current multi-currency balances, if any, being stored on the customer. If positive in a currency, the customer has a credit to apply to their next invoice denominated in that currency. If negative, the customer has an amount owed that will be added to their next invoice denominated in that currency. These balances do not refer to any unpaid invoices. They solely track amounts that have yet to be successfully applied to any invoice. A balance in a particular currency is only applied to any invoice as an invoice in that currency is finalized.
  25. * @property null|string $invoice_prefix The prefix for the customer used to generate unique invoice numbers.
  26. * @property null|\Stripe\StripeObject $invoice_settings
  27. * @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.
  28. * @property null|\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.
  29. * @property null|string $name The customer's full name or business name.
  30. * @property null|int $next_invoice_sequence The suffix of the customer's next invoice number, e.g., 0001.
  31. * @property null|string $phone The customer's phone number.
  32. * @property null|string[] $preferred_locales The customer's preferred locales (languages), ordered by preference.
  33. * @property null|\Stripe\StripeObject $shipping Mailing and shipping address for the customer. Appears on invoices emailed to this customer.
  34. * @property null|\Stripe\Collection<\Stripe\Account|\Stripe\BankAccount|\Stripe\Card|\Stripe\Source> $sources The customer's payment sources, if any.
  35. * @property null|\Stripe\Collection<\Stripe\Subscription> $subscriptions The customer's current subscriptions, if any.
  36. * @property null|\Stripe\StripeObject $tax
  37. * @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>.
  38. * @property null|\Stripe\Collection<\Stripe\TaxId> $tax_ids The customer's tax IDs.
  39. * @property null|string|\Stripe\TestHelpers\TestClock $test_clock ID of the test clock this customer belongs to.
  40. */
  41. class Customer extends ApiResource
  42. {
  43. const OBJECT_NAME = 'customer';
  44. use ApiOperations\All;
  45. use ApiOperations\Create;
  46. use ApiOperations\Delete;
  47. use ApiOperations\NestedResource;
  48. use ApiOperations\Retrieve;
  49. use ApiOperations\Search;
  50. use ApiOperations\Update;
  51. const TAX_EXEMPT_EXEMPT = 'exempt';
  52. const TAX_EXEMPT_NONE = 'none';
  53. const TAX_EXEMPT_REVERSE = 'reverse';
  54. public static function getSavedNestedResources()
  55. {
  56. static $savedNestedResources = null;
  57. if (null === $savedNestedResources) {
  58. $savedNestedResources = new Util\Set([
  59. 'source',
  60. ]);
  61. }
  62. return $savedNestedResources;
  63. }
  64. /**
  65. * @param null|array $params
  66. * @param null|array|string $opts
  67. *
  68. * @return \Stripe\Customer the updated customer
  69. */
  70. public function deleteDiscount($params = null, $opts = null)
  71. {
  72. $url = $this->instanceUrl() . '/discount';
  73. list($response, $opts) = $this->_request('delete', $url, $params, $opts);
  74. $this->refreshFrom(['discount' => null], $opts, true);
  75. return $this;
  76. }
  77. /**
  78. * @param string $id
  79. * @param null|array $params
  80. * @param null|array|string $opts
  81. *
  82. * @throws \Stripe\Exception\ApiErrorException if the request fails
  83. *
  84. * @return \Stripe\Collection<\Stripe\PaymentMethod> list of PaymentMethods
  85. */
  86. public static function allPaymentMethods($id, $params = null, $opts = null)
  87. {
  88. $url = static::resourceUrl($id) . '/payment_methods';
  89. list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
  90. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  91. $obj->setLastResponse($response);
  92. return $obj;
  93. }
  94. /**
  95. * @param string $payment_method
  96. * @param null|array $params
  97. * @param null|array|string $opts
  98. *
  99. * @throws \Stripe\Exception\ApiErrorException if the request fails
  100. *
  101. * @return \Stripe\Customer the retrieved customer
  102. */
  103. public function retrievePaymentMethod($payment_method, $params = null, $opts = null)
  104. {
  105. $url = $this->instanceUrl() . '/payment_methods/' . $payment_method;
  106. list($response, $opts) = $this->_request('get', $url, $params, $opts);
  107. $obj = \Stripe\Util\Util::convertToStripeObject($response, $opts);
  108. $obj->setLastResponse($response);
  109. return $obj;
  110. }
  111. /**
  112. * @param null|array $params
  113. * @param null|array|string $opts
  114. *
  115. * @throws \Stripe\Exception\ApiErrorException if the request fails
  116. *
  117. * @return \Stripe\SearchResult<Customer> the customer search results
  118. */
  119. public static function search($params = null, $opts = null)
  120. {
  121. $url = '/v1/customers/search';
  122. return self::_searchResource($url, $params, $opts);
  123. }
  124. const PATH_CASH_BALANCE = '/cash_balance';
  125. /**
  126. * @param string $id the ID of the customer to which the cash balance belongs
  127. * @param null|array $params
  128. * @param null|array|string $opts
  129. * @param mixed $cashBalanceId
  130. *
  131. * @throws \Stripe\Exception\ApiErrorException if the request fails
  132. *
  133. * @return \Stripe\CashBalance
  134. */
  135. public static function retrieveCashBalance($id, $cashBalanceId, $params = null, $opts = null)
  136. {
  137. return self::_retrieveNestedResource($id, static::PATH_CASH_BALANCE, $params, $opts);
  138. }
  139. /**
  140. * @param string $id the ID of the customer to which the cash balance belongs
  141. * @param null|array $params
  142. * @param null|array|string $opts
  143. * @param mixed $cashBalanceId
  144. *
  145. * @throws \Stripe\Exception\ApiErrorException if the request fails
  146. *
  147. * @return \Stripe\CashBalance
  148. */
  149. public static function updateCashBalance($id, $cashBalanceId, $params = null, $opts = null)
  150. {
  151. return self::_updateNestedResource($id, static::PATH_CASH_BALANCE, $params, $opts);
  152. }
  153. const PATH_BALANCE_TRANSACTIONS = '/balance_transactions';
  154. /**
  155. * @param string $id the ID of the customer on which to retrieve the customer balance transactions
  156. * @param null|array $params
  157. * @param null|array|string $opts
  158. *
  159. * @throws \Stripe\Exception\ApiErrorException if the request fails
  160. *
  161. * @return \Stripe\Collection<\Stripe\CustomerBalanceTransaction> the list of customer balance transactions
  162. */
  163. public static function allBalanceTransactions($id, $params = null, $opts = null)
  164. {
  165. return self::_allNestedResources($id, static::PATH_BALANCE_TRANSACTIONS, $params, $opts);
  166. }
  167. /**
  168. * @param string $id the ID of the customer on which to create the customer balance transaction
  169. * @param null|array $params
  170. * @param null|array|string $opts
  171. *
  172. * @throws \Stripe\Exception\ApiErrorException if the request fails
  173. *
  174. * @return \Stripe\CustomerBalanceTransaction
  175. */
  176. public static function createBalanceTransaction($id, $params = null, $opts = null)
  177. {
  178. return self::_createNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $params, $opts);
  179. }
  180. /**
  181. * @param string $id the ID of the customer to which the customer balance transaction belongs
  182. * @param string $balanceTransactionId the ID of the customer balance transaction to retrieve
  183. * @param null|array $params
  184. * @param null|array|string $opts
  185. *
  186. * @throws \Stripe\Exception\ApiErrorException if the request fails
  187. *
  188. * @return \Stripe\CustomerBalanceTransaction
  189. */
  190. public static function retrieveBalanceTransaction($id, $balanceTransactionId, $params = null, $opts = null)
  191. {
  192. return self::_retrieveNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $balanceTransactionId, $params, $opts);
  193. }
  194. /**
  195. * @param string $id the ID of the customer to which the customer balance transaction belongs
  196. * @param string $balanceTransactionId the ID of the customer balance transaction to update
  197. * @param null|array $params
  198. * @param null|array|string $opts
  199. *
  200. * @throws \Stripe\Exception\ApiErrorException if the request fails
  201. *
  202. * @return \Stripe\CustomerBalanceTransaction
  203. */
  204. public static function updateBalanceTransaction($id, $balanceTransactionId, $params = null, $opts = null)
  205. {
  206. return self::_updateNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $balanceTransactionId, $params, $opts);
  207. }
  208. const PATH_CASH_BALANCE_TRANSACTIONS = '/cash_balance_transactions';
  209. /**
  210. * @param string $id the ID of the customer on which to retrieve the customer cash balance transactions
  211. * @param null|array $params
  212. * @param null|array|string $opts
  213. *
  214. * @throws \Stripe\Exception\ApiErrorException if the request fails
  215. *
  216. * @return \Stripe\Collection<\Stripe\CustomerCashBalanceTransaction> the list of customer cash balance transactions
  217. */
  218. public static function allCashBalanceTransactions($id, $params = null, $opts = null)
  219. {
  220. return self::_allNestedResources($id, static::PATH_CASH_BALANCE_TRANSACTIONS, $params, $opts);
  221. }
  222. /**
  223. * @param string $id the ID of the customer to which the customer cash balance transaction belongs
  224. * @param string $cashBalanceTransactionId the ID of the customer cash balance transaction to retrieve
  225. * @param null|array $params
  226. * @param null|array|string $opts
  227. *
  228. * @throws \Stripe\Exception\ApiErrorException if the request fails
  229. *
  230. * @return \Stripe\CustomerCashBalanceTransaction
  231. */
  232. public static function retrieveCashBalanceTransaction($id, $cashBalanceTransactionId, $params = null, $opts = null)
  233. {
  234. return self::_retrieveNestedResource($id, static::PATH_CASH_BALANCE_TRANSACTIONS, $cashBalanceTransactionId, $params, $opts);
  235. }
  236. const PATH_SOURCES = '/sources';
  237. /**
  238. * @param string $id the ID of the customer on which to retrieve the payment sources
  239. * @param null|array $params
  240. * @param null|array|string $opts
  241. *
  242. * @throws \Stripe\Exception\ApiErrorException if the request fails
  243. *
  244. * @return \Stripe\Collection<\Stripe\BankAccount|\Stripe\Card|\Stripe\Source> the list of payment sources (BankAccount, Card or Source)
  245. */
  246. public static function allSources($id, $params = null, $opts = null)
  247. {
  248. return self::_allNestedResources($id, static::PATH_SOURCES, $params, $opts);
  249. }
  250. /**
  251. * @param string $id the ID of the customer on which to create the payment source
  252. * @param null|array $params
  253. * @param null|array|string $opts
  254. *
  255. * @throws \Stripe\Exception\ApiErrorException if the request fails
  256. *
  257. * @return \Stripe\BankAccount|\Stripe\Card|\Stripe\Source
  258. */
  259. public static function createSource($id, $params = null, $opts = null)
  260. {
  261. return self::_createNestedResource($id, static::PATH_SOURCES, $params, $opts);
  262. }
  263. /**
  264. * @param string $id the ID of the customer to which the payment source belongs
  265. * @param string $sourceId the ID of the payment source to delete
  266. * @param null|array $params
  267. * @param null|array|string $opts
  268. *
  269. * @throws \Stripe\Exception\ApiErrorException if the request fails
  270. *
  271. * @return \Stripe\BankAccount|\Stripe\Card|\Stripe\Source
  272. */
  273. public static function deleteSource($id, $sourceId, $params = null, $opts = null)
  274. {
  275. return self::_deleteNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
  276. }
  277. /**
  278. * @param string $id the ID of the customer to which the payment source belongs
  279. * @param string $sourceId the ID of the payment source to retrieve
  280. * @param null|array $params
  281. * @param null|array|string $opts
  282. *
  283. * @throws \Stripe\Exception\ApiErrorException if the request fails
  284. *
  285. * @return \Stripe\BankAccount|\Stripe\Card|\Stripe\Source
  286. */
  287. public static function retrieveSource($id, $sourceId, $params = null, $opts = null)
  288. {
  289. return self::_retrieveNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
  290. }
  291. /**
  292. * @param string $id the ID of the customer to which the payment source belongs
  293. * @param string $sourceId the ID of the payment source to update
  294. * @param null|array $params
  295. * @param null|array|string $opts
  296. *
  297. * @throws \Stripe\Exception\ApiErrorException if the request fails
  298. *
  299. * @return \Stripe\BankAccount|\Stripe\Card|\Stripe\Source
  300. */
  301. public static function updateSource($id, $sourceId, $params = null, $opts = null)
  302. {
  303. return self::_updateNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
  304. }
  305. const PATH_TAX_IDS = '/tax_ids';
  306. /**
  307. * @param string $id the ID of the customer on which to retrieve the tax ids
  308. * @param null|array $params
  309. * @param null|array|string $opts
  310. *
  311. * @throws \Stripe\Exception\ApiErrorException if the request fails
  312. *
  313. * @return \Stripe\Collection<\Stripe\TaxId> the list of tax ids
  314. */
  315. public static function allTaxIds($id, $params = null, $opts = null)
  316. {
  317. return self::_allNestedResources($id, static::PATH_TAX_IDS, $params, $opts);
  318. }
  319. /**
  320. * @param string $id the ID of the customer on which to create the tax id
  321. * @param null|array $params
  322. * @param null|array|string $opts
  323. *
  324. * @throws \Stripe\Exception\ApiErrorException if the request fails
  325. *
  326. * @return \Stripe\TaxId
  327. */
  328. public static function createTaxId($id, $params = null, $opts = null)
  329. {
  330. return self::_createNestedResource($id, static::PATH_TAX_IDS, $params, $opts);
  331. }
  332. /**
  333. * @param string $id the ID of the customer to which the tax id belongs
  334. * @param string $taxIdId the ID of the tax id to delete
  335. * @param null|array $params
  336. * @param null|array|string $opts
  337. *
  338. * @throws \Stripe\Exception\ApiErrorException if the request fails
  339. *
  340. * @return \Stripe\TaxId
  341. */
  342. public static function deleteTaxId($id, $taxIdId, $params = null, $opts = null)
  343. {
  344. return self::_deleteNestedResource($id, static::PATH_TAX_IDS, $taxIdId, $params, $opts);
  345. }
  346. /**
  347. * @param string $id the ID of the customer to which the tax id belongs
  348. * @param string $taxIdId the ID of the tax id to retrieve
  349. * @param null|array $params
  350. * @param null|array|string $opts
  351. *
  352. * @throws \Stripe\Exception\ApiErrorException if the request fails
  353. *
  354. * @return \Stripe\TaxId
  355. */
  356. public static function retrieveTaxId($id, $taxIdId, $params = null, $opts = null)
  357. {
  358. return self::_retrieveNestedResource($id, static::PATH_TAX_IDS, $taxIdId, $params, $opts);
  359. }
  360. }