Stripe invoiceitem attached to the wrong upcoming invoice
Fixes Stripe invoice items landing on the wrong upcoming invoice. Use when a one-off charge appears on a different customer's invoice or the wrong subscription cycle, usually due to customer vs subscription scoping. Not for proration or tax line issues.
TL;DR
Invoice items attach to a customer by default and land on that customer's next invoice, which surprises people expecting them on a specific subscription. Pass the subscription id when creating the item to pin it to that subscription's next invoice, or delete and recreate the item with the right scope. Always scope explicitly.
Error
```text
invoiceitem in_xxx attached to invoice in_yyy (wrong subscription period)
## Steps
1. Retrieve the invoice item and read its customer and subscription fields.
Expected: You see which scope it actually carries.
2. If the subscription field is empty, that is the bug: customer-scoped items join the next invoice for the whole customer.
Expected: Root cause confirmed.
3. Delete the mis-scoped item (only possible while it is still pending) and recreate it with the subscription id set.
Expected: The charge now targets the right subscription's next invoice.
4. If the wrong invoice already finalized, void it if unpaid or issue a credit note, then recreate correctly.
Expected: The books are fixed without double billing.
5. Make subscription id a required parameter in your invoice-item creation helper.
Expected: Future items cannot be created unscoped.
## When to use
- A one-off charge lands on the wrong invoice
- A customer has multiple subscriptions and the item picked the wrong one
- You expected subscription scoping but passed only a customer
## When not to use
- The item is correct but proration lines confuse the invoice layout
- The invoice already paid and you need a refund flow instead
- Tax behavior differs per subscription (that is a tax-settings issue)
## Compatibility
Stripe API 2018-05-21 and later; invoiceitems endpoint across all SDKs. Pending items are editable and deletable; invoiced items are not.
## Variant phrasings
### ### invoiceitem wrong subscription Stripe
### ### pending invoice item wrong invoice
### ### scope invoice item to subscription
## Root cause
Invoice items are customer-level ledger entries by default; Stripe sweeps every pending item for a customer into the next invoice generated for that customer, regardless of which subscription triggered the billing run. The subscription field exists precisely to narrow that sweep.
## Edge cases
- Items created moments before finalization can still sneak into the closing invoice
- Metered usage items behave the same way: scope them too
- Deleting a pending item is safe, but an item on a finalized invoice needs a credit note
## Provenance
Resolved from the public thread: https://vectle.com/posts/pst_N5VzVyu6bRsizJhSfEwuFw
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.