#.suryamani

1 messages · Page 1 of 1 (latest)

woeful spokeBOT
#

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.

foggy gorge
#

Hi

reef rapids
#

Yesterday you said to filter using previous attribute but it not working for me customer.subscription.updated triggers and send emails

foggy gorge
#

yes

reef rapids
#

is there is any event only for plan upgrade or downgrade?

foggy gorge
#

nope

reef rapids
#

How will i find difference between that is new subscription or plan upgrading or downgrding?

foggy gorge
#

by checking previous_attributes

reef rapids
#

By checking it is null or has values?

foggy gorge
#

By checking if there is a another price or the same price, if the there is another quantity or the same

reef rapids
#

ok

#

I will check

woeful spokeBOT
reef rapids
#

Where should i get previous attribute?

wooden oriole
#

Hi! I'm taking over this thread.

reef rapids
#

var stripeEvent = EventUtility.ParseEvent(json); stripeEvent.Data.PreviousAttributes IS this is correct way to get previous attribute

wooden oriole
#

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

reef rapids
#

ok

#

i need to check it in inside the customer.subscription.updated event condition, I'm i right?

wooden oriole
#

yes

reef rapids
#

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?

wooden oriole
#

Look at the data.previous_attributes, and if the price changed then it means it was an upgrade or a downgrade.

reef rapids
#

by checking price id or amount?

wooden oriole
#

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).

reef rapids
#

How should i get previous priceid and current priceid?, Which one will i get in previous attribute?

wooden oriole
#

the previous attribute will contain the previous price id

reef rapids
#

and the current one

wooden oriole
reef rapids
#

this also available in stripeEvent or not?

wooden oriole
#

Yes, the events contains a Subscription object in the payload.

reef rapids
wooden oriole
#

I guess stripeEvent.data.object.items.data.price.id

reef rapids
#

ok thank you i will try it

#

But got like this

astral cloak
#

Hi there 👋 jumping in as my teammate needed to step away, is there a question I can help answer?

reef rapids
#

Hii

astral cloak
#

Sorry, circling back as I'm still not sure what you were trying to ask with your most recent message, would you mind elaborating?

reef rapids
#

I need to check there is upgrading or downgrading so i need to get previous priceid and current priceid

astral cloak
#

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?

reef rapids
#

ok i will try

#

I got error on items the error is IHasObject does not contain definition for items

astral cloak
#

Did you also log the structure of the data you're receiving? Do you see an items array being included?

reef rapids
#

Yes it has items

astral cloak
#

Hm, what is IHasObject? I don't readily recognize that.

reef rapids
#

Error shows like this

astral cloak
#

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
reef rapids
#

I write like this var subscriptionObj = (Stripe.Subscription)stripeEvent.Data.Object;

#

Is this ok?

astral cloak
#

I suspect so, does it compile successfully and run as expected?

reef rapids
#

No

astral cloak
#

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?

reef rapids
astral cloak
#

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

reef rapids
#

ok thank you