在Laravel中实现Gocardless Webhook [英] Implement Gocardless webhook in Laravel

查看:121
本文介绍了在Laravel中实现Gocardless Webhook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在laravel中实现一个Webhook.

I was trying to implement a webhook in laravel.

我已经创建了访问令牌并且还创建了Webhook端点.

I have created access token and created webhook endpoint also.

我的webhook端点就像 https://www.example.com/gocardless.php

my webhook end point is like,https://www.example.com/gocardless.php

我的路线就像

Route::get('/gocardless.php', 
'\App\Http\Controllers\gocardlessController@remote')->name('remote');

类似的控制器代码,

class gocardlessController extends Controller
 {


  public function remote(Request $request)
  {

 $token ="token";

 $raw_payload = file_get_contents('php://input');

 $headers = getallheaders();


 $provided_signature = $headers["Webhook-Signature"];
 $calculated_signature = hash_hmac("sha256",$raw_payload,$token);
 if ($provided_signature == $calculated_signature) {

  $payload = json_decode($raw_payload, true);
   }
   }
   } 

但是当我点击以gocardless帐户发送测试Webhook时,他们会得到"405未找到方法"作为响应.

But when i clik on send test webhook in gocardless account,they are given "405 no method found" as responce.

我该如何解决?

推荐答案

The HTTP 405 error you're seeing indicates that your Laravel application doesn't know how to handle the method of the incoming request.

定义路由,以请求到端点的POST请求将收到网络响声.

GoCardless webhooks use the POST method to send you a request with a JSON body, but the route you've written is for handling a GET request (Route::get). To resolve this, you should define a route for POST requests to the endpoint which will receive webhooks.

这篇关于在Laravel中实现Gocardless Webhook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆