CustomerService.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe\Service;
  4. /**
  5. * @phpstan-import-type RequestOptionsArray from \Stripe\Util\RequestOptions
  6. * @psalm-import-type RequestOptionsArray from \Stripe\Util\RequestOptions
  7. */
  8. class CustomerService extends \Stripe\Service\AbstractService
  9. {
  10. /**
  11. * Returns a list of your customers. The customers are returned sorted by creation
  12. * date, with the most recent customers appearing first.
  13. *
  14. * @param null|array $params
  15. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  16. *
  17. * @throws \Stripe\Exception\ApiErrorException if the request fails
  18. *
  19. * @return \Stripe\Collection<\Stripe\Customer>
  20. */
  21. public function all($params = null, $opts = null)
  22. {
  23. return $this->requestCollection('get', '/v1/customers', $params, $opts);
  24. }
  25. /**
  26. * Returns a list of transactions that updated the customer’s <a
  27. * href="/docs/billing/customer/balance">balances</a>.
  28. *
  29. * @param string $parentId
  30. * @param null|array $params
  31. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  32. *
  33. * @throws \Stripe\Exception\ApiErrorException if the request fails
  34. *
  35. * @return \Stripe\Collection<\Stripe\CustomerBalanceTransaction>
  36. */
  37. public function allBalanceTransactions($parentId, $params = null, $opts = null)
  38. {
  39. return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/balance_transactions', $parentId), $params, $opts);
  40. }
  41. /**
  42. * Returns a list of transactions that modified the customer’s <a
  43. * href="/docs/payments/customer-balance">cash balance</a>.
  44. *
  45. * @param string $parentId
  46. * @param null|array $params
  47. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  48. *
  49. * @throws \Stripe\Exception\ApiErrorException if the request fails
  50. *
  51. * @return \Stripe\Collection<\Stripe\CustomerCashBalanceTransaction>
  52. */
  53. public function allCashBalanceTransactions($parentId, $params = null, $opts = null)
  54. {
  55. return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/cash_balance_transactions', $parentId), $params, $opts);
  56. }
  57. /**
  58. * Returns a list of PaymentMethods for a given Customer.
  59. *
  60. * @param string $id
  61. * @param null|array $params
  62. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  63. *
  64. * @throws \Stripe\Exception\ApiErrorException if the request fails
  65. *
  66. * @return \Stripe\Collection<\Stripe\PaymentMethod>
  67. */
  68. public function allPaymentMethods($id, $params = null, $opts = null)
  69. {
  70. return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/payment_methods', $id), $params, $opts);
  71. }
  72. /**
  73. * List sources for a specified customer.
  74. *
  75. * @param string $parentId
  76. * @param null|array $params
  77. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  78. *
  79. * @throws \Stripe\Exception\ApiErrorException if the request fails
  80. *
  81. * @return \Stripe\Collection<\Stripe\Account|\Stripe\BankAccount|\Stripe\Card|\Stripe\Source>
  82. */
  83. public function allSources($parentId, $params = null, $opts = null)
  84. {
  85. return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/sources', $parentId), $params, $opts);
  86. }
  87. /**
  88. * Returns a list of tax IDs for a customer.
  89. *
  90. * @param string $parentId
  91. * @param null|array $params
  92. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  93. *
  94. * @throws \Stripe\Exception\ApiErrorException if the request fails
  95. *
  96. * @return \Stripe\Collection<\Stripe\TaxId>
  97. */
  98. public function allTaxIds($parentId, $params = null, $opts = null)
  99. {
  100. return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/tax_ids', $parentId), $params, $opts);
  101. }
  102. /**
  103. * Creates a new customer object.
  104. *
  105. * @param null|array $params
  106. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  107. *
  108. * @throws \Stripe\Exception\ApiErrorException if the request fails
  109. *
  110. * @return \Stripe\Customer
  111. */
  112. public function create($params = null, $opts = null)
  113. {
  114. return $this->request('post', '/v1/customers', $params, $opts);
  115. }
  116. /**
  117. * Creates an immutable transaction that updates the customer’s credit <a
  118. * href="/docs/billing/customer/balance">balance</a>.
  119. *
  120. * @param string $parentId
  121. * @param null|array $params
  122. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  123. *
  124. * @throws \Stripe\Exception\ApiErrorException if the request fails
  125. *
  126. * @return \Stripe\CustomerBalanceTransaction
  127. */
  128. public function createBalanceTransaction($parentId, $params = null, $opts = null)
  129. {
  130. return $this->request('post', $this->buildPath('/v1/customers/%s/balance_transactions', $parentId), $params, $opts);
  131. }
  132. /**
  133. * Retrieve funding instructions for a customer cash balance. If funding
  134. * instructions do not yet exist for the customer, new funding instructions will be
  135. * created. If funding instructions have already been created for a given customer,
  136. * the same funding instructions will be retrieved. In other words, we will return
  137. * the same funding instructions each time.
  138. *
  139. * @param string $id
  140. * @param null|array $params
  141. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  142. *
  143. * @throws \Stripe\Exception\ApiErrorException if the request fails
  144. *
  145. * @return \Stripe\FundingInstructions
  146. */
  147. public function createFundingInstructions($id, $params = null, $opts = null)
  148. {
  149. return $this->request('post', $this->buildPath('/v1/customers/%s/funding_instructions', $id), $params, $opts);
  150. }
  151. /**
  152. * When you create a new credit card, you must specify a customer or recipient on
  153. * which to create it.
  154. *
  155. * If the card’s owner has no default card, then the new card will become the
  156. * default. However, if the owner already has a default, then it will not change.
  157. * To change the default, you should <a href="/docs/api#update_customer">update the
  158. * customer</a> to have a new <code>default_source</code>.
  159. *
  160. * @param string $parentId
  161. * @param null|array $params
  162. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  163. *
  164. * @throws \Stripe\Exception\ApiErrorException if the request fails
  165. *
  166. * @return \Stripe\Account|\Stripe\BankAccount|\Stripe\Card|\Stripe\Source
  167. */
  168. public function createSource($parentId, $params = null, $opts = null)
  169. {
  170. return $this->request('post', $this->buildPath('/v1/customers/%s/sources', $parentId), $params, $opts);
  171. }
  172. /**
  173. * Creates a new <code>tax_id</code> object for a customer.
  174. *
  175. * @param string $parentId
  176. * @param null|array $params
  177. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  178. *
  179. * @throws \Stripe\Exception\ApiErrorException if the request fails
  180. *
  181. * @return \Stripe\TaxId
  182. */
  183. public function createTaxId($parentId, $params = null, $opts = null)
  184. {
  185. return $this->request('post', $this->buildPath('/v1/customers/%s/tax_ids', $parentId), $params, $opts);
  186. }
  187. /**
  188. * Permanently deletes a customer. It cannot be undone. Also immediately cancels
  189. * any active subscriptions on the customer.
  190. *
  191. * @param string $id
  192. * @param null|array $params
  193. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  194. *
  195. * @throws \Stripe\Exception\ApiErrorException if the request fails
  196. *
  197. * @return \Stripe\Customer
  198. */
  199. public function delete($id, $params = null, $opts = null)
  200. {
  201. return $this->request('delete', $this->buildPath('/v1/customers/%s', $id), $params, $opts);
  202. }
  203. /**
  204. * Removes the currently applied discount on a customer.
  205. *
  206. * @param string $id
  207. * @param null|array $params
  208. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  209. *
  210. * @throws \Stripe\Exception\ApiErrorException if the request fails
  211. *
  212. * @return \Stripe\Discount
  213. */
  214. public function deleteDiscount($id, $params = null, $opts = null)
  215. {
  216. return $this->request('delete', $this->buildPath('/v1/customers/%s/discount', $id), $params, $opts);
  217. }
  218. /**
  219. * Delete a specified source for a given customer.
  220. *
  221. * @param string $parentId
  222. * @param string $id
  223. * @param null|array $params
  224. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  225. *
  226. * @throws \Stripe\Exception\ApiErrorException if the request fails
  227. *
  228. * @return \Stripe\Account|\Stripe\BankAccount|\Stripe\Card|\Stripe\Source
  229. */
  230. public function deleteSource($parentId, $id, $params = null, $opts = null)
  231. {
  232. return $this->request('delete', $this->buildPath('/v1/customers/%s/sources/%s', $parentId, $id), $params, $opts);
  233. }
  234. /**
  235. * Deletes an existing <code>tax_id</code> object.
  236. *
  237. * @param string $parentId
  238. * @param string $id
  239. * @param null|array $params
  240. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  241. *
  242. * @throws \Stripe\Exception\ApiErrorException if the request fails
  243. *
  244. * @return \Stripe\TaxId
  245. */
  246. public function deleteTaxId($parentId, $id, $params = null, $opts = null)
  247. {
  248. return $this->request('delete', $this->buildPath('/v1/customers/%s/tax_ids/%s', $parentId, $id), $params, $opts);
  249. }
  250. /**
  251. * Retrieves a Customer object.
  252. *
  253. * @param string $id
  254. * @param null|array $params
  255. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  256. *
  257. * @throws \Stripe\Exception\ApiErrorException if the request fails
  258. *
  259. * @return \Stripe\Customer
  260. */
  261. public function retrieve($id, $params = null, $opts = null)
  262. {
  263. return $this->request('get', $this->buildPath('/v1/customers/%s', $id), $params, $opts);
  264. }
  265. /**
  266. * Retrieves a specific customer balance transaction that updated the customer’s <a
  267. * href="/docs/billing/customer/balance">balances</a>.
  268. *
  269. * @param string $parentId
  270. * @param string $id
  271. * @param null|array $params
  272. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  273. *
  274. * @throws \Stripe\Exception\ApiErrorException if the request fails
  275. *
  276. * @return \Stripe\CustomerBalanceTransaction
  277. */
  278. public function retrieveBalanceTransaction($parentId, $id, $params = null, $opts = null)
  279. {
  280. return $this->request('get', $this->buildPath('/v1/customers/%s/balance_transactions/%s', $parentId, $id), $params, $opts);
  281. }
  282. /**
  283. * Retrieves a customer’s cash balance.
  284. *
  285. * @param string $parentId
  286. * @param null|array $params
  287. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  288. *
  289. * @throws \Stripe\Exception\ApiErrorException if the request fails
  290. *
  291. * @return \Stripe\CashBalance
  292. */
  293. public function retrieveCashBalance($parentId, $params = null, $opts = null)
  294. {
  295. return $this->request('get', $this->buildPath('/v1/customers/%s/cash_balance', $parentId), $params, $opts);
  296. }
  297. /**
  298. * Retrieves a specific cash balance transaction, which updated the customer’s <a
  299. * href="/docs/payments/customer-balance">cash balance</a>.
  300. *
  301. * @param string $parentId
  302. * @param string $id
  303. * @param null|array $params
  304. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  305. *
  306. * @throws \Stripe\Exception\ApiErrorException if the request fails
  307. *
  308. * @return \Stripe\CustomerCashBalanceTransaction
  309. */
  310. public function retrieveCashBalanceTransaction($parentId, $id, $params = null, $opts = null)
  311. {
  312. return $this->request('get', $this->buildPath('/v1/customers/%s/cash_balance_transactions/%s', $parentId, $id), $params, $opts);
  313. }
  314. /**
  315. * Retrieves a PaymentMethod object for a given Customer.
  316. *
  317. * @param string $parentId
  318. * @param string $id
  319. * @param null|array $params
  320. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  321. *
  322. * @throws \Stripe\Exception\ApiErrorException if the request fails
  323. *
  324. * @return \Stripe\PaymentMethod
  325. */
  326. public function retrievePaymentMethod($parentId, $id, $params = null, $opts = null)
  327. {
  328. return $this->request('get', $this->buildPath('/v1/customers/%s/payment_methods/%s', $parentId, $id), $params, $opts);
  329. }
  330. /**
  331. * Retrieve a specified source for a given customer.
  332. *
  333. * @param string $parentId
  334. * @param string $id
  335. * @param null|array $params
  336. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  337. *
  338. * @throws \Stripe\Exception\ApiErrorException if the request fails
  339. *
  340. * @return \Stripe\Account|\Stripe\BankAccount|\Stripe\Card|\Stripe\Source
  341. */
  342. public function retrieveSource($parentId, $id, $params = null, $opts = null)
  343. {
  344. return $this->request('get', $this->buildPath('/v1/customers/%s/sources/%s', $parentId, $id), $params, $opts);
  345. }
  346. /**
  347. * Retrieves the <code>tax_id</code> object with the given identifier.
  348. *
  349. * @param string $parentId
  350. * @param string $id
  351. * @param null|array $params
  352. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  353. *
  354. * @throws \Stripe\Exception\ApiErrorException if the request fails
  355. *
  356. * @return \Stripe\TaxId
  357. */
  358. public function retrieveTaxId($parentId, $id, $params = null, $opts = null)
  359. {
  360. return $this->request('get', $this->buildPath('/v1/customers/%s/tax_ids/%s', $parentId, $id), $params, $opts);
  361. }
  362. /**
  363. * Search for customers you’ve previously created using Stripe’s <a
  364. * href="/docs/search#search-query-language">Search Query Language</a>. Don’t use
  365. * search in read-after-write flows where strict consistency is necessary. Under
  366. * normal operating conditions, data is searchable in less than a minute.
  367. * Occasionally, propagation of new or updated data can be up to an hour behind
  368. * during outages. Search functionality is not available to merchants in India.
  369. *
  370. * @param null|array $params
  371. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  372. *
  373. * @throws \Stripe\Exception\ApiErrorException if the request fails
  374. *
  375. * @return \Stripe\SearchResult<\Stripe\Customer>
  376. */
  377. public function search($params = null, $opts = null)
  378. {
  379. return $this->requestSearchResult('get', '/v1/customers/search', $params, $opts);
  380. }
  381. /**
  382. * Updates the specified customer by setting the values of the parameters passed.
  383. * Any parameters not provided will be left unchanged. For example, if you pass the
  384. * <strong>source</strong> parameter, that becomes the customer’s active source
  385. * (e.g., a card) to be used for all charges in the future. When you update a
  386. * customer to a new valid card source by passing the <strong>source</strong>
  387. * parameter: for each of the customer’s current subscriptions, if the subscription
  388. * bills automatically and is in the <code>past_due</code> state, then the latest
  389. * open invoice for the subscription with automatic collection enabled will be
  390. * retried. This retry will not count as an automatic retry, and will not affect
  391. * the next regularly scheduled payment for the invoice. Changing the
  392. * <strong>default_source</strong> for a customer will not trigger this behavior.
  393. *
  394. * This request accepts mostly the same arguments as the customer creation call.
  395. *
  396. * @param string $id
  397. * @param null|array $params
  398. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  399. *
  400. * @throws \Stripe\Exception\ApiErrorException if the request fails
  401. *
  402. * @return \Stripe\Customer
  403. */
  404. public function update($id, $params = null, $opts = null)
  405. {
  406. return $this->request('post', $this->buildPath('/v1/customers/%s', $id), $params, $opts);
  407. }
  408. /**
  409. * Most credit balance transaction fields are immutable, but you may update its
  410. * <code>description</code> and <code>metadata</code>.
  411. *
  412. * @param string $parentId
  413. * @param string $id
  414. * @param null|array $params
  415. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  416. *
  417. * @throws \Stripe\Exception\ApiErrorException if the request fails
  418. *
  419. * @return \Stripe\CustomerBalanceTransaction
  420. */
  421. public function updateBalanceTransaction($parentId, $id, $params = null, $opts = null)
  422. {
  423. return $this->request('post', $this->buildPath('/v1/customers/%s/balance_transactions/%s', $parentId, $id), $params, $opts);
  424. }
  425. /**
  426. * Changes the settings on a customer’s cash balance.
  427. *
  428. * @param string $parentId
  429. * @param null|array $params
  430. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  431. *
  432. * @throws \Stripe\Exception\ApiErrorException if the request fails
  433. *
  434. * @return \Stripe\CashBalance
  435. */
  436. public function updateCashBalance($parentId, $params = null, $opts = null)
  437. {
  438. return $this->request('post', $this->buildPath('/v1/customers/%s/cash_balance', $parentId), $params, $opts);
  439. }
  440. /**
  441. * Update a specified source for a given customer.
  442. *
  443. * @param string $parentId
  444. * @param string $id
  445. * @param null|array $params
  446. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  447. *
  448. * @throws \Stripe\Exception\ApiErrorException if the request fails
  449. *
  450. * @return \Stripe\Account|\Stripe\BankAccount|\Stripe\Card|\Stripe\Source
  451. */
  452. public function updateSource($parentId, $id, $params = null, $opts = null)
  453. {
  454. return $this->request('post', $this->buildPath('/v1/customers/%s/sources/%s', $parentId, $id), $params, $opts);
  455. }
  456. /**
  457. * Verify a specified bank account for a given customer.
  458. *
  459. * @param string $parentId
  460. * @param string $id
  461. * @param null|array $params
  462. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  463. *
  464. * @throws \Stripe\Exception\ApiErrorException if the request fails
  465. *
  466. * @return \Stripe\Account|\Stripe\BankAccount|\Stripe\Card|\Stripe\Source
  467. */
  468. public function verifySource($parentId, $id, $params = null, $opts = null)
  469. {
  470. return $this->request('post', $this->buildPath('/v1/customers/%s/sources/%s/verify', $parentId, $id), $params, $opts);
  471. }
  472. }