CreditNoteService.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 CreditNoteService extends \Stripe\Service\AbstractService
  9. {
  10. /**
  11. * Returns a list of credit notes.
  12. *
  13. * @param null|array $params
  14. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  15. *
  16. * @throws \Stripe\Exception\ApiErrorException if the request fails
  17. *
  18. * @return \Stripe\Collection<\Stripe\CreditNote>
  19. */
  20. public function all($params = null, $opts = null)
  21. {
  22. return $this->requestCollection('get', '/v1/credit_notes', $params, $opts);
  23. }
  24. /**
  25. * When retrieving a credit note, you’ll get a <strong>lines</strong> property
  26. * containing the first handful of those items. There is also a URL where you can
  27. * retrieve the full (paginated) list of line items.
  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\CreditNoteLineItem>
  36. */
  37. public function allLines($parentId, $params = null, $opts = null)
  38. {
  39. return $this->requestCollection('get', $this->buildPath('/v1/credit_notes/%s/lines', $parentId), $params, $opts);
  40. }
  41. /**
  42. * Issue a credit note to adjust the amount of a finalized invoice. For a
  43. * <code>status=open</code> invoice, a credit note reduces its
  44. * <code>amount_due</code>. For a <code>status=paid</code> invoice, a credit note
  45. * does not affect its <code>amount_due</code>. Instead, it can result in any
  46. * combination of the following:.
  47. *
  48. * <ul> <li>Refund: create a new refund (using <code>refund_amount</code>) or link
  49. * an existing refund (using <code>refund</code>).</li> <li>Customer balance
  50. * credit: credit the customer’s balance (using <code>credit_amount</code>) which
  51. * will be automatically applied to their next invoice when it’s finalized.</li>
  52. * <li>Outside of Stripe credit: record the amount that is or will be credited
  53. * outside of Stripe (using <code>out_of_band_amount</code>).</li> </ul>
  54. *
  55. * For post-payment credit notes the sum of the refund, credit and outside of
  56. * Stripe amounts must equal the credit note total.
  57. *
  58. * You may issue multiple credit notes for an invoice. Each credit note will
  59. * increment the invoice’s <code>pre_payment_credit_notes_amount</code> or
  60. * <code>post_payment_credit_notes_amount</code> depending on its
  61. * <code>status</code> at the time of credit note creation.
  62. *
  63. * @param null|array $params
  64. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  65. *
  66. * @throws \Stripe\Exception\ApiErrorException if the request fails
  67. *
  68. * @return \Stripe\CreditNote
  69. */
  70. public function create($params = null, $opts = null)
  71. {
  72. return $this->request('post', '/v1/credit_notes', $params, $opts);
  73. }
  74. /**
  75. * Get a preview of a credit note without creating it.
  76. *
  77. * @param null|array $params
  78. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  79. *
  80. * @throws \Stripe\Exception\ApiErrorException if the request fails
  81. *
  82. * @return \Stripe\CreditNote
  83. */
  84. public function preview($params = null, $opts = null)
  85. {
  86. return $this->request('get', '/v1/credit_notes/preview', $params, $opts);
  87. }
  88. /**
  89. * When retrieving a credit note preview, you’ll get a <strong>lines</strong>
  90. * property containing the first handful of those items. This URL you can retrieve
  91. * the full (paginated) list of line items.
  92. *
  93. * @param null|array $params
  94. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  95. *
  96. * @throws \Stripe\Exception\ApiErrorException if the request fails
  97. *
  98. * @return \Stripe\Collection<\Stripe\CreditNoteLineItem>
  99. */
  100. public function previewLines($params = null, $opts = null)
  101. {
  102. return $this->requestCollection('get', '/v1/credit_notes/preview/lines', $params, $opts);
  103. }
  104. /**
  105. * Retrieves the credit note object with the given identifier.
  106. *
  107. * @param string $id
  108. * @param null|array $params
  109. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  110. *
  111. * @throws \Stripe\Exception\ApiErrorException if the request fails
  112. *
  113. * @return \Stripe\CreditNote
  114. */
  115. public function retrieve($id, $params = null, $opts = null)
  116. {
  117. return $this->request('get', $this->buildPath('/v1/credit_notes/%s', $id), $params, $opts);
  118. }
  119. /**
  120. * Updates an existing credit note.
  121. *
  122. * @param string $id
  123. * @param null|array $params
  124. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  125. *
  126. * @throws \Stripe\Exception\ApiErrorException if the request fails
  127. *
  128. * @return \Stripe\CreditNote
  129. */
  130. public function update($id, $params = null, $opts = null)
  131. {
  132. return $this->request('post', $this->buildPath('/v1/credit_notes/%s', $id), $params, $opts);
  133. }
  134. /**
  135. * Marks a credit note as void. Learn more about <a
  136. * href="/docs/billing/invoices/credit-notes#voiding">voiding credit notes</a>.
  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\CreditNote
  145. */
  146. public function voidCreditNote($id, $params = null, $opts = null)
  147. {
  148. return $this->request('post', $this->buildPath('/v1/credit_notes/%s/void', $id), $params, $opts);
  149. }
  150. }