<?php
class Payment extends CI_Controller{

    public function index($module='')
	{
		if(empty($module)){
			redirect('payment/bkash');
				exit();
		}
		if($module=='bkash'){
			$this->__acl_payment_bkash();
		} else if($this->gateway_model->exists($module)) {
            $this->__acl_payment_dynamic($module);
        } else show_404();
	}

	private function __acl_payment_dynamic($slug) {
        $request = $this->input->get(NULL, TRUE);
        if(isset($request['acl']) && !empty($request['acl'])) {
            $transaction = @base64_decode($request['acl']);
            if($this->session->userdata('logged') && $this->transaction_model->existsByTransactionUnpaid($transaction)) {
                if($transaction = $this->transaction_model->getByTransaction($transaction)) {
                    $this->__StoreCredentials($transaction, $this->aclKey($slug), $slug);
                } else show_404();
            } else show_404();
        } else {
            $gateway = $this->gateway_model->get($slug);
            $paymentTypeId = isset($request["paymenttypeid"]) && !empty($request["paymenttypeid"]) ? $request["paymenttypeid"] : "";
            $transId = isset($request["transid"]) && !empty($request["transid"]) ? $request["transid"] : "";
            $userId = isset($request["userid"]) && !empty($request["userid"]) ? $request["userid"] : "";
            $userType = isset($request["usertype"]) && !empty($request["usertype"]) ? $request["usertype"] : "";
            $transactionType = isset($request["transactiontype"]) && !empty($request["transactiontype"]) ? $request["transactiontype"] : "";
            $invoiceIds = isset($request["invoiceids"]) && !empty($request["invoiceids"]) ? $request["invoiceids"] : "";
            $debitNoteIds = isset($request["debitnoteids"]) && !empty($request["debitnoteids"]) ? $request["debitnoteids"] : "";
            $description = isset($request["description"]) && !empty($request["description"]) ? $request["description"] : "";
            $sellingCurrencyAmount = isset($request["sellingcurrencyamount"]) && !empty($request["sellingcurrencyamount"]) ? $request["sellingcurrencyamount"] : "";
            $accountingCurrencyAmount = isset($request["accountingcurrencyamount"]) && !empty($request["accountingcurrencyamount"]) ? $request["accountingcurrencyamount"] : "";
            $redirectUrl = isset($request["redirecturl"]) && !empty($request["redirecturl"]) ? $request["redirecturl"] : "";
            $checksum = isset($request["checksum"]) && !empty($request["checksum"]) ? $request["checksum"] : "";
            $key = $gateway->resellbizkey;
            $name = isset($request["name"]) && !empty($request["name"]) ? $request["name"] : "";
            $emailAddr = isset($request["emailAddr"]) && !empty($request["emailAddr"]) ? $request["emailAddr"] : "";
            $telNo = isset($request["telNo"]) && !empty($request["telNo"]) ? $request["telNo"] : "";
            $resellerCurrency = strtolower(isset($request["resellerCurrency"]) && !empty($request["resellerCurrency"]) ? $request["resellerCurrency"] : "");

            $data = array($paymentTypeId, $transId, $userId, $userType, $transactionType, $invoiceIds, $debitNoteIds, $description, $sellingCurrencyAmount, $accountingCurrencyAmount, $key);
            $defaultCurrency = $this->currency_model->getDefault(true);

            if(!empty($checksum) && !empty($key) && verifyChecksum($checksum, $data) && $sellingCurrencyAmount>0 && $sellingCurrencyAmount==$accountingCurrencyAmount) {
                if(!empty($transId) && $defaultCurrency && !empty($resellerCurrency) && strtolower($defaultCurrency->currency)==strtolower($resellerCurrency) ) {
                    if($this->transaction_model->existsByTransactionUnpaid($transId) || $this->transaction_model->existsByTransactionUnpaidRequested($transId)) {
                        if($transaction = $this->transaction_model->getByTransaction($transId)) {
                            $this->__StoreCredentials($transaction, $this->aclKey($slug), $slug);
                        } else show_404();
                    } else if(!$this->transaction_model->existsByTransaction($transId)) {
                        $bdtamount = currencyConvertToBDT($sellingCurrencyAmount, $defaultCurrency->rate);
                        $gatewaycharges = $gateway->charge>0?calculateCharges($bdtamount, $gateway->charge):0;
                        if($bdtamount>0){
                            $transaction = array (
                                "aclreference" => $this->transaction_model->generateReference(),
                                "aclbdtamount" => $bdtamount,
                                "aclgatewayfee" => $gatewaycharges,
                                "aclmethod" => $gateway->slug,
                                "paymenttypeid" => $paymentTypeId,
                                "transid" => $transId,
                                "userid" => $userId,
                                "usertype" => $userType,
                                "transactiontype" => $transactionType,
                                "invoiceids" => $invoiceIds,
                                "debitnoteids" => $debitNoteIds,
                                "description" => $description,
                                "sellingcurrencyamount" => $sellingCurrencyAmount,
                                "accountingcurrencyamount" => $accountingCurrencyAmount,
                                "redirecturl" => $redirectUrl,
                                "checksum" => $checksum,
                                "name" => $name,
                                "emailAddr" => $emailAddr,
                                "telNo" => $telNo,
                                "resellerCurrency" => $resellerCurrency
                            );
                            if($this->transaction_model->store($transaction)) {
                                if($transaction = $this->transaction_model->getByTransaction($transId)) {
                                    $this->__StoreCredentials($transaction, $this->aclKey($slug), $slug);
                                } else echo show_404();
                            } else show_404();
                        } else show_404();
                    } else show_404();
                } else show_404();
            } else if($this->session->has_userdata($this->aclKey($slug))) {
                $request = $this->session->userdata($this->aclKey($slug));
                if($this->transaction_model->existsByTransactionUnpaid($request->transid)) {
                    $data = array();
                    $maxupload = 7*1024;
                    $maxserver = aclServerUploadMax('K');
                    $data['uplimit'] = $maxserver > 0 ? ( $maxserver >= $maxupload ? $maxupload : $maxserver ) : 2048;
                    $data['gateway'] = $gateway;
                    $fields = @json_decode($gateway->fields, true);
                    $data['fields'] = array();
                    $data['fields_required'] = array();
                    $fieldsSort = explode(',', $gateway->fields_sort);
                    $data['validation_error'] = array();
                    $flaq = false;
                    foreach ($fieldsSort as $fs) {
                        if(array_key_exists($fs, $fields)) {
                            if(array_key_exists("enable", $fields[$fs]) && $fields[$fs]["enable"]=="on") {
                                $data['fields'][$fs] = $fields[$fs];
                                if(array_key_exists("required", $fields[$fs]) && $fields[$fs]["required"]=="on") {
                                    $data['fields_required'][] = $fs;
                                    if($fs!=='docupload') {
                                        $this->form_validation->set_rules($fs, $fields[$fs]['label'], 'trim|required');
                                        $flaq = true;
                                    }
                                }
                            }
                        }
                    }
                    $data['transaction'] = $request;
                    $data['slug'] = $slug;
                    if($this->form_validation->run() === FALSE && $flaq) {
                        $data['validation_error'] = $this->form_validation->error_array();
                        if(!empty($data['validation_error']) && in_array('docupload', $data['fields_required']) && (!isset($_FILES['docupload']['name']) || empty($_FILES['docupload']['name']))) {
                            $data['validation_error']['docupload'] = 'The '.xss_clean( $data['fields']['docupload']['label'] ).' field is required';
                        }
                    } else {
                        $error = false;
                        $update = array();
                        $pdata = $this->input->post(NULL, TRUE);
                        foreach ($data['fields'] as $fkey => $fval) {
                            if($fkey!='docupload') {
                                switch ($fkey) {
                                    case 'trxid':
                                        $update['acltrxid'] = array_key_exists($fkey, $pdata) && !empty($pdata[$fkey]) ? xss_clean(html_escape($pdata[$fkey])) : '';
                                        break;
                                    case 'senderac':
                                        $update['aclmethodnote'] = array_key_exists($fkey, $pdata) && !empty($pdata[$fkey]) ? xss_clean(html_escape($pdata[$fkey])) : '';
                                        break;
                                    case 'trxnote':
                                        $update['acldescription'] = array_key_exists($fkey, $pdata) && !empty($pdata[$fkey]) ? xss_clean(html_escape($pdata[$fkey])) : '';
                                        break;
                                }
                            }
                        }

                        if(array_key_exists('docupload', $data['fields'])) {
                            if(isset($_FILES['docupload']['name']) && !empty($_FILES['docupload']['name'])) {

                                $config = array();
                                $config['upload_path'] = FCPATH . 'private';
                                $config['allowed_types'] = 'png|jpg|gif|doc|docx|pdf';
                                $config['max_size'] = $data['uplimit'];
                                $config['remove_spaces'] = true;
                                $config['encrypt_name'] = true;
                                $this->load->library('upload', $config);

                                if($this->upload->do_upload('docupload')) {
                                    $ud = $this->upload->data();
                                    $update['acldocupload'] = 'private/'.$ud['file_name'];
                                } else {
                                    $error = true;
                                    $data['validation_error']['docupload'] = $this->upload->display_errors('', '');
                                }

                            } else if(in_array('docupload', $data['fields_required'])) {
                                $error = true;
                                if(isset($_FILES) && !empty($_FILES)) {
                                    $data['validation_error']['docupload'] = 'The '.xss_clean( $data['fields']['docupload']['label'] ).' field is required';
                                }
                            }
                        }
                        if(!$error) {
                            $update['aclrequested'] = '1';
                            $update['aclstatus'] = 'N';
                            if ($this->transaction_model->storePayment($request->transid, $request->aclreference, $update)) {
                                if(!empty($to = $this->settings_model->get('gatewayalert'))) {
                                    $from = 'no-replay@'.aclGetDomain();
                                    $subject = "Pending Approval ".xss_clean(html_escape($request->name))." (".$gateway->name.")";
                                    $amount = isset($request->aclbdtamount) ? $request->aclbdtamount : 0;
                                    $amount += isset($request->aclgatewayfee) ? $request->aclgatewayfee : 0;
                                    $amount = number_format($amount, 2, '.', '');

                                    $mail = "<p>The following Transaction has been initiated by your Customer/Sub-Reseller ".xss_clean(html_escape($request->name)).". However, the transaction is still pending.<p>";
                                    $mail .= "<p><h4><u>Transaction Details:</u></h4>ID - ".$request->transid."<br>Reference - ".$request->aclreference."<br>Amount - ".$amount." BDT</p>";
                                    $mail .= "<br><p><h4><u>Payment Details:</u></h4></p>";

                                    foreach ($data['fields'] as $fkey => $fval) {
                                        if($fkey!='docupload') {
                                            $mail .= "<p><b>".xss_clean($fval['label'])."</b><br>".(array_key_exists($fkey, $pdata) && !empty($pdata[$fkey]) ? xss_clean(html_escape($pdata[$fkey])) : 'N/A')."</p>";
                                        } else if($fkey=='docupload') {
                                            $mail .= "<p><b>".xss_clean($fval['label'])."</b><br>".(array_key_exists('acldocupload', $update) && !empty($update['acldocupload']) ? 'The file is attached to this email. However, if any problems arise, please use the following link to download it directly,<br><a href="'.base_url($update['acldocupload']).'">'.base_url($update['acldocupload']).'</a>' : 'N/A')."</p>";
                                        }
                                    }

                                    $mail .= "<br><p>You may choose to review it and either approve or cancel it using the instructions below -</p>";
                                    $mail .= "<p>1. Click on below URL ( Login if required )</p>";
                                    $mail .= '<p><a href="'.base_url('lbadmin/transaction/'.$request->aclreference).'">'.base_url('lbadmin/transaction/'.$request->aclreference).'</a>';
                                    $mail .= "<p>2. Review the transaction and Click on Pay or Cancel Transaction</p>";

                                    $this->load->library('email');
                                    $this->email->initialize(array('mailtype'=>'html'));
                                    $this->email->from($from, $request->name);
                                    $this->email->to($to);
                                    $this->email->subject($subject);
                                    $this->email->message($mail);
                                    if( array_key_exists('acldocupload', $update) && !empty($update['acldocupload']) ) {
                                        $this->email->attach(FCPATH . $update['acldocupload']);
                                    }
                                    $this->email->send();
                                }
                                redirect('payment/'.$slug);
                            } else {
                                $data['validation_error']['common'] = 'Transaction Failed Please Try Again';
                            }
                        }
                    }
                    $this->load->view('dynamic/index', $data);
                } else if($this->transaction_model->existsByTransactionUnpaidRequested($request->transid)) {
                    $data = array();
                    $data['gateway'] = $gateway;
                    $data['transaction'] = $request;
                    $this->load->view('dynamic/pending', $data);
                } else {
                    $this->__CleanCredentials('payment/'.$slug, $this->aclKey($slug));
                }
            }
            else show_404();
        }

    }

	private function __acl_payment_bkash() {
        $request = $this->input->get(NULL, TRUE);
        if(isset($request['acl']) && !empty($request['acl'])) {
            $transaction = @base64_decode($request['acl']);
            if($this->session->userdata('logged') && $this->transaction_model->existsByTransactionUnpaid($transaction)) {
                if($transaction = $this->transaction_model->getByTransaction($transaction)) {
                    $this->__StoreCredentials($transaction);
                } else show_404();
            } else show_404();
        } else {
            $paymentTypeId = isset($request["paymenttypeid"]) && !empty($request["paymenttypeid"]) ? $request["paymenttypeid"] : "";
            $transId = isset($request["transid"]) && !empty($request["transid"]) ? $request["transid"] : "";
            $userId = isset($request["userid"]) && !empty($request["userid"]) ? $request["userid"] : "";
            $userType = isset($request["usertype"]) && !empty($request["usertype"]) ? $request["usertype"] : "";
            $transactionType = isset($request["transactiontype"]) && !empty($request["transactiontype"]) ? $request["transactiontype"] : "";
            $invoiceIds = isset($request["invoiceids"]) && !empty($request["invoiceids"]) ? $request["invoiceids"] : "";
            $debitNoteIds = isset($request["debitnoteids"]) && !empty($request["debitnoteids"]) ? $request["debitnoteids"] : "";
            $description = isset($request["description"]) && !empty($request["description"]) ? $request["description"] : "";
            $sellingCurrencyAmount = isset($request["sellingcurrencyamount"]) && !empty($request["sellingcurrencyamount"]) ? $request["sellingcurrencyamount"] : "";
            $accountingCurrencyAmount = isset($request["accountingcurrencyamount"]) && !empty($request["accountingcurrencyamount"]) ? $request["accountingcurrencyamount"] : "";
            $redirectUrl = isset($request["redirecturl"]) && !empty($request["redirecturl"]) ? $request["redirecturl"] : "";
            $checksum = isset($request["checksum"]) && !empty($request["checksum"]) ? $request["checksum"] : "";
            $key = $this->settings_model->get('bkrskey');
            $name = isset($request["name"]) && !empty($request["name"]) ? $request["name"] : "";
            $emailAddr = isset($request["emailAddr"]) && !empty($request["emailAddr"]) ? $request["emailAddr"] : "";
            $telNo = isset($request["telNo"]) && !empty($request["telNo"]) ? $request["telNo"] : "";
            $resellerCurrency = strtolower(isset($request["resellerCurrency"]) && !empty($request["resellerCurrency"]) ? $request["resellerCurrency"] : "");

            $data = array($paymentTypeId, $transId, $userId, $userType, $transactionType, $invoiceIds, $debitNoteIds, $description, $sellingCurrencyAmount, $accountingCurrencyAmount, $key);
            $defaultCurrency = $this->currency_model->getDefault(true);
            $bkashCharges = $this->settings_model->get('bkashcharge');

            if(!empty($checksum) && !empty($key) && verifyChecksum($checksum, $data) && $sellingCurrencyAmount>0 && $sellingCurrencyAmount==$accountingCurrencyAmount) {
                if(!empty($transId) && $defaultCurrency && !empty($resellerCurrency) && strtolower($defaultCurrency->currency)==strtolower($resellerCurrency) ) {
                    if($this->transaction_model->existsByTransactionUnpaid($transId)) {
                        if($transaction = $this->transaction_model->getByTransaction($transId)) {
                            $this->__StoreCredentials($transaction);
                        } else show_404();
                    } else if(!$this->transaction_model->existsByTransaction($transId)) {
                        $bdtamount = currencyConvertToBDT($sellingCurrencyAmount, $defaultCurrency->rate);
                        $gatewaycharges = $bkashCharges>0?calculateCharges($bdtamount, $bkashCharges):0;
                        if($bdtamount>0){
                            $transaction = array (
                                "aclreference" => $this->transaction_model->generateReference(),
                                "aclbdtamount" => $bdtamount,
                                "aclgatewayfee" => $gatewaycharges,
                                "aclmethod" => "bkash",
                                "paymenttypeid" => $paymentTypeId,
                                "transid" => $transId,
                                "userid" => $userId,
                                "usertype" => $userType,
                                "transactiontype" => $transactionType,
                                "invoiceids" => $invoiceIds,
                                "debitnoteids" => $debitNoteIds,
                                "description" => $description,
                                "sellingcurrencyamount" => $sellingCurrencyAmount,
                                "accountingcurrencyamount" => $accountingCurrencyAmount,
                                "redirecturl" => $redirectUrl,
                                "checksum" => $checksum,
                                "name" => $name,
                                "emailAddr" => $emailAddr,
                                "telNo" => $telNo,
                                "resellerCurrency" => $resellerCurrency
                            );
                            if($this->transaction_model->store($transaction)) {
                                if($transaction = $this->transaction_model->getByTransaction($transId)) {
                                    $this->__StoreCredentials($transaction);
                                } else echo show_404();
                            } else show_404();
                        } else show_404();
                    } else show_404();
                } else show_404();
            } else if($this->session->has_userdata('bkashtransaction')) {
                $request = $this->session->userdata('bkashtransaction');
                if($this->transaction_model->existsByTransactionUnpaid($request->transid)) {
                    $data = array();
                    $this->form_validation->set_rules('bkashtrxid', 'bKash Transaction ID', 'trim|required|callback_TransactionApproval');
                    $this->form_validation->set_rules('bkashpaymethod', 'bKash Payment Method', 'trim|required|callback_VerifyBkashMethods');
                    if($this->form_validation->run() === FALSE){
                        unset($request);
                        $data['validation_error'] = implode('<br>', $this->form_validation->error_array());
                    } else {
                        if($transaction = $this->transaction_model->getByTransaction($request->transid)) {
                            $request = $transaction;
                            $trxID = $this->input->post('bkashtrxid');
                            $method = $this->input->post('bkashpaymethod');
                            $parse = $this->bKashRemote($trxID);
                            $reference = isset($request->aclreference) ? $request->aclreference : "";
                            $amount = isset($request->aclbdtamount) ? $request->aclbdtamount : 0;
                            $amount += isset($request->aclgatewayfee) ? $request->aclgatewayfee : 0;
                            $disableExprie = isset($request->acldisableexpire) && $request->acldisableexpire == 1 ? true : false;
                            if (isset($parse['transaction']['trxId']) &&
                                isset($parse['transaction']['trxStatus']) &&
                                isset($parse['transaction']['amount']) &&
                                isset($parse['transaction']['reference']) &&
                                isset($parse['transaction']['trxTimestamp']) &&
                                $parse['transaction']['trxStatus'] == "0000") {
                                if ((time() - (strtotime($parse['transaction']['trxTimestamp']))) < 86400 || $disableExprie) {
                                    if ($trxID == $parse['transaction']['trxId']) {
                                        if (number_format($amount, 2, '.', '') == $parse['transaction']['amount']) {
                                            if(!empty($reference) && $parse['transaction']['reference'] == $reference) {
                                                if($parse['transaction']['reversed'] == '0') {
                                                    if($this->transaction_model->storePayment($request->transid, $reference, array(
                                                        "acltrxid" => $parse['transaction']['trxId'],
                                                        "acldescription" => @json_encode($parse),
                                                        "aclmethodnote" => $method
                                                    ))) {
                                                        $acl_transId = $request->transid;
                                                        $acl_sellingCurrencyAmount = number_format(currencyConvertFromBDT($request->aclbdtamount, $defaultCurrency->rate), aclCalPLen($request->sellingcurrencyamount), '.', '');
                                                        $acl_accountingCurrencyAmount = $acl_sellingCurrencyAmount;
                                                        $acl_status = 'Y';
                                                        $acl_rKey = generateRkey();
                                                        $acl_checksum = generateChecksum(array($acl_transId, $acl_sellingCurrencyAmount, $acl_accountingCurrencyAmount, $acl_status, $acl_rKey, $key));
                                                        $acl_parameters = generateURLParameter(array(
                                                            "transid" => $acl_transId,
                                                            "status" => $acl_status,
                                                            "rkey" => $acl_rKey,
                                                            "checksum" => $acl_checksum,
                                                            "sellingamount" => $acl_sellingCurrencyAmount,
                                                            "accountingamount" => $acl_accountingCurrencyAmount
                                                        ));
                                                        $acl_redirect = $request->redirecturl.'?'.$acl_parameters;
                                                        $this->__CleanCredentials($acl_redirect);
                                                    } else {
                                                        $data['validation_error'] = 'System Error. Payment cannot be made';
                                                    }
                                                } else {
                                                    $data['validation_error'] = 'Maybe the payment has already been reversed';
                                                }
                                            } else {
                                                $data['validation_error'] = 'Invalid Payment Reference';
                                            }
                                        } else {
                                            $data['validation_error'] = 'Invalid Payment Amount';
                                        }
                                    } else {
                                        $data['validation_error'] = 'Invalid Transaction ID';
                                    }
                                } else {
                                    $data['validation_error'] = 'Transaction Expired. Contact support department';
                                }
                            } else {
                                $data['validation_error'] = $this->translateBkashError(isset($parse['transaction']['trxStatus']) ? $parse['transaction']['trxStatus'] : 0);
                            }
                        } else {
                            $data['validation_error'] = $request->transid.' The transaction has been canceled';
                        }
                    }
                    $this->load->view('bkash/index', $data);
                } else {
                    $this->__CleanCredentials('payment/bkash');
                }
            }
            else show_404();
        }
	}

	public function TransactionApproval($trxid) {
        $this->form_validation->set_message('TransactionApproval', 'Transaction already associated');
        return (!$this->transaction_model->existsByTrxId($trxid));
    }

    public function VerifyBkashMethods($method){
        $this->form_validation->set_message('VerifyBkashMethods', 'Invalid bKash Method');
        $methods = array('#bkash_app', '#mob_ussd');
        return in_array($method, $methods);
    }

    private function bKashRemote($trxId) {
        $cUrl = curl_init("https://www.bkashcluster.com:9081/dreamwave/merchant/trxcheck/sendmsg");

        $ctx = json_encode(array(
            "user" => $this->settings_model->get('bkashusername'),
            "pass" => $this->settings_model->get('bkashpassword'),
            "msisdn" => $this->settings_model->get('bkashmerchant'),
            "trxid" => $trxId
        ));


        curl_setopt($cUrl, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($cUrl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($cUrl, CURLOPT_POSTFIELDS, $ctx);
        curl_setopt($cUrl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($cUrl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($cUrl, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json',
                'Content-Length: ' . strlen($ctx)
            )
        );

        $cExec = curl_exec($cUrl);
        $jArr = json_decode($cExec, true);
        return $jArr;
    }


    private function translateBkashError($error) {
        $translate = array(
            '0000' => array (
                'c' => '0000',
                't' => 'Transaction Successful',
            ),
            '0010' => array (
                'c' => '0010',
                't' => 'Transaction Pending',
            ),
            '0011' => array (
                'c' => '0010',
                't' => 'Transaction Pending',
            ),
            '0100' => array (
                'c' => '0100',
                't' => 'Transaction Reversed',
            ),
            '0111' => array (
                'c' => '0111',
                't' => 'Transaction Failure',
            ),
            '1001' => array (
                'c' => '1001',
                't' => 'Invalid Merchant Account',
            ),
            '1002' => array (
                'c' => '1002',
                't' => 'Invalid trxID',
            ),
            '1003' => array (
                'c' => '1003',
                't' => 'Authorization Failed',
            ),
            '1004' => array (
                'c' => '1004',
                't' => 'Authorization Failed',
            )
        );

        $static = array(
            '9999' => 'System Error',
            '4001' => 'Try Again After 10 minutes'
        );

        $default = 'System Failure. Unkown Error';

        return array_key_exists($error, $translate) ? ( !empty($x = $this->settings_model->get('bkasherror'.$translate[$error]['c'])) && isset($x) ? $x : $translate[$error]['t'] ) : ( array_key_exists( $error, $static) ? $static[$error] : $default );
    }

	private function __StoreCredentials($transaction, $key='bkashtransaction', $slug='bkash') {
        $this->session->set_userdata($key, $transaction);
        redirect('payment/'.$slug);
    }

    private function aclKey($slug) {
        return md5('dynamictransaction'.$slug);
    }

    private function __CleanCredentials($redirect, $key='bkashtransaction') {
        $this->session->unset_userdata($key);
        redirect($redirect);
    }
}