can anyone help me covert folowing cgi to php?
#!/usr/bin/perl
#
CHANGE THE ABOVE TO POINT TO PERL 5.004 ON YOUR SERVER.
Usually either /usr/local/bin or /usr/bin/perl
Ask your hosting service or
via telenet enter: whereis perl
# Flush Perl buffers so output is sent directly to browser.
#
$| = 1;
# Tell the browser what is coming.
#
print "Content-type: text/html\n\n";
#################################################################################
Net_SSLeay-to-AuthorizeNet_v3.0_transact_dll_interface.cgi.
#
NOTE: This script is written to be run via http not telenet!
Example: Via a web browser enter:
#
All rights reserved.
#
This is ONLY a SAMPLE script to show how to send data to
AuthorizeNet, receive a reply back and parse the results.
What you do with the parsed results is up to you. This is NOT
meant to be a an entire transaction processing script!
#
Before attempting to use this check ALL your setting at AuthorizeNet
to make sure you have no conflicting setting. Also do NOT set any
fields as required in your AuthorizeNet setting. Instead do that
via your own scripting. Also you do need to set your AuthorizeNet
account to test mode while running this script. This script has
a form field to set your account to test mode when it runs.
Your account then swithes back to live mode automatically
for all other transactions not processed by this test script.
#
This version varies only slightly from authrequest.asp version.
It directs the data to;
$host = "secure.authorize.net";
$script = "/gateway/transact.dll
instead of
$host = "www.authorize.net";
$script = "/scripts/authnet25/AuthRequest.asp";
#
It also uses transact.dll v3.0 form field names in stead of
authrequest.asp field names.
#
I also used a slighlty different method of stuffing the data to sent
but it does exactlty the same thing.
#
SOME help is available via e-mail SOMETIMES from DocWebb@consultant.com
#
This script has been tested on a UNIX box running OpenBSD/i386 2.5
#
Prerequisites:
#
Hosting server must have installed;
a- Perl v5.004
nothing earlier works and no gurantee anything later works either.
c- Net::SSLeay v1.03, 4.1.1999, Sampo Kellomaki <sampo@iki.fi>
#
Sorry I can't guarantee this will work with anything except the above!
Use at your own risk!
#
If your hosting service doesn't have the above installed or is unwilling
to install it come see us at www.e-business-hosting.com where we already
have all the above installed AND we provide you with a working copy of
this script already installed so all you have to do is add your products
via the manager.cgi and start selling.
#
###################################################################################
EDIT THESE LINES
$login = "testdrive";
No password required by v3.0 transact.dll.
# Set these to your specific needs.
# See AuthorizeNet's v3.0 transact.dll documentation!
#
$adc_delim_data = "TRUE";
$adc_url = "FALSE";
$authorization_type = "AUTH_ONLY";
$an_version = "3.0";
# Simulate the basic required form data.
#
Your form field name Form field value entered by client.
#
$form_data{'first_name'} = "John";
$form_data{'last_name'} = "Doe";
$form_data{'payment_method'} = "CC";
$form_data{'card_num'} = "4007000000027";
$form_data{'expiration_date'} = "11/2001";
$form_data{'charge_amount'} = "49.95";
# NOTE: There are various test card numbers available.
# By using a specific card number and a specific amount
# while in test mode you can force v3.0 transact.dll to return
# various error messages to your script for testing purposes.
# If you get an error message while in test mode make sure you
# did not inadvertently use a test card and amount that was
# intended to produce an error message.
# If Net::SSLeay is installed as a local module uncomment the following
# line and edit it to point to the directory just above your Net directory.
# In this example line Net::SSLeay was installed locally and the SSLeay.PM
# file in my "/usr/local/lib/perl5/site_perl/Net" directory.
#
use lib '/usr/local/lib/perl5/site_perl';
DO NOT CHANGE ANYTHING BELOW HERE UNLESS YOU KNOW WHAT YOUR DOING!
# The following variables and form fields are the bare minimum
# required data. Please read the AuthorizeNet v3.0 transact.dll
# documentation for a complete list of form fields and their
# uses!
# In your actual script either commented out the following line
# or changed to "FALSE".
# NOTE: Transactions processed with this set to "TRUE" will
# will NOT appear in your transaction batch files at
# AuthorizeNet!
$test_mode = "TRUE";
$echo_data = "TRUE";
# Communications settings. These don't change.
#
$host = "secure.authorize.net";
$script = "/gateway/transact.dll";
$port = "443";
# Load the Net::SSLeay library and import some subroutines
# for our use.
#
use Net::SSLeay qw(post_https make_headers make_form);
# Uncomment the following line to turn on trace for
# even more debugging information.
# Trace can be 1,2 or 3. Default is 1.
#
#$Net::SSLeay::trace = 3;
# Version autodetect in OpenSSL is still broken so set it manually.
#
$Net::SSLeay::ssl_version = 3;
Fill in the v3.0 transact.dll fields with the data you
collected via your checkout form.
#
%form_data = make_form
(
'x_Login' => $login
,'x_Version' => $an_version
,'x_ADC_Delim_Data' => $adc_delim_data
,'x_ADC_URL' => $adc_url
,'x_Type' => $authorization_type
,'x_Test_Request' => $test_mode
,'x_Method' => $form_data{'payment_method'}
,'x_First_Name' => $form_data{'first_name'}
,'x_Last_Name' => $form_data{'last_name'}
,'x_Amount' => $form_data{'charge_amount'}
,'x_Card_Num' => $form_data{'card_num'}
,'x_Exp_Date' => $form_data{'expiration_date'}
,'x_Echo_Data' => $echo_data
);
# Send data via SSL and wait for reply via the same
# encrypted channel.
#
($reply_data, $reply_type, %reply_headers) =
post_https($host, $port, $script, '', %form_data);
SHOULD PUT A COMM FAILURE CHECK HERE
print "Sent the following string:<BR>";
print "https://secure.authorize.net/gateway/transact.dll?x_Login=testdrive&x_Version=3.0&x_ADC_Delimited_Data=TRUE&x_ADC_URL=FALSE&x_Type=AUTH_ONLY&x_Test_Request=TRUE&x_Method=CC&x_First_Name=John&x_Last_Name=Doe&x_Amount=49.95&x_Card_Num=4007000000027&x_Exp_Date=11/2001&x_Echo_Data=TRUE<BR><BR>";
The following displays the data received back from the v3.0
transact.dll. What your script does with the data is up to you!
# Display the reply headers.
#
print "Reply headers received from v3.0 transact.dll:<BR>";
foreach $key (keys %reply_headers)
{ print "$key: $reply_headers{$key}<BR>";
}
print "<BR>Reply type specification received from v3.0
transact.dll:<BR> $reply_type<BR>";
split out the returned fields
@ = split (/\,/, $reply_data);
# Print the unparsed reply_data.
#
print STDOUT "<BR>Unparsed reply data:<BR> $reply_data<BR>";
print "<BR>Data returned by v3.0 transact.dll
(see v3.0 transact.dll documentation for
a descriptions of each data item returned):<BR>";
$data_item = 1;
foreach(@)
{ print "Item $data_item: $_<BR>";
$data_item++;
}
EOF