PHP – TransFirst Payment Gateway

The given PHP Class helps you to make a 'Credit Card Sale Transaction with Standard Response'
with TransFirst Payment Gateway.

Code Example: Download Example
index.php
<?php
include "transfirst.class.php";
$tf_payment = new transfirst_payment();
$tf_payment->set_MerchantID("10011");
$tf_payment->set_RegKey("KK48NPYEJHMAH6DK");
$tf_payment->set_Amount("10.00");
$tf_payment->set_CardNumber("4111111111111111");
$tf_payment->set_CardHolderName("test");
$tf_payment->set_Expiration("1212"); // MMYY
$tf_payment->set_CVV2("123");
$tf_payment->set_RefID(rand());
$tf_payment->set_Address("12 St. Jon");
$tf_payment->set_ZipCode("92082");
$tf_payment->set_PaymentDesc("This is test paymnet");

$tf_response = $tf_payment->ccSettle();

preg_match("/Auth=(.*)&AVSCode=/Ui",$tf_response,$matches);
$Auth = $matches[1];
preg_match("/Notes=(.*)&User1=/Ui",$tf_response,$matches);
$Notes = $matches[1];

if($Auth=="" || $Auth=="Declined" ||  is_null($Auth)){
	echo "Card Declined: <br> Reason: $Notes";
}
else{
	echo "Card Accepted Successfully.";
}
?>
transfirst.class.php
<?php
class transfirst_payment{
	var $MerchantID;
	var $RegKey;
	var $Amount;
	var $TaxIndicator;
	var $SaleTaxAmount;
	var $PONumber;
	var $CardNumber;
	var $CardHolderName;
	var $CCMonth;
	var $CCYear;
	var $CVV2;
	var $RefID;
	var $Address;
	var $ZipCode;
	var $PaymentDesc;
	var $var;

	function set_MerchantID($value) {
		$this->MerchantID = urlencode($value);
	}
	function set_RegKey($value) {
		$this->RegKey = urlencode($value);
	}
	function set_Amount($value) {
		$this->Amount = $value;
	}
	function set_TaxIndicator($value) {
		$this->TaxIndicator = $value;
	}
	function set_SaleTaxAmount($value) {
		$this->SaleTaxAmount = $value;
	}
	function set_PONumber($value) {
		$this->PONumber = urlencode($value);
	}
	function set_CardNumber($value) {
		$this->CardNumber = $value;
	}
	function set_CardHolderName($value) {
		$this->CardHolderName = $value;
	}
	function set_CCMonth($value) {
		$this->CCMonth = $value;
	}
	function set_CCYear($value) {
		$this->CCYear = $value;
	}
	function set_CVV2($value) {
		$this->CVV2 = $value;
	}
	function set_RefID($value) {
		$this->RefID = $value;
	}
	function set_Address($value) {
		$this->Address = $value;
	}
	function set_ZipCode($value) {
		$this->ZipCode = $value;
	}
	function set_PaymentDesc($value) {
		$this->PaymentDesc = $value;
	}

	function ccSettle() {
    	$settle_data =  "MerchantID=" 		. $this->MerchantID .
						"&RegKey=" 			. $this->RegKey .
						"&Amount=" 			. $this->Amount .
						"&AccountNo=" 		. $this->CardNumber .
						"&CCMonth=" 		. $this->CCMonth .
						"&CCYear=" 			. $this->CCYear .
						"&CVV2=" 			. $this->CVV2 .
						"&RefID=" 			. $this->RefID;
		return $this->transFirst($settle_data);
	}

	function transFirst($auth_data) {
        $this->data = $auth_data;
        $this->url = 'https://webservices.primerchants.com/billing/TransactionCentral/processCC.asp?';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$this->url);
        curl_setopt($ch, CURLOPT_VERBOSE, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $this->data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        $this->response = curl_exec($ch);
		curl_close ($ch);
		return $this->response;
	}

} // end class
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *