<?php namespace TPS\Birzha\Classes;

use TPS\Birzha\Models\Settings;

class Senagat extends Payment
{
    protected function getApiCredentials()
    {
        return [
            'userName' => Settings::getValue('api_login_senagat'),
            'password' => Settings::getValue('api_password_senagat'),
        ];
        
    }

    protected function getApiUrl()
    {
        return 'https://epg.senagatbank.com.tm/epg/rest/';
    }

    protected function getRegistrationUri()
    {
        return 'register.do';
    }

    protected function getStatusUri()
    {
        return 'getOrderStatus.do';
    }

    protected function registerOrderParams($payment, $url)
    {
        return [
            'orderNumber'     => strtoupper(str_random(5)) . date('jn'),
            'amount'      => $payment->amount * 100, //multiply by 100 to obtain tenge
            'currency' => 934,
            'description' => 'Balansa pul goşmak - Birža şahsy otag',
            'returnUrl' => $url,
        ];
    }

    public function checkRegisterOrderErrorCode($registerOrderResponse)
    {
        return !isset($registerOrderResponse['errorCode']);
    }

    public function checkReturnUrlParams($returnUrlParams, $payment)
    {
        if($payment) {
            return true;
            
        } else {
            return false;
        }
    }

    public function checkOrderStatusResponseCodes($orderStatusResponse)
    {
        return $orderStatusResponse['ErrorCode'] == 0 && $orderStatusResponse['OrderStatus'] == 2;
    }
}