#avalari_code

1 messages ยท Page 1 of 1 (latest)

river grailBOT
#

๐Ÿ‘‹ 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/1416054006333313085

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

kindred grail
#
                var previousAttributes = stripeEvent.Data.PreviousAttributes;

                if (previousAttributes != null && previousAttributes.ContainsKey("items"))
                {
                    var previousItemsData = JObject.Parse(JsonConvert.SerializeObject(previousAttributes))
                        .SelectToken("items.data") as JArray;
                    
                    var currentItem = subscription.Items.Data.FirstOrDefault();
                    var currentPriceId = currentItem?.Price?.Id;
                    var currentProductId = currentItem?.Price?.ProductId;
                    
                    var previousItem = previousItemsData?.FirstOrDefault();
                    string previousPriceId = previousItem?["price"]?["id"]?.ToString();
                    string previousProductId = previousItem?["price"]?["product"]?.ToString();
                    
                    if (currentPriceId != previousPriceId || currentProductId != previousProductId)
                    {
                        await _webhookService.HandleSubscriptionUpdated(subscription);
                    }
                }
                break;```
#

I've been told from my previous question to try and omit CustomerSubscriptionUpdated event as it it mostly bloated.

#

But I can't find any other way around it

blazing osprey
#

Just to clarify, this upgrade/downgrade is happening after sign-up via Pricing Table, I imagine via Customer Portal?

blazing osprey
#

Then

Currently, in my CustomerSubscriptionUpdated webhook handler, Iโ€™m comparing the previousAttributes["items"] against the current subscription items to check if the price.id or product.id has changed. Is this the correct approach?
This is the correct approach -- inspecting the subscriptions items for price changes

#

The subscription items are the canonical source of truth here

kindred grail
#

is there a way of getting PreviousAttributes through SDK without manual json parsing?

blazing osprey
kindred grail
#

got it, thanks for clarification ๐Ÿ™‚