<?php
class sandbox
{
	function __construct()
    {
       $this->Provider = "SANDBOX ViralPAY (674001044)";
	   uses_functions('random');
    }
	public function setData($data)
	{
		$this->receiveData = 
		$this->Data = $data;
	
	}
	function getStatus($current)
	{
		global $sgbd;
		
		if($current['ServiceCode']=='banque' or $current['ServiceCode']=='bank')
		{
			$query = "select * from banks where bank_number = '".$current['transaction_id']."'";
			
			$info = $sgbd->query($query)->row_array();
			if($info['Paid']==1) return "SUCCESS";
			elseif($info['Paid']==-1) return "FAILED";
			$jour3 = 3600*3*24;
			$delta = strtotime(datetime())-strtotime($current['Jour']);
			if($delta>$jour3) return 'Cancelled';
			
		}
		else
		{
			$current = $sgbd->query("select * from transactions where transaction_id ='".$current['transaction_id']."'")->row_array();
			$time = 
			$status = array('FAILED','Cancelled','Success');
			
			$delta = strtotime(datetime())-strtotime($current['Jour']);
			if($delta>3) return 'SUCCESS';
			if($delta>60) return 'SUCCESS';
			
			$r = rand(0,2);
			
		}
		
		return "PENDING";

	}
	function randomStatus()
	{
		$i = rand(1,6);
		switch($i)
		{
			case 1:
			case 2:
				$status = "FAILED";
			break;
			case 4:
			case 5:
			case 6:
				$status = "SUCCESS";
			break;
			default :
				$status = "FAILED";
		}
		return $status;
	}

    function Retrait()
	{
		$status = $this->randomStatus();
		
		$reponse = array
		(
			"transaction_id"=> $this->IDTransaction,
			"order_id"=> $this->Data['order_id'],
			"phone_number"=> $this->Data['international_phone'],
			"amount"=>$this->Data['amount_total'],
			"fees"=>$this->Data['fees'],
			"taxes"=>$this->Data['taxes'],
			"status"=>'PENDING',
			"reference_id"=> $this->Data['reference_id'],
			"provider_id"=> "SANDBOX-".random_number(8),
			"provider_code"=>"SANDBOX"
		);
		if($this->Data['operator']=='wave')
		{
			$reponse['provider_link']= "https://paydunya.com/sandbox-checkout/invoice/test_eXyyse5PuZ";
		}
		if(!empty($reponse)) $this->Return['reponse'] = $reponse;
		
	}
	
	function Depot()
	{
		$status = $this->randomStatus();
		$reponse = array
		(
			"transaction_id"=> $this->IDTransaction,
			"order_id"=> $this->Data['order_id'],
			"phone_number"=> $this->Data['international_phone'],
			"amount"=>$this->Data['amount'],
			"fees"=>$this->Data['fees'],
			"taxes"=>$this->Data['taxes'],
			"status"=>'PENDING',
			"reference_id"=> $this->Data['reference_id'],
			"provider_id"=> "SANDBOX-".random_number(8),
			"provider_code"=>"SANDBOX"
		);
		
		if(!empty($reponse)) $this->Return['reponse'] = $reponse;
	}
	function BankTransfert()
	{
		$status = 'PENDING';//$this->randomStatus();
		global $sgbd;
		
		$reponse= array
		(
			"amount"=>$this->Montant,
			"status"=>'PENDING',
			"transaction_id"=> $this->IDTransaction,
			"bank_account_number"=> $this->Data['bank_account_number'],
			"bank_account_name"=> $this->Data['bank_account_name'],
			"reference_id"=> $this->Reference,
			"provider_id"=> "BANK-".random_number(8),
			"uid"=> getUUID(),
			"sender_number"=> $this->Data['sender_number']
		);
		if(!empty($reponse)) $this->Return['reponse'] = $reponse;
	}
}



?>