<?php
class myFatoorah extends CFormModel
{
    public $type = 'myfatoorah';
    private $trType = 23;
    private $comment;

    public $action;
    private $token;
    private $NotificationOption = 'LNK';


    /* - ----- - - - - -- - - - - - - -*/
    public $CustomerName;
    public $DisplayCurrencyIso;
    public $MobileCountryCode;
    public $CustomerMobile;
    public $CustomerEmail;
    public $InvoiceValue;
    public $CallBackUrl;
    public $ErrorUrl;
    public $Language = 'en';
    public $CustomerReference;
    public $CustomerCivilId;
    public $UserDefinedField;
    public $ExpireDate;

    public $Address;

    public $ItemName;
    public $Quantity = 1;
    public $UnitPrice;

    /* - ----- - - - - -- - - - - - - -*/

    //response
    /*public $IsSuccess;
    public $Message;
    public $ValidationErrors;
    public $Data;*/

    // return
    public $paymentId;
    public $Id;
    public $IsSuccess;
    public $Message;
    public $Summary;
    public $InvoiceStatus;
    public $TransactionStatus;
    public $pc_type;
    /* - ----- - - - - -- - - - - - - -*/

    public $credentials = 'myfatoorah';
    private $cred_ar = [];

    private $currencies = array('USD'=>'USD', /*'AED'=>'AED', */'KWD'=>'KWD' /*,'SAR'=>'SAR'*/);

    public function rules(){
        return array(
            array('CustomerName, DisplayCurrencyIso, CustomerMobile, CustomerEmail, InvoiceValue, CallBackUrl, ErrorUrl, CustomerReference, CustomerCivilId, UserDefinedField, Address, ItemName, UnitPrice', 'required', 'on'=>'deposit', 'message'=> Yii::t("main","36_cannot_be_blank")),
            array('paymentId', 'required', 'on'=>'return', 'message'=> Yii::t("main","36_cannot_be_blank")),
            array('Id', 'safe', 'on'=>'return', 'message'=> Yii::t("main","36_cannot_be_blank")),
            array('IsSuccess, Message, InvoiceValue, InvoiceStatus, CustomerReference, Summary, UserDefinedField, TransactionStatus', 'safe', 'on'=>'return', 'message'=> Yii::t("main","36_cannot_be_blank")),

            //array('amount, currency, account', 'required', 'on'=>'return', 'message'=> Yii::t("main","36_cannot_be_blank")),
            //array('transactionId, status, description, amount, currency', 'required', 'on'=>'response', 'message'=> Yii::t("main","36_cannot_be_blank")),
        );
    }

    public function init()
    {
        /*$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
        if ($ip == '162.13.154.241') {
         var_dump($_SERVER['SERVER_NAME']);die();
        }*/

        $this->cred_ar = [
            //'myfatoorah' =>      ['trType' => 23, 'action' => '/payment/PaymentRedirect', 'ref' => 'my.swissfs.com'],
            'myfatoorah' =>      ['trType' => 42, 'action' => '/payment/PaymentRedirect', 'ref' => $_SERVER['SERVER_NAME']],
            'myfatoorah_acc2' => ['trType' => 24, 'action' => 'https://pay.oxygen-media.com/payment/PaymentRedirect', 'ref' => 'pay.oxygen-media.com'],
            'myfatoorah_acc3' => ['trType' => 25, 'action' => 'https://deposit.swiss-global.info/payment/PaymentRedirect', 'ref' => 'deposit.swiss-global.info'],
            'myfatoorah_acc4' => ['trType' => 23, 'action' => '/payment/PaymentRedirect', 'ref' => $_SERVER['SERVER_NAME']],
            //'myfatoorah_acc4' => ['trType' => 42, 'action' => '/payment/PaymentRedirect', 'ref' => 'my.swissfs.com'],
        ];

        //$this->action = 'https://apitest.myfatoorah.com';
        //$this->action = 'https://api.myfatoorah.com';
        //$this->token = "7Fs7eBv21F5xAocdPvvJ-sCqEyNHq4cygJrQUFvFiWEexBUPs4AkeLQxH4pzsUrY3Rays7GVA6SojFCz2DMLXSJVqk8NG-plK-cZJetwWjgwLPub_9tQQohWLgJ0q2invJ5C5Imt2ket_-JAlBYLLcnqp_WmOfZkBEWuURsBVirpNQecvpedgeCx4VaFae4qWDI_uKRV1829KCBEH84u6LYUxh8W_BYqkzXJYt99OlHTXHegd91PLT-tawBwuIly46nwbAs5Nt7HFOozxkyPp8BW9URlQW1fE4R_40BXzEuVkzK3WAOdpR92IkV94K_rDZCPltGSvWXtqJbnCpUB6iUIn1V-Ki15FAwh_nsfSmt_NQZ3rQuvyQ9B3yLCQ1ZO_MGSYDYVO26dyXbElspKxQwuNRot9hi3FIbXylV3iN40-nCPH4YQzKjo5p_fuaKhvRh7H8oFjRXtPtLQQUIDxk-jMbOp7gXIsdz02DrCfQIihT4evZuWA6YShl6g8fnAqCy8qRBf_eLDnA9w-nBh4Bq53b1kdhnExz0CMyUjQ43UO3uhMkBomJTXbmfAAHP8dZZao6W8a34OktNQmPTbOHXrtxf6DS-oKOu3l79uX_ihbL8ELT40VjIW3MJeZ_-auCPOjpE3Ax4dzUkSDLCljitmzMagH2X8jN8-AYLl46KcfkBV";
        //$this->token = "8vRQNS6dFFgTGOfHmHUeXKHOvMVNm2bFBwkQSQiBp8yn-DMWfJioAsE6-ANj_6Z74iZYettf4bU6zZLw7Hlw4UKSdB9aDIRAeJr_qXxRqxz8z-R1-26UDVgLZdwGKJzRMa09L-kCIfJ7loyRUmZlxiq3N1UCts2mOeaGSBU1V09W-kF91S_11NZK97pjcpnjrlVLjPn0nFNWioQzX_ltlEv5lpYRdHKstLAiv1tb2Ia7G-Y2Oyi9KppPTyD6gZmV9YoRxZWslfRKakTi710Fjvv60mm8VFaF342_Gzg5g5qoUJz0NHZh9V9aJV1jkZ6ClKRQBHMPUiP5xSoa1GWSpbolxor2Ak-gVWPQwHMpWKo_pwGFDmcdyCBVemuaSsu3wVlrd-Z60Bj1w_U0PN_EjKdPsFyHbRl3jWlP-vtm6j_vcPUxM9V_4Dt0G76F9wO-d6UdiHVpmw0JeQRK0NmGj7VUZgni7_KsvPQhLoKqshpRMprAwHfXw2xbGigUMhd9eV0AU2mGxIls_ZSccz1w9TzID2-_QtsCK0IoUV8TQzj9IJXqfT_zEn82mdsiivnZriumirF8pBRhzskhH1U6LIJsO2qeP5BB99l-a6G4ldO8TLg_FBPQi_4whYlShn5SUwMminQKJfLQGoeJIxFLwGfSwwXyeSqxwY3HCJGKrRilReb-";

//var_dump($this->getScenario());die();
        /*if ($_SERVER['REMOTE_ADDR'] == '46.98.64.234' || $_SERVER['REMOTE_ADDR'] == '46.98.252.74') {
            var_dump($this->getScenario());die();
        }*/

        if(strstr($this->getScenario(), '|')){
            $tmp = explode('|', $this->getScenario());
            if(isset($tmp[0])){
                $this->setScenario($tmp[0]);
            }

            if(isset($tmp[1])){
                $this->credentials = $tmp[1];
            }
        }

        $this->initCredentials();

//        if(wlParams::get('officeCode') == 44){
//            $ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
//            if ($ip == '162.13.154.241') {
//                $this->currencies['SAR'] = 'SAR';
//            }
//        }

    }

    public function initCredentials(){
        if($this->credentials == 'myfatoorah'){
            $this->token = Yii::app()->params['fatoorah_token'];
            $this->comment = Yii::app()->params['fatoorah_token_comment'] !== '' ? Yii::app()->params['fatoorah_token_comment'] : '';
            $this->action = Yii::app()->params['fatoorah_action'];
        }elseif($this->credentials == 'myfatoorah_acc2'){
            $this->token = Yii::app()->params['fatoorah_token_acc2'];
            $this->action = Yii::app()->params['fatoorah_action_acc2'];
        }elseif($this->credentials == 'myfatoorah_acc3'){
            $this->token = Yii::app()->params['fatoorah_token_acc3'];
            $this->action = Yii::app()->params['fatoorah_action_acc3'];
        }elseif($this->credentials == 'myfatoorah_acc4'){
            $this->token = Yii::app()->params['fatoorah_token_acc4'];
            $this->comment = Yii::app()->params['fatoorah_token_acc4_comment'] !== '' ? Yii::app()->params['fatoorah_token_acc4_comment'] : '';
            $this->action = Yii::app()->params['fatoorah_action_acc4'];
        }
        // $this->action = Yii::app()->params['fatoorah_action'];
    }

    public function getAttribute($name){
        return $this->$name;
    }

    public function attributeLabels(){
        return array(
            'CustomerReference' => Yii::t("main",'157_account'),
            'InvoiceValue' => Yii::t("funds",'9_amount'),
        );
    }

    public function initData($data)
    {
        $data2 = array();

        $Registration = new Registration('Individual');
        $countries_code_two = $Registration->GetCountry('two');
        $Registration->initIndv();

        $server = ((isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') ? 'https:' : 'http:').'//'.$_SERVER["SERVER_NAME"];
        $data2['data']['UserDefinedField'] = $this->UserDefinedField = uniqid();


        $data2['data']['DisplayCurrencyIso'] = $this->DisplayCurrencyIso = $data["currency"];
        $data2['data']['InvoiceValue'] = $this->InvoiceValue = $this->UnitPrice = (float)$data["amount"];
        $data2['data']['CustomerReference'] = $this->CustomerReference = $this->ItemName = (int)$data["transferTo"];

        if($data['currency'] !== 'KWD'){
            $this->InvoiceValue = $this->UnitPrice = round(stFunctions::currConv($this->DisplayCurrencyIso, 'KWD', $this->InvoiceValue), 2);
            $this->DisplayCurrencyIso = 'KWD';
        }

        $this->CustomerName = $Registration->firstName.' '.$Registration->lastName;
        $this->CustomerMobile = substr(str_replace(' ', '', $Registration->phone), -11);
        $this->CustomerEmail = $Registration->email;
        $this->Address = $Registration->address;
        $this->CallBackUrl = $server.'/fatoorahTrans?success&cred='.$this->credentials;
        $this->ErrorUrl = $server.'/fatoorahTrans?error&cred='.$this->credentials;

        /*if ($_SERVER['REMOTE_ADDR'] == '46.98.64.234' || $_SERVER['REMOTE_ADDR'] == '46.98.252.74') {
            var_dump($this->CustomerMobile);die();
        }*/

        if($this->credentials == 'myfatoorah_acc2' && Yii::app()->params['type'] == 'SwissSA'){
            $type = 'oxygen';
        }elseif($this->credentials == 'myfatoorah_acc3'){
            $type = 'global';
        }elseif($this->credentials == 'myfatoorah_acc4'){
            $type = 'gcc';
        }else{
            $type = Yii::app()->params['type'];
        }



        $data = [
            'NotificationOption' => $this->NotificationOption,
            'CustomerName' => $this->CustomerName,
            'DisplayCurrencyIso' => $this->DisplayCurrencyIso,
            'MobileCountryCode' => $this->MobileCountryCode,
            'CustomerMobile' => $this->CustomerMobile,
            'CustomerEmail' => $this->CustomerEmail,
            'InvoiceValue' => $this->InvoiceValue,
            'CallBackUrl' => $this->CallBackUrl,
            'ErrorUrl' => $this->ErrorUrl,
            'Language' => $this->Language,
            'CustomerReference' => $this->CustomerReference.'|'.$data2['data']['InvoiceValue'].'|'.$data2['data']['DisplayCurrencyIso'].'|'.$type,
            'CustomerCivilId' => '', //Yii::app()->user->id,
            'UserDefinedField' => $this->UserDefinedField,
            'ExpireDate' => '',
            'CustomerAddress' => [
                'Block' => '',
                'Street' => '',
                'HouseBuildingNo' => '',
                'Address' => $this->Address,
                'AddressInstructions' => '',
            ],
            'InvoiceItems' => [[
                'ItemName' => $this->ItemName,
                'Quantity' => $this->Quantity,
                'UnitPrice' => $this->UnitPrice,
            ]]
        ];


        $result = $this->getPaymentUrl($data);

        /*$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
        if ($ip == '162.13.154.241') {
            var_dump($result, $data);die();
        }*/

        if(isset($result['IsSuccess']) && $result['IsSuccess']){
            $data2['data']["link"] = $result['Data']['InvoiceURL'];

            $data2["action"] = $this->cred_ar[$this->credentials]['action'];
        }else{
            $f = fopen($_SERVER["DOCUMENT_ROOT"].'/protected/runtime/log/fatoorah.txt',"a");
            fwrite($f, date('Y-m-d H:i:s').' initData '.$this->credentials .' '.json_encode($result).'  ||||| '.json_encode($data).'<br/>\n
            ');

            $_SESSION['message'][] = array("text" => $result['Message'], "action" => Yii::app()->controller->id . "/" . Yii::app()->controller->action->id, "type" => "error");
        }

        //var_dump($result);die();
        //var_dump($data2);die();
        /* ----------------------------------------------------------- */



        //$data2["action"] = $data2['data']['link'];
        $data2["message"] = Yii::t("funds","446_you_will_redir_secure_payment");
        $data2['type'] = $this->credentials;


        return $data2;
    }

    private function getPaymentUrl($data) {

        /*if ($_SERVER['REMOTE_ADDR'] == '46.98.64.234' || $_SERVER['REMOTE_ADDR'] == '46.98.252.74') {
            var_dump($this->token);die();
        }*/

        $curl = curl_init();

        /*$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
        if ($ip == '162.13.154.241') {
            var_dump($this->action."/v2/SendPayment", $this->cred_ar[$this->credentials]['ref'], json_encode($data), array("Authorization: Bearer ".$this->token,"Content-Type: application/json"));die();
        }*/

        curl_setopt_array($curl, array(
            CURLOPT_URL => $this->action."/v2/SendPayment",
            CURLOPT_CUSTOMREQUEST => "POST",
            //CURLOPT_CONNECTTIMEOUT => 5,
            CURLOPT_REFERER => $this->cred_ar[$this->credentials]['ref'],
            //CURLOPT_POSTFIELDS => "{\"NotificationOption\":\"LNK\",\"CustomerName\": \"Ahmed\",\"DisplayCurrencyIso\": \"KWD\", \"MobileCountryCode\":\"+965\",\"CustomerMobile\": \"92249038\",\"CustomerEmail\": \"aramadan@myfatoorah.com\",\"InvoiceValue\": 100,\"CallBackUrl\": \"https://google.com\",\"ErrorUrl\": \"https://google.com\",\"Language\": \"en\",\"CustomerReference\" :\"ref 1\",\"CustomerCivilId\":12345678,\"UserDefinedField\": \"Custom field\",\"ExpireDate\": \"\",\"CustomerAddress\" :{\"Block\":\"\",\"Street\":\"\",\"HouseBuildingNo\":\"\",\"Address\":\"\",\"AddressInstructions\":\"\"},\"InvoiceItems\": [{\"ItemName\": \"Product 01\",\"Quantity\": 1,\"UnitPrice\": 100}]}",
            CURLOPT_POSTFIELDS => json_encode($data),
            CURLOPT_HTTPHEADER => array("Authorization: Bearer ".$this->token,"Content-Type: application/json"),

        ));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        $response = curl_exec($curl);
       /*  $err = curl_error($curl);
        $ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
        if ($ip == '162.13.154.241') {
            var_dump($this->action."/v2/SendPayment", json_encode($data), array("Authorization: Bearer ".$this->token,"Content-Type: application/json"), $response, $err);die();
        } */

        /*$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
        if ($ip == '162.13.154.241') {
            var_dump($response, $err, $this->action."/v2/SendPayment", $this->cred_ar[$this->credentials]['ref'], $this->token, $this->comment, $data);die();
        }*/

        curl_close($curl);



        return json_decode($response, true);
    }

    public function getPaymentStatus() {
        $curl = curl_init();

        $data = [
            'Key' => $this->paymentId,
            'KeyType' => 'PaymentId',
        ];

        curl_setopt_array($curl, array(
            CURLOPT_URL => $this->action."/v2/GetPaymentStatus",
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_REFERER => $this->cred_ar[$this->credentials]['ref'],
            CURLOPT_POSTFIELDS => json_encode($data),
            CURLOPT_HTTPHEADER => array("Authorization: Bearer ".$this->token,"Content-Type: application/json"),

        ));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        $response = json_decode(curl_exec($curl), true);
        $err = curl_error($curl);
        curl_close($curl);

        $f = fopen($_SERVER["DOCUMENT_ROOT"].'/protected/runtime/log/fatoorah.txt',"a");
        fwrite($f, date('Y-m-d H:i:s').' getPaymentStatus  '.$this->credentials .' '.$_SERVER['REMOTE_ADDR'].' '.date('Y-m-d H:i:s').' '.json_encode($response).'<br/>\n
		');


        $this->attributes = $response;
        if(isset($response["Data"])){
            $this->attributes = $response["Data"];
        }

        $lastTr = array_pop($response["Data"]['InvoiceTransactions']);

        $this->TransactionStatus = $lastTr['TransactionStatus'];
        $this->Message = $lastTr['Error'];

        /*if ($_SERVER['REMOTE_ADDR'] == '46.98.17.9' || $_SERVER['REMOTE_ADDR'] == '46.98.252.74') {
            var_dump(222, $this->TransactionStatus);die();
        }*/
        $tmp = explode('|',$this->CustomerReference);
        $this->CustomerReference = $tmp[0];
        $this->Summary = $tmp[1];
        $this->DisplayCurrencyIso = $tmp[2];
        $this->pc_type = $tmp[3];

        if ($_SERVER['REMOTE_ADDR'] == '46.98.17.9') {
            var_dump($response);die();
        }
        //var_dump($this->DisplayCurrencyIso);die();

        return $response;
    }


    public function newTransaction($accountID, $value, $transactionID, $currency = 'KWD', $Id = ''){

        //var_dump($this->cred_ar[$this->credentials]['trType'], $this->credentials);die();

        /*$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
        if ($ip == '162.13.154.241') {
            var_dump(Yii::app()->params['json_server'].'/API/Transactions/NewTransaction?guid='.Yii::app()->user->id.'&transactionID='.trim($transactionID).'&currency='.$currency.'&value='.$value.'&Id='.$Id.'&accountID='.$accountID.'&trType='.$this->cred_ar[$this->credentials]['trType']);die();
        }*/


        $Info = Yii::app()->curl->get(Yii::app()->params['json_server'].'/API/Transactions/NewTransaction?guid='.Yii::app()->user->id.'&transactionID='.trim($transactionID).'&currency='.$currency.'&value='.$value.'&Id='.$Id.'&accountID='.$accountID.'&trType='.$this->cred_ar[$this->credentials]['trType'].($this->comment !== '' ? '&comment='.$this->comment : '')); // $this->cred_ar[$this->credentials]['trType']

        /*$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
        if ($ip == '162.13.154.241') {
         var_dump($Info, Yii::app()->params['json_server'].'/API/Transactions/NewTransaction?guid='.Yii::app()->user->id.'&transactionID='.trim($transactionID).'&currency='.$currency.'&value='.$value.'&Id='.$Id.'&accountID='.$accountID.'&trType='.$this->cred_ar[$this->credentials]['trType'].($this->comment !== '' ? '&comment='.$this->comment : ''));die();
        }*/

        $f = fopen($_SERVER["DOCUMENT_ROOT"].'/protected/runtime/log/fatoorah.txt',"a");
        fwrite($f, date('Y-m-d H:i:s').' newFatoorahTransaction  '.$this->credentials .' '.Yii::app()->params['json_server'].'/API/Transactions/NewTransaction?guid='.Yii::app()->user->id.'&transactionID='.trim($transactionID).'&currency='.$currency.'&value='.$value.'&Id='.$Id.'&accountID='.$accountID.'&trType='.$this->cred_ar[$this->credentials]['trType'].($this->comment !== '' ? '&comment='.$this->comment : '').' ||||| '.json_encode($Info).'<br/>\n
		');

        return  $Info;
    }

    public function ApplyTransaction(){
        $Info = Yii::app()->curl->get(Yii::app()->params['json_server'].'/API/Transactions/ApplyMyFatoorahTransaction?errorcode='.($this->TransactionStatus == 'Succss' ? 'APPROVED' : 'ERROR').'&transactionid='.$this->UserDefinedField.'&depValue=0&currency=');

        //var_dump($Info, Yii::app()->params['json_server'].'/API/Transactions/ApplyMyFatoorahTransaction?errorcode='.($this->IsSuccess ? 'APPROVED' : 'ERROR').'&transactionid='.$this->UserDefinedField.'&depValue=0&currency=');die();

        $f = fopen($_SERVER["DOCUMENT_ROOT"].'/protected/runtime/log/fatoorah.txt',"a");
        fwrite($f, date('Y-m-d H:i:s').' ApplyFatoorahTransaction  '.$this->credentials .' '.Yii::app()->params['json_server'].'/API/Transactions/ApplyMyFatoorahTransaction?errorcode='.($this->TransactionStatus == 'Succss' ? 'APPROVED' : 'ERROR').'&transactionid='.$this->UserDefinedField.'&depValue=0&currency= ||||| '.json_encode($Info).'<br/>\n
		');

        //var_dump($Info, Yii::app()->params['json_server'].'/API/Transactions/ApplyMyFatoorahTransaction?errorcode='.($this->status == 'success' ? 'success' : 'error').'&transactionid='.$this->transactionId.'&depValue=0&currency=');die();

        return  $Info;
    }

    public function checkResponse()
    {
        return true;

    }



    /*public function showRedirectLink()
    {
        $server = ((isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') ? 'https:' : 'http:').'//'.$_SERVER["SERVER_NAME"];

        if(strstr($this->udf5, '_')){
            $tmp = explode('_', $this->udf5);
            if(isset($tmp[1]) && $tmp[1] === 44){
                $server = 'https://my.swissfs.sa.com';
            }elseif(isset($tmp[1]) && $tmp[1] === '44sifx'){
                $server = 'https://my.sifx.sa.com';
            }
        }

        return 'REDIRECT='.$server."/transaction.html?PaymentID=" . $this->paymentid . "&Result=" . $this->result . "&PostDate=" . $this->postdate . "&TranID=" . $this->tranid . "&Auth=" . $this->auth . "&Ref=" . $this->ref . "&TrackID=" . $this->trackid . "&UDF1=" . $this->udf1 . "&UDF2=" .$this->udf2  . "&UDF3=" . $this->udf3  . "&UDF4=" . $this->udf4 . "&UDF5=" . $this->udf5  ;
	}*/

    public function initResponse($data)
    {
        if(!empty($data)){
            $SignatureHandler = new SignatureHandler($this->getSecret());
            $this->Callback = new Callback($data, $SignatureHandler);


            $details = $this->Callback->getPayment();

            $this->transactionId = $this->Callback->getPaymentId();
            $this->status = $this->Callback->getPaymentStatus();
            $this->description = $details['description'];
            $this->amount = $details['sum']['amount'];
            $this->currency = $details['sum']['currency'];

        }
    }

}
