Upcoming invoices are missing ids

362 views
Skip to first unread message

Rares Saftoiu

unread,
Jul 21, 2014, 2:19:35 PM7/21/14
to api-d...@lists.stripe.com
Hi,

I tried the following code, as per the docs, to close an upcoming invoice before it is billed:

>>> invoice = stripe.Invoice.upcoming(customer="...")
>>> invoice.closed = True
>>> invoice.save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/fedora/deploy/master/lib/python2.7/site-packages/stripe/resource.py", line 282, in save
    self.refresh_from(self.request('post', self.instance_url(),
  File "/home/fedora/deploy/master/lib/python2.7/site-packages/stripe/resource.py", line 210, in instance_url
    'has invalid ID: %r' % (type(self).__name__, id), 'id')
InvalidRequestError: Could not determine which URL to request: Invoice instance has invalid ID: None

If I pull it using  stripe.Invoice.all(customer='...') it comes back as part of the response and I can then close it.

This looks like inconsistent behavior from the API, would appreciate any thoughts/help.

Thanks,
-Rares

Jim Danz

unread,
Jul 21, 2014, 2:27:32 PM7/21/14
to api-d...@lists.stripe.com
Hi Rares,

When you "retrieve" an upcoming invoice, you are getting a preview
into what the invoice will look like when it is created at the end of
the billing period. However, the invoice that you're looking at does
not yet exist -- it's just a preview -- so there's no ID for it, and
it cannot be closed.

If you would like to close an invoice before it is billed, I would
recommend listening to our `invoice.created` webhook and closing the
invoice off of that. We wait one hour between successful delivery of
the `invoice.created` webhook and our first payment attempt on the
invoice. We do that for this exact reason -- so that people can
implement any custom logic they want including adding items to
invoices, or closing them before payment is attempted.

Hope this helps, though sorry for the trouble here.

Best,
Jim
> --
> You received this message because you are subscribed to the Google Groups
> "Stripe API Discussion" group.
> To post to this group, send email to api-d...@lists.stripe.com.
> Visit this group at
> http://groups.google.com/a/lists.stripe.com/group/api-discuss/.
>
> To unsubscribe from this group and stop receiving emails from it, send an
> email to api-discuss...@lists.stripe.com.

Andy Cohen

unread,
Jul 21, 2014, 2:31:38 PM7/21/14
to api-d...@lists.stripe.com
An upcoming invoice is just a preview.  It doesn't actually exist yet, so you cannot close it.  If you wish to close an invoice before it gets paid.  You will need to listen for the "invoice.created" webhook, and then close it.  Stripe will not pay an invoice until one hour after receiving a 200/okay response from the "Invoice.created" webhook, so you don't have to worry about missing it for any reason.

Hope that clears things up for you.

Cheers,

-Andy
--

Rares Saftoiu - Shopventory

unread,
Jul 21, 2014, 2:34:35 PM7/21/14
to api-d...@lists.stripe.com
I understand that, but then why does that same upcoming invoice come back from the stripe.Invoice.all call, which I can then close? Seems like inconsistent behavior to me.

Thanks,
-Rares

---
Rares Saftoiu 
CMO & Co-Founder, Shopventory
@RaresMan


--
You received this message because you are subscribed to a topic in the Google Groups "Stripe API Discussion" group.

Rares Saftoiu - Shopventory

unread,
Jul 21, 2014, 2:35:28 PM7/21/14
to api-d...@lists.stripe.com
Also, I can close that same invoice from the stripe UI, so it can definitely be closed, I am just wondering why the api/ui are behaving differently.

Thanks again,
---
Rares Saftoiu 
CMO & Co-Founder, Shopventory
@RaresMan


Andy Cohen

unread,
Jul 21, 2014, 2:39:24 PM7/21/14
to api-d...@lists.stripe.com
Nice one Jim 😉 
-Andy

Jim Danz

unread,
Jul 21, 2014, 2:39:55 PM7/21/14
to api-d...@lists.stripe.com
The upcoming invoice does not come back from the stripe.Invoice.all
call, and it cannot be closed in the dashboard UI (the UI just
backends to the API).

I wonder if there are just 2 invoices that are looking similar, that
are throwing you for a loop for that reason?
Would be happy to discuss off-list if that's more appropriate (you can
share with me the invoice id, and I can take a look).

But the upcoming invoice 1) does not have an id, 2) does not come back
in stripe.Invoice.all.

On Mon, Jul 21, 2014 at 11:35 AM, Rares Saftoiu - Shopventory

Rares Saftoiu - Shopventory

unread,
Jul 21, 2014, 2:55:45 PM7/21/14
to api-d...@lists.stripe.com
Thanks Jim,

Looks like you're right, there were in fact 2 invoices that looked almost exactly the same, which is where the confusion was coming from.

Thanks again,
-Rares

---
Rares Saftoiu 
CMO & Co-Founder, Shopventory
@RaresMan


Jim Danz

unread,
Jul 21, 2014, 3:21:43 PM7/21/14
to api-d...@lists.stripe.com
Perfect, makes sense. Sorry for the confusion there, and thanks for
circling back! I'm going to make a light edit to the docs to try to
clarify this.

On Mon, Jul 21, 2014 at 11:55 AM, Rares Saftoiu - Shopventory
Reply all
Reply to author
Forward
0 new messages