Stripe, users can not download their invoice
it is posible :) works like a charm with the Python API.
import stripe
import requests
stripe_keys = {'secret_key': 'XXXxxxx','publishable_key': 'XXXxxxx'}
stripe.api_key = stripe_keys['secret_key']
stripe_subscription_id = 'XXXXXXX'
invoices = stripe.Invoice.list(subscription=stripe_subscription_id)
for inv in invoices:
pdf = inv.invoice_pdf
invoice_file = requests.get(pdf)
open('C://User//XXXXX//Desktop//invoice.pdf', 'wb').write(invoice_file.content)
Stripe does not support downloading the invoice as a PDF at the moment via the API and it is only available in the dashboard instead.
For now, the best solution is to build your own invoice receipt/pdf instead. You can retrieve the Invoice object via the API which tells you what the invoice is for: period, amount, when it was paid, what's in that invoice, etc. And you can then generate your own receipt for your customers on your end.
Stripe DOES support this now. The PDF link is available by listing the invoices via the API and accessing the invoice_pdf
attribute of an invoice.
Here's how you can get an array of invoices with their PDF links:
const invoicesResponse = await stripe.invoices.list({ customer: customerStripeId });
const invoices = invoicesResponse.map(invoice => ({
invoiceId: invoice['id'],
pdf: invoice['invoice_pdf'],
}));
return invoices;
Here's the API docs: https://stripe.com/docs/api/invoices/object#invoice_object-invoice_pdf Thanks @avelis for the suggestion.