Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

SOLVED! I had forgotten to redirect STDIN and STDOUT to /dev/null

I have a client whose web store software will interface with Authorize.Net, but waits until it has built a job before responding. This often takes longer than Authorize.Net's timeout. So what I want to do is put a CGI script up to accept the POST response from Authorize.Net, immediately respond positively to Authorize.Net, then send the POST data from Authorize.Net on to the web store. I've got the CGI script together. Authorize.Net successfully communicates with the CGI script, and that CGI script is capable of passing the POST data on. However, no matter what I do, it seems, when I pass the POST data on, i'm waiting on the web store to respond before Authorize.Net gets my response.


#!/usr/bin/perl # A script to accept a POST response from Authorize.Net and pass the d +ata to Xerox use strict; use CGI; use Digest::MD5 qw/md5_hex/; use LWP; use Config::YAML; use CGI::Carp qw(fatalsToBrowser); use POSIX qw/strftime/; use Time::HiRes qw/time/; use Data::Dumper; my $configFile = 'adn_helper.yaml'; for (0..$#ARGV) { $configFile = $ARGV[$_ + 1] and last if /--config/; } my $config = Config::YAML->new( config => $configFile, timeout => 60, db_host => q/localhost/, db_name => q/adn_passthrough_log/, ); for (qw/salt loginID postURL/) { die "Missing required key \"$_\" in configuration file" unless $co +nfig->{$_}; } my $query = new CGI; $query->import_names('Q'); my $t0 = time; my $old_handle = select(STDOUT); local $| = 1; select($old_handle); syswrite STDOUT, "Content-type: text/html\n\n"; my $md5 = md5_hex($config->{salt}, $config->{loginID}, $Q::x_trans_id, + $Q::x_amount); if (lc($md5) eq lc($Q::x_MD5_Hash)) { my $browser = getBrowser($Q::sid); my %hash; $hash{$_} = $query->param($_) for $query->param; logline(" params: ", Dumper [$query->param]); logline(" ", Dumper \%hash); syswrite STDOUT, "Your card was successfully charged for \$$Q::x_a +mount<br>\n" if $Q::x_response_reason_code == 1; syswrite STDOUT, "Your card could not be charged. $Q::x_response_ +reason_text<br>\n" if $Q::x_response_reason_code == 2; syswrite STDOUT, "There was an error processing your card: $Q::x_r +esponse_reason_text<br>\n" if $Q::x_response_reason_code > 2; my $pid = fork; my $elapsed = time - $t0; if ($pid) { # parent logline(" time elapsed in responding to Authorize.Net and fork +ing: $elapsed"); logline(" forked, child pid $pid"); close STDOUT; exit; } open STDIN, "</dev/null"; open STDOUT, ">/dev/null"; $t0 = time; my $response = $browser->post($config->{postURL}, [%hash]); $elapsed = time - $t0; logline(" time elapsed in waiting for response from Xerox: $elapse +d"); logline(" query: ", Dumper $query); logline(" response: ", Dumper $response); } else { logger($query, undef); print "This transaction could not be processed due to a checksum m +ismatch.<br>"; # possible spoofing attack } sub logger { use DBI; my ($query, $response, $elapsed) = @_; my $dbh = DBI->connect("DBI:mysql:$config->{db_name};host=$config- +>{db_host}", $config->{db_username}, $config->{db_password}, { RaiseE +rror => 1 }) || die "Could not connect to logging database: $DBI::errstr"; open my $out, ">>/tmp/passthrough.log"; print $out strftime("%Y-%m-%d %T\n", localtime(time)); print $out "Elapsed: $elapsed\n"; print $out "Query\n"; print $out Dumper $query, "\n"; print $out "Response\n"; print $out Dumper $response, "\n"; close $out; } sub logline { open my $out, ">>/tmp/passthrough.log"; print $out strftime("%Y-%m-%d %T", localtime(time)), @_, "\n"; } sub getBrowser { my $sid = shift; open my $out, ">>/tmp/passthrough.log"; print $out strftime("%Y-%m-%d %T: ", localtime(time)), "Creating L +WP::UserAgent with Session ID $sid, user-agent $ENV{HTTP_USER_AGENT}\ +n"; close $out; my $browser = LWP::UserAgent->new(); $browser->timeout($config->{timeout}); $browser->cookie_jar({}); $browser->agent($ENV{HTTP_USER_AGENT}); # $cookie_jar->set_cookie( $version, $key, $val, $path, $domain, $port +, $path_spec, $secure, $maxage, $discard, \%rest ) $browser->cookie_jar->set_cookie(1, 'SessionID', "SessionID=$sid", + '/'); return $browser; }

In reply to Responding to Authorize.Net by PopeFelix

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (3)
    As of 2018-03-21 23:27 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (272 votes). Check out past polls.