Oops! An Error Occurred The server returned a "405 Method Not Allowed". in coinbasecommerce webhook subscription endpoints URL

i try to make payment receive by coinbase commerce in laravel app ,i successfully make charge for coinbase commerce ,problem happen in webhook event subscriptions .

here is routes for webhook

  Route::post('/webhook',[App\Http\Controllers\HomeController::class, 'handleWebhook'])->name('charge.webhook');

POST method for webhoo event subscription and here is handleWebhook function

  public function handleWebhook(Request $request)
    {
         

        // Retrieve the webhook payload
        $payload = $request->getContent();
        $event = json_decode($payload, true);

           // Retrieve the transaction metadata
        $metadata = $event['data']['metadata'];

         // Retrieve the transaction charge ID from the metadata
         $trx = $metadata['trx'];

         $data = Deposit::where('trx', $trx)->sorderBy('id', 'DESC')->first();
         $coinbaseAccwebhook = $data->gateway->val2;
     
        // Verify the signature
    
        $headerSignature = $request->header('X-CC-Webhook-Signature');
        $isValidSignature = hash_hmac('sha256', $payload, $coinbaseAccwebhook) === $headerSignature;
        if (!$isValidSignature) {
            return response()->json(['error' => 'Invalid signature'], 400);
        }
    
     

       

        // Retrieve the transaction hash ID, amount, and status from the webhook event
        $transactionId = $event['data']['payments'][0]['transaction_id'];
        $amount = $event['data']['pricing']['local']['amount'];

  
        
    
        if ($event['type'] === 'charge:created') {

            $payment = new Payment;
            $payment['user_id'] = Auth::id();
            $payment['gateway_id'] = $data->gateway->id;
            $payment['trx'] =  $transactionId;
            $payment['amount'] =$data->amount;
            $payment['dpamount'] =$amount;
            $payment['trx_charge'] =$data->trx_charge;
            $payment['status'] = "pending";
            $payment->save();
          } 

        if ($event['type'] === 'charge:pending') {
            Payment::where('trx', $transactionId)
            ->where('user_id', Auth::id())
            ->update(['status' => "pending"]);
        } 
        if ($event['type'] === 'charge:confirmed') {
            if ($data->status == 0) {
                        $data->status = 1;
                        $data->save();

                        $user = User::find($data->user_id);
                        $user->balance += $amount-($data->trx_charge);
                        $user->save();

            }

            $message ='<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">Your Payment is received.</p>';

            sendSmtpMail($user['email'], 'Success Payment', $user['username'], $message);
       
          

            Payment::where('trx', $transactionId)
            ->where('user_id', Auth::id())
            ->update(['status' => "confirmed"]);

            
        } 
        if ($event['type'] === 'charge:resolved') {
           
            if ($data->status == 0) {
                $data->status = 1;
                $data->save();

                $user = User::find($data->user_id);
                $user->balance += $amount-($data->trx_charge);
                $user->save();

           }
          
           $message ='<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">Your Payment is received.but underpaid payment ,Admin resolved it by incoming amount.</p>';

           sendSmtpMail($user['email'], 'Success Payment ', $user['username'], $message);
       
           
            Payment::where('trx', $transactionId)
            ->where('user_id', Auth::id())
            ->update(['status' => "confirmed"]);

        }

    
    
        return response()->json(['status' => 'success']);
    }
    

when i send coin using this function, although coin received in coinbasecommerce , not work in event subscription , no event come out , what am i missing ,

here is webhook subscription endpoint url

https://mydomain/webhook

when i click thois link

Oops! An Error Occurred
The server returned a "405 Method Not Allowed".
Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.

can someone help me ,how to fix this . it look like handleWebhook function is ok but i not found why event not receive.

anyone please help me out

Welcome to the Coinbase Cloud Developer forum, @kyawswarlin! To further help you with your concern, we suggest you to open a support ticket with our team with the following details:

  • Please provide the code snippet you provided here to demonstrate the problem you are encountering including generating a Signature and Timestamp. Kindly ensure to exclude your API credentials for security reasons.

Upon creating a support ticket, kindly include the link of this forum so that the team will be aware that it’s you. Additionally, please use the email address associated with your Coinbase account. Thank you and have a nice day!

1 Like