#Sen-webhooks

1 messages · Page 1 of 1 (latest)

hushed sparrow
#

@rugged crest hi! not sure I understand. A webhook is a notification Stripe sends to you. E.g. something happens on your Stripe account like a payment being completed, and Stripe sends a HTTP request to your web server with an event to notify you of that happening, your server accepts the request and can do whatever processing it needs

rugged crest
#

I will explain it:
If subscription switch using stripe API then webhook event run.customer.subscription.updated
The same event will run when the subscription end of the period (recurring)

So now I have added logic from my side when switch API runs. it is working but at the same time customer.subscription.updated event also run.
Now problem is that my subscriptions data updated twice you know. So i needed to prevent that

hushed sparrow
#

is it a problem that the data is updated twice?

#

ultimately if you listen to both events you just have to make sure your code can gracefully handle this case

rugged crest
# hushed sparrow is it a problem that the data is updated twice?

Yes, exactly but I do have not any reference that I could check if subscription data is already updated.
That's why asking any reference available inside the webhook response object.

Ex: I have subscribed to gold plan and subscription data stored.

  1. Subscription switch to silver using API and I will update gold data to silver data right.
  2. At the same time stripe webhook run. I have also put logic for updating subscription data ( here data will updated twice )
hushed sparrow
#

why is it a problem though? you are just updating the subscription to the same thing(like 1 update is changing gold to silver, and the next one, it's updating from silver to silver so nothing changed so it's probably not a problem)

#

there's no direct way in the event to avoid this, it's just that you have to build your implementation to be "idempotent"

rugged crest
hushed sparrow
#

I think you'd just have to redesign how you do the update to not require the old state or if you really need it, keep the old state in a separate table in the database(like have an "archive" table with snapshots of the old versions)