<?php

use Mtc\Plugins\Judopay\Classes\Judopay;

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

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

header('Content-Type: application/json');

$res = [];

if(empty($payment = $_POST) || empty($_SESSION['order_id'])) {
    http_response_code(401);
    die;
}

$order = new \Order($_SESSION["judopay-{$payment['yourPaymentReference']}"] ?? NULL ?: $_SESSION['order_id']);
Judopay::finalizePayment($_GET['method'] ?? 'form', $order, $payment);

$res['code'] = 200;
$res['redirect'] = Judopay::REDIRECT_URL;

echo json_encode($res);
die;
