InvoiceService.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 InvoiceService extends \Stripe\Service\AbstractService
  9. {
  10. /**
  11. * Adds multiple line items to an invoice. This is only possible when an invoice is
  12. * still a draft.
  13. *
  14. * @param string $id
  15. * @param null|array $params
  16. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  17. *
  18. * @throws \Stripe\Exception\ApiErrorException if the request fails
  19. *
  20. * @return \Stripe\Invoice
  21. */
  22. public function addLines($id, $params = null, $opts = null)
  23. {
  24. return $this->request('post', $this->buildPath('/v1/invoices/%s/add_lines', $id), $params, $opts);
  25. }
  26. /**
  27. * You can list all invoices, or list the invoices for a specific customer. The
  28. * invoices are returned sorted by creation date, with the most recently created
  29. * invoices appearing first.
  30. *
  31. * @param null|array $params
  32. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  33. *
  34. * @throws \Stripe\Exception\ApiErrorException if the request fails
  35. *
  36. * @return \Stripe\Collection<\Stripe\Invoice>
  37. */
  38. public function all($params = null, $opts = null)
  39. {
  40. return $this->requestCollection('get', '/v1/invoices', $params, $opts);
  41. }
  42. /**
  43. * When retrieving an invoice, you’ll get a <strong>lines</strong> property
  44. * containing the total count of line items and the first handful of those items.
  45. * There is also a URL where you can retrieve the full (paginated) list of line
  46. * items.
  47. *
  48. * @param string $parentId
  49. * @param null|array $params
  50. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  51. *
  52. * @throws \Stripe\Exception\ApiErrorException if the request fails
  53. *
  54. * @return \Stripe\Collection<\Stripe\InvoiceLineItem>
  55. */
  56. public function allLines($parentId, $params = null, $opts = null)
  57. {
  58. return $this->requestCollection('get', $this->buildPath('/v1/invoices/%s/lines', $parentId), $params, $opts);
  59. }
  60. /**
  61. * This endpoint creates a draft invoice for a given customer. The invoice remains
  62. * a draft until you <a href="#finalize_invoice">finalize</a> the invoice, which
  63. * allows you to <a href="#pay_invoice">pay</a> or <a href="#send_invoice">send</a>
  64. * the invoice to your customers.
  65. *
  66. * @param null|array $params
  67. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  68. *
  69. * @throws \Stripe\Exception\ApiErrorException if the request fails
  70. *
  71. * @return \Stripe\Invoice
  72. */
  73. public function create($params = null, $opts = null)
  74. {
  75. return $this->request('post', '/v1/invoices', $params, $opts);
  76. }
  77. /**
  78. * At any time, you can preview the upcoming invoice for a customer. This will show
  79. * you all the charges that are pending, including subscription renewal charges,
  80. * invoice item charges, etc. It will also show you any discounts that are
  81. * applicable to the invoice.
  82. *
  83. * Note that when you are viewing an upcoming invoice, you are simply viewing a
  84. * preview – the invoice has not yet been created. As such, the upcoming invoice
  85. * will not show up in invoice listing calls, and you cannot use the API to pay or
  86. * edit the invoice. If you want to change the amount that your customer will be
  87. * billed, you can add, remove, or update pending invoice items, or update the
  88. * customer’s discount.
  89. *
  90. * You can preview the effects of updating a subscription, including a preview of
  91. * what proration will take place. To ensure that the actual proration is
  92. * calculated exactly the same as the previewed proration, you should pass the
  93. * <code>subscription_details.proration_date</code> parameter when doing the actual
  94. * subscription update. The recommended way to get only the prorations being
  95. * previewed is to consider only proration line items where
  96. * <code>period[start]</code> is equal to the
  97. * <code>subscription_details.proration_date</code> value passed in the request.
  98. *
  99. * Note: Currency conversion calculations use the latest exchange rates. Exchange
  100. * rates may vary between the time of the preview and the time of the actual
  101. * invoice creation. <a href="https://docs.stripe.com/currencies/conversions">Learn
  102. * more</a>
  103. *
  104. * @param null|array $params
  105. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  106. *
  107. * @throws \Stripe\Exception\ApiErrorException if the request fails
  108. *
  109. * @return \Stripe\Invoice
  110. */
  111. public function createPreview($params = null, $opts = null)
  112. {
  113. return $this->request('post', '/v1/invoices/create_preview', $params, $opts);
  114. }
  115. /**
  116. * Permanently deletes a one-off invoice draft. This cannot be undone. Attempts to
  117. * delete invoices that are no longer in a draft state will fail; once an invoice
  118. * has been finalized or if an invoice is for a subscription, it must be <a
  119. * href="#void_invoice">voided</a>.
  120. *
  121. * @param string $id
  122. * @param null|array $params
  123. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  124. *
  125. * @throws \Stripe\Exception\ApiErrorException if the request fails
  126. *
  127. * @return \Stripe\Invoice
  128. */
  129. public function delete($id, $params = null, $opts = null)
  130. {
  131. return $this->request('delete', $this->buildPath('/v1/invoices/%s', $id), $params, $opts);
  132. }
  133. /**
  134. * Stripe automatically finalizes drafts before sending and attempting payment on
  135. * invoices. However, if you’d like to finalize a draft invoice manually, you can
  136. * do so using this method.
  137. *
  138. * @param string $id
  139. * @param null|array $params
  140. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  141. *
  142. * @throws \Stripe\Exception\ApiErrorException if the request fails
  143. *
  144. * @return \Stripe\Invoice
  145. */
  146. public function finalizeInvoice($id, $params = null, $opts = null)
  147. {
  148. return $this->request('post', $this->buildPath('/v1/invoices/%s/finalize', $id), $params, $opts);
  149. }
  150. /**
  151. * Marking an invoice as uncollectible is useful for keeping track of bad debts
  152. * that can be written off for accounting purposes.
  153. *
  154. * @param string $id
  155. * @param null|array $params
  156. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  157. *
  158. * @throws \Stripe\Exception\ApiErrorException if the request fails
  159. *
  160. * @return \Stripe\Invoice
  161. */
  162. public function markUncollectible($id, $params = null, $opts = null)
  163. {
  164. return $this->request('post', $this->buildPath('/v1/invoices/%s/mark_uncollectible', $id), $params, $opts);
  165. }
  166. /**
  167. * Stripe automatically creates and then attempts to collect payment on invoices
  168. * for customers on subscriptions according to your <a
  169. * href="https://dashboard.stripe.com/account/billing/automatic">subscriptions
  170. * settings</a>. However, if you’d like to attempt payment on an invoice out of the
  171. * normal collection schedule or for some other reason, you can do so.
  172. *
  173. * @param string $id
  174. * @param null|array $params
  175. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  176. *
  177. * @throws \Stripe\Exception\ApiErrorException if the request fails
  178. *
  179. * @return \Stripe\Invoice
  180. */
  181. public function pay($id, $params = null, $opts = null)
  182. {
  183. return $this->request('post', $this->buildPath('/v1/invoices/%s/pay', $id), $params, $opts);
  184. }
  185. /**
  186. * Removes multiple line items from an invoice. This is only possible when an
  187. * invoice is still a draft.
  188. *
  189. * @param string $id
  190. * @param null|array $params
  191. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  192. *
  193. * @throws \Stripe\Exception\ApiErrorException if the request fails
  194. *
  195. * @return \Stripe\Invoice
  196. */
  197. public function removeLines($id, $params = null, $opts = null)
  198. {
  199. return $this->request('post', $this->buildPath('/v1/invoices/%s/remove_lines', $id), $params, $opts);
  200. }
  201. /**
  202. * Retrieves the invoice with the given ID.
  203. *
  204. * @param string $id
  205. * @param null|array $params
  206. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  207. *
  208. * @throws \Stripe\Exception\ApiErrorException if the request fails
  209. *
  210. * @return \Stripe\Invoice
  211. */
  212. public function retrieve($id, $params = null, $opts = null)
  213. {
  214. return $this->request('get', $this->buildPath('/v1/invoices/%s', $id), $params, $opts);
  215. }
  216. /**
  217. * Search for invoices you’ve previously created using Stripe’s <a
  218. * href="/docs/search#search-query-language">Search Query Language</a>. Don’t use
  219. * search in read-after-write flows where strict consistency is necessary. Under
  220. * normal operating conditions, data is searchable in less than a minute.
  221. * Occasionally, propagation of new or updated data can be up to an hour behind
  222. * during outages. Search functionality is not available to merchants in India.
  223. *
  224. * @param null|array $params
  225. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  226. *
  227. * @throws \Stripe\Exception\ApiErrorException if the request fails
  228. *
  229. * @return \Stripe\SearchResult<\Stripe\Invoice>
  230. */
  231. public function search($params = null, $opts = null)
  232. {
  233. return $this->requestSearchResult('get', '/v1/invoices/search', $params, $opts);
  234. }
  235. /**
  236. * Stripe will automatically send invoices to customers according to your <a
  237. * href="https://dashboard.stripe.com/account/billing/automatic">subscriptions
  238. * settings</a>. However, if you’d like to manually send an invoice to your
  239. * customer out of the normal schedule, you can do so. When sending invoices that
  240. * have already been paid, there will be no reference to the payment in the email.
  241. *
  242. * Requests made in test-mode result in no emails being sent, despite sending an
  243. * <code>invoice.sent</code> event.
  244. *
  245. * @param string $id
  246. * @param null|array $params
  247. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  248. *
  249. * @throws \Stripe\Exception\ApiErrorException if the request fails
  250. *
  251. * @return \Stripe\Invoice
  252. */
  253. public function sendInvoice($id, $params = null, $opts = null)
  254. {
  255. return $this->request('post', $this->buildPath('/v1/invoices/%s/send', $id), $params, $opts);
  256. }
  257. /**
  258. * At any time, you can preview the upcoming invoice for a customer. This will show
  259. * you all the charges that are pending, including subscription renewal charges,
  260. * invoice item charges, etc. It will also show you any discounts that are
  261. * applicable to the invoice.
  262. *
  263. * Note that when you are viewing an upcoming invoice, you are simply viewing a
  264. * preview – the invoice has not yet been created. As such, the upcoming invoice
  265. * will not show up in invoice listing calls, and you cannot use the API to pay or
  266. * edit the invoice. If you want to change the amount that your customer will be
  267. * billed, you can add, remove, or update pending invoice items, or update the
  268. * customer’s discount.
  269. *
  270. * You can preview the effects of updating a subscription, including a preview of
  271. * what proration will take place. To ensure that the actual proration is
  272. * calculated exactly the same as the previewed proration, you should pass the
  273. * <code>subscription_details.proration_date</code> parameter when doing the actual
  274. * subscription update. The recommended way to get only the prorations being
  275. * previewed is to consider only proration line items where
  276. * <code>period[start]</code> is equal to the
  277. * <code>subscription_details.proration_date</code> value passed in the request.
  278. *
  279. * Note: Currency conversion calculations use the latest exchange rates. Exchange
  280. * rates may vary between the time of the preview and the time of the actual
  281. * invoice creation. <a href="https://docs.stripe.com/currencies/conversions">Learn
  282. * more</a>
  283. *
  284. * @param null|array $params
  285. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  286. *
  287. * @throws \Stripe\Exception\ApiErrorException if the request fails
  288. *
  289. * @return \Stripe\Invoice
  290. */
  291. public function upcoming($params = null, $opts = null)
  292. {
  293. return $this->request('get', '/v1/invoices/upcoming', $params, $opts);
  294. }
  295. /**
  296. * When retrieving an upcoming invoice, you’ll get a <strong>lines</strong>
  297. * property containing the total count of line items and the first handful of those
  298. * items. There is also a URL where you can retrieve the full (paginated) list of
  299. * line items.
  300. *
  301. * @param null|array $params
  302. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  303. *
  304. * @throws \Stripe\Exception\ApiErrorException if the request fails
  305. *
  306. * @return \Stripe\Collection<\Stripe\InvoiceLineItem>
  307. */
  308. public function upcomingLines($params = null, $opts = null)
  309. {
  310. return $this->requestCollection('get', '/v1/invoices/upcoming/lines', $params, $opts);
  311. }
  312. /**
  313. * Draft invoices are fully editable. Once an invoice is <a
  314. * href="/docs/billing/invoices/workflow#finalized">finalized</a>, monetary values,
  315. * as well as <code>collection_method</code>, become uneditable.
  316. *
  317. * If you would like to stop the Stripe Billing engine from automatically
  318. * finalizing, reattempting payments on, sending reminders for, or <a
  319. * href="/docs/billing/invoices/reconciliation">automatically reconciling</a>
  320. * invoices, pass <code>auto_advance=false</code>.
  321. *
  322. * @param string $id
  323. * @param null|array $params
  324. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  325. *
  326. * @throws \Stripe\Exception\ApiErrorException if the request fails
  327. *
  328. * @return \Stripe\Invoice
  329. */
  330. public function update($id, $params = null, $opts = null)
  331. {
  332. return $this->request('post', $this->buildPath('/v1/invoices/%s', $id), $params, $opts);
  333. }
  334. /**
  335. * Updates an invoice’s line item. Some fields, such as <code>tax_amounts</code>,
  336. * only live on the invoice line item, so they can only be updated through this
  337. * endpoint. Other fields, such as <code>amount</code>, live on both the invoice
  338. * item and the invoice line item, so updates on this endpoint will propagate to
  339. * the invoice item as well. Updating an invoice’s line item is only possible
  340. * before the invoice is finalized.
  341. *
  342. * @param string $parentId
  343. * @param string $id
  344. * @param null|array $params
  345. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  346. *
  347. * @throws \Stripe\Exception\ApiErrorException if the request fails
  348. *
  349. * @return \Stripe\InvoiceLineItem
  350. */
  351. public function updateLine($parentId, $id, $params = null, $opts = null)
  352. {
  353. return $this->request('post', $this->buildPath('/v1/invoices/%s/lines/%s', $parentId, $id), $params, $opts);
  354. }
  355. /**
  356. * Updates multiple line items on an invoice. This is only possible when an invoice
  357. * is still a draft.
  358. *
  359. * @param string $id
  360. * @param null|array $params
  361. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  362. *
  363. * @throws \Stripe\Exception\ApiErrorException if the request fails
  364. *
  365. * @return \Stripe\Invoice
  366. */
  367. public function updateLines($id, $params = null, $opts = null)
  368. {
  369. return $this->request('post', $this->buildPath('/v1/invoices/%s/update_lines', $id), $params, $opts);
  370. }
  371. /**
  372. * Mark a finalized invoice as void. This cannot be undone. Voiding an invoice is
  373. * similar to <a href="#delete_invoice">deletion</a>, however it only applies to
  374. * finalized invoices and maintains a papertrail where the invoice can still be
  375. * found.
  376. *
  377. * Consult with local regulations to determine whether and how an invoice might be
  378. * amended, canceled, or voided in the jurisdiction you’re doing business in. You
  379. * might need to <a href="#create_invoice">issue another invoice</a> or <a
  380. * href="#create_credit_note">credit note</a> instead. Stripe recommends that you
  381. * consult with your legal counsel for advice specific to your business.
  382. *
  383. * @param string $id
  384. * @param null|array $params
  385. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  386. *
  387. * @throws \Stripe\Exception\ApiErrorException if the request fails
  388. *
  389. * @return \Stripe\Invoice
  390. */
  391. public function voidInvoice($id, $params = null, $opts = null)
  392. {
  393. return $this->request('post', $this->buildPath('/v1/invoices/%s/void', $id), $params, $opts);
  394. }
  395. }