#.suryamani
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.
- .suryamani, 1 day ago, 23 messages
- .suryamani, 1 day ago, 43 messages
- .suryamani, 4 days ago, 19 messages
- .suryamani, 5 days ago, 10 messages
Hi
Yesterday you said to filter using previous attribute but it not working for me customer.subscription.updated triggers and send emails
yes
is there is any event only for plan upgrade or downgrade?
nope
Here are all the webhook events:
https://stripe.com/docs/billing/subscriptions/webhooks#events
How will i find difference between that is new subscription or plan upgrading or downgrding?
by checking previous_attributes
By checking it is null or has values?
By checking if there is a another price or the same price, if the there is another quantity or the same
Where should i get previous attribute?
Hi! I'm taking over this thread.
var stripeEvent = EventUtility.ParseEvent(json); stripeEvent.Data.PreviousAttributes IS this is correct way to get previous attribute
When you receieve a webhook event, it will contain many properties that are listed here: https://stripe.com/docs/api/events/object
One of them is data.previous_attributes
Object containing the names of the updated attributes and their values prior to the event (only included in events of type *.updated). If an array attribute has any updated elements, this object contains the entire array.
Probably stripeEvent.data.previous_attributes
ok
i need to check it in inside the customer.subscription.updated event condition, I'm i right?
yes
but i need to filter outside of the customer.subscription.updated event condition how should i filter it?
First i need to check its upgrade or downgrade and if it is upgrade or downgrade then only i allow to customer.subscription.updated event condition to send email
How will i do that?
Look at the data.previous_attributes, and if the price changed then it means it was an upgrade or a downgrade.
by checking price id or amount?
If the price ID changed, you know it's either an upgrade or a downgrade. Then you can check the price amount to know which one it is (upgrade or downgrade).
How should i get previous priceid and current priceid?, Which one will i get in previous attribute?
the previous attribute will contain the previous price id
and the current one
In the event payload you get a Subscription object, which contains the current (new) price: https://stripe.com/docs/api/subscriptions/object#subscription_object-items-data-price
this also available in stripeEvent or not?
Yes, the events contains a Subscription object in the payload.
can you send like this to get current price id?
I guess stripeEvent.data.object.items.data.price.id
Hi there 👋 jumping in as my teammate needed to step away, is there a question I can help answer?
Hii
Sorry, circling back as I'm still not sure what you were trying to ask with your most recent message, would you mind elaborating?
I need to check there is upgrading or downgrading so i need to get previous priceid and current priceid
Your friend told me to get current price id by using this one stripeEvent.data.object.items.data.price.id but i got like in image i have sent
I think that makes sense, the autocomplete won't know what fields are available on that object, because it doesn't know what type of object will be in data.object yet.
If you build out the suggested path and run the code, what behavior are you seeing? Have you tried logging the shape of data.object that you're currently seeing?
ok i will try
I got error on items the error is IHasObject does not contain definition for items
Did you also log the structure of the data you're receiving? Do you see an items array being included?
Yes it has items
Hm, what is IHasObject? I don't readily recognize that.
Ah, sorry, that's dotnet code, right? I overlooked that initially, and since that is a strongly typed language you can't blindly traverse object structures. You'll first need to cast the object in the Event body to the corresponding object type. So for Subscriptions, you'll want something like:
{
var subscription = stripeEvent.Data.Object as Subscription;
// Subscription processing logic goes here
}```
Our example webhook endpoint helps show an example that looks for a couple different types of Events and casts the object inside of the Event accordingly:
https://stripe.com/docs/webhooks/quickstart?lang=dotnet
I write like this var subscriptionObj = (Stripe.Subscription)stripeEvent.Data.Object;
Is this ok?
I suspect so, does it compile successfully and run as expected?
No
What's the error you're seeing during compilation or runtime, or are errors being avoided but the code is not doing what you're hoping?
When i write this stripeEvent.data.object.items.data.price.id it shows error like in previous image
Yup, you won't write that anymore. You're moving stripeEvent.data.object into a Subscription object (named subscriptionObj). After casting the data as a Subscription object, you would then traverse the Subscription's properties. Something like subscriptionObj.items.data[0].price.id
ok thank you