#gruneth_invoice-lists
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1288203757154340976
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello,
my current Code:
func (paymentHandler *PaymentHandler) CountTotalInvoices(subscriptionID string) (int64, error) {
stripe.Key = paymentHandler.StripeConnection.Key
params := &stripe.InvoiceListParams{
Subscription: stripe.String(subscriptionID),
}
var totalResults int64
var iter *invoice.Iter
for {
iter = invoice.List(params)
if !iter.Next() {
break
}
totalResults++
params.StartingAfter = stripe.String(iter.Invoice().ID)
}
if err := iter.Err(); err != nil {
return 0, err
}
return totalResults, nil
}
@bleak minnow The only way in the API is the List Invoices API https://docs.stripe.com/api/invoices/list with the subscription: 'sub_123' parameter and then paginating until you count all of them yes
gruneth_invoice-lists
Well I found there was a possiblility with expand and total_count but seems deprecated.
If you don't need real time correct answers you can use the Search API. It has a subscription filter for Invoices https://docs.stripe.com/search#query-fields-for-invoices and there's the ability to count
yeah total_count is deprecated on the List APIs and not something you should use. It exists but is broken in some cases and unreliable so don't use that. Been undocumented for like 8+ years
What do you mean with not real time with the Search API?