#Reitrac
1 messages · Page 1 of 1 (latest)
Have a webhook with 4 events : checkout
my webbook is inside stipe-php/webhook.php in ftp and my webhook url is :
https://fairescales.monagraphic-dev.com/stripe-php/webhook.php
In my switch ($event->type) i try to add SQL request to write in my databse but it doesnt works. I have the same code for another website and it works perfectly :/
Webbook always return 400 ERR
My url is success after payment :
access=ok&session_id=cs_test_a16fZ5ru4tyzMZSiqrGRI6Fj2DN3muz2qKC6TKVjJZtGDLZk3tZyozI6XA
The 400 error comes from your code
So what do you see in your server console for that error?
Have you added logs to figure out why your webhook handler code is returning a 400?
Problaly because my webhook is not writing in database so i try to load some variable doesnt exist
Okay so then you are going to need to debug the issue with your database
That isn't really a Stripe-specific issue in that case so I won't be able to help much
i remove my code
and let only :
case 'checkout.session.completed':
$sql = "INSERT INTO stripe (transaction, prix, statut,email, nom, id_produit, checkout_session, test) VALUES ('123456789', '1000', 'OK', 'nicolas@monagraphic.com', 'nicolas', '123', '123456789', 'test')";
$conn->exec($sql);
break;
but always same error
If you remove the database insertion does it work?
Okay and what is the error message?
You are going to need to provide way more information for me to help you.
in front office, not error.
Only error in stripe dashboard
When i check the webhook in dashboard, all informations are loaded in query but the respons is 400 ERR
You code is sending that error as a response to Stripe
That is how a Webhook works. We send the Webhook to your endpoint then you respond to it.
The response is what you see in your Dashboard
Can you share your webhook handler code?
You can drop the code between three backticks like this
Or you can attach a txt file
Can you also provide an Event ID from your Dashboard?
Yep the evt_xxx
Okay give me a sec to look
Okay in your code for try { $event = \Stripe\Webhook::constructEvent( $payload, $sig_header, $endpoint_secret ); } catch(\UnexpectedValueException $e) { // Invalid payload http_response_code(400); exit(); } catch(\Stripe\Exception\SignatureVerificationException $e) { // Invalid signature http_response_code(400); exit(); }
Let's add a string in each response that differentiates those 400s
You could also add an error_log there
Ah wait a second
Is your endpoint public?
From looking at that event you provided internally it looks like we aren't able to reach your endpoint at all since the IP is in a private range.
my host IP ?
Yep
You need to adjust your server config to make that endpoint public so Stripe can POST to it
I have to contact my host so ?
If you don't know how to adjust the config yourself then yes
Sure thing
Host return me that IP is not private
Hmm okay well let's check that then by adding a log at the beginning of your endpoint before your handler and ensuring you see that log when you trigger an event
i remove my webhook.php and add the clean code that stripe give me to try
That is a good option as well
400ERR with the default file
Can you give me the Event ID that you tested with?
evt_1MrLlfDyNb2IQXqaKpFU8yS6
Okay so yeah for that Event that was sent to your we_1MrKfWDyNb2IQXqalGZflC0F endpoint it does appear to be public.
Did you change the webhook secret to match the one for that endpoint?
When i create new webhook, the secret is not the same that when i go to my webhook and click on reveal
reveal = Secret signing key
You need to use the secret for the endpoint that you are testing with
Otherwise you are going to hit the 400 in your code for failed webhook verification
i check my other webhook file and the key is the same
Right it shouldn't be the same though if this is a different endpoint?
Okay let's pause
Can you adjust your code to clarify the 400s that you are responding with
So send back a string as well that indicates which 400 it is
try {
$event = \Stripe\Webhook::constructEvent(
$payload, $sig_header, $endpoint_secret
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
http_response_code('code 1');
exit();
} catch(\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
http_response_code('code 2');
exit();
}
can i replace my success URL by the default html file ?
I'm not a PHP expert but not sure it will let you send a string here actually with http_response_code
Not sure what you mean by that
Sorry I don't understand
it seems works
my host remove a protection
named "Tiger protect"
BUT
ho no
not works
it works only when i remove http_response_code(400); to string
evt_1MrLwkDyNb2IQXqaM53jmvt9
Works
Yep I see you responded to that Event successfully
Next event you triggered?
When i remove 400 from http_response_code('code 1');event works
when i add 400 (default option) it doesnt works
but webhooks doesnt write in my database...
Okay so then seems that you are actually hitting that error.
Where is that response in your code?
400 ?
Yeah the one that you said you removed and then added back and now you hit that error
Which error block is it in?
i dont know, when i change for a string, i have no error...
Right because you are sending back the response there to Stripe, so if you don't send an error response then that means you don't see an error in Stripe. But your webhook handler still hit an error.
perhaps
^^"
To sum up, the payments go through and work. The webhook is loaded but stops at an error and therefore does not generate any code below.
If I add the default file provided by STRIPE, I get the same error
Yeah so we need to know which error you are actually hitting in your webhook handler code so we can debug that
That is why I was saying before to make the errors that you are responding with unique
So we know where in your code it is erroring
// Invalid payload
OR
// Invalid signature
Yep so which one?
Add an echo right before your http_response_code
Like we show here: https://stripe.com/docs/webhooks/quickstart?lang=php
// Invalid payload
echo '⚠️ Webhook error while parsing basic request.';
http_response_code(400);
exit();
}```
600 is returned
So
// Invalid signature
http_response_code(600);
exit();
}`````
Invalid signature
Event : evt_1MrME3DyNb2IQXqa4iZnmppR
Great okay so now we need to check on the Webhook secret that you are using
It likely isn't the one for that endpoint
Yep