CustomerService.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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
  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
  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. * List sources for a specified customer.
  39. *
  40. * @param string $parentId
  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
  47. */
  48. public function allSources($parentId, $params = null, $opts = null)
  49. {
  50. return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/sources', $parentId), $params, $opts);
  51. }
  52. /**
  53. * Returns a list of tax IDs for a 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
  62. */
  63. public function allTaxIds($parentId, $params = null, $opts = null)
  64. {
  65. return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/tax_ids', $parentId), $params, $opts);
  66. }
  67. /**
  68. * Creates a new customer object.
  69. *
  70. * @param null|array $params
  71. * @param null|array|\Stripe\Util\RequestOptions $opts
  72. *
  73. * @throws \Stripe\Exception\ApiErrorException if the request fails
  74. *
  75. * @return \Stripe\Customer
  76. */
  77. public function create($params = null, $opts = null)
  78. {
  79. return $this->request('post', '/v1/customers', $params, $opts);
  80. }
  81. /**
  82. * Creates an immutable transaction that updates the customer’s credit <a
  83. * href="/docs/billing/customer/balance">balance</a>.
  84. *
  85. * @param string $parentId
  86. * @param null|array $params
  87. * @param null|array|\Stripe\Util\RequestOptions $opts
  88. *
  89. * @throws \Stripe\Exception\ApiErrorException if the request fails
  90. *
  91. * @return \Stripe\CustomerBalanceTransaction
  92. */
  93. public function createBalanceTransaction($parentId, $params = null, $opts = null)
  94. {
  95. return $this->request('post', $this->buildPath('/v1/customers/%s/balance_transactions', $parentId), $params, $opts);
  96. }
  97. /**
  98. * When you create a new credit card, you must specify a customer or recipient on
  99. * which to create it.
  100. *
  101. * If the card’s owner has no default card, then the new card will become the
  102. * default. However, if the owner already has a default, then it will not change.
  103. * To change the default, you should <a href="/docs/api#update_customer">update the
  104. * customer</a> to have a new <code>default_source</code>.
  105. *
  106. * @param string $parentId
  107. * @param null|array $params
  108. * @param null|array|\Stripe\Util\RequestOptions $opts
  109. *
  110. * @throws \Stripe\Exception\ApiErrorException if the request fails
  111. *
  112. * @return \Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  113. */
  114. public function createSource($parentId, $params = null, $opts = null)
  115. {
  116. return $this->request('post', $this->buildPath('/v1/customers/%s/sources', $parentId), $params, $opts);
  117. }
  118. /**
  119. * Creates a new <code>TaxID</code> object for a customer.
  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\TaxId
  128. */
  129. public function createTaxId($parentId, $params = null, $opts = null)
  130. {
  131. return $this->request('post', $this->buildPath('/v1/customers/%s/tax_ids', $parentId), $params, $opts);
  132. }
  133. /**
  134. * Permanently deletes a customer. It cannot be undone. Also immediately cancels
  135. * any active subscriptions on the customer.
  136. *
  137. * @param string $id
  138. * @param null|array $params
  139. * @param null|array|\Stripe\Util\RequestOptions $opts
  140. *
  141. * @throws \Stripe\Exception\ApiErrorException if the request fails
  142. *
  143. * @return \Stripe\Customer
  144. */
  145. public function delete($id, $params = null, $opts = null)
  146. {
  147. return $this->request('delete', $this->buildPath('/v1/customers/%s', $id), $params, $opts);
  148. }
  149. /**
  150. * Removes the currently applied discount on a 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 deleteDiscount($id, $params = null, $opts = null)
  161. {
  162. return $this->request('delete', $this->buildPath('/v1/customers/%s/discount', $id), $params, $opts);
  163. }
  164. /**
  165. * @param string $parentId
  166. * @param string $id
  167. * @param null|array $params
  168. * @param null|array|\Stripe\Util\RequestOptions $opts
  169. *
  170. * @throws \Stripe\Exception\ApiErrorException if the request fails
  171. *
  172. * @return \Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  173. */
  174. public function deleteSource($parentId, $id, $params = null, $opts = null)
  175. {
  176. return $this->request('delete', $this->buildPath('/v1/customers/%s/sources/%s', $parentId, $id), $params, $opts);
  177. }
  178. /**
  179. * Deletes an existing <code>TaxID</code> object.
  180. *
  181. * @param string $parentId
  182. * @param string $id
  183. * @param null|array $params
  184. * @param null|array|\Stripe\Util\RequestOptions $opts
  185. *
  186. * @throws \Stripe\Exception\ApiErrorException if the request fails
  187. *
  188. * @return \Stripe\TaxId
  189. */
  190. public function deleteTaxId($parentId, $id, $params = null, $opts = null)
  191. {
  192. return $this->request('delete', $this->buildPath('/v1/customers/%s/tax_ids/%s', $parentId, $id), $params, $opts);
  193. }
  194. /**
  195. * Retrieves the details of an existing customer. You need only supply the unique
  196. * customer identifier that was returned upon customer creation.
  197. *
  198. * @param string $id
  199. * @param null|array $params
  200. * @param null|array|\Stripe\Util\RequestOptions $opts
  201. *
  202. * @throws \Stripe\Exception\ApiErrorException if the request fails
  203. *
  204. * @return \Stripe\Customer
  205. */
  206. public function retrieve($id, $params = null, $opts = null)
  207. {
  208. return $this->request('get', $this->buildPath('/v1/customers/%s', $id), $params, $opts);
  209. }
  210. /**
  211. * Retrieves a specific customer balance transaction that updated the customer’s <a
  212. * href="/docs/billing/customer/balance">balances</a>.
  213. *
  214. * @param string $parentId
  215. * @param string $id
  216. * @param null|array $params
  217. * @param null|array|\Stripe\Util\RequestOptions $opts
  218. *
  219. * @throws \Stripe\Exception\ApiErrorException if the request fails
  220. *
  221. * @return \Stripe\CustomerBalanceTransaction
  222. */
  223. public function retrieveBalanceTransaction($parentId, $id, $params = null, $opts = null)
  224. {
  225. return $this->request('get', $this->buildPath('/v1/customers/%s/balance_transactions/%s', $parentId, $id), $params, $opts);
  226. }
  227. /**
  228. * Retrieve a specified source for a given customer.
  229. *
  230. * @param string $parentId
  231. * @param string $id
  232. * @param null|array $params
  233. * @param null|array|\Stripe\Util\RequestOptions $opts
  234. *
  235. * @throws \Stripe\Exception\ApiErrorException if the request fails
  236. *
  237. * @return \Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  238. */
  239. public function retrieveSource($parentId, $id, $params = null, $opts = null)
  240. {
  241. return $this->request('get', $this->buildPath('/v1/customers/%s/sources/%s', $parentId, $id), $params, $opts);
  242. }
  243. /**
  244. * Retrieves the <code>TaxID</code> object with the given identifier.
  245. *
  246. * @param string $parentId
  247. * @param string $id
  248. * @param null|array $params
  249. * @param null|array|\Stripe\Util\RequestOptions $opts
  250. *
  251. * @throws \Stripe\Exception\ApiErrorException if the request fails
  252. *
  253. * @return \Stripe\TaxId
  254. */
  255. public function retrieveTaxId($parentId, $id, $params = null, $opts = null)
  256. {
  257. return $this->request('get', $this->buildPath('/v1/customers/%s/tax_ids/%s', $parentId, $id), $params, $opts);
  258. }
  259. /**
  260. * Updates the specified customer by setting the values of the parameters passed.
  261. * Any parameters not provided will be left unchanged. For example, if you pass the
  262. * <strong>source</strong> parameter, that becomes the customer’s active source
  263. * (e.g., a card) to be used for all charges in the future. When you update a
  264. * customer to a new valid card source by passing the <strong>source</strong>
  265. * parameter: for each of the customer’s current subscriptions, if the subscription
  266. * bills automatically and is in the <code>past_due</code> state, then the latest
  267. * open invoice for the subscription with automatic collection enabled will be
  268. * retried. This retry will not count as an automatic retry, and will not affect
  269. * the next regularly scheduled payment for the invoice. Changing the
  270. * <strong>default_source</strong> for a customer will not trigger this behavior.
  271. *
  272. * This request accepts mostly the same arguments as the customer creation call.
  273. *
  274. * @param string $id
  275. * @param null|array $params
  276. * @param null|array|\Stripe\Util\RequestOptions $opts
  277. *
  278. * @throws \Stripe\Exception\ApiErrorException if the request fails
  279. *
  280. * @return \Stripe\Customer
  281. */
  282. public function update($id, $params = null, $opts = null)
  283. {
  284. return $this->request('post', $this->buildPath('/v1/customers/%s', $id), $params, $opts);
  285. }
  286. /**
  287. * Most credit balance transaction fields are immutable, but you may update its
  288. * <code>description</code> and <code>metadata</code>.
  289. *
  290. * @param string $parentId
  291. * @param string $id
  292. * @param null|array $params
  293. * @param null|array|\Stripe\Util\RequestOptions $opts
  294. *
  295. * @throws \Stripe\Exception\ApiErrorException if the request fails
  296. *
  297. * @return \Stripe\CustomerBalanceTransaction
  298. */
  299. public function updateBalanceTransaction($parentId, $id, $params = null, $opts = null)
  300. {
  301. return $this->request('post', $this->buildPath('/v1/customers/%s/balance_transactions/%s', $parentId, $id), $params, $opts);
  302. }
  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\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  312. */
  313. public function updateSource($parentId, $id, $params = null, $opts = null)
  314. {
  315. return $this->request('post', $this->buildPath('/v1/customers/%s/sources/%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 verifySource($parentId, $id, $params = null, $opts = null)
  328. {
  329. return $this->request('post', $this->buildPath('/v1/customers/%s/sources/%s/verify', $parentId, $id), $params, $opts);
  330. }
  331. }