[ic] Running Script as interchange user

Mark Halliday bmhtdev at yahoo.co.uk
Mon May 22 12:22:59 EDT 2006


--- JT Justman <jt-lists at sirius.airdelights.com> wrote:

> 
> Hi again, Mark. Sorry I hadn't replied before; I was out of town over
> the weekend showing off my new baby boy.

Congratulations!

> There are a lot of considerations here, and that's probably why
> nobody
> else jumped on this.

JT, 

Sorry for being a bit slow on the uptake, but I am teaching myself
Linux, perl and interchange at the same time.  Having reread both your
answers, I think what I want to do is to use an actionmap.  If I
understand things correctly this will use a url to run some perl code.

So I have defined an actionmap called abc in catalog.cfg (see below). 
When I enable ipns with the url: www.example.com/cgi-bin/store/abc, the
apache logs show a 200 response, but nothing happens.  I presume my
problem is one of perl syntax.  Does anyone see any glaring errors?  I
have added the return 0 line in the belief that if anyone else happens
on the url they will get no response.

ActionMap abc <<EOR
sub{
     # read post from PayPal system and add 'cmd'
     read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
     $query .= '&cmd=_notify-validate';

     # post back to PayPal system to validate
     use LWP::UserAgent;
     $ua = new LWP::UserAgent;
     $req = new HTTP::Request
'POST','http://www.sandbox.paypal.com/uk/cgi-bin/webscr';
     $req->content_type('application/x-www-form-urlencoded');
     $req->content($query);
     $res = $ua->request($req);

     # split posted variables into pairs
     @pairs = split(/&/, $query);
     $count = 0;
     foreach $pair (@pairs) {
     ($name, $value) = split(/=/, $pair);
     $value =~ tr/+/ /;
     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
     $variable{$name} = $value;
     $count++;
     }

     # assign posted variables to local variables
     $item_name = $variable{'item_name'};
     $item_number = $variable{'item_number'};
     $payment_status = $variable{'payment_status'};
     $payment_amount = $variable{'mc_gross'};
     $payment_currency = $variable{'mc_currency'};
     $txn_id = $variable{'txn_id'};
     $receiver_email = $variable{'receiver_email'};
     $payer_email = $variable{'payer_email'};

     if ($res->is_error) {
     # HTTP error
     }
     ##elsif ($res->content eq 'VERIFIED') {
     # check the $payment_status=Completed
     # check that $txn_id has not been previously processed
     # check that $receiver_email is your Primary PayPal email
     # check that $payment_amount/$payment_currency are correct
     # process payment
     ##}
     ##elsif ($res->content eq 'INVALID') {
     # log for manual investigation
     ##}
     else {
     # error
     }
     #print "content-type: text/plain\n\n";
     #Temporarily create file
     use File::Temp;

     my $basedir = '/tmp/ipn';

     mkdir $basedir unless -d $basedir;
     my $tmp = File::Temp->new( DIR => $basedir );
     my $tmpnam = $tmp->filename;

     open OUT, "> $tmpnam" or die "Cannot create $tmpnam: $!\n";
     return 0;
}
EOR



Send instant messages to your online friends http://uk.messenger.yahoo.com 


More information about the interchange-users mailing list