#Temple

1 messages · Page 1 of 1 (latest)

high magnetBOT
viral notch
#

👋 happy to help

tall vessel
#

Hey

viral notch
#

400s are bad requests, meaning that there's something wrong in the params you sent

#

do you have a request ID I can take a look at?

tall vessel
#

So taking a look at the response i am getting this is what i recieve ```Stripe\Exception\SignatureVerificationException: No signatures found matching the expected signature for payload in C:\Projects\WebServer\www_php_includes\stripe-php\lib\Exception\SignatureVerificationException.php:28

#

In our logs it does not show and failed requests

#

only in our webhooks

#

I have event ids if that helps

viral notch
tall vessel
#
    exit;

  require 'stripe-php/init.php';

  // The library needs to be configured with your account's secret key.
  // Ensure the key is kept out of any version control system you might be using.
  $stripe = new \Stripe\StripeClient(STRIPE_PRIVATE_KEY);

  // This is your Stripe CLI webhook secret for testing your endpoint locally.
  $endpoint_secret = 'whsec_***';

  $payload = @file_get_contents('php://input');
  
  $sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
  $event = null;

  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
    echo $e;
    http_response_code(400);
    exit();
  }

  // Handle the event
  switch ($event->type) {
    case 'checkout.session.async_payment_failed':
    $session = $event->data->object;
    case 'checkout.session.async_payment_succeeded':
    $session = $event->data->object;
    case 'checkout.session.completed':
    $session = $event->data->object;
    // ... handle other event types
    default:
    echo 'Received unknown event type ' . $event->type;
  }

  http_response_code(200);``` I have commented out our endpoint secret, here is the code we are using
viral notch
#

it seems ok

#

maybe the secret is wrong

#

you need to get the secret from the terminal after running stripe listen --forward-to

tall vessel
#

I will look into the secret, give me a moment

#

It appears the secret was incorrect however now we are getting a different 400 error Stripe\Exception\SignatureVerificationException: Timestamp outside the tolerance zone

viral notch
#

what's the event ID?

tall vessel
#

evt_1MgkXXLOGsYi0T0ccQnEKNf7

#

We use UTC time and confirmed the time is in sync with Stripe so we are not too sure where to go from here

viral notch
#

still taking a look just give me a second

#

basically you can't retry an event past a certain time

tall vessel
#

Im guessing the reason for the error is I see all the tests are being done with the same event id

#

I tried again with a different event id and we are getting a time difference of 3648

#

evt_1Mgm91LOGsYi0T0cmg4GM0qm

dreamy turtle
#

well there's two possible reasons

#

one is your server's clock is out of sync and is running slow/fast compared to the actual time

#

the other is that you are manually sending an old copy of the event to your server for testing instead of triggering new events from Stripe directly

tall vessel
#

This is the code we have for the time

#

We have fixed the issue by manually adding 1 hour

dreamy turtle
dreamy turtle
tall vessel
#

Asking my dev right now, I will get back to you when he responds

dreamy turtle
#

ah ok I thought we were talking to the dev, this server is for dev questions

tall vessel
#

Here is the updated code

dreamy turtle
#

he other is that you are manually sending an old copy of the event to your server for testing instead of triggering new events from Stripe directly
can you clarify that too

dreamy turtle
tall vessel
tall vessel
dreamy turtle
#

so is the issue resolved?

tall vessel
#

Yes this issue has been resolved. We are now getting success codes

#

Thank you

dreamy turtle
#

great!