#1 (permalink)  
Old 04-06-2008, 11:30 PM
Administrator
 
Join Date: Apr 2008
Posts: 151
Default Example Payment Module (authorize.net)

This is an example of how to create payment modules and to return the correct values.
The clients credit card information is stored encrypted, but when it gets to the payment module it comes unencrypted.

PHP Code:
<?php
class authorize_net{
    var 
$ModuleId;
    var 
$Result = array();
    function 
authorize_net($id=false){
        
$this->ModuleId $id;
    }
    function 
ModuleOptions(){
        
$options = array(
                            
                            array(
'formtype' => 'text''description' => LANG_NAME'name' => 'name''value' => 'Authorize.net Payment Module'),
                            array(
'formtype' => 'text''description' => 'Account Id''name' => 'auth_net_login_id''value' => ''),
                            array(
'formtype' => 'text''description' => 'Trans Key''name' => 'auth_net_tran_key''value' => ''),
                            array(
'formtype' => 'select''description' => 'Testing''name' => 'testing''value' => array('1' => 'Yes''0' => 'No')),
                                        
                        );
        return 
$options;
    }
    function 
GetModuleOptions(){
        
$xml '<nixbill>
                    <command>GetPaymentModule</command> 
                    <hash>'
.GetApiHash().'</hash>
                    <moduleid>'
.$this->ModuleId.'</moduleid>
                </nixbill>
                '
;
        
$result API($xml);
        return 
$result;        
    }
    function 
Process($process){
        
        
$options $this->GetModuleOptions();
        
        switch(
$options['NIXBILL'][0]['RESULT'][0]['OPTIONS'][0]['OPTION_TESTING'][0]['VALUE']){
            case 
0:
            
$mode 'LIVE';
            
$auth_net_url "https://secure.authorize.net/gateway/transact.dll";
            break;
            case 
1:
            
$mode 'TEST';
            
$auth_net_url "https://test.authorize.net/gateway/transact.dll";
            break;
        }

        
$auth_net_login_id $options['NIXBILL'][0]['RESULT'][0]['OPTIONS'][0]['OPTION_AUTH_NET_LOGIN_ID'][0]['VALUE'];
        
$auth_net_tran_key $options['NIXBILL'][0]['RESULT'][0]['OPTIONS'][0]['OPTION_AUTH_NET_TRAN_KEY'][0]['VALUE'];
    
        switch(
$process['action']){
            case 
'sale':

                
$authnet_values                = array
                (
                    
"x_login"                => $auth_net_login_id,
                    
"x_version"                => "3.1",
                    
"x_delim_char"            => "|",
                    
"x_delim_data"            => "TRUE",
                    
"x_url"                    => "FALSE",
                    
"x_type"                => "AUTH_CAPTURE",
                    
"x_method"                => "CC",
                    
"x_tran_key"            => $auth_net_tran_key,
                    
"x_relay_response"        => "FALSE",
                    
"x_card_num"            => $process['cardnumber'],//"4242424242424242",
                    
"x_exp_date"            => $process['expiration'],// ie 0907,
                    
"x_amount"                => $process['amount'],
                    
"x_first_name"            => $process['fname'],
                    
"x_last_name"            => $process['lname'],
                    
"x_address"                => $process['address'],
                    
"x_city"                => $process['city'],
                    
"x_state"                => $process['state'],
                    
"x_zip"                    => $process['zipcode'],
                );
                
            break;
            case 
'auth':
            
            
            
            break;
            case 
'refund':
            
                
$authnet_values                = array
                (
                    
"x_login"                => $auth_net_login_id,
                    
"x_version"                => "3.1",
                    
"x_delim_char"            => "|",
                    
"x_delim_data"            => "TRUE",
                    
"x_url"                    => "FALSE",
                    
"x_type"                => "CREDIT",
                    
"x_trans_id"            => $process['cctransactionid'],
                    
"x_method"                => "CC",
                    
"x_tran_key"            => $auth_net_tran_key,
                    
"x_relay_response"        => "FALSE",
                    
"x_card_num"            => $process['cardnumber'],//"4242424242424242",
                
);
            
            break;
            case 
'capture':
            
             
            
            break;
        }
        
$fields "";
        foreach( 
$authnet_values as $key => $value $fields .= "$key=" urlencode$value ) . "&";
        
$ch curl_init($auth_net_url); 
        
curl_setopt($chCURLOPT_HEADER0); // set to 0 to eliminate header info from response
        
curl_setopt($chCURLOPT_RETURNTRANSFER1); // Returns response data instead of TRUE(1)
        
curl_setopt($chCURLOPT_POSTFIELDSrtrim$fields"& " )); // use HTTP POST to send form data
        
curl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE); // uncomment this line if you get no gateway response. ###
        
$resp curl_exec($ch); //execute post and get results
        
curl_close ($ch);
        
//print_r($resp);
        
$return explode('|'$resp);
        switch(
$return[0]){
            case 
1:
            
$status 1;
            break;
            case 
2:
            
$status 0;
            break;
            case 
3:
            
$status 'E';
            break;
            default:
            
$status 'E';
        }
        
$result['transid']             = $return[6];
        
$result['status']            = $status;
        
$result['avs']                = $return[5];
        
$result['cvv2']                = $return[38];
        
$result['authcode']            = $return[4];
        
$result['message']            = $return[3];
        
$result['response']         = $resp;

        
        
        
$this->Result $result;
    }
    function 
GetResult(){
        return 
$this->Result;
    }
    
}

/*

example response

1|1|1|(TESTMODE) This transaction has been approved.|000000|P|0||Recycled Toner Cartridges|12.23|CC|auth_capture||Charles D.|Gaulle||342 N. Main Street #150|Ft. Worth|TX|12345||||||||||||||||||FACF27AECF14DC5616A4F52205BAD505|||||||||||||||||||||||||||||||FALSE|Customer Birth Month: 12|Customer Birth Day: 1|Customer Birth Year: 1959|Promotion: Spring Sale

*/


?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 08:43 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0