#.suryamani

1 messages ยท Page 1 of 1 (latest)

torn marshBOT
rough thunder
#

๐Ÿ‘‹ how may I help?

rough thunder
#

would you mind elaborating your question?

proud walrus
#

If invoice.payment.failed event is generated in stripeEvent.Type then payment Failed mail is sent to customer but unfortunately for me customer.subscription.updated event is generate in stripeEvent.Type, I'm asking you to how i will solve it

rough thunder
#

what's the code you're executing?

proud walrus
rough thunder
#

so you're saying you're not receiving the invoice.payment_failed event?

proud walrus
#

yes

rough thunder
#

would you mind sharing your account ID?

proud walrus
#

account ID means

rough thunder
#

your account ID that looks like acct_xxx

proud walrus
#

acct_1N51ZTLabf7E4J4F

rough thunder
proud walrus
#

but i received customer.subscription.updated event

proud walrus
paper spoke
#

Hi there ๐Ÿ‘‹ jumping in as my teammate needed to step away, please bear with me a moment while I catch up on the thread.

paper spoke
#

It's expected for customer.subscription.updated Events to also be generated alongside invoice.payment_failed Events when you're working with Subscriptions. The Events show the Subscriptions moving from having a status of active to being past_due.

What is your desired outcome here, to not take action on those Events?

proud walrus
#

But for me only one event will generate, i need to send email based on webhooks event

paper spoke
#

What do you mean by that? You said more than one Event type is being generated, so I don't understand what you're trying to convey when you say only one event will generate.

proud walrus
#

did you see that video

paper spoke
#

What video?

paper spoke
#

Oh, didn't realize that was a video, just looked like a random link. It's prompting me to download and I'm not comfortable downloading random files. Can you describe what you were hoping I would learn from it?

proud walrus
#

This was my screen record this will describe you what issue I'm facing

paper spoke
#

I don't have a program readily available to open that filetype.

#

Are you able to describe the concern in a message?

proud walrus
#

If you see that video you will clearly understand so only i send that

paper spoke
#

I get that, but I don't have a way to view the video, which is why I'm hoping you can describe the issue you're having to me so I can provide assistance for that.

proud walrus
#

I'm configure in my command prompt for local testing

#

I'm testing auto renewal in Stripe

#

It hit the API when I'm testing

#

Now I will create customer and create subscription for that customer and pay using 4242 4242 4242 4242 this card at the time it hit API and customer.subscription.created event will generate and I'm using test clock to advance time For auto renewal but now I'm using 4000 0000 0000 0341 this card to check payment failed sequence But here also it HIT API but customer.subscription.updated event only generate

#

That is my issue

paper spoke
#

Can you share the ID of the Subscription you created for your testing?

proud walrus
#

You mean Subscription ID

paper spoke
#

yes

proud walrus
#

sub_1NzeHxLabf7E4J4F51hkbuZx

paper spoke
#

Okay, what I see:

  1. A request was made to create a Subscription in a Test Clock
  2. The Test Clock's time is advanced.
  3. The payments for the Invoices that are created fail

For the failures I'm seeing multiple types of Events generated, invoice.finalized when the Invoice is finalized, invoice.payment_failed when the payment fails, customer.subscription.updated when the payment failure causes the Subscription to be updated, and some others.

Is your concern that you aren't seeing/receiving all of those Event types?

proud walrus
#

this all events are only shown here only

#

In my code only customer.subscription.updated event is generates

paper spoke
#

Nope, your code doesn't control what Events are generated, that's controlled by Stripe and we will always generate the Events based on their triggering criteria (there are a handful of Event types that are exceptions to this, but none of them are ones being discussed here).

Your code can control what type of Events it takes action on, but it cannot prevent us from generating Events of a specific type.

proud walrus
#

Ok but I'm facing this issue how will sort it out

paper spoke
#

What issue?

#

If you're not going to have the webhook endpoint you create later listen for those types of Events, then you can just ignore them now. To avoid your server returning 500s, you can have a final else block that catches all other Event types, returns a 200, and then doesn't do anything with the event.

proud walrus
#

the issue im facing is this one

#

I'm only get customer.subscription.updated but I need to send emails based on events generates here

paper spoke
# proud walrus I'm only get customer.subscription.updated but I need to send emails based on ev...

This either isn't true or I don't understand what you're trying to convey, because you shared a screenshot above showing a lot more types of Events being generated.

The Event type you have circled is for pending updates:
https://stripe.com/docs/billing/subscriptions/pending-updates
so far I'm not seeing any requests that use pending updates, so it's expected that Events related to that aren't being generated.

proud walrus
#

See that stripeEvent.type I'm saying about that

#

I write if condition for that If StripeEvent.type == any event

#

Like this

torn marshBOT
proud walrus
#

If stripeEvent.Type is equal any event then program goes inside the condition and email will sent to that user

paper spoke
#

Okay, if you tightly scope the Events that your webhook endpoint is listening for when you register it in your Stripe account, then that seems like a fine approach. I would recommend being extra careful about expanding what Event types that webhook endpoint listens to in the future though. Was there a question you had about that approach?

proud walrus
#

No

paper spoke
#

Gotcha, was I able to address your concern?

proud walrus
#

No

paper spoke
#

I'm sorry to hear that, can you try again to describe your concern to me then? I'm still not grasping what the issue is here.

proud walrus
#

please See the video to understand my concern

paper spoke
#

Provide it to me in a form I can watch and I will.

paper spoke
#

I see you scrolling through your dashboard, and then clicking through breakpoints in your code.

#

I don't have any better understanding of what your concern is.

proud walrus
#

After go to my code stripeEvent.Type will generate based on subscription

#

But here stripeEvent.Type shows only this event customer.subscription.updated event

paper spoke
#

Oh, like you aren't seeing the other Event types make their way into the if/else logic you showed above?

#

Looking at the output from the CLI, it looks like it is forwarding the Events to your local endpoint, and is receiving 500 statuses in response. That makes it seem like those Events are making it to your endpoint, but the code is not able to handle them as expected and is returning an error. Do you see any errors/exceptions from earlier in your endpoint logic when those other event types are forwarded? Do you have a line further up that is filtering out anything that isn't a customer.subscription.updated Event?

proud walrus
#

No errors will I get

paper spoke
#

Your server is returning 500s to the CLI, an error is happening somewhere, unless you intentionally coded your endpoint to respond with a 500 status sometimes.

proud walrus
#

This the reason I will not get other events I'm I right

paper spoke
#

The CLI is forwarding the Events to your server, you need to debug your code to try to figure out why those are not making it to the if/else logic you shared above. Do you hvae your full webhook endpoint code that you can share?

proud walrus
paper spoke
#

My guess is it's crashing on this line:
var subscriptionObj = (Stripe.Subscription)stripeEvent.Data.Object;

Looks like you're trying to cast data.object to a Subscription, and I wouldn't expect that to work for event types that don't start with customer.subscription., because other Event types won't contain a Subscription object, so I would expect that cast to fail. You're likely not seeing the errors because you wrapped the whole thing in a try block, but don't log the encountered error in your catch block.

proud walrus
#

Is any other way to solve it

paper spoke
#

You need to restructure your logic, you shouldn't try to cast something as a particular type of object unless you know what that object will be. So your code that works with Subscription objects, should only be called once you've checked the event type and ensure it will contain a Subscription. You can also update your catch block so it logs these errors for your, it will make your job debugging this much easier.

proud walrus
#

If I delete that line it throws error for getting customerid

paper spoke
#

Yup, because you try to pull the Customer from the Subscription.
.Where(mapping => mapping.CustomerID == subscriptionObj.CustomerId)

#

To summarize, these Events are being sent to your endpoint, but your code is crashing because it's not written to handle the Event types that it's receiving. You'll need to rewrite your logic so that doesn't happen. Any actions that expect a specific type of object be in the Event, will need to be written so that they only execute when you know that is the object type that will be in the Event's data.

#

Well, not crashing, because it's catching and ignoring the errors that are thrown.

proud walrus
#

ok thank you so much

#

You will stay calm and clear my all doubts

paper spoke
#

Sorry if it was a bit rough at the beginning, but I knew we'd be able to get aligned and get this sorted out for you!