InvoiceService.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe\Service;
  4. class InvoiceService extends \Stripe\Service\AbstractService
  5. {
  6. /**
  7. * You can list all invoices, or list the invoices for a specific customer. The
  8. * invoices are returned sorted by creation date, with the most recently created
  9. * invoices appearing first.
  10. *
  11. * @param null|array $params
  12. * @param null|array|\Stripe\Util\RequestOptions $opts
  13. *
  14. * @throws \Stripe\Exception\ApiErrorException if the request fails
  15. *
  16. * @return \Stripe\Collection
  17. */
  18. public function all($params = null, $opts = null)
  19. {
  20. return $this->requestCollection('get', '/v1/invoices', $params, $opts);
  21. }
  22. /**
  23. * When retrieving an invoice, you’ll get a <strong>lines</strong> property
  24. * containing the total count of line items and the first handful of those items.
  25. * There is also a URL where you can retrieve the full (paginated) list of line
  26. * items.
  27. *
  28. * @param string $parentId
  29. * @param null|array $params
  30. * @param null|array|\Stripe\Util\RequestOptions $opts
  31. *
  32. * @throws \Stripe\Exception\ApiErrorException if the request fails
  33. *
  34. * @return \Stripe\Collection
  35. */
  36. public function allLines($parentId, $params = null, $opts = null)
  37. {
  38. return $this->requestCollection('get', $this->buildPath('/v1/invoices/%s/lines', $parentId), $params, $opts);
  39. }
  40. /**
  41. * This endpoint creates a draft invoice for a given customer. The draft invoice
  42. * created pulls in all pending invoice items on that customer, including
  43. * prorations. The invoice remains a draft until you <a
  44. * href="#finalize_invoice">finalize</a> the invoice, which allows you to <a
  45. * href="#pay_invoice">pay</a> or <a href="#send_invoice">send</a> the invoice to
  46. * your customers.
  47. *
  48. * @param null|array $params
  49. * @param null|array|\Stripe\Util\RequestOptions $opts
  50. *
  51. * @throws \Stripe\Exception\ApiErrorException if the request fails
  52. *
  53. * @return \Stripe\Invoice
  54. */
  55. public function create($params = null, $opts = null)
  56. {
  57. return $this->request('post', '/v1/invoices', $params, $opts);
  58. }
  59. /**
  60. * Permanently deletes a one-off invoice draft. This cannot be undone. Attempts to
  61. * delete invoices that are no longer in a draft state will fail; once an invoice
  62. * has been finalized or if an invoice is for a subscription, it must be <a
  63. * href="#void_invoice">voided</a>.
  64. *
  65. * @param string $id
  66. * @param null|array $params
  67. * @param null|array|\Stripe\Util\RequestOptions $opts
  68. *
  69. * @throws \Stripe\Exception\ApiErrorException if the request fails
  70. *
  71. * @return \Stripe\Invoice
  72. */
  73. public function delete($id, $params = null, $opts = null)
  74. {
  75. return $this->request('delete', $this->buildPath('/v1/invoices/%s', $id), $params, $opts);
  76. }
  77. /**
  78. * Stripe automatically finalizes drafts before sending and attempting payment on
  79. * invoices. However, if you’d like to finalize a draft invoice manually, you can
  80. * do so using this method.
  81. *
  82. * @param string $id
  83. * @param null|array $params
  84. * @param null|array|\Stripe\Util\RequestOptions $opts
  85. *
  86. * @throws \Stripe\Exception\ApiErrorException if the request fails
  87. *
  88. * @return \Stripe\Invoice
  89. */
  90. public function finalizeInvoice($id, $params = null, $opts = null)
  91. {
  92. return $this->request('post', $this->buildPath('/v1/invoices/%s/finalize', $id), $params, $opts);
  93. }
  94. /**
  95. * Marking an invoice as uncollectible is useful for keeping track of bad debts
  96. * that can be written off for accounting purposes.
  97. *
  98. * @param string $id
  99. * @param null|array $params
  100. * @param null|array|\Stripe\Util\RequestOptions $opts
  101. *
  102. * @throws \Stripe\Exception\ApiErrorException if the request fails
  103. *
  104. * @return \Stripe\Invoice
  105. */
  106. public function markUncollectible($id, $params = null, $opts = null)
  107. {
  108. return $this->request('post', $this->buildPath('/v1/invoices/%s/mark_uncollectible', $id), $params, $opts);
  109. }
  110. /**
  111. * Stripe automatically creates and then attempts to collect payment on invoices
  112. * for customers on subscriptions according to your <a
  113. * href="https://dashboard.stripe.com/account/billing/automatic">subscriptions
  114. * settings</a>. However, if you’d like to attempt payment on an invoice out of the
  115. * normal collection schedule or for some other reason, you can do so.
  116. *
  117. * @param string $id
  118. * @param null|array $params
  119. * @param null|array|\Stripe\Util\RequestOptions $opts
  120. *
  121. * @throws \Stripe\Exception\ApiErrorException if the request fails
  122. *
  123. * @return \Stripe\Invoice
  124. */
  125. public function pay($id, $params = null, $opts = null)
  126. {
  127. return $this->request('post', $this->buildPath('/v1/invoices/%s/pay', $id), $params, $opts);
  128. }
  129. /**
  130. * Retrieves the invoice with the given ID.
  131. *
  132. * @param string $id
  133. * @param null|array $params
  134. * @param null|array|\Stripe\Util\RequestOptions $opts
  135. *
  136. * @throws \Stripe\Exception\ApiErrorException if the request fails
  137. *
  138. * @return \Stripe\Invoice
  139. */
  140. public function retrieve($id, $params = null, $opts = null)
  141. {
  142. return $this->request('get', $this->buildPath('/v1/invoices/%s', $id), $params, $opts);
  143. }
  144. /**
  145. * Stripe will automatically send invoices to customers according to your <a
  146. * href="https://dashboard.stripe.com/account/billing/automatic">subscriptions
  147. * settings</a>. However, if you’d like to manually send an invoice to your
  148. * customer out of the normal schedule, you can do so. When sending invoices that
  149. * have already been paid, there will be no reference to the payment in the email.
  150. *
  151. * Requests made in test-mode result in no emails being sent, despite sending an
  152. * <code>invoice.sent</code> event.
  153. *
  154. * @param string $id
  155. * @param null|array $params
  156. * @param null|array|\Stripe\Util\RequestOptions $opts
  157. *
  158. * @throws \Stripe\Exception\ApiErrorException if the request fails
  159. *
  160. * @return \Stripe\Invoice
  161. */
  162. public function sendInvoice($id, $params = null, $opts = null)
  163. {
  164. return $this->request('post', $this->buildPath('/v1/invoices/%s/send', $id), $params, $opts);
  165. }
  166. /**
  167. * At any time, you can preview the upcoming invoice for a customer. This will show
  168. * you all the charges that are pending, including subscription renewal charges,
  169. * invoice item charges, etc. It will also show you any discounts that are
  170. * applicable to the invoice.
  171. *
  172. * Note that when you are viewing an upcoming invoice, you are simply viewing a
  173. * preview – the invoice has not yet been created. As such, the upcoming invoice
  174. * will not show up in invoice listing calls, and you cannot use the API to pay or
  175. * edit the invoice. If you want to change the amount that your customer will be
  176. * billed, you can add, remove, or update pending invoice items, or update the
  177. * customer’s discount.
  178. *
  179. * You can preview the effects of updating a subscription, including a preview of
  180. * what proration will take place. To ensure that the actual proration is
  181. * calculated exactly the same as the previewed proration, you should pass a
  182. * <code>proration_date</code> parameter when doing the actual subscription update.
  183. * The value passed in should be the same as the
  184. * <code>subscription_proration_date</code> returned on the upcoming invoice
  185. * resource. The recommended way to get only the prorations being previewed is to
  186. * consider only proration line items where <code>period[start]</code> is equal to
  187. * the <code>subscription_proration_date</code> on the upcoming invoice resource.
  188. *
  189. * @param null|array $params
  190. * @param null|array|\Stripe\Util\RequestOptions $opts
  191. *
  192. * @throws \Stripe\Exception\ApiErrorException if the request fails
  193. *
  194. * @return \Stripe\Invoice
  195. */
  196. public function upcoming($params = null, $opts = null)
  197. {
  198. return $this->request('get', '/v1/invoices/upcoming', $params, $opts);
  199. }
  200. /**
  201. * When retrieving an upcoming invoice, you’ll get a <strong>lines</strong>
  202. * property containing the total count of line items and the first handful of those
  203. * items. There is also a URL where you can retrieve the full (paginated) list of
  204. * line items.
  205. *
  206. * @param null|array $params
  207. * @param null|array|\Stripe\Util\RequestOptions $opts
  208. *
  209. * @throws \Stripe\Exception\ApiErrorException if the request fails
  210. *
  211. * @return \Stripe\Invoice
  212. */
  213. public function upcomingLines($params = null, $opts = null)
  214. {
  215. return $this->request('get', '/v1/invoices/upcoming/lines', $params, $opts);
  216. }
  217. /**
  218. * Draft invoices are fully editable. Once an invoice is <a
  219. * href="/docs/billing/invoices/workflow#finalized">finalized</a>, monetary values,
  220. * as well as <code>collection_method</code>, become uneditable.
  221. *
  222. * If you would like to stop the Stripe Billing engine from automatically
  223. * finalizing, reattempting payments on, sending reminders for, or <a
  224. * href="/docs/billing/invoices/reconciliation">automatically reconciling</a>
  225. * invoices, pass <code>auto_advance=false</code>.
  226. *
  227. * @param string $id
  228. * @param null|array $params
  229. * @param null|array|\Stripe\Util\RequestOptions $opts
  230. *
  231. * @throws \Stripe\Exception\ApiErrorException if the request fails
  232. *
  233. * @return \Stripe\Invoice
  234. */
  235. public function update($id, $params = null, $opts = null)
  236. {
  237. return $this->request('post', $this->buildPath('/v1/invoices/%s', $id), $params, $opts);
  238. }
  239. /**
  240. * Mark a finalized invoice as void. This cannot be undone. Voiding an invoice is
  241. * similar to <a href="#delete_invoice">deletion</a>, however it only applies to
  242. * finalized invoices and maintains a papertrail where the invoice can still be
  243. * found.
  244. *
  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\Invoice
  252. */
  253. public function voidInvoice($id, $params = null, $opts = null)
  254. {
  255. return $this->request('post', $this->buildPath('/v1/invoices/%s/void', $id), $params, $opts);
  256. }
  257. }