<?php

header("Expires: 0");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

header('Content-Type: text/event-stream');
header("Content-Type: application/json; charset=UTF-8");

error_reporting(1);


require_once 'PaymentSystem.php';
require_once('Crypter.php');
require_once('../DAL/DAL.php');
require_once('../DAL/sms/SendMessage.php');
$payment = new PaymentSystem(new SendMessage(), new DAL('constant.php'), new crypter());
// get the HTTP method, path and body of the request
try {
    $method = $_SERVER['REQUEST_METHOD'];
    if (isset($_SERVER['PATH_INFO'])) {
        $request = explode('/', trim($_SERVER['PATH_INFO'], '/'));
        $input = json_decode(file_get_contents('php://input'), true);
        if (count($request) > 0) {
            $count = (int)preg_replace('/[^a-z0-9_]+/i', '', array_shift($request));
            if ($count >= 3 && count($request) == $count && $payment->ValidateRequest($count, $request)) {
                $payment->Set($request)->Run();
            } else {
                //property not exist
                $payment->error();
            }
        } else {
            //property not exist
            $payment->error();
        }
    } else {
        //property not exist
        $payment->error();
    }
} catch (Exception $e) {
    $payment->error();
}