<?php

use Illuminate\Support\Facades\Log;
use Mtc\Plugins\RyftPay\Classes\RyftPay;

$path = '../../../';

require_once $path . 'core/includes/header.inc.php';

$payload = @file_get_contents('php://input');

try {
    $event = json_decode($payload, true);
    if (empty($event)) {
        throw new UnexpectedValueException('Empty payload');
    }
    Log::debug(print_r($event, true));
    RyftPay::processWebhookRequest($event);
} catch (UnexpectedValueException|Exception $e) {
    // Invalid payload
    return response('', 400);
}
