#omaradelp4er

1 messages ยท Page 1 of 1 (latest)

ornate sphinxBOT
stuck dagger
#

Hi ๐Ÿ‘‹ how can I help?

#

@prisma path I've created a thread for you, lets discuss your concern here.

prisma path
#

ok

stuck dagger
#

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

prisma path
#

and after this i check the database and found that email don't saved

stuck dagger
#

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?

prisma path
#

this is my stripe cli

stuck dagger
#

Your endpoint returning a 400 typically means it is encountering an error somewhere, what debugging have you done on your endpoint code so far?

prisma path
#

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?

stuck dagger
#

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.

stuck dagger
prisma path
#

no

prisma path
stuck dagger
#

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.

prisma path
#

ok tell me how to debug it

stuck dagger
#

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?

prisma path
#

yes

stuck dagger
#

Okay, what errors are you seeing thrown when your code runs?

prisma path
#

this is the output

stuck dagger
#

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?

prisma path
#

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

stuck dagger
#

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
prisma path
#

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

stuck dagger
#

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?

prisma path
#

how to know it?

stuck dagger
#

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?

prisma path
#

from nuget manager

stuck dagger
#

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

stuck dagger
ornate sphinxBOT
prisma path
#

this what you mean?

stuck dagger
#

No, I meant these lines that you logged earlier, which are cut off in the screenshot:

prisma path
stuck dagger
#

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

prisma path
#

i will try it

#

it works thanks but i got new error

#

i cant get customer email from session it always null

#

@stuck dagger

stuck dagger
#

Can you share the ID of an Event (evt_123) where you're seeing that value is null?

prisma path
stuck dagger
#

Can you copy that Event ID and paste it here?

prisma path
#

evt_1Myc4BBJXqEpbaRDYcabqPol

stuck dagger
#

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

prisma path
#

how to get the email?

#

i can't get it

stuck dagger
#

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.