#!/usr/bin/perl -w use POSIX qw(strftime); use Digest::HMAC_MD5 qw(hmac_md5 hmac_md5_hex); ##======================================================================|| ## PERL Script for nopercart.js || ## to connect to Authorize.net using the SIM method. || ## || ## Note: $loginID, $transactionKey values must be replaced with || ## those for YOUR account at Authorize.net. || ## see also: http://developer.authorize.net || ##======================================================================|| my $loginID = "5DD42Vfr2"; my $transactionKey = "2Kfg5GC3dDP2p45e"; my $testMode = "false"; my $url = "https://test.authorize.net/gateway/transact.dll"; ##my $url = "https://secure.authorize.net/gateway/transact.dll"; ############################################################### ## urlDecode -- Decode an URL-encoded string ## ############################################################### sub urlDecode { my ($string) = @_; $string =~ tr/+/ /; $string =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex($1))/eg; $string =~ s/['"]/\'/g; return ($string); } ############################################################### ## processCGI -- Retrieve form-data submitted via GET or ## ## POST method and decode it; each field can then be ## ## accessed as $ by the name of the field ## ############################################################### sub processCGI { local ($cgiData, $key, $value, $pair, @pairs); if ($ENV{'REQUEST_METHOD'} eq 'GET') {$cgiData = $ENV{'QUERY_STRING'};} else {$cgiData = ;} @pairs = split (/&/, $cgiData); foreach $pair (@pairs) { ($key, $value) = split (/\=/, $pair); $key = &urlDecode($key); $value = &urlDecode($value); if(defined ${$key}) {${$key} .= ", ".$value;} else {${$key} = $value;} } } ############################################################### ## MAIN ## ############################################################### &processCGI; ##get passed-in variables ## Generate invoice using date+time; sequencenumber randomly; timestamp using time: my $invoice = strftime "%Y%m%d%H%M%S", localtime; my $sequence = int(rand(1000)); my $timeStamp = time(); ## Generate the SIM fingerprint: my $fingerprint = hmac_md5_hex($loginID . "^" . $sequence . "^" . $timeStamp . "^" . $x_amount . "^", $transactionKey); ## Produce HTML: print "Content-type: text/html\n\n"; print "Load Authorize.net Payment Page"; print "

Connecting to our secure payment-processor $url...
logonID:$loginID; transactionKey:$transactionKey;
Amount:$x_amount; Description:$x_description
"; print "

"; print " "; print " "; print " "; print " "; print " "; print " "; print " "; print " "; print " "; print " "; print "
"; exit;