#Zil
1 messages · Page 1 of 1 (latest)
Well yes, but it seems I cannot delete the draft invoice.
draft_invoices = Stripe::Invoice.list(customer: customer_id, status: :draft, subscription: subscription.processor_id)
if draft_invoices.present?
draft_invoice = draft_invoices.first
Stripe::Invoice.void_invoice(draft_invoice.id)
end
I cannot void it because it is in draft state
What do you mean by "can't"? Do you get an error message? Can you share the request ID?
So this throws You can only pass in open invoices. This invoice isn't open.
Have you tried this: https://stripe.com/docs/api/invoices/delete
Permanently deletes a one-off invoice draft.
Ha wait, this won't work for subscriptions invoice
I guess you could keep the invoice as draft and never finalize it. To make sure it's not finalized automatically, update the invoice to auto_advance:false https://stripe.com/docs/api/invoices/update#update_invoice-auto_advance
I was thinking of calling Stripe to check if there are draft invoices for subscription and forbidding users to upgrade/downgrade while they use the pricing page.
Are there any negative consequences of having draft invoices that never finalize?
auto_advance: false is an option. If I process events in the background, there could still be race conditions (upgrading the last second), but the probability is much lower. In that case we would need to make a refund if it ever happens.
Are there any negative consequences of having draft invoices that never finalize?
No I don't think so
auto_advance: false is an option. If I process events in the background, there could still be race conditions (upgrading the last second), but the probability is much lower. In that case we would need to make a refund if it ever happens.
Yes makes sense
Ok thanks. I will try this solution right now.
Should I use some time filter when fetching for an invoice, or should I just grab the last draft invoice and update it?
Hey! Taking over for my colleague.
To achieve what exactly ?
In invoice.paid webhook I am fetching for draft invoices that might have been issued.
And I will be setting it to auto_advance: false
Not sure I understand this part sorry, the invoice you'll receive is paid already, what draft invoices are you trying to fetch
Reading the previous conversation...
You should refer to invoice.created event and mark the invoice as auto_advance: false
No. User upgrades after the invoice is already created
If it does not upgrade, the invoice should be collected
I am trying to prevent double charging the user
Ok so try to search for all the customer invoices and update all necessary invoices:
https://stripe.com/docs/api/invoices/search
Thanks. Implemented it and it seems to work. Thanks.
Cool!