CustomerService.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe\Service;
  4. class CustomerService extends \Stripe\Service\AbstractService
  5. {
  6. /**
  7. * Returns a list of your customers. The customers are returned sorted by creation
  8. * date, with the most recent customers appearing first.
  9. *
  10. * @param null|array $params
  11. * @param null|array|\Stripe\Util\RequestOptions $opts
  12. *
  13. * @throws \Stripe\Exception\ApiErrorException if the request fails
  14. *
  15. * @return \Stripe\Collection<\Stripe\Customer>
  16. */
  17. public function all($params = null, $opts = null)
  18. {
  19. return $this->requestCollection('get', '/v1/customers', $params, $opts);
  20. }
  21. /**
  22. * Returns a list of transactions that updated the customer’s <a
  23. * href="/docs/billing/customer/balance">balances</a>.
  24. *
  25. * @param string $parentId
  26. * @param null|array $params
  27. * @param null|array|\Stripe\Util\RequestOptions $opts
  28. *
  29. * @throws \Stripe\Exception\ApiErrorException if the request fails
  30. *
  31. * @return \Stripe\Collection<\Stripe\CustomerBalanceTransaction>
  32. */
  33. public function allBalanceTransactions($parentId, $params = null, $opts = null)
  34. {
  35. return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/balance_transactions', $parentId), $params, $opts);
  36. }
  37. /**
  38. * Returns a list of PaymentMethods for a given Customer.
  39. *
  40. * @param string $id
  41. * @param null|array $params
  42. * @param null|array|\Stripe\Util\RequestOptions $opts
  43. *
  44. * @throws \Stripe\Exception\ApiErrorException if the request fails
  45. *
  46. * @return \Stripe\Collection<\Stripe\Customer>
  47. */
  48. public function allPaymentMethods($id, $params = null, $opts = null)
  49. {
  50. return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/payment_methods', $id), $params, $opts);
  51. }
  52. /**
  53. * List sources for a specified customer.
  54. *
  55. * @param string $parentId
  56. * @param null|array $params
  57. * @param null|array|\Stripe\Util\RequestOptions $opts
  58. *
  59. * @throws \Stripe\Exception\ApiErrorException if the request fails
  60. *
  61. * @return \Stripe\Collection<\Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source>
  62. */
  63. public function allSources($parentId, $params = null, $opts = null)
  64. {
  65. return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/sources', $parentId), $params, $opts);
  66. }
  67. /**
  68. * Returns a list of tax IDs for a customer.
  69. *
  70. * @param string $parentId
  71. * @param null|array $params
  72. * @param null|array|\Stripe\Util\RequestOptions $opts
  73. *
  74. * @throws \Stripe\Exception\ApiErrorException if the request fails
  75. *
  76. * @return \Stripe\Collection<\Stripe\TaxId>
  77. */
  78. public function allTaxIds($parentId, $params = null, $opts = null)
  79. {
  80. return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/tax_ids', $parentId), $params, $opts);
  81. }
  82. /**
  83. * Creates a new customer object.
  84. *
  85. * @param null|array $params
  86. * @param null|array|\Stripe\Util\RequestOptions $opts
  87. *
  88. * @throws \Stripe\Exception\ApiErrorException if the request fails
  89. *
  90. * @return \Stripe\Customer
  91. */
  92. public function create($params = null, $opts = null)
  93. {
  94. return $this->request('post', '/v1/customers', $params, $opts);
  95. }
  96. /**
  97. * Creates an immutable transaction that updates the customer’s credit <a
  98. * href="/docs/billing/customer/balance">balance</a>.
  99. *
  100. * @param string $parentId
  101. * @param null|array $params
  102. * @param null|array|\Stripe\Util\RequestOptions $opts
  103. *
  104. * @throws \Stripe\Exception\ApiErrorException if the request fails
  105. *
  106. * @return \Stripe\CustomerBalanceTransaction
  107. */
  108. public function createBalanceTransaction($parentId, $params = null, $opts = null)
  109. {
  110. return $this->request('post', $this->buildPath('/v1/customers/%s/balance_transactions', $parentId), $params, $opts);
  111. }
  112. /**
  113. * When you create a new credit card, you must specify a customer or recipient on
  114. * which to create it.
  115. *
  116. * If the card’s owner has no default card, then the new card will become the
  117. * default. However, if the owner already has a default, then it will not change.
  118. * To change the default, you should <a href="/docs/api#update_customer">update the
  119. * customer</a> to have a new <code>default_source</code>.
  120. *
  121. * @param string $parentId
  122. * @param null|array $params
  123. * @param null|array|\Stripe\Util\RequestOptions $opts
  124. *
  125. * @throws \Stripe\Exception\ApiErrorException if the request fails
  126. *
  127. * @return \Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  128. */
  129. public function createSource($parentId, $params = null, $opts = null)
  130. {
  131. return $this->request('post', $this->buildPath('/v1/customers/%s/sources', $parentId), $params, $opts);
  132. }
  133. /**
  134. * Creates a new <code>TaxID</code> object for a customer.
  135. *
  136. * @param string $parentId
  137. * @param null|array $params
  138. * @param null|array|\Stripe\Util\RequestOptions $opts
  139. *
  140. * @throws \Stripe\Exception\ApiErrorException if the request fails
  141. *
  142. * @return \Stripe\TaxId
  143. */
  144. public function createTaxId($parentId, $params = null, $opts = null)
  145. {
  146. return $this->request('post', $this->buildPath('/v1/customers/%s/tax_ids', $parentId), $params, $opts);
  147. }
  148. /**
  149. * Permanently deletes a customer. It cannot be undone. Also immediately cancels
  150. * any active subscriptions on the customer.
  151. *
  152. * @param string $id
  153. * @param null|array $params
  154. * @param null|array|\Stripe\Util\RequestOptions $opts
  155. *
  156. * @throws \Stripe\Exception\ApiErrorException if the request fails
  157. *
  158. * @return \Stripe\Customer
  159. */
  160. public function delete($id, $params = null, $opts = null)
  161. {
  162. return $this->request('delete', $this->buildPath('/v1/customers/%s', $id), $params, $opts);
  163. }
  164. /**
  165. * Removes the currently applied discount on a customer.
  166. *
  167. * @param string $id
  168. * @param null|array $params
  169. * @param null|array|\Stripe\Util\RequestOptions $opts
  170. *
  171. * @throws \Stripe\Exception\ApiErrorException if the request fails
  172. *
  173. * @return \Stripe\Customer
  174. */
  175. public function deleteDiscount($id, $params = null, $opts = null)
  176. {
  177. return $this->request('delete', $this->buildPath('/v1/customers/%s/discount', $id), $params, $opts);
  178. }
  179. /**
  180. * @param string $parentId
  181. * @param string $id
  182. * @param null|array $params
  183. * @param null|array|\Stripe\Util\RequestOptions $opts
  184. *
  185. * @throws \Stripe\Exception\ApiErrorException if the request fails
  186. *
  187. * @return \Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  188. */
  189. public function deleteSource($parentId, $id, $params = null, $opts = null)
  190. {
  191. return $this->request('delete', $this->buildPath('/v1/customers/%s/sources/%s', $parentId, $id), $params, $opts);
  192. }
  193. /**
  194. * Deletes an existing <code>TaxID</code> object.
  195. *
  196. * @param string $parentId
  197. * @param string $id
  198. * @param null|array $params
  199. * @param null|array|\Stripe\Util\RequestOptions $opts
  200. *
  201. * @throws \Stripe\Exception\ApiErrorException if the request fails
  202. *
  203. * @return \Stripe\TaxId
  204. */
  205. public function deleteTaxId($parentId, $id, $params = null, $opts = null)
  206. {
  207. return $this->request('delete', $this->buildPath('/v1/customers/%s/tax_ids/%s', $parentId, $id), $params, $opts);
  208. }
  209. /**
  210. * Retrieves a Customer object.
  211. *
  212. * @param string $id
  213. * @param null|array $params
  214. * @param null|array|\Stripe\Util\RequestOptions $opts
  215. *
  216. * @throws \Stripe\Exception\ApiErrorException if the request fails
  217. *
  218. * @return \Stripe\Customer
  219. */
  220. public function retrieve($id, $params = null, $opts = null)
  221. {
  222. return $this->request('get', $this->buildPath('/v1/customers/%s', $id), $params, $opts);
  223. }
  224. /**
  225. * Retrieves a specific customer balance transaction that updated the customer’s <a
  226. * href="/docs/billing/customer/balance">balances</a>.
  227. *
  228. * @param string $parentId
  229. * @param string $id
  230. * @param null|array $params
  231. * @param null|array|\Stripe\Util\RequestOptions $opts
  232. *
  233. * @throws \Stripe\Exception\ApiErrorException if the request fails
  234. *
  235. * @return \Stripe\CustomerBalanceTransaction
  236. */
  237. public function retrieveBalanceTransaction($parentId, $id, $params = null, $opts = null)
  238. {
  239. return $this->request('get', $this->buildPath('/v1/customers/%s/balance_transactions/%s', $parentId, $id), $params, $opts);
  240. }
  241. /**
  242. * Retrieve a specified source for a given customer.
  243. *
  244. * @param string $parentId
  245. * @param string $id
  246. * @param null|array $params
  247. * @param null|array|\Stripe\Util\RequestOptions $opts
  248. *
  249. * @throws \Stripe\Exception\ApiErrorException if the request fails
  250. *
  251. * @return \Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  252. */
  253. public function retrieveSource($parentId, $id, $params = null, $opts = null)
  254. {
  255. return $this->request('get', $this->buildPath('/v1/customers/%s/sources/%s', $parentId, $id), $params, $opts);
  256. }
  257. /**
  258. * Retrieves the <code>TaxID</code> object with the given identifier.
  259. *
  260. * @param string $parentId
  261. * @param string $id
  262. * @param null|array $params
  263. * @param null|array|\Stripe\Util\RequestOptions $opts
  264. *
  265. * @throws \Stripe\Exception\ApiErrorException if the request fails
  266. *
  267. * @return \Stripe\TaxId
  268. */
  269. public function retrieveTaxId($parentId, $id, $params = null, $opts = null)
  270. {
  271. return $this->request('get', $this->buildPath('/v1/customers/%s/tax_ids/%s', $parentId, $id), $params, $opts);
  272. }
  273. /**
  274. * Updates the specified customer by setting the values of the parameters passed.
  275. * Any parameters not provided will be left unchanged. For example, if you pass the
  276. * <strong>source</strong> parameter, that becomes the customer’s active source
  277. * (e.g., a card) to be used for all charges in the future. When you update a
  278. * customer to a new valid card source by passing the <strong>source</strong>
  279. * parameter: for each of the customer’s current subscriptions, if the subscription
  280. * bills automatically and is in the <code>past_due</code> state, then the latest
  281. * open invoice for the subscription with automatic collection enabled will be
  282. * retried. This retry will not count as an automatic retry, and will not affect
  283. * the next regularly scheduled payment for the invoice. Changing the
  284. * <strong>default_source</strong> for a customer will not trigger this behavior.
  285. *
  286. * This request accepts mostly the same arguments as the customer creation call.
  287. *
  288. * @param string $id
  289. * @param null|array $params
  290. * @param null|array|\Stripe\Util\RequestOptions $opts
  291. *
  292. * @throws \Stripe\Exception\ApiErrorException if the request fails
  293. *
  294. * @return \Stripe\Customer
  295. */
  296. public function update($id, $params = null, $opts = null)
  297. {
  298. return $this->request('post', $this->buildPath('/v1/customers/%s', $id), $params, $opts);
  299. }
  300. /**
  301. * Most credit balance transaction fields are immutable, but you may update its
  302. * <code>description</code> and <code>metadata</code>.
  303. *
  304. * @param string $parentId
  305. * @param string $id
  306. * @param null|array $params
  307. * @param null|array|\Stripe\Util\RequestOptions $opts
  308. *
  309. * @throws \Stripe\Exception\ApiErrorException if the request fails
  310. *
  311. * @return \Stripe\CustomerBalanceTransaction
  312. */
  313. public function updateBalanceTransaction($parentId, $id, $params = null, $opts = null)
  314. {
  315. return $this->request('post', $this->buildPath('/v1/customers/%s/balance_transactions/%s', $parentId, $id), $params, $opts);
  316. }
  317. /**
  318. * @param string $parentId
  319. * @param string $id
  320. * @param null|array $params
  321. * @param null|array|\Stripe\Util\RequestOptions $opts
  322. *
  323. * @throws \Stripe\Exception\ApiErrorException if the request fails
  324. *
  325. * @return \Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  326. */
  327. public function updateSource($parentId, $id, $params = null, $opts = null)
  328. {
  329. return $this->request('post', $this->buildPath('/v1/customers/%s/sources/%s', $parentId, $id), $params, $opts);
  330. }
  331. /**
  332. * @param string $parentId
  333. * @param string $id
  334. * @param null|array $params
  335. * @param null|array|\Stripe\Util\RequestOptions $opts
  336. *
  337. * @throws \Stripe\Exception\ApiErrorException if the request fails
  338. *
  339. * @return \Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  340. */
  341. public function verifySource($parentId, $id, $params = null, $opts = null)
  342. {
  343. return $this->request('post', $this->buildPath('/v1/customers/%s/sources/%s/verify', $parentId, $id), $params, $opts);
  344. }
  345. }