Location: PHPKode > scripts > TransFirst Payment Class > transfirst-payment-class/transfirst_payment_class.php
<?php
/**
 * TRANSFIRST_PAYMENT implements an interface called 'TFConsts' (tfconsts_int.php).
 * This interface contains some basic constants related to your merchant account.
 *
 * TRANSFIRST_PAYMENT contains four methods.
 * 
 * CCVERIFY is used for transactionCode '30' (authorization) transactions.
 * It takes five variables as input:
 * Credit card #, credit card exp month, credit card exp year,
 * billing street address, and billing zip code. The other fields
 * as seen are hard coded into the method and are unique to your
 * merchant account/situation. It builds a string in the format
 * required by TransFirst's eLink online payment processing service.
 * This string is passed to the transFirst method to process the
 * actual card transaction.
 *
 * You can see that we're passing a transactionAmount of 1 cent.
 * TransFirst requires an actual amount to post to the card for
 * verification. Funds posted to cards in a code '30' transaction
 * are dropped within 24 hours.
 *
 * CCSETTLE is used for transactionCode '32' (settlement) transactions.
 * It takes an array as input as seen below. The other fields as seen
 * are hard coded into the method and are unique to your merchant
 * account/situation. It builds a string in the format required by
 * TransFirst's eLink online payment processing service. This string
 * is passed to the transFirst method to process the actual card
 * transaction.
 *
 * TRANSFIRST takes a string formatted per TransFirst's specifications
 * and submits it to the eLink online payment processing service, using
 * cURL(1). The elink service then returns a pipe-delimited string detailing
 * whether the transaction was successful or failed, and why. This string
 * is broken down into its pertinent parts which are then loaded into properties
 * that will be available in the calling application through the use of the
 * getVars method. Many more items are available than referenced here.
 *
 * GETVARS takes a property name and returns that property's corresponding
 * value to the calling application.
 *
 * PLEASE SEE documentation provided by TransFirst when you sign up for ePay
 * for the full documentation on the ePay/eLink service. This class is by no
 * means a complete usage of all of the options available through this service.
 *
 * - 1 (from http://us3.php.net/manual/en/curl.requirements.php):
 * In order to use PHP's cURL functions you need to install the ยป libcurl package.
 * PHP requires that you use libcurl 7.0.2-beta or higher. In PHP 4.2.3, you will
 * need libcurl version 7.9.0 or higher. From PHP 4.3.0, you will need a libcurl
 * version that's 7.9.8 or higher. PHP 5.0.0 requires a libcurl version 7.10.5 or greater.
 *
 * Copyright 2009 Geoff Foley
 * Distributed under the terms of the GNU General Public License
 * http://www.gnu.org/licenses/gpl-3.0.txt
 */

require('tfconsts_int.php');

class transfirst_payment implements TFConsts {

	public function ccVerify($ccNo,$ccExpMo,$ccExpYr,$billAdd1,$billZip) {
        $verify_data = "ePayAccountNum=".TFConsts::TFAccountNumber."&".
                       "password=".TFConsts::TFAccountPassword."&".
                       "transactionCode=30&".
                       "orderNum=ccVerification&".
                       "transactionAmount=0.01&".
                       "cardAccountNum={$ccNo}&".
                       "expirationDate={$ccExpMo}{$ccExpYr}&".
                       "cardHolderZip={$billZip}&".
                       "cardHolderAddress={$billAdd1}&".
                       "InstallmentNum=01&".
                       "InstallmentOf=01&".
                       "eCommerce=Y&".
                       "testTransaction=N";
        $this->transFirst($verify_data);
    }

    public function ccSettle($settleDataArray) {
        $settle_data = "ePayAccountNum=".TFConsts::TFAccountNumber."&".
                       "password=".TFConsts::TFAccountPassword."&".
                       "transactionCode=32&".
                       "orderNum={$settleDataArray["orderNum"]}&".
                       "transactionAmount={$settleDataArray["transactionAmount"]}&".
                       "cardAccountNum={$settleDataArray["cardAccountNum"]}&".
                       "expirationDate={$settleDataArray["expirationDate"]}&".
                       "cardHolderZip={$settleDataArray["cardHolderZip"]}&".
                       "InstallmentNum=01&".
                       "InstallmentOf=01&".
                       "cardHolderName={$settleDataArray["cardHolderName"]}&".
                       "cardHolderAddress={$settleDataArray["cardHolderAddress"]}&".
                       "cardHolderCity={$settleDataArray["cardHolderCity"]}&".
                       "cardHolderState={$settleDataArray["cardHolderState"]}&".
                       "cardHolderEmail={$settleDataArray["cardHolderEmail"]}&".
                       "cardHolderPhone={$settleDataArray["cardHolderPhone"]}&".
                       "customerNum={$settleDataArray["customerNum"]}&".
                       "CVV2={$settleDataArray["CVV2"]}&".
                       "eCommerce=Y&".
                       "testTransaction=N&".
                       "MerchantCustServNum=".TFConsts::MerchantCustServNum."&".
                       "duplicateChecking=Y&".
                       "PaymentDescriptor=".TFConsts::PaymentDescriptor."&".
                       "TaxIndicator={$settleDataArray["TaxIndicator"]}&".
                       "TotalTaxAmount={$settleDataArray["TotalTaxAmount"]}";
        $this->transFirst($settle_data);
    }

	public function transFirst($auth_data) {
        $this->data = $auth_data;
        $this->url = 'https://epaysecure1.transfirst.com/elink/authpd.asp';
        $this->ch = curl_init();
        curl_setopt($this->ch, CURLOPT_URL,$this->url);
        curl_setopt($this->ch, CURLOPT_VERBOSE, 0);
        curl_setopt($this->ch, CURLOPT_POST, 1);
        curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->data);
        curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,1);
        $this->authorize = curl_exec($this->ch);
        curl_close ($this->ch);
        $this->response = split('\|', $this->authorize);
        $this->trans_status = explode('|', $this->response[10]);
        $this->tf_trans_status = $this->trans_status[0];
        $this->trans_refno = explode('|', $this->response[13]);
        $this->tf_trans_refno = $this->trans_refno[0];
        $this->avs_response = explode('|', $this->response[21]);
        $this->avs_response_code = $this->avs_response[0];
        $this->ext_trans_status = explode('|', $this->response[26]);
        $this->tf_ext_trans_status = $this->ext_trans_status[0];
	}

    public function getVars($var) {
		return $this->$var;
	}
}
?>
Return current item: TransFirst Payment Class