我第一次使用Webhooks进行测试。我想建立一个Webhook(使用GoCardless.com)。
我在沙箱帐户中创建了一个访问令牌和Webhook端点。 URL - http://test.com/remote_gocardless
我的路线是,
Route::post('/remote_gocardless','remotegocardlessController@remote')->name('remote');
控制器是,
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
class remotegocardlessController extends Controller
{
public function remote()
{
$token ="tunnelnew";
$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);
foreach ($payload["events"] as $event) {
switch ($event["resource_type"]) {
case "mandates":
process_mandate_events($event);
break;
case "payments":
process_payment_events($event);
break;
case "subscriptions":
process_subscription_events($event);
break;
}
}
header("HTTP/1.1 200 OK");
} else {
header("HTTP/1.1 498 Invalid Token");
}
}
}
沙盒帐户中的响应就像, 500内部服务器错误。
我是否需要添加任何其他代码才能在laravel中实现webhook? 我们可以将网址设为http而不是https吗?