Remote server at mydomain.org returned an HTTP 302 when send test in coinbasecommerce webhook endpoint URL

i have this handleWebhook() function to receive coinbase webhook events

 public function handleWebhook(Request $request)
    {
         
        try {
        // Retrieve the webhook payload
      $payload = file_get_contents("php://input");
    
      $event = json_decode($payload, true);
      if (!$event) {
          return response()->json(['error' => 'Invalid JSON payload'], 400);
      }
           // Retrieve the transaction metadata
        $metadata = $event['data']['metadata'];

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

         $data = Deposit::where('trx', $trx)->orderBy('id', 'DESC')->first();
         $coinbaseAccwebhook = $data->gateway->val2;
     
        // Verify the signature
  
       $headerSignature = $_SERVER['HTTP_X_CC_WEBHOOK_SIGNATURE'];

        $isValidSignature = hash_hmac('sha256', $payload,$coinbaseAccwebhook ) === $headerSignature;
      
        if (!$isValidSignature) {
            return response()->json(['error' => 'Invalid signature'], 400);
        }else{
               // 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:confirmed') {

            if ($data->status == 0) {
                        $data->status = 1;
                        $data->save();

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

            }

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

            
        } 
       
        return response()->json(['success' => ' signature'], 200);
        
        }
   
    
    } catch (Exception $e) {
        return response()->json(['error' => 'An error occurred while processing the webhook'], 500);
    }


    }

here is route

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

here is exception csrf token for this route in verifyCsrfToken.php

 protected $except = [
        '/webhook/coinbase',
    ];

after that , i make send test in coinbasecommerce notification webhook endpoint URL . enter image description here

it show error

Remote server at mydomain returned an HTTP 302

is it coinbase server side error or not. if not what happening in my laravel code .

I test this code in live nginx AWS EC2 server with https domain .

I want to receive coinbase commerce webhook event correctly .

Can someone help me.

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 a code snippet you are using to receive Coinbase webhook events
  • Please provide a screenshot of the error code you are experiencing

If you have any more information or screenshots that can demonstrate your concern, feel free to share it with us. Please ensure to send any images or screenshots as attachments, as we’re unable to see images/screenshots when they are inserted in the body of your email and be reminded to omit any personal info.

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!

why not answer here.dont make bot reply.respect your user.this error make non sense.any error from coinbase side??why not simple.

Hi @kyawswarlin! Please be informed that submitting a ticket to our support team is the best way to investigate your concern and to see if there’s a coding issue.

Rest assured that you are not talking to a bot. Our team of dedicated support professionals is committed to providing you with the help you need and you can trust that we will work hard to resolve your problem.

As mentioned above, we suggest you to open a support ticket with our team with the following details to best address your concern:

  • Please provide a code snippet you are using to receive Coinbase webhook events
  • Please provide a screenshot of the error code you are experiencing

And if you have any additional information/screenshot that can demonstrate your concern, feel free to share it with us. Please ensure to send any images or screenshots as attachments, as we’re unable to see images/screenshots when they are inserted in the body of your email and be reminded to omit any personal info. Please include the link to this forum in your support ticket so that the team knows it’s you and please use the email address associated with your Coinbase account as well.

We appreciate your patience and understanding.

2 Likes