<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Payment extends MY_Controller {

    function __construct() {
        parent::__construct();
    }

    function index() {
        
        $tran = array(
            'merchantID' => '101599',
            'action' => 'SALE',
            'type' => '1',
            'currencyCode' => '826',
            'amount' => 1010,
            'countryCode' => '826',
            'transactionUnique'=>'33467',
            'orderRef'=>'Offer37Fresh7Blame',
            'cardNumber' => '4929 4212 3460 0821',
            'cardExpiryDate'=>'1220',
            'cardCVV'=>'356',
        );
        
        ksort($tran);
        $str= http_build_query($tran,'','&');
        $str=str_replace(array('%0D%0A','%0A%0D','%0D'),'%0A',$str);
        $str.='Offer37Fresh7Blame';
        $signature=hash('SHA512',$str);
        $tran['signature']=$signature;
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $tran);
        curl_setopt($curl, CURLOPT_URL, 'https://gateway.retailmerchantservices.co.uk/direct/');
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($curl);
        curl_close($curl);
        $result = urldecode($result);
        parse_str($result,$result);
        debugPrint($result);
        //responseCode=66343&responseMessage=ERROR+CODE+%28RC_INVALID_SIGNATURE%29&responseStatus=2
        //responseCode=66087&responseMessage=ERROR+CODE+%28RC_MISSING_SIGNATURE%29&responseStatus=2

       
    }

}
