• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stripe / stripe-php / 6739065778

02 Nov 2023 10:48PM UTC coverage: 63.972% (-0.3%) from 64.225%
6739065778

push

github

web-flow
Merge pull request #1598 from stripe/latest-codegen-beta

Update generated code for beta

15 of 15 new or added lines in 2 files covered. (100.0%)

2429 of 3797 relevant lines covered (63.97%)

3.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.47
/lib/Service/InvoiceService.php
1
<?php
2

3
// File generated from our OpenAPI spec
4

5
namespace Stripe\Service;
6

7
class InvoiceService extends \Stripe\Service\AbstractService
8
{
9
    /**
10
     * You can list all invoices, or list the invoices for a specific customer. The
11
     * invoices are returned sorted by creation date, with the most recently created
12
     * invoices appearing first.
13
     *
14
     * @param null|array $params
15
     * @param null|array|\Stripe\Util\RequestOptions $opts
16
     *
17
     * @throws \Stripe\Exception\ApiErrorException if the request fails
18
     *
19
     * @return \Stripe\Collection<\Stripe\Invoice>
20
     */
21
    public function all($params = null, $opts = null)
1✔
22
    {
23
        return $this->requestCollection('get', '/v1/invoices', $params, $opts);
1✔
24
    }
25

26
    /**
27
     * When retrieving an invoice, you’ll get a <strong>lines</strong> property
28
     * containing the total count of line items and the first handful of those items.
29
     * There is also a URL where you can retrieve the full (paginated) list of line
30
     * items.
31
     *
32
     * @param string $parentId
33
     * @param null|array $params
34
     * @param null|array|\Stripe\Util\RequestOptions $opts
35
     *
36
     * @throws \Stripe\Exception\ApiErrorException if the request fails
37
     *
38
     * @return \Stripe\Collection<\Stripe\InvoiceLineItem>
39
     */
40
    public function allLines($parentId, $params = null, $opts = null)
1✔
41
    {
42
        return $this->requestCollection('get', $this->buildPath('/v1/invoices/%s/lines', $parentId), $params, $opts);
1✔
43
    }
44

45
    /**
46
     * When retrieving an invoice, there is an includable payments property containing
47
     * the first handful of those items. There is also a URL where you can retrieve the
48
     * full (paginated) list of payments.
49
     *
50
     * @param string $parentId
51
     * @param null|array $params
52
     * @param null|array|\Stripe\Util\RequestOptions $opts
53
     *
54
     * @throws \Stripe\Exception\ApiErrorException if the request fails
55
     *
56
     * @return \Stripe\Collection<\Stripe\InvoicePayment>
57
     */
58
    public function allPayments($parentId, $params = null, $opts = null)
×
59
    {
60
        return $this->requestCollection('get', $this->buildPath('/v1/invoices/%s/payments', $parentId), $params, $opts);
×
61
    }
62

63
    /**
64
     * Attaches a PaymentIntent to the invoice, adding it to the list of
65
     * <code>payments</code>. When the PaymentIntent’s status changes to
66
     * <code>succeeded</code>, the payment is credited to the invoice, increasing its
67
     * <code>amount_paid</code>. When the invoice is fully paid, the invoice’s status
68
     * becomes <code>paid</code>.
69
     *
70
     * If the PaymentIntent’s status is already <code>succeeded</code> when it is
71
     * attached, it is credited to the invoice immediately.
72
     *
73
     * Related guide: <a href="/docs/invoicing/payments/create">Create an invoice
74
     * payment</a>
75
     *
76
     * @param string $id
77
     * @param null|array $params
78
     * @param null|array|\Stripe\Util\RequestOptions $opts
79
     *
80
     * @throws \Stripe\Exception\ApiErrorException if the request fails
81
     *
82
     * @return \Stripe\Invoice
83
     */
84
    public function attachPaymentIntent($id, $params = null, $opts = null)
×
85
    {
86
        return $this->request('post', $this->buildPath('/v1/invoices/%s/attach_payment_intent', $id), $params, $opts);
×
87
    }
88

89
    /**
90
     * This endpoint creates a draft invoice for a given customer. The invoice remains
91
     * a draft until you <a href="#finalize_invoice">finalize</a> the invoice, which
92
     * allows you to <a href="#pay_invoice">pay</a> or <a href="#send_invoice">send</a>
93
     * the invoice to your customers.
94
     *
95
     * @param null|array $params
96
     * @param null|array|\Stripe\Util\RequestOptions $opts
97
     *
98
     * @throws \Stripe\Exception\ApiErrorException if the request fails
99
     *
100
     * @return \Stripe\Invoice
101
     */
102
    public function create($params = null, $opts = null)
1✔
103
    {
104
        return $this->request('post', '/v1/invoices', $params, $opts);
1✔
105
    }
106

107
    /**
108
     * Permanently deletes a one-off invoice draft. This cannot be undone. Attempts to
109
     * delete invoices that are no longer in a draft state will fail; once an invoice
110
     * has been finalized or if an invoice is for a subscription, it must be <a
111
     * href="#void_invoice">voided</a>.
112
     *
113
     * @param string $id
114
     * @param null|array $params
115
     * @param null|array|\Stripe\Util\RequestOptions $opts
116
     *
117
     * @throws \Stripe\Exception\ApiErrorException if the request fails
118
     *
119
     * @return \Stripe\Invoice
120
     */
121
    public function delete($id, $params = null, $opts = null)
1✔
122
    {
123
        return $this->request('delete', $this->buildPath('/v1/invoices/%s', $id), $params, $opts);
1✔
124
    }
125

126
    /**
127
     * Stripe automatically finalizes drafts before sending and attempting payment on
128
     * invoices. However, if you’d like to finalize a draft invoice manually, you can
129
     * do so using this method.
130
     *
131
     * @param string $id
132
     * @param null|array $params
133
     * @param null|array|\Stripe\Util\RequestOptions $opts
134
     *
135
     * @throws \Stripe\Exception\ApiErrorException if the request fails
136
     *
137
     * @return \Stripe\Invoice
138
     */
139
    public function finalizeInvoice($id, $params = null, $opts = null)
1✔
140
    {
141
        return $this->request('post', $this->buildPath('/v1/invoices/%s/finalize', $id), $params, $opts);
1✔
142
    }
143

144
    /**
145
     * Marking an invoice as uncollectible is useful for keeping track of bad debts
146
     * that can be written off for accounting purposes.
147
     *
148
     * @param string $id
149
     * @param null|array $params
150
     * @param null|array|\Stripe\Util\RequestOptions $opts
151
     *
152
     * @throws \Stripe\Exception\ApiErrorException if the request fails
153
     *
154
     * @return \Stripe\Invoice
155
     */
156
    public function markUncollectible($id, $params = null, $opts = null)
1✔
157
    {
158
        return $this->request('post', $this->buildPath('/v1/invoices/%s/mark_uncollectible', $id), $params, $opts);
1✔
159
    }
160

161
    /**
162
     * Stripe automatically creates and then attempts to collect payment on invoices
163
     * for customers on subscriptions according to your <a
164
     * href="https://dashboard.stripe.com/account/billing/automatic">subscriptions
165
     * settings</a>. However, if you’d like to attempt payment on an invoice out of the
166
     * normal collection schedule or for some other reason, you can do so.
167
     *
168
     * @param string $id
169
     * @param null|array $params
170
     * @param null|array|\Stripe\Util\RequestOptions $opts
171
     *
172
     * @throws \Stripe\Exception\ApiErrorException if the request fails
173
     *
174
     * @return \Stripe\Invoice
175
     */
176
    public function pay($id, $params = null, $opts = null)
1✔
177
    {
178
        return $this->request('post', $this->buildPath('/v1/invoices/%s/pay', $id), $params, $opts);
1✔
179
    }
180

181
    /**
182
     * Retrieves the invoice with the given ID.
183
     *
184
     * @param string $id
185
     * @param null|array $params
186
     * @param null|array|\Stripe\Util\RequestOptions $opts
187
     *
188
     * @throws \Stripe\Exception\ApiErrorException if the request fails
189
     *
190
     * @return \Stripe\Invoice
191
     */
192
    public function retrieve($id, $params = null, $opts = null)
1✔
193
    {
194
        return $this->request('get', $this->buildPath('/v1/invoices/%s', $id), $params, $opts);
1✔
195
    }
196

197
    /**
198
     * Retrieves the invoice payment with the given ID.
199
     *
200
     * @param string $parentId
201
     * @param string $id
202
     * @param null|array $params
203
     * @param null|array|\Stripe\Util\RequestOptions $opts
204
     *
205
     * @throws \Stripe\Exception\ApiErrorException if the request fails
206
     *
207
     * @return \Stripe\InvoicePayment
208
     */
209
    public function retrievePayment($parentId, $id, $params = null, $opts = null)
×
210
    {
211
        return $this->request('get', $this->buildPath('/v1/invoices/%s/payments/%s', $parentId, $id), $params, $opts);
×
212
    }
213

214
    /**
215
     * Search for invoices you’ve previously created using Stripe’s <a
216
     * href="/docs/search#search-query-language">Search Query Language</a>. Don’t use
217
     * search in read-after-write flows where strict consistency is necessary. Under
218
     * normal operating conditions, data is searchable in less than a minute.
219
     * Occasionally, propagation of new or updated data can be up to an hour behind
220
     * during outages. Search functionality is not available to merchants in India.
221
     *
222
     * @param null|array $params
223
     * @param null|array|\Stripe\Util\RequestOptions $opts
224
     *
225
     * @throws \Stripe\Exception\ApiErrorException if the request fails
226
     *
227
     * @return \Stripe\SearchResult<\Stripe\Invoice>
228
     */
229
    public function search($params = null, $opts = null)
×
230
    {
231
        return $this->requestSearchResult('get', '/v1/invoices/search', $params, $opts);
×
232
    }
233

234
    /**
235
     * Stripe will automatically send invoices to customers according to your <a
236
     * href="https://dashboard.stripe.com/account/billing/automatic">subscriptions
237
     * settings</a>. However, if you’d like to manually send an invoice to your
238
     * customer out of the normal schedule, you can do so. When sending invoices that
239
     * have already been paid, there will be no reference to the payment in the email.
240
     *
241
     * Requests made in test-mode result in no emails being sent, despite sending an
242
     * <code>invoice.sent</code> event.
243
     *
244
     * @param string $id
245
     * @param null|array $params
246
     * @param null|array|\Stripe\Util\RequestOptions $opts
247
     *
248
     * @throws \Stripe\Exception\ApiErrorException if the request fails
249
     *
250
     * @return \Stripe\Invoice
251
     */
252
    public function sendInvoice($id, $params = null, $opts = null)
1✔
253
    {
254
        return $this->request('post', $this->buildPath('/v1/invoices/%s/send', $id), $params, $opts);
1✔
255
    }
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 a
273
     * <code>proration_date</code> parameter when doing the actual subscription update.
274
     * The value passed in should be the same as the
275
     * <code>subscription_proration_date</code> returned on the upcoming invoice
276
     * resource. The recommended way to get only the prorations being previewed is to
277
     * consider only proration line items where <code>period[start]</code> is equal to
278
     * the <code>subscription_proration_date</code> on the upcoming invoice resource.
279
     *
280
     * @param null|array $params
281
     * @param null|array|\Stripe\Util\RequestOptions $opts
282
     *
283
     * @throws \Stripe\Exception\ApiErrorException if the request fails
284
     *
285
     * @return \Stripe\Invoice
286
     */
287
    public function upcoming($params = null, $opts = null)
1✔
288
    {
289
        return $this->request('get', '/v1/invoices/upcoming', $params, $opts);
1✔
290
    }
291

292
    /**
293
     * When retrieving an upcoming invoice, you’ll get a <strong>lines</strong>
294
     * property containing the total count of line items and the first handful of those
295
     * items. There is also a URL where you can retrieve the full (paginated) list of
296
     * line items.
297
     *
298
     * @param null|array $params
299
     * @param null|array|\Stripe\Util\RequestOptions $opts
300
     *
301
     * @throws \Stripe\Exception\ApiErrorException if the request fails
302
     *
303
     * @return \Stripe\Collection<\Stripe\InvoiceLineItem>
304
     */
305
    public function upcomingLines($params = null, $opts = null)
1✔
306
    {
307
        return $this->requestCollection('get', '/v1/invoices/upcoming/lines', $params, $opts);
1✔
308
    }
309

310
    /**
311
     * Draft invoices are fully editable. Once an invoice is <a
312
     * href="/docs/billing/invoices/workflow#finalized">finalized</a>, monetary values,
313
     * as well as <code>collection_method</code>, become uneditable.
314
     *
315
     * If you would like to stop the Stripe Billing engine from automatically
316
     * finalizing, reattempting payments on, sending reminders for, or <a
317
     * href="/docs/billing/invoices/reconciliation">automatically reconciling</a>
318
     * invoices, pass <code>auto_advance=false</code>.
319
     *
320
     * @param string $id
321
     * @param null|array $params
322
     * @param null|array|\Stripe\Util\RequestOptions $opts
323
     *
324
     * @throws \Stripe\Exception\ApiErrorException if the request fails
325
     *
326
     * @return \Stripe\Invoice
327
     */
328
    public function update($id, $params = null, $opts = null)
1✔
329
    {
330
        return $this->request('post', $this->buildPath('/v1/invoices/%s', $id), $params, $opts);
1✔
331
    }
332

333
    /**
334
     * Mark a finalized invoice as void. This cannot be undone. Voiding an invoice is
335
     * similar to <a href="#delete_invoice">deletion</a>, however it only applies to
336
     * finalized invoices and maintains a papertrail where the invoice can still be
337
     * found.
338
     *
339
     * @param string $id
340
     * @param null|array $params
341
     * @param null|array|\Stripe\Util\RequestOptions $opts
342
     *
343
     * @throws \Stripe\Exception\ApiErrorException if the request fails
344
     *
345
     * @return \Stripe\Invoice
346
     */
347
    public function voidInvoice($id, $params = null, $opts = null)
1✔
348
    {
349
        return $this->request('post', $this->buildPath('/v1/invoices/%s/void', $id), $params, $opts);
1✔
350
    }
351
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc