#-*-Perl-*- #register-eauth-tclink.txt #install with "update-sysStrings register-eauth-# < register-eauth-tclink.txt" #where # is the credit card tender number. make sure to set eauth in the tender table/program ############################################################################################# #this code makes sure the customer has the credit available on his/her card to make the purchase #this sample version uses the GPL client from #http://www.trustcommerce.com/ #you need to install their TCLink perl client #this doesn't use avs or cvv ######################################################################### #If other processors/gateways have open source or public domain clients,# #I'm willing to write wrappers like this for them, as well. # # jburrell(at)users.sf.net # ######################################################################### #the mag stripe reading part assumes that you have a reader like our ikb-5700 that #only sends track 2 data use Net::TCLink; #this is the trustcommerce.com client my %dta; my $str = SysString->new; if(!$str->open('ccauth-tclink-custid')) { print STDERR "register-eauth-5 couldn't load the ccauth-tclink-custid from the database\n"; return 0; } $dta{'custid'} = $str->{'data'}; if(!$str->open('ccauth-tclink-password')) { print STDERR "register-eauth-5 couldn't load the ccauth-tclink-custid from the database\n"; return 0; } $dta{'password'} = $str->{'data'}; $ccNum = ""; $ccType = ""; my $r; ($r) = main::getResponses("show", "Swipe card or enter card number"); &main::clearEntry; if($r =~ /=/) { #this is a swipe $dta{'track2'} = $r; $r =~ /^(\d*)=/; $ccNum = $1; $dta{'cc'} = $ccNum; $r =~ /(=)(\d{2})(\d{2})/; $dta{'exp'} = "$3$2"; } else { #this is a manual entry if(!($r =~ /^\d{13,16}$/)) { &main::infoPrint("Incorrect number of digits for a card number.\n\nRe-tender."); return 0; } $ccNum = $r; ($r) = main::getResponses("show", "Enter the expiration date (MMYY)\n\nOr press \"No\" to cancel"); &main::clearEntry; if(!($r =~ /^\d{4}$/)) { &main::infoPrint("Incorrect number of digits for an expiration date or tender canceled.\n\nRe-tender."); return 0; } $dta{'cc'} = $ccNum; $dta{'exp'} = $r; } $dta{'amount'} = $amt; $dta{'action'} = 'preauth'; &main::infoPrint("Please wait, authorizing the transaction..."); my %result = Net::TCLink::send(%dta); if($result{'status'} ne 'approved') { #tell the clerk what the problem is my $decline; $decline = 'Declined (Possibly NSF)' if $result{'declinetype'} eq 'decline'; $decline = 'Declined (Call for Auth is unsupported)' if $result{'declinetype'} eq 'call'; $decline = 'Card Number Error (Possibly a Typo)' if $result{'declinetype'} eq 'carderror'; $decline = 'Merchant Limit Reached' if $result{'declinetype'} =~ /limit$/; &main::infoPrint("Authorization Failed.\n\nReason: $decline"); my($key, $value); print STDERR "%result\n"; while(($key, $value) = each %result) { print STDERR "\t$key=$value\n"; } return 0; } $ccAuth = $result{'transid'}; &main::infoPrint(""); #print the card info on the customer's receipt if($ccNum =~ /^4/) { $ccType = "Visa"; } elsif($ccNum =~ /^5/) { $ccType = "Master Card"; } elsif($ccNum =~ /^34/ or $ccNum =~ /^37/) { $ccType = "American Express"; } elsif($ccNum =~ /^30/ or $ccNum =~ /^36/ or $ccNum =~ /^38/) { $ccType = "Diners Club"; } elsif($ccNum =~ /^6011/) { $ccType = "Discover/Novus"; } elsif($ccNum =~ /^35/) { $ccType = "JCB Card"; } else { $ccType = "Unknown"; } $main::printer->printFormatted(sprintf("%-40.40s\n%-40.40s\n%-40.40s\n", "Card Number: $ccNum","Type: $ccType", "Authorization: $ccAuth")); #it's authorized my($key, $value); print STDERR "%result\n"; while(($key, $value) = each %result) { print STDERR "\t$key=$value\n"; } return 1;