Zend - The PHP Company




Commerce

Add Code


pfpro.class - Verisign payflowpro class  

Type: class
Added by: Chikki
Entered: 01/08/2002
Last modified: 08/12/2001
Rating: ***** (4 votes)
Views: 8019
A Verisign pfpro class for managing credit card transactions through Verisign. Includes ability to do AVS checks and add order comments.


<?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
?> 


Usage Example


See the example


Rate This Script





Search



This Category All Categories