#stephy

1 messages · Page 1 of 1 (latest)

rocky emberBOT
willow yew
#

Hi

amber jetty
#

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

willow yew
#

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.

amber jetty
#

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 ?

willow yew
#

For Stripe & webhook side this seems to work correctly, as it responded with 200 status

#

What is the issue you are having exactly ?

safe knoll
#

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?

amber jetty
#

issue is with backend code that i written where i check with the events so got issue there..

willow yew
#

What is the issue, you are still not sharing enough details ...

amber jetty
#

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.

light quiver
#

Hi! I'm taking over from my colleague. Please, give me a moment to catch up.

#

So is your own business logic not working?

amber jetty
#

yes

light quiver
#

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?

amber jetty
#

public function handleWebhook(Request $request)

#

this is my function

#

inside this whatever i gave is not working

light quiver
#

What do you mean by "not working" exactly?

amber jetty
#

to go to this function i create webhooks. with url stripe/webhook

light quiver
#

Sorry, I am not following. In order to help you I need a detailed description of the issue.

safe knoll
#

@amber jetty is your code inside the switch case executing or not? can do you add an echo or a dd and see?

amber jetty
#

thanks you