#.suryamani
1 messages ยท Page 1 of 1 (latest)
๐ how may I help?
would you mind elaborating your question?
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
what's the code you're executing?
else if (stripeEvent.Type == Events.InvoicePaymentFailed)
{
var paymentMethod = stripeEvent.Data.Object as PaymentMethod;
//EmailInvitations.SendSubscriptionRenewalPaymentFailedMail(userEmail, displayName, companyName, AppSetting.AppRedirectUrl);
EmailInvitations.SendSubscriptionRenewalPaymentFailedMail("suryamanivannan1226@gmail.com", "Surya", "Reinvent", AppSetting.AppRedirectUrl);
}
so you're saying you're not receiving the invoice.payment_failed event?
yes
would you mind sharing your account ID?
account ID means
your account ID that looks like acct_xxx
you can get it from https://dashboard.stripe.com/settings/account
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
acct_1N51ZTLabf7E4J4F
as you can see here https://dashboard.stripe.com/test/events/evt_1NzfFALabf7E4J4FGI0mTuoW you received the event
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
but i received customer.subscription.updated event
See this one you understand what issue I'm facing
Hi there ๐ jumping in as my teammate needed to step away, please bear with me a moment while I catch up on the thread.
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?
But for me only one event will generate, i need to send email based on webhooks event
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.
did you see that video
What video?
this one
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?
I don't have a program readily available to open that filetype.
Are you able to describe the concern in a message?
If you see that video you will clearly understand so only i send that
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.
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
Can you share the ID of the Subscription you created for your testing?
You mean Subscription ID
yes
sub_1NzeHxLabf7E4J4F51hkbuZx
Okay, what I see:
- A request was made to create a Subscription in a Test Clock
- The Test Clock's time is advanced.
- 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?
this all events are only shown here only
In my code only customer.subscription.updated event is generates
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.
Ok but I'm facing this issue how will sort it out
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.
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
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.
See that stripeEvent.type I'm saying about that
I write if condition for that If StripeEvent.type == any event
Like this
If stripeEvent.Type is equal any event then program goes inside the condition and email will sent to that user
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?
No
Gotcha, was I able to address your concern?
No
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.
please See the video to understand my concern
Provide it to me in a form I can watch and I will.
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.
After go to my code stripeEvent.Type will generate based on subscription
But here stripeEvent.Type shows only this event customer.subscription.updated event
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?
No errors will I get
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.
This the reason I will not get other events I'm I right
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?
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.
Is any other way to solve it
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.
If I delete that line it throws error for getting customerid
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.
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!