<?php
/*
	--------------------
	--> DOCUMENTITION <--
	--------------------
	## Class :: ManageContractAddDaysToNextBillDt
	--------------------
	R :: required 
	O :: optional 
	--------------------
	## Valid fields ::   
	> UserName :: username || R 
	> Password :: password || R
	> Vendor :: merchant id || R
	> CustomerKey :: customer id || R
	> ContractKey :: unique key for Contract || R
	> NumOfDays :: The number of days to be added to the Next-Bill date || R || integer
	
	
	
	--------------------
	## Response :: 
	success ::  Array([ContractKey] =>  -- ,[CustomerKey] => -- ,[Vendor] =>  -- ,[code] =>  OK ,[error] =>  OK ,[Username] =>  -- )
	error ::  Array ( [code] =>  Not_Enough_Privilege ,[error] =>  Not enough privilege to access this merchant )
	--------------------
	## Sample code :: 
	> creating 
	$return = \Encgateway\ManageContractAddDaysToNextBillDt::create(array('UserName'=> 'test_emp','Password' => '123456','Vendor' => '107','CustomerKey' => '45','ContractKey' => '18','NumOfDays' => 10,'ExtData' => ''));

*/

namespace Encgateway;

class ManageContractAddDaysToNextBillDt extends ApiResource {
	
	public static $data = array(); 
	
	public static $processors = "ManageContractAddDaysToNextBillDt";
	
	/* 
		validate parameter for add update and delete payment method  
	*/
	public static function validParams($param){
		$rule = array(
			'UserName' => 'required',
			'Password' => 'required',
			'Vendor' => 'required',
			'CustomerKey' => 'required',
			'ContractKey' => 'required',
			'NumOfDays' => 'required|integer',
		);
		if(isset($param['ApiToken']) ) {
			unset($rule['UserName']);
			unset($rule['Password']);
		}
		$is_valid = GUMP::is_valid($param,$rule);
		
		return $is_valid;
	}
	
	
	/* 
		function for creating payment method 
	*/
	public static function create($params = null) {	
		self::$data['params'] 	= $params;
		self::$data['success'] 	= 0;
		self::$data['error'] 	= '';
		if(self::_validateArray($params)){
			if(Apib::getApiKey()) {
				$params['ApiToken'] = Apib::getApiKey();
			}
			$ret = self::validParams($params);
			if($ret == 1){
				$response = self::_doTrans($params,self::$processors);
				self::$data['response'] = $response; 
				if(isset($response['ContractKey']) && isset($response['CustomerKey']) && isset($response['Vendor'])) : 
					self::$data['success'] = 1;
				endif;
			}else{
				self::$data['error'] = $ret;
			}
			
		}else{
			self::$data['error']['invalid_argument'] = 'Array is not valid, You must pass array is argument.';
		}
		
		self::$data = self::responseFormat(self::$data,Apib::getOutputFormat());
		return self::$data;
    }
}