#stephy
1 messages · Page 1 of 1 (latest)
Hi
hi.. i create a webhooks and try to mange in back end also .. this is my evnt id :- evt_1Nvc8NEZ1Pyl4W3kT0h4XbfO
and my issue is i gave some switch cases and inside the case i wriiten insert query but in backend these are not working
in backend these are not working
What is not working exactly ?
What I can see is your webhook endpoint responded with 200
Which is good
You probably need to double check your query insert in your backend
that has no link with Stripe APIs
That's your own integration.
public function handleWebhook(Request $request)
{
$keys = PaymentCredentials::where('mode_active', '1')->where('type_payment', 'stripe')->first();
\Stripe\Stripe::setApiKey($keys->secret_key);
$stripe = new \Stripe\StripeClient($keys->secret_key);
$endpoint_secret = 'whsec_xxxxxx';
// $stripeSignature = $request->header('HTTP_STRIPE_SIGNATURE');
// dd($stripeSignature);
$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
\Log::error('UnexpectedValueException: ' . $e->getMessage());
return response('', 400);
} catch (\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
\Log::error('SignatureVerificationException: ' . $e->getMessage());
return response('', 400);
}
switch ($event->type)
case 'checkout.session.completed':
$session = $event->data->object
// WebhookEvent::create([
// 'type' => $event->type,
// 'payload' => $payload, // Save the payload if needed
// 'event_details' => json_encode($session), // Store event details
// ]);
DB::table('webhook_events')->insert([
'type' => $event->type,
'payload' => $payload,
]);
default:
echo 'Received unknown event type ' . $event->type;
}
return response('');
}
this is what i written
is this is correct ?
For Stripe & webhook side this seems to work correctly, as it responded with 200 status
What is the issue you are having exactly ?
have you tried adding a dd inside the switch case? and what is the data type for the payload column? try adding a `try catch block for your switch and see if there is any error
are you using Laravel?
issue is with backend code that i written where i check with the events so got issue there..
What is the issue, you are still not sharing enough details ...
i create webhooks and which is ok when i check in stripe dashboard. now my concern is i need to update the status of payment in backend so i written some code for that .ehich i given above ..to mange these events i gave switch commands but that is not working.
Hi! I'm taking over from my colleague. Please, give me a moment to catch up.
So is your own business logic not working?
yes
I don't know how you business logic works so it's hard for me to investigate this for you.
What's exactly not working?
public function handleWebhook(Request $request)
this is my function
inside this whatever i gave is not working
What do you mean by "not working" exactly?
to go to this function i create webhooks. with url stripe/webhook
Sorry, I am not following. In order to help you I need a detailed description of the issue.
@amber jetty is your code inside the switch case executing or not? can do you add an echo or a dd and see?
thanks you