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

class Home extends CI_Controller {
	public function index()
	{
		$data=array();
		if (!empty($this->input->post())) {
			$data['txnid'] = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
			// $data['txnid'] = 50123;
		    $data['email'] = $this->input->post('email');
		    $data['phone'] = $this->input->post('phone');
		    $data['firstname'] = $this->input->post('firstname');
		    $data['lastname'] = $this->input->post('lastname');
		    $data['amount'] = $this->input->post('amount');
		    $data['productinfo'] = "Payment By User";
		    $data['key'] = MERCHANT_KEY;
		    $data['hash']         = '';
		    //Below is the required format need to hash it and send it across payumoney page. UDF means User Define Fields.
		    $hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
		    $hashVarsSeq = explode('|', $hashSequence);
		    $hash_string = '';  
		   	foreach($hashVarsSeq as $hash_var) {
		      $hash_string .= isset($data[$hash_var]) ? $data[$hash_var] : '';
		      $hash_string .= '|';
		    }

		    $hash_string .= SALT;
		    $data['post'] = $this->input->post();
		    $data['hash'] = strtolower(hash('sha512', $hash_string));
		    $data['action'] = PAYU_BASE_URL . '/_payment';        
		    $data['posted']=$data;
			$this->load->view('homepage',$data);
		}else{
			$this->load->view('homepage2',$data);
		}
	}

	public function order_success() {
		if (!empty($this->input->post())) {
	    	$this->load->view('status', $this->input->post());
		}

	}

	public function order_fail() {
		if (!empty($this->input->post())) {
	    	$this->load->view('status', $this->input->post());
		}

	}

}
