Invoice.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe;
  4. /**
  5. * Invoices are statements of amounts owed by a customer, and are either
  6. * generated one-off, or generated periodically from a subscription.
  7. *
  8. * They contain <a href="https://stripe.com/docs/api#invoiceitems">invoice items</a>, and proration adjustments
  9. * that may be caused by subscription upgrades/downgrades (if necessary).
  10. *
  11. * If your invoice is configured to be billed through automatic charges,
  12. * Stripe automatically finalizes your invoice and attempts payment. Note
  13. * that finalizing the invoice,
  14. * <a href="https://stripe.com/docs/invoicing/integration/automatic-advancement-collection">when automatic</a>, does
  15. * not happen immediately as the invoice is created. Stripe waits
  16. * until one hour after the last webhook was successfully sent (or the last
  17. * webhook timed out after failing). If you (and the platforms you may have
  18. * connected to) have no webhooks configured, Stripe waits one hour after
  19. * creation to finalize the invoice.
  20. *
  21. * If your invoice is configured to be billed by sending an email, then based on your
  22. * <a href="https://dashboard.stripe.com/account/billing/automatic">email settings</a>,
  23. * Stripe will email the invoice to your customer and await payment. These
  24. * emails can contain a link to a hosted page to pay the invoice.
  25. *
  26. * Stripe applies any customer credit on the account before determining the
  27. * amount due for the invoice (i.e., the amount that will be actually
  28. * charged). If the amount due for the invoice is less than Stripe's <a href="/docs/currencies#minimum-and-maximum-charge-amounts">minimum allowed charge
  29. * per currency</a>, the
  30. * invoice is automatically marked paid, and we add the amount due to the
  31. * customer's credit balance which is applied to the next invoice.
  32. *
  33. * More details on the customer's credit balance are
  34. * <a href="https://stripe.com/docs/billing/customer/balance">here</a>.
  35. *
  36. * Related guide: <a href="https://stripe.com/docs/billing/invoices/sending">Send invoices to customers</a>
  37. *
  38. * @property null|string $id Unique identifier for the object. This property is always present unless the invoice is an upcoming invoice. See <a href="https://stripe.com/docs/api/invoices/upcoming">Retrieve an upcoming invoice</a> for more details.
  39. * @property string $object String representing the object's type. Objects of the same type share the same value.
  40. * @property null|string $account_country The country of the business associated with this invoice, most often the business creating the invoice.
  41. * @property null|string $account_name The public name of the business associated with this invoice, most often the business creating the invoice.
  42. * @property null|(string|\Stripe\TaxId)[] $account_tax_ids The account tax IDs associated with the invoice. Only editable when the invoice is a draft.
  43. * @property int $amount_due Final amount due at this time for this invoice. If the invoice's total is smaller than the minimum charge amount, for example, or if there is account credit that can be applied to the invoice, the <code>amount_due</code> may be 0. If there is a positive <code>starting_balance</code> for the invoice (the customer owes money), the <code>amount_due</code> will also take that into account. The charge that gets generated for the invoice will be for the amount specified in <code>amount_due</code>.
  44. * @property int $amount_paid The amount, in cents (or local equivalent), that was paid.
  45. * @property int $amount_remaining The difference between amount_due and amount_paid, in cents (or local equivalent).
  46. * @property int $amount_shipping This is the sum of all the shipping amounts.
  47. * @property null|string|\Stripe\Application $application ID of the Connect Application that created the invoice.
  48. * @property null|int $application_fee_amount The fee in cents (or local equivalent) that will be applied to the invoice and transferred to the application owner's Stripe account when the invoice is paid.
  49. * @property int $attempt_count Number of payment attempts made for this invoice, from the perspective of the payment retry schedule. Any payment attempt counts as the first attempt, and subsequently only automatic retries increment the attempt count. In other words, manual payment attempts after the first attempt do not affect the retry schedule. If a failure is returned with a non-retryable return code, the invoice can no longer be retried unless a new payment method is obtained. Retries will continue to be scheduled, and attempt_count will continue to increment, but retries will only be executed if a new payment method is obtained.
  50. * @property bool $attempted Whether an attempt has been made to pay the invoice. An invoice is not attempted until 1 hour after the <code>invoice.created</code> webhook, for example, so you might not want to display that invoice as unpaid to your users.
  51. * @property null|bool $auto_advance Controls whether Stripe performs <a href="https://stripe.com/docs/invoicing/integration/automatic-advancement-collection">automatic collection</a> of the invoice. If <code>false</code>, the invoice's state doesn't automatically advance without an explicit action.
  52. * @property \Stripe\StripeObject $automatic_tax
  53. * @property null|string $billing_reason <p>Indicates the reason why the invoice was created.</p><p>* <code>manual</code>: Unrelated to a subscription, for example, created via the invoice editor. * <code>subscription</code>: No longer in use. Applies to subscriptions from before May 2018 where no distinction was made between updates, cycles, and thresholds. * <code>subscription_create</code>: A new subscription was created. * <code>subscription_cycle</code>: A subscription advanced into a new period. * <code>subscription_threshold</code>: A subscription reached a billing threshold. * <code>subscription_update</code>: A subscription was updated. * <code>upcoming</code>: Reserved for simulated invoices, per the upcoming invoice endpoint.</p>
  54. * @property null|string|\Stripe\Charge $charge ID of the latest charge generated for this invoice, if any.
  55. * @property string $collection_method Either <code>charge_automatically</code>, or <code>send_invoice</code>. When charging automatically, Stripe will attempt to pay this invoice using the default source attached to the customer. When sending an invoice, Stripe will email this invoice to the customer with payment instructions.
  56. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  57. * @property string $currency Three-letter <a href="https://www.iso.org/iso-4217-currency-codes.html">ISO currency code</a>, in lowercase. Must be a <a href="https://stripe.com/docs/currencies">supported currency</a>.
  58. * @property null|\Stripe\StripeObject[] $custom_fields Custom fields displayed on the invoice.
  59. * @property null|string|\Stripe\Customer $customer The ID of the customer who will be billed.
  60. * @property null|\Stripe\StripeObject $customer_address The customer's address. Until the invoice is finalized, this field will equal <code>customer.address</code>. Once the invoice is finalized, this field will no longer be updated.
  61. * @property null|string $customer_email The customer's email. Until the invoice is finalized, this field will equal <code>customer.email</code>. Once the invoice is finalized, this field will no longer be updated.
  62. * @property null|string $customer_name The customer's name. Until the invoice is finalized, this field will equal <code>customer.name</code>. Once the invoice is finalized, this field will no longer be updated.
  63. * @property null|string $customer_phone The customer's phone number. Until the invoice is finalized, this field will equal <code>customer.phone</code>. Once the invoice is finalized, this field will no longer be updated.
  64. * @property null|\Stripe\StripeObject $customer_shipping The customer's shipping information. Until the invoice is finalized, this field will equal <code>customer.shipping</code>. Once the invoice is finalized, this field will no longer be updated.
  65. * @property null|string $customer_tax_exempt The customer's tax exempt status. Until the invoice is finalized, this field will equal <code>customer.tax_exempt</code>. Once the invoice is finalized, this field will no longer be updated.
  66. * @property null|\Stripe\StripeObject[] $customer_tax_ids The customer's tax IDs. Until the invoice is finalized, this field will contain the same tax IDs as <code>customer.tax_ids</code>. Once the invoice is finalized, this field will no longer be updated.
  67. * @property null|string|\Stripe\PaymentMethod $default_payment_method ID of the default payment method for the invoice. It must belong to the customer associated with the invoice. If not set, defaults to the subscription's default payment method, if any, or to the default payment method in the customer's invoice settings.
  68. * @property null|string|\Stripe\Account|\Stripe\BankAccount|\Stripe\Card|\Stripe\Source $default_source ID of the default payment source for the invoice. It must belong to the customer associated with the invoice and be in a chargeable state. If not set, defaults to the subscription's default source, if any, or to the customer's default source.
  69. * @property \Stripe\TaxRate[] $default_tax_rates The tax rates applied to this invoice, if any.
  70. * @property null|string $description An arbitrary string attached to the object. Often useful for displaying to users. Referenced as 'memo' in the Dashboard.
  71. * @property null|\Stripe\Discount $discount Describes the current discount applied to this invoice, if there is one. Not populated if there are multiple discounts.
  72. * @property (string|\Stripe\Discount)[] $discounts The discounts applied to the invoice. Line item discounts are applied before invoice discounts. Use <code>expand[]=discounts</code> to expand each discount.
  73. * @property null|int $due_date The date on which payment for this invoice is due. This value will be <code>null</code> for invoices where <code>collection_method=charge_automatically</code>.
  74. * @property null|int $effective_at The date when this invoice is in effect. Same as <code>finalized_at</code> unless overwritten. When defined, this value replaces the system-generated 'Date of issue' printed on the invoice PDF and receipt.
  75. * @property null|int $ending_balance Ending customer balance after the invoice is finalized. Invoices are finalized approximately an hour after successful webhook delivery or when payment collection is attempted for the invoice. If the invoice has not been finalized yet, this will be null.
  76. * @property null|string $footer Footer displayed on the invoice.
  77. * @property null|\Stripe\StripeObject $from_invoice Details of the invoice that was cloned. See the <a href="https://stripe.com/docs/invoicing/invoice-revisions">revision documentation</a> for more details.
  78. * @property null|string $hosted_invoice_url The URL for the hosted invoice page, which allows customers to view and pay an invoice. If the invoice has not been finalized yet, this will be null.
  79. * @property null|string $invoice_pdf The link to download the PDF for the invoice. If the invoice has not been finalized yet, this will be null.
  80. * @property \Stripe\StripeObject $issuer
  81. * @property null|\Stripe\StripeObject $last_finalization_error The error encountered during the previous attempt to finalize the invoice. This field is cleared when the invoice is successfully finalized.
  82. * @property null|string|\Stripe\Invoice $latest_revision The ID of the most recent non-draft revision of this invoice
  83. * @property \Stripe\Collection<\Stripe\InvoiceLineItem> $lines The individual line items that make up the invoice. <code>lines</code> is sorted as follows: (1) pending invoice items (including prorations) in reverse chronological order, (2) subscription items in reverse chronological order, and (3) invoice items added after invoice creation in chronological order.
  84. * @property bool $livemode Has the value <code>true</code> if the object exists in live mode or the value <code>false</code> if the object exists in test mode.
  85. * @property null|\Stripe\StripeObject $metadata Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
  86. * @property null|int $next_payment_attempt The time at which payment will next be attempted. This value will be <code>null</code> for invoices where <code>collection_method=send_invoice</code>.
  87. * @property null|string $number A unique, identifying string that appears on emails sent to the customer for this invoice. This starts with the customer's unique invoice_prefix if it is specified.
  88. * @property null|string|\Stripe\Account $on_behalf_of The account (if any) for which the funds of the invoice payment are intended. If set, the invoice will be presented with the branding and support information of the specified account. See the <a href="https://stripe.com/docs/billing/invoices/connect">Invoices with Connect</a> documentation for details.
  89. * @property bool $paid Whether payment was successfully collected for this invoice. An invoice can be paid (most commonly) with a charge or with credit from the customer's account balance.
  90. * @property bool $paid_out_of_band Returns true if the invoice was manually marked paid, returns false if the invoice hasn't been paid yet or was paid on Stripe.
  91. * @property null|string|\Stripe\PaymentIntent $payment_intent The PaymentIntent associated with this invoice. The PaymentIntent is generated when the invoice is finalized, and can then be used to pay the invoice. Note that voiding an invoice will cancel the PaymentIntent.
  92. * @property \Stripe\StripeObject $payment_settings
  93. * @property int $period_end End of the usage period during which invoice items were added to this invoice. This looks back one period for a subscription invoice. Use the <a href="/api/invoices/line_item#invoice_line_item_object-period">line item period</a> to get the service period for each price.
  94. * @property int $period_start Start of the usage period during which invoice items were added to this invoice. This looks back one period for a subscription invoice. Use the <a href="/api/invoices/line_item#invoice_line_item_object-period">line item period</a> to get the service period for each price.
  95. * @property int $post_payment_credit_notes_amount Total amount of all post-payment credit notes issued for this invoice.
  96. * @property int $pre_payment_credit_notes_amount Total amount of all pre-payment credit notes issued for this invoice.
  97. * @property null|string|\Stripe\Quote $quote The quote this invoice was generated from.
  98. * @property null|string $receipt_number This is the transaction number that appears on email receipts sent for this invoice.
  99. * @property null|\Stripe\StripeObject $rendering The rendering-related settings that control how the invoice is displayed on customer-facing surfaces such as PDF and Hosted Invoice Page.
  100. * @property null|\Stripe\StripeObject $shipping_cost The details of the cost of shipping, including the ShippingRate applied on the invoice.
  101. * @property null|\Stripe\StripeObject $shipping_details Shipping details for the invoice. The Invoice PDF will use the <code>shipping_details</code> value if it is set, otherwise the PDF will render the shipping address from the customer.
  102. * @property int $starting_balance Starting customer balance before the invoice is finalized. If the invoice has not been finalized yet, this will be the current customer balance. For revision invoices, this also includes any customer balance that was applied to the original invoice.
  103. * @property null|string $statement_descriptor Extra information about an invoice for the customer's credit card statement.
  104. * @property null|string $status The status of the invoice, one of <code>draft</code>, <code>open</code>, <code>paid</code>, <code>uncollectible</code>, or <code>void</code>. <a href="https://stripe.com/docs/billing/invoices/workflow#workflow-overview">Learn more</a>
  105. * @property \Stripe\StripeObject $status_transitions
  106. * @property null|string|\Stripe\Subscription $subscription The subscription that this invoice was prepared for, if any.
  107. * @property null|\Stripe\StripeObject $subscription_details Details about the subscription that created this invoice.
  108. * @property null|int $subscription_proration_date Only set for upcoming invoices that preview prorations. The time used to calculate prorations.
  109. * @property int $subtotal Total of all subscriptions, invoice items, and prorations on the invoice before any invoice level discount or exclusive tax is applied. Item discounts are already incorporated
  110. * @property null|int $subtotal_excluding_tax The integer amount in cents (or local equivalent) representing the subtotal of the invoice before any invoice level discount or tax is applied. Item discounts are already incorporated
  111. * @property null|int $tax The amount of tax on this invoice. This is the sum of all the tax amounts on this invoice.
  112. * @property null|string|\Stripe\TestHelpers\TestClock $test_clock ID of the test clock this invoice belongs to.
  113. * @property null|\Stripe\StripeObject $threshold_reason
  114. * @property int $total Total after discounts and taxes.
  115. * @property null|\Stripe\StripeObject[] $total_discount_amounts The aggregate amounts calculated per discount across all line items.
  116. * @property null|int $total_excluding_tax The integer amount in cents (or local equivalent) representing the total amount of the invoice including all discounts but excluding all tax.
  117. * @property \Stripe\StripeObject[] $total_tax_amounts The aggregate amounts calculated per tax rate for all line items.
  118. * @property null|\Stripe\StripeObject $transfer_data The account (if any) the payment will be attributed to for tax reporting, and where funds from the payment will be transferred to for the invoice.
  119. * @property null|int $webhooks_delivered_at Invoices are automatically paid or sent 1 hour after webhooks are delivered, or until all webhook delivery attempts have <a href="https://stripe.com/docs/billing/webhooks#understand">been exhausted</a>. This field tracks the time when webhooks for this invoice were successfully delivered. If the invoice had no webhooks to deliver, this will be set while the invoice is being created.
  120. */
  121. class Invoice extends ApiResource
  122. {
  123. const OBJECT_NAME = 'invoice';
  124. use ApiOperations\NestedResource;
  125. use ApiOperations\Update;
  126. const BILLING_REASON_AUTOMATIC_PENDING_INVOICE_ITEM_INVOICE = 'automatic_pending_invoice_item_invoice';
  127. const BILLING_REASON_MANUAL = 'manual';
  128. const BILLING_REASON_QUOTE_ACCEPT = 'quote_accept';
  129. const BILLING_REASON_SUBSCRIPTION = 'subscription';
  130. const BILLING_REASON_SUBSCRIPTION_CREATE = 'subscription_create';
  131. const BILLING_REASON_SUBSCRIPTION_CYCLE = 'subscription_cycle';
  132. const BILLING_REASON_SUBSCRIPTION_THRESHOLD = 'subscription_threshold';
  133. const BILLING_REASON_SUBSCRIPTION_UPDATE = 'subscription_update';
  134. const BILLING_REASON_UPCOMING = 'upcoming';
  135. const COLLECTION_METHOD_CHARGE_AUTOMATICALLY = 'charge_automatically';
  136. const COLLECTION_METHOD_SEND_INVOICE = 'send_invoice';
  137. const CUSTOMER_TAX_EXEMPT_EXEMPT = 'exempt';
  138. const CUSTOMER_TAX_EXEMPT_NONE = 'none';
  139. const CUSTOMER_TAX_EXEMPT_REVERSE = 'reverse';
  140. const STATUS_DRAFT = 'draft';
  141. const STATUS_OPEN = 'open';
  142. const STATUS_PAID = 'paid';
  143. const STATUS_UNCOLLECTIBLE = 'uncollectible';
  144. const STATUS_VOID = 'void';
  145. /**
  146. * This endpoint creates a draft invoice for a given customer. The invoice remains
  147. * a draft until you <a href="#finalize_invoice">finalize</a> the invoice, which
  148. * allows you to <a href="#pay_invoice">pay</a> or <a href="#send_invoice">send</a>
  149. * the invoice to your customers.
  150. *
  151. * @param null|array $params
  152. * @param null|array|string $options
  153. *
  154. * @throws \Stripe\Exception\ApiErrorException if the request fails
  155. *
  156. * @return \Stripe\Invoice the created resource
  157. */
  158. public static function create($params = null, $options = null)
  159. {
  160. self::_validateParams($params);
  161. $url = static::classUrl();
  162. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  163. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  164. $obj->setLastResponse($response);
  165. return $obj;
  166. }
  167. /**
  168. * Permanently deletes a one-off invoice draft. This cannot be undone. Attempts to
  169. * delete invoices that are no longer in a draft state will fail; once an invoice
  170. * has been finalized or if an invoice is for a subscription, it must be <a
  171. * href="#void_invoice">voided</a>.
  172. *
  173. * @param null|array $params
  174. * @param null|array|string $opts
  175. *
  176. * @throws \Stripe\Exception\ApiErrorException if the request fails
  177. *
  178. * @return \Stripe\Invoice the deleted resource
  179. */
  180. public function delete($params = null, $opts = null)
  181. {
  182. self::_validateParams($params);
  183. $url = $this->instanceUrl();
  184. list($response, $opts) = $this->_request('delete', $url, $params, $opts);
  185. $this->refreshFrom($response, $opts);
  186. return $this;
  187. }
  188. /**
  189. * You can list all invoices, or list the invoices for a specific customer. The
  190. * invoices are returned sorted by creation date, with the most recently created
  191. * invoices appearing first.
  192. *
  193. * @param null|array $params
  194. * @param null|array|string $opts
  195. *
  196. * @throws \Stripe\Exception\ApiErrorException if the request fails
  197. *
  198. * @return \Stripe\Collection<\Stripe\Invoice> of ApiResources
  199. */
  200. public static function all($params = null, $opts = null)
  201. {
  202. $url = static::classUrl();
  203. return static::_requestPage($url, \Stripe\Collection::class, $params, $opts);
  204. }
  205. /**
  206. * Retrieves the invoice with the given ID.
  207. *
  208. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  209. * @param null|array|string $opts
  210. *
  211. * @throws \Stripe\Exception\ApiErrorException if the request fails
  212. *
  213. * @return \Stripe\Invoice
  214. */
  215. public static function retrieve($id, $opts = null)
  216. {
  217. $opts = \Stripe\Util\RequestOptions::parse($opts);
  218. $instance = new static($id, $opts);
  219. $instance->refresh();
  220. return $instance;
  221. }
  222. /**
  223. * Draft invoices are fully editable. Once an invoice is <a
  224. * href="/docs/billing/invoices/workflow#finalized">finalized</a>, monetary values,
  225. * as well as <code>collection_method</code>, become uneditable.
  226. *
  227. * If you would like to stop the Stripe Billing engine from automatically
  228. * finalizing, reattempting payments on, sending reminders for, or <a
  229. * href="/docs/billing/invoices/reconciliation">automatically reconciling</a>
  230. * invoices, pass <code>auto_advance=false</code>.
  231. *
  232. * @param string $id the ID of the resource to update
  233. * @param null|array $params
  234. * @param null|array|string $opts
  235. *
  236. * @throws \Stripe\Exception\ApiErrorException if the request fails
  237. *
  238. * @return \Stripe\Invoice the updated resource
  239. */
  240. public static function update($id, $params = null, $opts = null)
  241. {
  242. self::_validateParams($params);
  243. $url = static::resourceUrl($id);
  244. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  245. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  246. $obj->setLastResponse($response);
  247. return $obj;
  248. }
  249. const BILLING_CHARGE_AUTOMATICALLY = 'charge_automatically';
  250. const BILLING_SEND_INVOICE = 'send_invoice';
  251. /**
  252. * @param null|array $params
  253. * @param null|array|string $opts
  254. *
  255. * @throws \Stripe\Exception\ApiErrorException if the request fails
  256. *
  257. * @return \Stripe\Invoice the added invoice
  258. */
  259. public function addLines($params = null, $opts = null)
  260. {
  261. $url = $this->instanceUrl() . '/add_lines';
  262. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  263. $this->refreshFrom($response, $opts);
  264. return $this;
  265. }
  266. /**
  267. * @param null|array $params
  268. * @param null|array|string $opts
  269. *
  270. * @throws \Stripe\Exception\ApiErrorException if the request fails
  271. *
  272. * @return \Stripe\Invoice the created invoice
  273. */
  274. public static function createPreview($params = null, $opts = null)
  275. {
  276. $url = static::classUrl() . '/create_preview';
  277. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  278. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  279. $obj->setLastResponse($response);
  280. return $obj;
  281. }
  282. /**
  283. * @param null|array $params
  284. * @param null|array|string $opts
  285. *
  286. * @throws \Stripe\Exception\ApiErrorException if the request fails
  287. *
  288. * @return \Stripe\Invoice the finalized invoice
  289. */
  290. public function finalizeInvoice($params = null, $opts = null)
  291. {
  292. $url = $this->instanceUrl() . '/finalize';
  293. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  294. $this->refreshFrom($response, $opts);
  295. return $this;
  296. }
  297. /**
  298. * @param null|array $params
  299. * @param null|array|string $opts
  300. *
  301. * @throws \Stripe\Exception\ApiErrorException if the request fails
  302. *
  303. * @return \Stripe\Invoice the uncollectible invoice
  304. */
  305. public function markUncollectible($params = null, $opts = null)
  306. {
  307. $url = $this->instanceUrl() . '/mark_uncollectible';
  308. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  309. $this->refreshFrom($response, $opts);
  310. return $this;
  311. }
  312. /**
  313. * @param null|array $params
  314. * @param null|array|string $opts
  315. *
  316. * @throws \Stripe\Exception\ApiErrorException if the request fails
  317. *
  318. * @return \Stripe\Invoice the paid invoice
  319. */
  320. public function pay($params = null, $opts = null)
  321. {
  322. $url = $this->instanceUrl() . '/pay';
  323. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  324. $this->refreshFrom($response, $opts);
  325. return $this;
  326. }
  327. /**
  328. * @param null|array $params
  329. * @param null|array|string $opts
  330. *
  331. * @throws \Stripe\Exception\ApiErrorException if the request fails
  332. *
  333. * @return \Stripe\Invoice the removed invoice
  334. */
  335. public function removeLines($params = null, $opts = null)
  336. {
  337. $url = $this->instanceUrl() . '/remove_lines';
  338. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  339. $this->refreshFrom($response, $opts);
  340. return $this;
  341. }
  342. /**
  343. * @param null|array $params
  344. * @param null|array|string $opts
  345. *
  346. * @throws \Stripe\Exception\ApiErrorException if the request fails
  347. *
  348. * @return \Stripe\Invoice the sent invoice
  349. */
  350. public function sendInvoice($params = null, $opts = null)
  351. {
  352. $url = $this->instanceUrl() . '/send';
  353. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  354. $this->refreshFrom($response, $opts);
  355. return $this;
  356. }
  357. /**
  358. * @param null|array $params
  359. * @param null|array|string $opts
  360. *
  361. * @throws \Stripe\Exception\ApiErrorException if the request fails
  362. *
  363. * @return \Stripe\Invoice the upcoming invoice
  364. */
  365. public static function upcoming($params = null, $opts = null)
  366. {
  367. $url = static::classUrl() . '/upcoming';
  368. list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
  369. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  370. $obj->setLastResponse($response);
  371. return $obj;
  372. }
  373. /**
  374. * @param null|array $params
  375. * @param null|array|string $opts
  376. *
  377. * @throws \Stripe\Exception\ApiErrorException if the request fails
  378. *
  379. * @return \Stripe\Collection<\Stripe\InvoiceLineItem> list of invoice line items
  380. */
  381. public static function upcomingLines($params = null, $opts = null)
  382. {
  383. $url = static::classUrl() . '/upcoming/lines';
  384. list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
  385. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  386. $obj->setLastResponse($response);
  387. return $obj;
  388. }
  389. /**
  390. * @param null|array $params
  391. * @param null|array|string $opts
  392. *
  393. * @throws \Stripe\Exception\ApiErrorException if the request fails
  394. *
  395. * @return \Stripe\Invoice the updated invoice
  396. */
  397. public function updateLines($params = null, $opts = null)
  398. {
  399. $url = $this->instanceUrl() . '/update_lines';
  400. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  401. $this->refreshFrom($response, $opts);
  402. return $this;
  403. }
  404. /**
  405. * @param null|array $params
  406. * @param null|array|string $opts
  407. *
  408. * @throws \Stripe\Exception\ApiErrorException if the request fails
  409. *
  410. * @return \Stripe\Invoice the voided invoice
  411. */
  412. public function voidInvoice($params = null, $opts = null)
  413. {
  414. $url = $this->instanceUrl() . '/void';
  415. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  416. $this->refreshFrom($response, $opts);
  417. return $this;
  418. }
  419. /**
  420. * @param null|array $params
  421. * @param null|array|string $opts
  422. *
  423. * @throws \Stripe\Exception\ApiErrorException if the request fails
  424. *
  425. * @return \Stripe\SearchResult<\Stripe\Invoice> the invoice search results
  426. */
  427. public static function search($params = null, $opts = null)
  428. {
  429. $url = '/v1/invoices/search';
  430. return static::_requestPage($url, \Stripe\SearchResult::class, $params, $opts);
  431. }
  432. const PATH_LINES = '/lines';
  433. /**
  434. * @param string $id the ID of the invoice on which to retrieve the invoice line items
  435. * @param null|array $params
  436. * @param null|array|string $opts
  437. *
  438. * @throws \Stripe\Exception\ApiErrorException if the request fails
  439. *
  440. * @return \Stripe\Collection<\Stripe\InvoiceLineItem> the list of invoice line items
  441. */
  442. public static function allLines($id, $params = null, $opts = null)
  443. {
  444. return self::_allNestedResources($id, static::PATH_LINES, $params, $opts);
  445. }
  446. }