<?php

namespace App\Http\Controllers;

use App\Services\GenericPaymentGatewayService;
use Illuminate\Http\Request;

class PaymentWebhookController extends Controller
{
    public function __invoke(Request $request, GenericPaymentGatewayService $gateway)
    {
        $payload = $request->all();
        $signature = $request->header('X-Signature') ?? $request->header('X-RaseedNow-Signature');

        abort_unless($gateway->verifyWebhook($payload, $signature), 403);

        $gateway->applyWebhook($payload);

        return response()->json(['ok' => true]);
    }
}
