I'm testing using Webhooks for the first time. I want to set up a Webhook (using GoCardless.com).
I have created a acces token and Webhook endpoints in my sandbox account. URL-http://test.com/remote_gocardless
My route is,
Route::post('/remote_gocardless','remotegocardlessController@remote')->name('remote');
Controller is,
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");
}
}
}
response in sandbox account is like, 500 Internal Server Error.
Is there is any other code i have to add for implementing webhook in laravel? Can we give url as http instead of https?