#dancamdev
1 messages · Page 1 of 1 (latest)
Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
Hello 👋
I need to keep a counter of how many discounts have been used by each user. Ideally, through the webhooks, whenever a subscription is updated and I find the discount invoice item, I'd increment the counter.
The negative invoice item doesn't really update the subscription object, right?
It offsets the invoice total resulting in discounted amount due.
One option I can think of is to list all invoice items for a customer
https://stripe.com/docs/api/invoiceitems/list
Have you tried it yet?
Yeah, the first part was indeed my main issue. I have not tried listing the invoice items as I wouldn't really know what to do with them.
Another option comes to mind, what if I check for subscriptions.update and see if the amount paid is less than the one of the attached product? Would that work?
Another one might be, since the invoice item will be applied for sure to the next payment, I can increment the counter when I create the invoice item?
I'm not sure if stripe creates more invoice items during the subscription flow though
Another one might be, since the invoice item will be applied for sure to the next payment, I can increment the counter when I create the invoice item?
You could do that.
I'm not sure if stripe creates more invoice items during the subscription flow though
It's possible that multiple invoice items get associated with one invoice
So you could listen to customer.subscription.updated event but the information you need will be on the invoice
you could check subscription's associated invoice's lines array.
the invoice items would be listed as line_item object
"object": "list",
"data": [
{
"id": "xx_xxxx",
"object": "line_item",
...
}
]
}
Subscription related items are listed as type subscription_item
does this mean that if in the customer_subscription_updated I find a line item I can easily tell that is the discount invoice item? Since I'm not applying any other items to the subscriptions anyway.
yup
awesome! thanks for the help