#Reitrac

1 messages · Page 1 of 1 (latest)

delicate tartanBOT
left tangle
#

Hi there

#

What does "not loaded" mean exactly?

#

Can you give me more details?

lethal dune
#

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

left tangle
#

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?

lethal dune
#

Problaly because my webhook is not writing in database so i try to load some variable doesnt exist

left tangle
#

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

lethal dune
#

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

left tangle
#

If you remove the database insertion does it work?

lethal dune
#

i try

#

nop

#

error 400

#

again

#

:/

left tangle
#

Okay and what is the error message?

#

You are going to need to provide way more information for me to help you.

lethal dune
#

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

left tangle
#

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?

lethal dune
#

yes, let me just hide my secret key

#

can i send php file here ?

left tangle
#

You can drop the code between three backticks like this

#

Or you can attach a txt file

lethal dune
left tangle
#

Can you also provide an Event ID from your Dashboard?

lethal dune
#

start by we_ ?

#

evt_1MrLDaDyNb2IQXqaro6gZAdE

#

we_1MrKfWDyNb2IQXqalGZflC0F

left tangle
#

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.

lethal dune
#

my host IP ?

left tangle
#

Yep

lethal dune
#

How can solve it ?

#

:/

left tangle
#

You need to adjust your server config to make that endpoint public so Stripe can POST to it

lethal dune
#

I have to contact my host so ?

left tangle
#

If you don't know how to adjust the config yourself then yes

lethal dune
#

ok i'll contact them

#

thanks a lot

left tangle
#

Sure thing

lethal dune
#

Host return me that IP is not private

left tangle
#

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

lethal dune
#

i remove my webhook.php and add the clean code that stripe give me to try

left tangle
#

That is a good option as well

lethal dune
#

400ERR with the default file

left tangle
#

Can you give me the Event ID that you tested with?

lethal dune
#

evt_1MrLlfDyNb2IQXqaKpFU8yS6

left tangle
#

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?

lethal dune
#

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

left tangle
#

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

lethal dune
#

i check my other webhook file and the key is the same

left tangle
#

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

lethal dune
#
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 ?

left tangle
#

I'm not a PHP expert but not sure it will let you send a string here actually with http_response_code

left tangle
lethal dune
#

checkout.session.completed

#

Hoste remove "tiger protec"

left tangle
#

Sorry I don't understand

lethal dune
#

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

left tangle
#

Yep I see you responded to that Event successfully

lethal dune
#

Yes

#

but the next one was error

left tangle
#

Next event you triggered?

lethal dune
#

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...

left tangle
#

Okay so then seems that you are actually hitting that error.

#

Where is that response in your code?

lethal dune
#

400 ?

left tangle
#

Yeah the one that you said you removed and then added back and now you hit that error

#

Which error block is it in?

lethal dune
#

i dont know, when i change for a string, i have no error...

left tangle
#

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.

lethal dune
#

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

left tangle
#

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

lethal dune
#

// Invalid payload

OR

// Invalid signature

left tangle
#

Yep so which one?

lethal dune
#

As i said, i dont know

#

Ok

left tangle
#

Add an echo right before your http_response_code

lethal dune
#

I changed 400 with another code

#

100 and 600

left tangle
#
  // Invalid payload
  echo '⚠️  Webhook error while parsing basic request.';
  http_response_code(400);
  exit();
}```
lethal dune
#

600 is returned

#

So

#
  // Invalid signature
  http_response_code(600);
  exit();
}`````

Invalid signature
#

Event : evt_1MrME3DyNb2IQXqa4iZnmppR

delicate tartanBOT
left tangle
#

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

lethal dune
#

Ok

#

where can i find my secret ?

#

Click on reveal ?

left tangle
#

Yep

lethal dune
#

It works

#

I replace this key several time

#

...

#

thanks a lot for your patience !