#szy_subscription-update-events

1 messages ยท Page 1 of 1 (latest)

wet jettyBOT
#

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

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

hazy wyvern
#

HI ๐Ÿ‘‹

This webhook event has nothing to do with changing products/prices on a subscription. What information are you trying to get from it?

#

For all our .updated webhook events, the best way to identify what changed is to review the previous_attributes property.

In this case, it looks like the billing cycle updated and a new Invoice was generated since the attributes that were changed are billing cycle timestamps and invoice ID

previous_attributes: {
    current_period_end: 1727799723,
    current_period_start: 1725207723,
    latest_invoice: "in_1PuGZkC5Vnk6f7u9NJh2bL3P"
  }
main vapor
#

Hey, In the end I want to get the name of the product I'm switching my subscription to.

hazy wyvern
#

No product was switched here

#

Do you have an example event where a product was changed?

#

Ultimately you will need to identify which subscription item was updated, then get the price ID from that subscription item and use it to retrieve the Price object with the Product information expanded from the API

https://docs.stripe.com/api/prices/object

#

But it can be helpful to talk through an example, so I'd like to see an event where the product changed so we can talk through it

main vapor
#

I'm receiving a webhook whenever I switch plans in my application. I'm changing my subscription from "Basic" to "Premium".

hazy wyvern
#

Okay. Do you have an example ID of a customer.subscription.updated webhook event where you changed price/product ?

main vapor
#

yes

#

evt_1Q58q7C5Vnk6f7u9EI0WlBH7

hazy wyvern
#

Thanks, taking a look

#

Nope sorry that isn't what happened here

#

The only thing changed was the billing cycle

#

Again, look at previous_attributes

"previous_attributes": {
      "current_period_end": 1727799723,
      "current_period_start": 1725207723,
      "latest_invoice": "in_1PuGZkC5Vnk6f7u9NJh2bL3P"
    }

If you changed products, there would be a price ID here

#

If you look at the previous_attributes property, you will see that a Subscription Item has been updated

  previous_attributes: {
    items: {
      data: [
        {
          id: "si_QuO9MuwLv5IHh0",
          object: "subscription_item",
          billing_thresholds: null,
           .....
#

So, to get the product you are changing to, you would retrieve that Subscription Item from the data object you received.

 items: {
      object: "list",
      data: [
        {
          id: "si_QuOaCl9fskbKHD",
          object: "subscription_item",
          billing_thresholds: null,
          created: 1727188368,
          discounts: [],
          metadata: {},
          plan: {
            id: "price_1PGI2yC5Vnk6f7u9UdLD9SOs",  // <- this is the ID you need
#

Actually, you can get the Product ID from the price attribute and just retrieve that, if all you care about is the name

#

But generally, I find it helpful to have both Product and Price data

main vapor
#

okay, i need time to look into my code again

#

but thank you for the resources

hazy wyvern
#

Sure thing, happy to help ๐Ÿ™‚