#avalari_code
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/1416054006333313085
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
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
Just to clarify, this upgrade/downgrade is happening after sign-up via Pricing Table, I imagine via Customer Portal?
yes
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 subscriptionsitemsforpricechanges
The subscription items are the canonical source of truth here
is there a way of getting PreviousAttributes through SDK without manual json parsing?
Not as far as i know, it's just a hashmap because its ~never going to be a complete object that can map to any of our full object types
https://github.com/stripe/stripe-java/blob/v29.5.0/src/main/java/com/stripe/model/Event.java#L347-L354
got it, thanks for clarification ๐