Code Samples

PHP Sample

     This class creates, and passes the XML file required to integrate Linkpoint payment system into a website. It builds the XML based on information sent to it, and then handles the passing, and receiving of the XML file. It also includes Fraud Protection.

<?php
/*
 * Created on May 2, 2008
 * This Payment class utilizes LinkPoint located at 
 * www.linkpointcentral.com. This function uses the 
 * Direct Approach  to sending the xml to LinkPoint 
 * and requires cURL to be used.
 */
class PaymentProcess{
    
/*Class global variables*/
    
var $DebugMessage='';/*This will spit back a 
    debug message*/
    
var $CertificateLoc='';/*The location of 
    the LinkPoint Certificate 
    File*/
    
var $Host='staging.linkpt.net';/*The host 
    where the merchant gateway is 
    pointing, to test account set to 
    staging.linkpt.net else secure.linkpt.net*/
    
var $Port='1129';
    var 
$ProcessErrors='';
    var 
$XML='';
    var 
$ReturnedInfo='';
    var 
$AVSFraudProtect=false;
    var 
$FraudDetected=false;
    function 
GetHostString()
    {
        
$HostString="https://"$this->Host .":"$this->Port ."/LSGSXML";
        return 
$HostString;
    }
    
/*START: A list of functions to build the xml to send*/
    
function StartBuildXML()
    {
        
$this->XML .='<order>';
        return 
true;
    }
    function 
SetOptions($Result,$OrderType)
    {
        
/*Result can be set to: LIVE (Set to this is it is live 
         * and not being tested), GOOD (For a good response back 
         * from Gateway during testing), DECLINE (For a declined 
         * response back from Gateway during testing), DUPLICATE 
         * (For a duplicate response back from Gateway during 
         * testing) OrderType can be set to: SALE, PREAUTH 
         * (To Authorize card before a shipment), POSTAUTH 
         * (To receive payment after shipment), VOID, CREDIT, 
         * CALCSHIPPING, CALCTAX
        */
        
$this->XML .='<orderoptions>';
            
$this->XML .='<result>';
                
$this->XML .=strtoupper($Result);
            
$this->XML .='</result>';
            
$this->XML .='<ordertype>';
                
$this->XML .=strtoupper($OrderType);
            
$this->XML .='</ordertype>';
        
$this->XML .='</orderoptions>';
        return 
true;   
    }
    function 
SetMerchant($StoreNumber)
    {
        
$this->XML .='<merchantinfo>';
            
$this->XML .='<configfile>';
                
$this->XML .=$StoreNumber;
            
$this->XML .='</configfile>';
        
$this->XML .='</merchantinfo>';
        return 
true;
    }
    function 
SetPaymentType($PaymentTypeArray)
    {
        
/*$PaymentTypeArray=array('Type'=>'type of payment: CREDIT',
         *                             'CardNum' => 'CreditCardNumber',
         *                             'ExpMonth' => 'Month card 
         *                                             is expiring',
         *                             'ExpYear' => 'Expiration Year',
         *                             'cvmvalue' => 'security code 
         *                                             for AVS or 
         *                                             credit code fraud 
         *                                             detection',
         *                             'cvmindicator' => 'state of the 
         *                                                 code for 
         *                                 AVS or credit code fraud 
     *                                     detection (set to:
         *provided, not_provided, illegible, not_present, 
         *no_imprint)' );
         */
        
switch(strtoupper($PaymentTypeArray['Type']))
        {
            case 
"CREDIT":
                 
$PaymentTypeArray['ExpMonth']=
                 
sprintf("%02d"$PaymentTypeArray['ExpMonth']);
                  
$PaymentTypeArray['ExpYear']=
                  
sprintf("%02d"$PaymentTypeArray['ExpYear']);
                
$this->XML .='<creditcard>';
                    
$this->XML .='<cardnumber>';
                        
$this->XML .=$PaymentTypeArray['CardNum'];
                    
$this->XML .='</cardnumber>';
                    
$this->XML .='<cardexpmonth>';
                        
$this->XML .=$PaymentTypeArray['ExpMonth'];
                    
$this->XML .='</cardexpmonth>';
                    
$this->XML .='<cardexpyear>';
                        
$this->XML .=$PaymentTypeArray['ExpYear'];
                    
$this->XML .='</cardexpyear>';
                    if ((!empty(
$PaymentTypeArray['cvmindicator']))
                         || (!empty(
$PaymentTypeArray['cvmvalue']))){
                        
$this->XML .='<cvmvalue>';
                            
$this->XML .=$PaymentTypeArray['cvmvalue'];
                        
$this->XML .='</cvmvalue>';
                        
$this->XML .='<cvmindicator>';
                            
$this->XML .=$PaymentTypeArray['cvmindicator'];
                        
$this->XML .='</cvmindicator>';
                    }else{
                        if (!empty(
$this->AVSFraudProtect)){
                            
$this->DebugMessage=$this->DebugMessage 
                            
'<h2>AVS Fraud Error: You have this set, ' .
                            
'but you fail to send the cvm value, and ' .
                            
'cvm indicator.</h2><br />';   
                        }   
                    }
                
$this->XML .='</creditcard>';   
            break;   
        }
        return 
true;   
    }
    function 
SetDetails($PONum,$TaxExempt)
    {
        
$this->XML .='<transactiondetails>';
            
$this->XML .='<ponumber>';
                
$this->XML .=$PONum;
            
$this->XML .='</ponumber>';
            
$this->XML .='<taxexempt>';
                
$this->XML .=$TaxExempt;
            
$this->XML .='</taxexempt>';
        
$this->XML .='</transactiondetails>';
        return 
true;   
    }
    function 
SetBilling($BillingArray)
    {
    
/*$BillingArray=array('Name'=>'customer name',
     *                             'Company' => 'company name',
     *                             'AddrNum' => 'The street number, 
     *                                 required for AVS',
     *                             'Address1' => 'Address 1',
     *                             'Address2' => 'Address 2',
     *                             'City' => 'City',
     *                             'State' => 'state US Codes only',
     *                             'Zip' => 'zip code required for AVS',
     *                          'Country' => 'Country Codes only',
     *                          'Phone' => 'phone number',
     *                          'Email' => 'email',
     *                             );
     */
    /*AddrNum is the street number in the address, this is used 
     * for AVS and card code fraud protection*/
        
$this->XML .='<billing>';
            
$this->XML .='<name>';
                
$this->XML .=$BillingArray['Name'];
            
$this->XML .='</name>';
            
$this->XML .='<company>';
                
$this->XML .=$BillingArray['Company'];
            
$this->XML .='</company>';
            
$this->XML .='<address1>';
                
$this->XML .=$BillingArray['Address1'];
            
$this->XML .='</address1>';
            
$this->XML .='<address2>';
                
$this->XML .=$BillingArray['Address2'];
            
$this->XML .='</address2>';
            
$this->XML .='<city>';
                
$this->XML .=$BillingArray['City'];
            
$this->XML .='</city>';
            
$this->XML .='<state>';
                
$this->XML .=$BillingArray['State'];
            
$this->XML .='</state>';
            
$this->XML .='<country>';
                
$this->XML .=$BillingArray['Country'];
            
$this->XML .='</country>';
            
$this->XML .='<phone>';
                
$this->XML .=$BillingArray['Phone'];
            
$this->XML .='</phone>';
            
$this->XML .='<email>';
                
$this->XML .=$BillingArray['Email'];
            
$this->XML .='</email>';
        if ((!empty(
$BillingArray['AddrNum'])
             && (!empty(
$BillingArray['Zip'])))){
                
$this->XML .='<addrnum>';
                    
$this->XML .=$BillingArray['AddrNum'];
                
$this->XML .='</addrnum>';
                
$this->XML .='<zip>';
                    
$this->XML .=$BillingArray['Zip'];
                
$this->XML .='</zip>';
        }else{
            if (!empty(
$this->AVSFraudProtect)){
                
$this->DebugMessage=$this->DebugMessage 
                
'<h2>AVS Fraud Error: You have this set, ' .
                
'but you fail to send the AddrNum, and Zip ' .
                
'Code.</h2><br />';   
            }else{
                
$this->XML .='<zip>';
                    
$this->XML .=$BillingArray['Zip'];
                
$this->XML .='</zip>';   
            }
        }
        
$this->XML .='</billing>';
        return 
true;   
    }
    function 
SetShipping($ShippingArray)
    {
    
/*$ShippingArray=array('Name'=>'customer name',
     *                             'Address1' => 'Address 1',
     *                             'Address2' => 'Address 2',
     *                             'City' => 'City',
     *                             'State' => 'state US Codes only',
     *                             'Zip' => 'zip code required 
     *                                 for AVS',
     *                             'Country' => 'Country Codes only',
     *                             'Weight' => 'decimal - total weight
     *                                  of product',
     *                             'Items' => 'decimal - total number 
     *                                 of items',
     *                             'Carrier'=>'integer - carrier to 
     *                                 be used',
     *                             'Total'=>'decimal - the order total 
     *                                 before shipping charges'
     *                             );
     */
    /*AddrNum is the street number in the address, this is used for 
     * AVS and card code fraud protection*/
        
$this->XML .='<shipping>';
            
$this->XML .='<name>';
                
$this->XML .=$ShippingArray['Name'];
            
$this->XML .='</name>';
            
$this->XML .='<address1>';
                
$this->XML .=$ShippingArray['Address1'];
            
$this->XML .='</address1>';
            
$this->XML .='<address2>';
                
$this->XML .=$ShippingArray['Address2'];
            
$this->XML .='</address2>';
            
$this->XML .='<city>';
                
$this->XML .=$ShippingArray['City'];
            
$this->XML .='</city>';
            
$this->XML .='<state>';
                
$this->XML .=$ShippingArray['State'];
            
$this->XML .='</state>';
            
$this->XML .='<country>';
                
$this->XML .=$ShippingArray['Country'];
            
$this->XML .='</country>';
            
$this->XML .='<zip>';
                
$this->XML .=$ShippingArray['Zip'];
            
$this->XML .='</zip>';
        if (!empty(
$ShippingArray['Weight'])){
                
$this->XML .='<weight>';
                    
$this->XML .=$ShippingArray['Weight'];
                
$this->XML .='</weight>';
        }
        if (!empty(
$ShippingArray['Items'])){
                
$this->XML .='<items>';
                    
$this->XML .=$ShippingArray['Items'];
                
$this->XML .='</items>';
        }
        if (!empty(
$ShippingArray['Carrier'])){
                
$this->XML .='<carrier>';
                    
$this->XML .=$ShippingArray['Carrier'];
                
$this->XML .='</carrier>';
        }
        if (!empty(
$ShippingArray['Total'])){
                
$this->XML .='<total>';
                    
$this->XML .=$ShippingArray['Total'];
                
$this->XML .='</total>';
        }
        
$this->XML .='</shipping>';
        return 
true;   
    }
    function 
SetTotal($Total)
    {
        
$this->XML .='<payment>';
            
$this->XML .='<chargetotal>';
                
$this->XML .=$Total;
            
$this->XML .='</chargetotal>';
        
$this->XML .='</payment>';
        return 
true;       
    }
    function 
EndBuildXML()
    {
        
$this->XML .='</order>';
        
$PrettyXML=htmlspecialchars($this->XML);
        
$PrettyXML=str_replace('&gt;&lt;','&gt;<br />&lt;',$PrettyXML);
        
$this->DebugMessage=$this->DebugMessage 
        
'Sent XML:<br />' $PrettyXML '<br />';
        return 
true;
    }
    
/*END: A list of functions to build the xml to send, call 
     * BuildXml($Result,$OrderType,$MerchantNumber,$PaymentTypeArray
     * ,$Total); 
     * to build it*/
    /*START: Instatiate the merchant Gateway and send XML*/
    
function SendXML()
    {
        
$Send curl_init ();
        
curl_setopt ($SendCURLOPT_URL,$this->GetHostString());
        
curl_setopt ($SendCURLOPT_POST1);
        
curl_setopt ($SendCURLOPT_POSTFIELDS$this->XML); 
        
//the string we built above
        
curl_setopt ($SendCURLOPT_SSLCERT$this->CertificateLoc);
        
curl_setopt ($SendCURLOPT_RETURNTRANSFER1);
        if (
$this->Host=='staging.linkpt.net')
        {
            
/*the client is testing*/
            
curl_setopt ($SendCURLOPT_SSL_VERIFYHOST0);
            
curl_setopt ($SendCURLOPT_SSL_VERIFYPEER0);
        }
        
// curl_setopt ($Send, CURLOPT_VERBOSE, 1); 
        // optional -verbose debug output
        // not for production use
        //send the string to LSGS
        
$this->ReturnedInfocurl_exec ($Send);
        if (
curl_errno($Send))
        {
            
$this->ProcessErrors=curl_error($Send);
            
$this->DebugMessage=$this->DebugMessage 
            
'<br />cURL Error:<br />' curl_error($Send);
        } else
        {
            
curl_close($Send);
        }
        if (!empty(
$this->ProcessErrors)){
            return 
false;
        }else{
            if (
$this->ReturnProcessor())
            {
                return 
true;
            }else{
                return 
false;
            }   
        }   
    }
    
/*END: Instatiate the merchant Gateway and send XML*/
    /*START: Process all returned info*/
    
function ReturnProcessor()
    {
        
$CheckErrors=false;
        
/*Convert the Returned XML to an array*/
        
$PrettyXML=htmlspecialchars($this->ReturnedInfo);
        
$PrettyXML=str_replace('&gt;&lt;','&gt;<br />&lt;',$PrettyXML);
        
$this->DebugMessage=$this->DebugMessage 
        
'<br /><hr />Returned XML:<br />' $PrettyXML '<br />';
        
preg_match_all("/<(.*?)>(.*?)\</"
        
$this->ReturnedInfo$ReturnArray,PREG_SET_ORDER);
        
$n 0;
        while (isset(
$ReturnArray[$n]))
        {
            
$ReturnArray[$ReturnArray[$n][1]] = 
            
strip_tags($ReturnArray[$n][0]);
            
$n++;
        }
        
$this->DebugMessage=$this->DebugMessage 
        
'<br />Returned Errors:<br />';
        while (list(
$key$value) = each($ReturnArray))
        {
            $
$key $value;
            
$this->DebugMessage=$this->DebugMessage 
            
'* ' $key '=' .  $value '<br />';
        }
        
/*first check if it has been approved*/
        
switch(strtoupper($r_approved)){
            case 
"APPROVED":
                
$this->DebugMessage=$this->DebugMessage 
                
'<h1>Result: Approved->Code: ' $r_avs '</h1>';
                return 
true;
            break;
            case 
"DECLINED":
                
$this->DebugMessage=$this->DebugMessage 
                
'<h1>Result: Declined</h1>';
                return 
false;
            break;
            case 
"FRAUD":
                
$this->FraudDetected=true;
                
$this->DebugMessage=$this->DebugMessage 
                
'<h1>Result: Fraud</h1>';
                return 
false;
            break;
        }
    }
    
/*END: Process all returned info*/   
}
?>

Calling the class:

<?php
        
require_once('../PaymentProcessClass.php');
        
$PaymentTypeArray=array('Type'=>'CREDIT',
                                 
'CardNum' => $CCNum,
                                 
'ExpMonth' => $ExpMonth,
                                 
'ExpYear' => $ExpYear,
                                 
'cvmvalue' => $CCV,
                                 
'cvmindicator' => $CVMIndicator
                                
);
        
$BillingArray=array('Name'=>$Name,
                            
'Company' => $Company ' - ' $Occupation,
                            
'AddrNum' => $AddrNum,
                            
'Address1' => $AddrNum " " $Address1,
                            
'Address2' => $Address2,
                            
'City' => $City,
                            
'State' => $StateFinal,
                            
'Zip' => $Zip,
                            
'Country' => $Country,
                            
'Phone' => $Phone,
                            
'Email' => $Email
                            
);
        
$ShippingArray=array('Name'=>$Name,
                            
'Address1' => $ResAddrNum " " 
                                            
$ResAddress1,
                            
'Address2' => $ResAddress2,
                            
'City' => $ResCity,
                            
'State' => $ResStateFinal,
                            
'Zip' => $ResZip,
                            
'Country' => $ResCountry,
                            
'Weight' => '',
                            
'Items' => '',
                            
'Carrier'=>'',
                            
'Total'=>''
                            
);
        
$StoreId='33333333';
        
$PONum='Donation ' date('M j, Y');/*Get this from the visitor*/
        
$TaxExempt='Y';
        
$Result='LIVE';
        
$OrderType='SALE';
        
$PaymentProcess=new PaymentProcess;
        
$PaymentProcess->Host='secure.linkpt.net';
        
$PaymentProcess->Port='1129';
        
$PaymentProcess->CertificateLoc='CERT/33333333.pem';
        
$PaymentProcess->AVSFraudProtect=true;
        
$PaymentProcess->StartBuildXML();
        
$PaymentProcess->SetOptions($Result,$OrderType);
        
$PaymentProcess->SetMerchant($StoreId);
        
$PaymentProcess->SetPaymentType($PaymentTypeArray);
        
$PaymentProcess->SetDetails($PONum,$TaxExempt);
        
$PaymentProcess->SetBilling($BillingArray);
        
$PaymentProcess->SetShipping($ShippingArray);
        
$PaymentProcess->SetTotal($DonateAmount);
        
$PaymentProcess->EndBuildXML();
        if(
$PaymentProcess->SendXML()){
            
/*The process had no problems*/   
                
$Message='<h4>Thank you for your donation.  ' .
                        
'A receipt will be emailed to you ' .
                        
'shortly.  We greatly appreciate your ' .
                        
'contributions.</h4>';
        }else{
            
/*The process had problems*/
            
$message=$PaymentProcess->ProcessErrors;
            if (!empty(
$PaymentProcess->FraudDetected)){
                
$Message='<h5>There was a problem with the' .
                        
' transaction.  Please try another ' .
                        
'card or contact us by email here: ' .
                        
'contact@here.com.</h5>';
            }
            
$Message='<h5>There was a problem with the ' .
                    
'transaction.  Please try another card or  ' .
                    
'contact us by email here: contact@here.com.</h5>';   
        }
?>

Back to the Top

JavaScript Sample

These JavaScript functions create a rotating slide show utilizing the Prototype JavaScript Framework, and Scriptaculous Effects. It makes an initial AJAX call to get all the images from a database, creates an XML file, parses the XML file, and then it displays the images by fading in and out at a set interval. To see it in action, visit Http://www.caltorque.com.


	var ImageArray=new Array();/*Array to hold all the images*/
	var LinkArray=new Array();/*Array to hold all the links*/
	var ImageNumber=0;
	var SlideShowLength='';
	function SlideShow(){
	    new Ajax.Request('code/ajax_scripts/SlideShow.php',{
	        method: 'get',
	        onSuccess: function(transport)
	            {
	                var xml = transport.responseXML.documentElement;
	                /*In order to fix IE. We have to add 
	                .documentElement, IE seems to have trouble with 
	                XML if the server does not set the content 
	                type of the file*/
	                var ImageHolder=xml;
	                var cells=
	                ImageHolder.getElementsByTagName('images');
	                for (var i = 0; i < cells.length; i++) {
	                    ImageArray[i]=cells[i].firstChild.data;
	                    LinkArray[i]=cells[i].getAttribute('link');
	                }
	                SlideShowLength=ImageArray.length;
	                ActivateShow(true,false);
	            },
	        onFailure: function(){ alert('Something went wrong...') }
	    });
	}
	function ActivateShow(FirstRun,BypassTimeout){
	    new Effect.Fade('SlideShow',{afterFinish: function (){
            var newlink=document.createElement('a');
            newlink.setAttribute('href',LinkArray[ImageNumber]);
            newlink.setAttribute('title','Click Here for Product Details');
            var newimg=document.createElement('img');
            newimg.src=ImageArray[ImageNumber];
            newimg.alt='Click Here for Product Details';
            newlink.appendChild(newimg);
            $('SlideShow').update(newlink);
            new Effect.Appear('SlideShow');
            }});
	    var MaxNumImages=SlideShowLength-1;
	    if (ImageNumber==MaxNumImages){
	        /*Start the slides over*/
	        ImageNumber=0;
	    }else{
	        ImageNumber++;
	    }
	    if (FirstRun){
	        setInterval ( "ActivateShow(false,true)", 7000);
	    }
	    return true;
	}
	window.onload =SlideShow;

PHP page called using AJAX.

<?php
/* Copyright 2008 Salamander Web Solutions (http://www.myownsalamander.com)
 * Last Modified By: Technoguru
 * Created on Jun 13, 2008
 * generate an xml for the slideshow
 */
     
include("../functions/dbconnect.php");
    
$dbLink=dbconnect();
     
header("content-type: text/xml");
     
$xml='<slideshow>';
     
$productQuery="SELECT id, sku, name, summary FROM products " .
             
"WHERE publish='1' ORDER BY RAND()";
    
$prodQuery=mysql_query("$productQuery")or die('prodQuery failed: '
                                                     
mysql_error());
    
$prodRows=mysql_num_rows($prodQuery);
    if (
$prodRows 0)
    {
        while (
$SqlRes=mysql_fetch_array($prodQuery))
        {
            
extract($SqlRes);
            
$cleanName=htmlspecialchars($name);
            
$imageFile="../../assets/images/products/" $id 
                                                    
"__lrg.jpg";
            if (
file_exists($imageFile))
            {
                
$xml.='<images link="default.php?page=prodDetails' .
                        
'&amp;prodId=' $id '">assets/images/' .
                        
'products/' $id '__lrg.jpg</images>';
            }
            
$id='';
            
$sku='';
            
$name='';
            
$summary='';
            
$cleanName='';
            
$imageFile='';
            
$image='';
        }
    }
$xml .='</slideshow>';
echo 
'<?xml version="1.0" encoding="UTF-8" ?>';
$xml preg_replace('/[\r\n\t]+/'''$xml);
echo 
$xml;
?>

The HTML where the slide show is dynamically displayed.


<div id="SlideShowHolder">
	<div id="SlideShow">
    	<!-- Place one default image here -->
    </div>
</div>

Back to the Top

WordPress Freebies

Two Ways to Live Widget

Description: Displays an image that links to the Two Ways to Live. You can choose between three different images in order to best fit your site theme.

WordPress Version: Only tested on WordPress 2.7

Installation

  1. Download and unzip the widget from here.
  2. Upload the folder to your wp-content/plugins folder.
  3. Log into your WordPress Admin.
  4. Click on "Plugins" on the left column.
  5. Find the Plugin named "Two Ways To Live" under the Inactive Plugins header, and click activate.
  6. Click on "Appearance" and then "Widgets".
  7. Click the "Add" link next to "Two Ways To Live", and drag it to the appropriate place in your widget order.
  8. Click "Edit" and select the image that you want to display.
  9. Finally click the "Save Changes" button.

Bookmark and Share

Back to the Top

Unreached People of the Day

Description: Displays a widget for the Unreached People of the Day from the Joshua Project.

WordPress Version: Only tested on WordPress 3.1

Note: The column where this is displayed must be at least 190px wide.

Installation

  1. Download and unzip the widget from here.
  2. Upload the folder to your wp-content/plugins folder.
  3. Log into your WordPress Admin.
  4. Click on "Plugins" on the left column.
  5. Find the Plugin named "Unreached People of the World" under the Inactive Plugins header, and click activate.
  6. Click on "Appearance" and then "Widgets".
  7. Click the "Add" link next to "UnreachedPeoplePlugin", and drag it to the appropriate place in your widget order.
  8. Click the "Save Changes" button.

Bookmark and Share

Back to the Top

Search ESV Bible

Description: Displays a form to search the ESV Bible from your WordPress Blog.

WordPress Version: Only tested on WordPress 2.7

Installation

  1. Download and unzip the widget from here.
  2. Upload the folder to your wp-content/plugins folder.
  3. Log into your WordPress Admin.
  4. Click on "Plugins" on the left column.
  5. Find the Plugin named "Search ESV Bible" under the Inactive Plugins header, and click activate.
  6. Click on "Appearance" and then "Widgets".
  7. Click the "Add" link next to "SearchESVPlugin", and drag it to the appropriate place in your widget order.
  8. Click the "Save Changes" button.

Bookmark and Share

Back to the Top

Adobe FLEX & AIR Freebies

Unreached People of the Day Widget

Description: I revamped the Joshua Project "Unreached People of the Day" widget, and redeveloped it on a FLEX and Adobe AIR platform. Now you can get the data right on your desktop using the versatile Adobe AIR software, or you can embed the flash directly into any of your websites.


Installation for Website

To embed this widget into your current website, simply copy the following embed code and place it where you would like the application to reside.


Installation for Adobe AIR

  1. Download & Install the Adobe AIR software by clicking here.
  2. Download & open the Adobe AIR package located here.

Bookmark and Share

Back to the Top