#!/usr/local/bin/perl ########################################################### # Please make sure that your using the correct perl # # location (SHEBANG) for this script to execute # # properly. Check with your web host. # ########################################################### ########################################################### # # # D O C U M E N T A T I O N # # # # This CGI/PERL code has been successfully tested on # # third-party web servers and performed according to # # documented Advanced Integration Method (AIM) # # standards. # # # # Last updated September 2004. # # # # For complete and freely available documentation, # # please visit the Authorize.Net web site at: # # # # http://www.authorizenet.com/support/guides.php # # # ########################################################### ########################################################### # # # When you upload (FTP) this CGI/PERL script to your web # # server, please make sure that the CHMOD has been set # # 755. # # # # If you are using a command-line tool to assign # # permissions to this file, please make sure it has read # # and execute privileges for everyone -- otherwise, the # # code cannot be excuted. # # # ########################################################### ########################################################### # # # Make sure you have the LWP module installed and verify # # which version you are using, since you need to # # reference that version number in your code. # # # ########################################################### use LWP 5.69; use HTTP::Request::Common qw( POST ); ########################################################### # # # For an easy way to find out which PERL modules are # # available on your web server, consider the freely # # available ENV.PL script: # # # # ####################################### # # ## Server Info CGI v1.08 © 2000 ## # # ## http://www.widexl.com ## # # ## Made by Henk Boonstra ## # # ####################################### # # # ########################################################### ############################################### # ENTER YOUR LOGIN ID AND PASSWORD HERE # ############################################### my $auth_net_login_id = "ENTER LOGIN ID HERE"; my $auth_net_tran_key = "ENTER TRAN KEY HERE"; my $request_values = { x_test_request => "TRUE", x_login => $auth_net_login_id, x_tran_key => $auth_net_tran_key, ########################################################### # # # Please, pay special attention to the version number. # # Unless you have a specific reason to make a change, # # leave it at 3.1. # # # # Ideally, you would already have set it to 3.1 in the # # Merchant Interface to make sure all of your trans- # # actions will by default follow the 3.1 protocol # # # ########################################################### x_version => "3.1", ########################################################### # # # Make absolutely sure that you use a delimiter that # # will not show up in any legitimate name, billing # # address, product descriptions, etc. # # # # For this reason, we prefer using the pipe character: # # # # | # # # # # # If necessary, make sure you search for and replace # # the delimiter character before you accept and process # # user input -- so that parsing and evaluating the # # returned string from Authorize.Net will not be # # negatively affected. # # # ########################################################### x_delim_char => "|", x_delim_data => "TRUE", x_adc_url => "FALSE", x_type => "AUTH_CAPTURE", x_card_num => "4242424242424242", x_exp_date => "1209", x_description => "Recycled Toner Cartridges", x_amount => "12.23", x_first_name => "Charles D.", x_last_name => "Gaulle", x_address => "342 N. Main Street #150", x_city => "Ft. Worth", x_state => "TX", x_zip => "12345", x_country => "USA", x_company => "ACME USA", x_cust_id => "dpb-11937-84065", x_invoice_num => "0722031200-PM", x_phone => "1-888-555-1234", x_fax => "1-888-555-2345", ########################################################### # # # NOTE: The @ symbol in the e-mail address must be # # encoded or else you will have to escape it when you # # parse the return string in CGI/Perl # # # # Instead of @ use @ # # # # You don't have to use extensive encoding as shown in # # this example. # # # ########################################################### x_email => "customer@customer.com", x_email_customer => "FALSE", x_ship_to_first_name => "Donovan", x_ship_to_last_name => "Leitch", x_ship_to_company => "ACME Explosives & Anvils", x_ship_to_address => "4567 Wilshire Blvd.", x_ship_to_city => "Los Angeles", x_ship_to_state => "California", x_ship_to_zip => "98765-0987", x_ship_to_country => "USA", x_po_num => "1837350987", x_tax => "6.25", x_tax_exempt => "TRUE", x_freight => "11.25", x_duty => "0.00", ########################################################### # # # M E R C H A N T D E F I N E D V A L U E S # # # # You can define any number of special, custom fields # # to have them accompany a transaction. # # # ########################################################### CustomerBirthMonth => "12", CustomerBirthDay => "1", CustomerBirthYear => "1959", }; ########################################################### # # # For the purpose of this demonstration, we have hard- # # coded a number of values that will get posted to the # # Authorize.Net payment processor. # # # # Obviously, in a real-world e-commerce situation, you # # would have securely collected most of the data through # # a shopping cart or by some other means. # # # # Moreover, you could have obviously supplied many more # # values (see the AIM API Guide for specific # # information), but it varies from merchant to merchant, # # dependent on their business models, accounting needs, # # etc. as to which information gets collected. # # # ########################################################### ########################################################### # # # The following four lines demonstrate how to post the # # transaction data securely to Authorize.Net. # # You may of course adjust this code to your liking. # # We simply wanted to provide a working approach to # # those who don't want to spend a lot of time learning # # CGI/PERL (or don't have the resources to do custom CGI # # programming. # # # #---------------------------------------------------------# # NOTE: # #---------------------------------------------------------# # For testing purposes, we are submitting all # # transactions to the certification server. If you have # # a valid merchant account with Authorize.Net, and if # # you are done testing, you must post to the actual # # transaction server, as outlined in your merchant # # information that you should have received when you # # opened the Authorize.Net account. # # # #---------------------------------------------------------# # For assistance with your Authorize.Net merchant # # account, please contact Authorize.Net Customer Support # # at: # # 1-877-447-3938 # #---------------------------------------------------------# # # ########################################################### my $useragent = LWP::UserAgent->new( protocols_allowed => ["https"] ); my $request = POST( "https://test.authorize.net/gateway/transact.dll", $request_values ); # Uncomment the line ABOVE for test accounts or BELOW for live merchant accounts # my $request = POST( "https://secure.authorize.net/gateway/transact.dll", $request_values ); my $response = $useragent->request( $request ); my @responses = split( /$request_values->{x_delim_char}/, $response->content ); ########################################################### # # # The remaining code simply demonstrates how to # # # # 1. get to the response string from Authorize.Net # # 2. how to iterate through the response string to get # # specific information and display it in a web # # browser # # # # Obviously, you are welcome to add on to the existing # # code, build your own custom functions to process the # # information, and so forth. # # # # Please keep in mind that we are following the 3.1 AIM # # standards, as documented. In particular, this means # # that we are processing the response string from # # Authorize.Net with regards to the 39th field (Card # # Code Response) to address CVV2, CVC2 and CID # # responses. # # # ########################################################### print "Content-type: text/html\n\n"; $header = qq|
| "; print "Response Code:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Response Sub-Code:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Response Reason Code:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Response Reason Text:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Approval Code:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "AVS Result Code:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Transaction ID:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Invoice Number:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Description:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Amount:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Method:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Transaction Type:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Customer ID:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Cardholder First Name:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Cardholder Last Name:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Company:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Billing Address:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "City:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "State:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "ZIP/Postal Code:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Country:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Phone:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Fax:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "E-Mail Address:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Ship-to First Name:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Ship-to Last Name:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Ship-to Company:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Ship-to Address:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Ship-to City:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Ship-to State:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Ship-to ZIP/Postal Code:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Ship-to Country:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Tax Amount:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Duty Amount:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Freight Amount:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Tax Exempt Flag:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "PO Number:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "MD5 Hash:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Card Code Verification Result:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Reserved for future use:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "Merchant-defined:"; print " | "; print "@words[$i]\n"; print " | |
| "; print "$ctr: @words[$i]\n"; print " | ||