#native_company# #native_desc#
#native_cta#

pfpro.class – verisign payflowpro class

By Ori Staub
on August 1, 2002

Version: 0.1.1

Type: Class

Category: Shopping Carts

License: GNU General Public License

Description: A class for use with the verisign pfpro extension.

Ability to fully manage credit card transactions online using Verisign pfpro.

Includes, sale, authorize, capture, credit and more. Support for AVS (Address Verification)

<?php
/**
* Verisign pfpro class
* Verisign pfpro payment processing class
* 
* copyright (c) 2002 Ori Staub, Zucker and Staub Ltd You may use, modify and distribute
* this class freely provided this original copyright header remains intact.
* Any questions or comments, email ori_at_chikki_dot_net
* 
* version 0.1.1
*/
class pfpro {
        
    var $host;
    var $port;
    var $timeout;
    var $proxyaddress;
    var $proxyport;
    var $proxyuser;
    var $proxypassword;
    
    var $transaction; // Array to hold transaction
    var $result; // Results

    // Constructor
    function pfpro() {
        $this->transaction = Array();
        $this->result = Array();
        
        $this->transaction['VENDOR']  = "VENDOR";   /* case-sensitive login. */
        $this->transaction['USER']    = "USER";     /* case-sensitive. Use your login for this parameter. In future releases you will be able to use this parameter to create multiple users for a single account. */
        $this->transaction['PWD']     = "PASSWORD"; /* Case-sensitive password */
        $this->transaction['PARTNER'] = "VeriSign"; /* This field is case-sensitive. Your partner ID is provided to you by the authorized VeriSign Reseller who signed you up for the Payflow Pro service. If you signed up yourself, use VeriSign. */
        
        $this->host = "test-payflow.verisign.com";
        $this->port = 443;
        $this->timeout = 30;
        $this->proxyaddress = null;
        $this->proxyport = null;
        $this->proxyuser = null;
        $this->proxypassword = null;
    }


    /**
     * @return void
     * @param amount float
     * @param card_no int
     * @param exp_month int
     * @param exp_year int
     * @desc Charge and settle a transaction using a credit card.
     */
    function sale($amount, $card_no, $exp_month, $exp_year) {
        $this->transaction['TRXTYPE'] = "S";
        $this->transaction['TENDER'] = "C";
        $this->transaction['AMT'] = sprintf("%.2f", $amount);
        $this->transaction['ACCT'] = ereg_replace("[^0-9]","",$card_no);
        $this->transaction['EXPDATE'] = $exp_month . substr($exp_year, -2);
    }
    

    /**
     * @return void
     * @param amount float
     * @param card_no int
     * @param exp_month int
     * @param exp_year int
     * @desc Authorize a credit card for later settlement.
     */
    function authorize($amount, $card_no, $exp_month, $exp_year) {
        $this->transaction['TRXTYPE'] = "A";
        $this->transaction['TENDER'] = "C";
        $this->transaction['AMT'] = sprintf("%.2f", $amount);
        $this->transaction['ACCT'] = ereg_replace("[^0-9]","",$card_no);
        $this->transaction['EXPDATE'] = $exp_month . substr($exp_year, -2);
    }
    
    
    /**
     * @return void
     * @param PNREF string
     * @param amount float
     * @desc Request a settlement from a previous authorization request. Optional amount to specify a lower or higher (additional charges apply) amount
     */
    function capture($PNREF, $amount = "") {
        if ($amount != "") {
            // Specify lower amount to capture if supplied
            $this->transaction['AMT'] = $amount;    
        }
        $this->transaction['TRXTYPE'] = "D";
        $this->transaction['TENDER'] = "C";
        $this->transaction['ORIGID'] = $PNREF;
    }
    
    
    /**
     * @return void
     * @param PNREF string
     * @param amount float
     * @param card_no int
     * @param exp_month int
     * @param exp_year int
     * @desc Issue a credit. Either using original PNREF or a credit card
     */
    function credit($PNREF = "", $amount = "", $card_no = "", $exp_month = "", $exp_year = "") {
        if (!$PNREF && !$card_no) {
            print "You must supply either a card no or original transaction PNREF to issue a credit";
            return 0;    
        }
        if ($amount) {
            // Specify lower amount to capture if supplied
            $this->transaction['AMT'] = $amount;    
        }
        if ($PNREF) {
            $this->transaction['ORIGID'] = $PNREF;
        } elseif ($card_no) {
            $this->transaction['ACCT'] = ereg_replace("[^0-9]","",$card_no);
            $this->transaction['EXPDATE'] = $exp_month . substr($exp_year, -2);
        }
        $this->transaction['TRXTYPE'] = "C";
        $this->transaction['TENDER'] = "C";        
    }

    
    /**
     * @return void
     * @param PNREF string
     * @desc A void prevents a transaction from being settled. A void does not release the authorization (hold on funds) on the cardholder account
     */
    function void_sale($PNREF) {
        $this->transaction['TRXTYPE'] = "V";
        $this->transaction['TENDER'] = "C";
        $this->transaction['ORIGID'] = $PNREF;
    }
    
    
    /**
     * @return void
     * @param avs_address string
     * @param avs_zip int
     * @desc Optional, used for AVS check (Address Verification Service)
     */
    function AVS($avs_address = "", $avs_zip = "") {
        $this->transaction["STREET[".strlen($avs_address)."]"] = $avs_address;
        $this->transaction['ZIP'] = ereg_replace("[^0-9]","",$avs_zip);
    }
    
    
    function comments($comment1 = "", $comment2 = "") {
        $this->transaction["COMMENT1[".strlen($comment1)."]"] = $comment1;
        $this->transaction["COMMENT2[".strlen($comment2)."]"] = $comment2;
    }
    

    /**
     * @return array
     * @desc Process the transaction. Result contains the response from Verisign.
     */
    function process() {
        pfpro_init();
        $this->result = pfpro_process($this->transaction,$this->host,$this->port,$this->timeout,$this->proxyaddress,$this->proxyport,$this->proxyuser, $this->proxypassword);
        pfpro_cleanup();
    }
} // end pfpro class
?> 

-- EXAMPLE --

<?php
// example using pfproc.class library
// Please consult the payflowpro guide available from the Verisign Manager (https://manager.verisign.com)

// include the pfpro.class file
require('pfpro.class.php');

// create a new instance
$tx = new pfpro;

// For a sale - settle imediately
$tx->sale(22.22, "4111 1111 1111 1111","02","2003");

// For an authorization (settle later)
$tx->authorize(22.22, "4111 1111 1111 1111","02","2002");

// To credit a customer using a PNREF - same amount
$tx->credit("VABC12345678");

// To credit a customer using a PNREF - different amount
$tx->credit("VABC12345678",10.10);

// To credit a customer using a credit card - same amount
$tx->credit("","","4111 1111 1111 1111","02","2003");

// To credit a customer using a credit card - different amount
$tx->credit("",10.10,"4111 1111 1111 1111","02","2003");

// Capture a previous Authorize - same amount
$tx->capture("VABC12345678");

// Capture a previous Authorize - different amount
$tx->capture("VABC12345678",10.10);

// To void a sale a previous sale - supply the original PNREF
$tx->void_sale("VABC12345678");

// optional - can check AVS (Address Verification)
$tx->AVS("434 Test Ave","32612-3422");

// optional - add order comments
$tx->comments("comment 1", "comment 2");

// process order - send to Verisign
$tx->process();

print "<pre>";
print_r ($tx->transaction);
print_r ($tx->result);
print "</pre>";

?>