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

class Payonline extends MY_Controller {

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

	}


	public function index()
	{
		$data['page'] 		= 'Home';
		$data['pageTitle'] 	= 'Log in';

		// print_r(getUserDetails()->data[0]->_id); 

		 $userid = $this->input->get('memberId'); 

		$data['servicesDetail'] = array();
		if($this->session->userdata('logged_in') == 1)
		{


			if ($userid == $this->session->userdata('id')) {
				

				$serviceId = $this->input->get('serviceId');

				$ch = curl_init();
				curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

				curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'].getServiceDetailbyId()['url']);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
				curl_setopt($ch, CURLOPT_POST, 1);
				curl_setopt($ch, CURLOPT_POSTFIELDS, "{          
					\"_id\": \"".$serviceId."\",          
					\"productId\":\" ".ApiBaseUrl()['productID']."\",           
					\"clientId\": \"".ApiBaseUrl()['clientID']."\",           
					\"username\":\"asdf\"        
				}");

				$headers = array();
				$headers[] = 'Content-Type: application/json';
				curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

				$result = curl_exec($ch);

				$response = json_decode($result);

				if (curl_errno($ch)) {
					echo 'Error:' . curl_error($ch);
				}

				if (isset($response) && $response->statusCode == 1 && !empty($response->data) ) {
					$data['servicesDetail'] = json_decode(json_encode($response->data[0]), true);
					$data['header_data'] = getWebSyncsData('Header Settings', 'headerSettings', '');
					$this->load->view('payonline/login',$data);	
				}else{
					echo 'Sorry! This Service in not available.';
				}
			}else{
				echo 'Sorry! This service is not requested by you.<br>';
				echo 'Go Back to<a href="'.base_url('services').'">  Home</a>';
			}

		}else{
			$data['header_data'] = getWebSyncsData('Header Settings', 'headerSettings', '');


		

			$this->load->view('payonline/login',$data);		
		}

	}

	
}
