#!/usr/bin/perl -w##### PayPal PDT (Payment Data Transfer) CGI#Brent Crouch #http://www.brentcrouch.com###use strict;use CGI qw(:all unescape);use CGI::Carp qw(fatalsToBrowser);# These modules are required to make the secure HTTP request to PayPal.use LWP::UserAgent;use Crypt::SSLeay;# Javascript modules go heremy $JSCRIPT_HEAD=<EOF_HEAD ;my $JSCRIPT_BODY=< EOF_BODY ;my $auth_token = "-nwJzMe3nAz6e7FHYQmzCXXXXXXXXXXXXXXXXXXXXXX";sub done_text { return (p('Your transaction has been completed, and a receipt for your purchase has been emailed to you. You may log into your account at www.paypal.com to view details of this transaction. You will now be sent to the download area.'), end_html());}print header(), start_html(-title=>'Paypal Processing Script', -head=>meta({-http_equiv=>'refresh',-content=>'1; URL=http://www.jillianentertainment.com/XXXX/XXXXXX.html'}), -script=>$JSCRIPT_HEAD );print $JSCRIPT_BODY; #Puts Javascript code into HTML BODY# Set up the secure request to the PayPal server to fetch the transaction infomy $paypal_server = "www.paypal.com";my $transaction = param("tx");if (not $transaction) { print (h2("The transaction ID was not found."), done_text()); exit();}my $paypal_url = "https://$paypal_server/cgi-bin/webscr";my $query = join("&", "cmd=_notify-synch", "tx=$transaction", "at=$auth_token");my $user_agent = new LWP::UserAgent;my $request = new HTTP::Request("POST", $paypal_url);$request->content_type("application/x-www-form-urlencoded");$request->content($query);# Make the requestmy $result = $user_agent->request($request);if ($result->is_error) { print(h1("An error was encountered"), br(), p("An error was encountered contacting the PayPal server:"), $result->error_as_HTML, done_text()); exit();}# Decode the response into individual lines and unescape any HTML escapesmy @response = split("\n", unescape($result->content));# The status is always the first line of the response.my $status = shift @response;if ($status eq "SUCCESS") { # success my %transaction; foreach my $response_line (@response) { my ($key, $value) = split "=", $response_line; $transaction{$key} = $value; } print((''),(''),(''));#Google Analytics Tracking Codeprint qq[];} elsif ($status eq "FAIL") { print(h2("Unable to retrieve transaction details.")); # failure} else { # unknown error print(h2("Error retrieving transaction details."));}print done_text();