Akopia Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

[mv] have a strong start on an authorize.net module for MV4, need help.




Hello! 

 Over the weekend I began writing an authorizenet module for Minivend 4.
My progress is attached. This is to be considered Extreme Alpha because
I haven't gotten it to work yet. :) 
 I got it installed, set up my catalog as I thought it should be, and
tried it out it. I got no errors at all, but nothing appears to have
been charged to the account. So I'm experiencing silent failure. Nothing
in the catalog error log, nothing in the minivend error log. Also, I'm
still getting emailed the credit card numbers as the vendor, which I
expected wouldn't happen if it was being sent to cybercash. 

Here's what I added to the 'basic' checkout page:

<snip>
<INPUT type=hidden NAME=mv_click VALUE=CyberCash>
                      [set CyberCash]
                              mv_cyber_mode=mauthonly
                      [/set]
</snip>

I realize it clearly says "CyberCash" in two places here, but I tried
"authorizenet" in place of this and it made no difference. It also seems
that Cybercash or "cyber_" variables are still referenced even in
non-cybercash hookups. Here's what my order profile looks like:

<snip>
__NAME__                            checkout_profile
fname=required
lname=required
address1=required
city=required
country=required
[if value country =~ /^(US|CA)$/i]
	state=state_province "[value state]" is not a valid US/Canada state or province.
	zip=postcode "[value zip]" is not a valid US/Canada postal code.
	&or phone_day=phone, phone_night=phone Must have evening or day phone_number
[else]
	&or phone_day=phone, phone_night=phone Must have evening or day phone_number
[/else]
[/if]

&fatal = yes
email=required
email=email
&set=mv_email [value email]

&set = mv_payment Incomplete

&credit_card=standard keep
&charge=custom authorizenet
&set=mv_payment Real-time ([var MV_PAYMENT_MODE]) Credit Card 

[/elsif]
[/if]

&final = yes
__END__
</snip>

In my minivend.cfg file I have the line:

#include globalsub/authorizenet  

and that directory and file exists. 

I think my question is "How can I tell if my authorizenet routine is
even being called?" (Well, I suppose I could pepper it with print
statements to standard out). Also, can I have an example of setting up a
non-cybercash payment service with MV4? Any help you have on this is
appreciated. I'm going to go on vacation till Monday while you think
about it. :-p

Thanks,

    -mark

  <<-------------------------------------------------------------->>
personal website                <    Summersault Website Design
   http://mark.stosberg.com/     >       http://www.summersault.com/
# Connection routine for AuthorizeNet version 3 using the 'ADC Direct Response' method.
# by mark@summersault.com with code reused and inspired by 
#	Mike Heins <mike@minivend.com>
#	webmaster@nameastar.net
#   Jeff Nappi <brage@cyberhighway.net>

Variable AUTHORIZENET_HELP <<EOV

 1. Modify minivend.cfg to use this file.
 
	#include globalsub/authorizenet

 2. Modify catalog.cfg to set the server and your Signio account info

	
 # Username and password
 Variable MV_PAYMENT_ID      YourAuthorizeNetID
 Variable MV_PAYMENT_SECRET  YourAuthorizeNetPassword

 3. Set in checkout profile:

 &charge custom authorizenet

 4. Make sure CreditCardAuto is off (default in MV4)

 5. Restart Minivend.

EOV

GlobalSub <<EOS
sub authorizenet {
	my ($user, $secret, $amount) = @_;
	 
	my (%actual) = Vend::Order::map_actual();
	 
	if (! $user ) {
		$user    =  $::Variable->{MV_PAYMENT_ID} ||
                    $::Variable->{CYBER_ID}
                    or return undef;
	}
	
	if(! $secret) {
        $secret  =  $::Variable->{MV_PAYMENT_SECRET} ||
                    $::Variable->{CYBER_SECRET}
                    or return undef;
    }
    
    my $server  =   $::Variable->{MV_PAYMENT_SERVER} ||
                    $::Variable->{CYBER_SERVER} ||
                    'secure.authorize.net';
                    
    my $script 	=   $::Variable->{MV_PAYMENT_SCRIPT} ||
                    $::Variable->{CYBER_SCRIPT} ||
                    '/gateway/transact.dll';
                    
    my $port    =   $::Variable->{MV_PAYMENT_PORT} ||
                    $::Variable->{CYBER_PORT} ||
                    443;
                    
	my $precision = $::Variable->{MV_PAYMENT_PRECISION} ||
                    $::Variable->{CYBER_PRECISION} ||
                    2;                    
    
	$actual{mv_credit_card_exp_month} =~ s/\D//g;
    $actual{mv_credit_card_exp_month} =~ s/^0+//;
    $actual{mv_credit_card_exp_year} =~ s/\D//g;
    $actual{mv_credit_card_exp_year} =~ s/\d\d(\d\d)/$1/;

    $actual{mv_credit_card_number} =~ s/\D//g;

    my $exp = sprintf '%02d%02d',
                        $actual{mv_credit_card_exp_month},
                        $actual{mv_credit_card_exp_year};                    
                        
	 $actual{cyber_mode} = 'AUTH_CAPTURE'
        unless $actual{cyber_mode};
	
	my %type_map = (
		mauth_capture 			=>	'AUTH_CAPTURE',
		mauthonly				=>	'AUTH_ONLY',
		CAPTURE_ONLY			=>  'CAPTURE_ONLY',
		CREDIT					=>	'CREDIT',
		VOID					=>	'VOID',
		PRIOR_AUTH_CAPTURE		=>	'PRIOR_AUTH_CAPTURE',

	);                       
	
	if (defined $type_map{$actual{cyber_mode}}) {
        $actual{cyber_mode} = $type_map{$actual{cyber_mode}};
    }
    else {
        $actual{cyber_mode} = 'AUTH_CAPTURE';
    }

    if(! $amount) {
        $amount = Vend::Interpolate::total_cost();
        $amount = sprintf("%.${precision}f", $amount);
    } 
    
    my($orderID);
    my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time());

    # We'll make an order ID based on date, time, and MiniVend session

    # $mon is the month index where Jan=0 and Dec=11, so we use
    # $mon+1 to get the more familiar Jan=1 and Dec=12
    $orderID = sprintf("%02d%02d%02d%02d%02d%05d%s",
            $year + 1900,$mon + 1,$mday,$hour,$min,$Vend::SessionName);
            
	 # Authorize.Net Version on the left, Minivend on the right
	 my %varmap = ( qw/
                            x_Card_Num		mv_credit_card_number
                            x_Zip     	 	zip
                            x_Address  	   	address
                            x_Type  		mv_payment_mode
        /
    );  
    
    my %query = (
                    x_Amount    		=> $amount,
                    x_Exp_Date  		=> $exp,
                    x_Method    		=> 'CC',
                    x_Invoice_Num      	=> $orderID,
                    x_Password  		=> $secret,
                    x_Login     		=> $user,
                    x_Version   		=> '3.0',
                    x_ADC_URL   		=> 'FALSE',
                    x_ADC_Delim_Data	=> 'TRUE',


    );
    
    for (keys %varmap) {
        $query{$_} = $actual{$varmap{$_}};
    }

    my @query;

    for (keys %query) {
        my $key = $_;
        my $val = $query{$key};
        $val =~ s/["\$\n\r]//g;
        $val =~ s/\$//g;
        my $len = length($val);
        if($val =~ /[&=]/) {
            $key .= "[$len]";
        }
        push @query, "$key=$val";
    }
    my $string = join '&', @query;
    
    use Net::SSLeay;
    
    my ($page, $response, %reply_headers)
                = post_https($server, $port, $script, '', 
                       make_form(
                               %query
                       ));
	
#::logDebug(qq{signio decline=$decline result: $result});

    # Minivend names are on the  left, Authorize.Net on the right
    my %result_map = ( qw/
            MStatus               x_response_code
            pop.status            x_response_code
            MErrMsg               x_response_reason_text
            pop.error-message     x_response_reason_text
            order-id              x_trans_id
            pop.order-id          x_trans_id
            pop.auth-code         x_auth_code
            pop.avs_code          x_avs_code
            pop.avs_zip           x_zip
            pop.avs_addr          x_address
    /
    );          
    
    my ($response_code,
    	$response_subcode,
    	$response_reason_code,
    	$response_reason_text,
    	$auth_code,
    	$avs_code,
    	$trans_id) = split (/,/,$page);

    my %result;
    if ($response_code == 1) {
    	$result{MStatus} = 'success';
    	$result{'order-id'} = 1; # ? Why this this set to 1? -mark
    } else {
    	$result{MStatus} = 'failure';

		# NOTE: A lot more AVS codes could be checked for here. 
    	if ($avs_code eq 'N') {
    		$result{MErrMsg} = "You must enter the correct billing address of your credit card. The bank returned the following error: " . $response_reason_text;
    	} else {
    		$result{MErrMsg} = $response_reason_text
    	}
    }
    
    return (%result);

}
EOS


Search for: Match: Format: Sort by: