Upcoming Invoice has no id
baarde opened this issue · comments
When retrieving the upcoming invoice for a customer, the decoding fails as the response does not contain an id for the upcoming invoice (the invoice does not exist yet).
I see several ways to solve that issue but they're all bad:
- Make
Invoice.id
optional. (but it's inconsistent and breaks source compatibility) - Add a new
UpcomingInvoice
type. (but it's inelegant) - Implement
init(from:)
and generate a fake id if it's missing. (but We're Not Hackers!)
Does anybody have a better idea? What solution is the least bad?
That doesn’t make sense. There should always be an id for a model type 🤔
I've never heard of such a thing. Do you have an example JSON payload you can show us? If you do, i'l like to contact stripe about this and see what they say
Here's what I get from https://api.stripe.com/v1/invoices/upcoming?customer=cus_DnV6VISHNLWp3u&subscription=sub_DoG9rVZ9yGQcmv
:
{
"object": "invoice",
"amount_due": 4000,
"amount_paid": 0,
"amount_remaining": 4000,
"application_fee": null,
"attempt_count": 0,
"attempted": false,
"billing": "charge_automatically",
"billing_reason": "upcoming",
"charge": null,
"closed": false,
"currency": "eur",
"customer": "cus_DnV6VISHNLWp3u",
"date": 1542555735,
"description": "",
"discount": null,
"due_date": null,
"ending_balance": 0,
"forgiven": false,
"lines": {
"object": "list",
"data": [
{
"id": "sli_b7e1521f97c8df",
"object": "line_item",
"amount": 4000,
"currency": "eur",
"description": "1 × Test Product (at €40.00 / month)",
"discountable": true,
"livemode": false,
"metadata": {
},
"period": {
"end": 1545147735,
"start": 1542555735
},
"plan": {
"id": "plan_DoG8w6QuhyuiIv",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 4000,
"billing_scheme": "per_unit",
"created": 1539877276,
"currency": "eur",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {
},
"nickname": "test_monthly",
"product": "prod_DOIdWznp6eBlmN",
"tiers": null,
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"proration": false,
"quantity": 1,
"subscription": "sub_DoG9rVZ9yGQcmv",
"subscription_item": "si_DoG9GCGzb8kBS7",
"type": "subscription"
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/invoices/upcoming/lines?customer=cus_DnV6VISHNLWp3u\u0026subscription=sub_DoG9rVZ9yGQcmv"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": 1542559335,
"number": "0ECAD41-0004",
"paid": false,
"period_end": 1542555735,
"period_start": 1539877335,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"subscription": "sub_DoG9rVZ9yGQcmv",
"subtotal": 4000,
"tax": null,
"tax_percent": null,
"total": 4000,
"webhooks_delivered_at": null
}
I've found the following resources:
- Stack Overflow: Stripe.net upcoming invoice id is null when fetching with .Net library
- Stripe API: Description of
invoice.upcoming
event:
The received
Invoice
object will not have an invoice ID.
Ahhhhhh I see I see
I’d be ok with making it optional and writing a comment about that SO answer as a reference.