<?php

	header('Content-Type: application/json');
	ini_set('display_startup_errors',1);
	ini_set('display_errors',1);
	error_reporting(1);
	ini_set("log_errors", 1);
	ini_set("error_log", "php-error.log");

	date_default_timezone_set('Asia/Kolkata');

	require_once("database.php");



	class PaymentList
	{
		private $conn;

		function __Construct()
		{
			$dbconnect = new Database();
			$this->conn = $dbconnect->getConnection();

		}


		function getPaymentList()
		{

		   try{

				$stmt  = $this->conn->prepare("select a.id, a.refer_id, a.email_id, a.order_id,  a.total_amount, a.payment_date, a.cheque_no, a.txn_no,
				a.bank_name, a.processing_fees, a.amount_received, b.name, b.last_name from my_payment_info as a left join my_registration as b on a.refer_id=b.refer_id order by a.payment_date DESC");
				$stmt->execute();
				$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
			 	return $result;
			
			  }catch(Exception $err){

				return 0;

			  } 
		
		}


		function getPaymentData($id)
		{

		   try{

				$stmt  = $this->conn->prepare("select a.id, a.refer_id, a.email_id, a.order_id, a.total_amount, a.payment_date, a.cheque_no, a.txn_no,
				a.bank_name, a.processing_fees, a.amount_received, b.name, b.last_name from my_payment_info as a left join my_registration as b on a.refer_id=b.refer_id where a.id='$id' order by a.payment_date DESC");
				$stmt->execute();
				$result = $stmt->fetch(PDO::FETCH_ASSOC);
			 	return $result;
			
			  }catch(Exception $err){

				return 0;

			  } 
		
		}


    }

	$result = array();
	$payment = new PaymentList();

	if(!empty($_REQUEST['payment_id']))
		$paymentList = $payment->getPaymentData($_REQUEST['payment_id']);

	else
		$paymentList = $payment->getPaymentList();

	$result['success'] = true;
	$result['message'] = "Success";
	$result['paymentList'] = $paymentList;
	echo json_encode($result);



?>

