#omaradelp4er
1 messages ยท Page 1 of 1 (latest)
Hi ๐ how can I help?
@prisma path I've created a thread for you, lets discuss your concern here.
ok
pasting your context:
i make checkout api and it works good and make a webhook handler but dont work correct here is my code for webhook and when i listen to it it came with 400 it mean it work good
and after this i check the database and found that email don't saved
So to make sure I understand, you have a webhook endpoint that is receiving events but your endpoint is responding to those with a 400?
this is my stripe cli
Your endpoint returning a 400 typically means it is encountering an error somewhere, what debugging have you done on your endpoint code so far?
my endpoint for checkout session works great and return the session url and i use it to pay and it completes succcesssfully ican see it on my dashpord
but the problem is in the webhook
i can't do debugging on it,can i?
Apologies for my lack of clarity, I'm not asking about your code that is creating the Checkout Sessions, I'm asking about the code that you're running on your webhook endpoint that is receiving the Events that are being sent. That is code that you own and operate, so you should have access to debug it.
When the code shown here is run, are any errors thrown?
no
but how i debug it it just work on cli and dashbord
Sorry, that doesn't make much sense, your webhook endpoint code doesn't run in the CLI or the Dashboard so I'm not sure how those are related.
When using a webhook endpoint to listen for Events, Stripe sends Events to your server that is hosting your webhook endpoint and running the code for it. Your server then responds back to Stripe with it's response, if that response is a 400 that is your server/code returning that response and we won't have insight into why it's doing that.
ok tell me how to debug it
You need to figure out why your code is returning a 400. It looks like you have a line to return BadRequest on Line 82, what exception are you seeing in your server logs that is causing your code to go to that section?
Did you set your endpointSecret variable to match the endpoint secret that Stripe CLI provided when you ran stripe listen?
yes
Okay, what errors are you seeing thrown when your code runs?
this is the output
Hm, that doesn't share much context, can you log out the exception that is being encountered so we can see more details about it?
i comment this lines var stripeEvent = EventUtility.ConstructEvent(
// json,
// Request.Headers["Stripe-Signature"],
// _config["Stripe:WebhookSecret"]
// ); : and in the cli it get 200 it means the error in this
So that's the code throwing the exception, but if you don't log out the exception then we still don't know what the exception is.
Typically that function fails for one of two reasons:
- the request payload being provided has been altered
- the signing secret being used isn't correct
i make this to log the error in pic(1) and this i got on the output pic(2)
i also log the json and got it right
The console output is cut off so I can't see all of it, but it looks like there is an API version mismatch between the API version that is pinned to version of our library you're using and the API version that Events are being sent to your endpoint with.
What version of our SDK are you using, and what is the default API version of your Stripe account?
how to know it?
Actually it looks like the error line tells us the version the Events are being generated in, 2020-08-27, so we just need to know what version of the Stripe library you're using to know what version it is expecting.
How did you install the Stripe library?
from nuget manager
Gotcha, so that looks like our newest version of that library, which I believe is pinned to what is currently the newest version of our API. (Since languages like .NET are strongly typed, our libraries for those have to be pinned to specific API versions so the library can consistently put the information into the same object shapes)
For testing purposes, you should be able to run the Stripe CLI with the --latest option to force Events to be sent in the most recent API version.
stripe listen --latest
Does the end of the log lines here say the SDK was expecting Events to be in version 2022-11-15?
No, I meant these lines that you logged earlier, which are cut off in the screenshot:
Gotcha, yup, it was expecting them in the newest API version, so the --latest tag should allow you to test. When it comes time to register your endpoint (rather than using the CLI to forward Events), you'll want to make sure that you set the API version of the endpoint so it matches the API version that the library is pinned to:
https://stripe.com/docs/api/webhook_endpoints/create#create_webhook_endpoint-api_version
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
i will try it
it works thanks but i got new error
i cant get customer email from session it always null
@stuck dagger
Can you share the ID of an Event (evt_123) where you're seeing that value is null?
Can you copy that Event ID and paste it here?
evt_1Myc4BBJXqEpbaRDYcabqPol
Gotcha, the customer_email field you're referring to is used for prefilling a customer's email address in the Checkout Session:
https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-customer_email
I think you're looking for the email field inside of the customer_details hash:
https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-customer_details-email
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Looks like CustomerDetails is what you're looking for, does session.CustomerDetails.Email give you what you're looking for? I"m not exactly sure what the syntax for that in .net is offhand, but believe that is the value you're trying to get to.