<?php
    
class upayApi
{

    private string $_table = 'shop_orders';
    private string $primaryKey = 'order_id';


    public  $endpoint = 'http://sandbox-api.via.uz/';
    private $client_id = '';
    private $client_secret = '';


    public $param;
    public $method;
    
    
    public function __construct()
    {  
        $request_body  = file_get_contents('php://input');
        $this->param = json_decode($request_body, true);  
                    
    }
    

    /**
     * Authorizes session and handles requests.
     */
    public function setParams()
    {
        if ($this->param) {
            $result = connect($this->_table)->select('order_id, amount, status')
                ->where($this->primaryKey, $this->param['personalAccount'])
                ->where('amount', $this->param['upayPaymentAmount'])->get('array');

            if ($result) {
                $this->send(1, "Успешно");
            } else {
                $this->send(0,  "Клиент с таким номером не найден.");
                
            }
            
        }
         
        
    }
  
    
    public function send($result, $message = null)
    {
        header('Content-Type: application/json; charset=UTF-8');

        $response['status']  = $result;
        $response['message'] = $message;

        echo json_encode($response);
    }
    
}
    