inblosam has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to get the instant payment notification module on paypal to work with my server. I have this script running fine on regular transactions, but on subscriptions it doesn't work. PayPal said that the subscriptions engine that interacts with the database is pickier than the standard one, and that it only accepts the variables from your script if they are in the same order that was sent. I can't seem to get them to be in the same order as they were sent to me. Any ideas?
#!/usr/bin/perl my $query=''; my @inp=split(/\:/,$input{input_fields}); foreach my $ikey (@inp){ next if $ikey=~/inview|cid/is; $query .= "\&$ikey=$input{$ikey}"; } $query .= '&cmd=_notify-validate'; # post back to PayPal system to validate (in same order as they passed + it to us) use LWP::UserAgent; $ua = new LWP::UserAgent; $req = new HTTP::Request 'POST','http://www.paypal.com/cgi-bin/webscr' +; $req->content_type('application/x-www-form-urlencoded'); $req->content($query); $res = $ua->request($req); my $result=''; if ($res->is_error) { $result='HTTP Error'; print 'HTTP Error\n'; } else{ $result = $input{payment_status}; } print "\nRESULT:$result\n";


Michael Jensen
michael at inshift.com
http://www.inshift.com

Replies are listed 'Best First'.
Re: post variables in same order
by chromatic (Archbishop) on Jun 27, 2002 at 20:01 UTC
    My idea that running under strict with warnings enabled would reveal that you haven't defined %input -- at least, not in the code you've posted here. If you use CGI.pm, you might find that the query_string() function comes in handy.
Re: post variables in same order
by dws (Chancellor) on Jun 27, 2002 at 20:24 UTC
    You don't mention how you're getting the parameters, but if you're using CGI.pm, all_parameters() will return a list of parameters, in the order they were received.

    You might also carefully examine the post request you're creating, by adding   print $req->as_string(); Building a request by hand (instead of using HTTP::Request::Common) takes great care. In particular, you need to ensure that the content is URL encoded. Your script doesn't guarantee that.

      In using CGI.pm, what do I need my "use" statement to refer to? I tried searching on CPAN for it, but that didn't help. I know I've seen it used before somewhere. Does "all_parameters()" return the list in a hash?
      Thanks!!

      Michael Jensen
      michael at inshift.com
      http://www.inshift.com
        In using CGI.pm, what do I need my "use" statement to refer to?

        Hm.. all_parameters() doesn't seem to be part of the public API for CGI.pm. To use it, you need to create an instance of CGI, and invoke all_parameters() as a method call.

        use CGI; ... my $cgi = new CGI(); ... my @paramsInOrder = $cgi->all_parameters();
        should do what you need.

•Re: post variables in same order
by merlyn (Sage) on Jun 27, 2002 at 21:20 UTC
    it only accepts the variables from your script if they are in the same order that was sent
    That's a fairly bad design. No browser guarantees that. No spec guarantees that. They must have checked with "both browsers" {choke} and decided that this is the way that it always works. How sad. How stupid. How typical.

    -- Randal L. Schwartz, Perl hacker

      Actually, it is not a browser interfacing with the script. How it ends up working (which I think is still lame (sad, stupid, and typical, quote/unquote)) is a transaction happens from a browser that posts to them, then their server posts to my script on my server, which then posts back to them, and waits then receives a response back. Some of it is for security, validity, etc. I still think it is lame that they check for an exact order though. Thanks everybody for the help.

      Michael Jensen
      michael at inshift.com
      http://www.inshift.com
Re: post variables in same order
by Aristotle (Chancellor) on Jun 27, 2002 at 21:46 UTC
    Beaten to all the punch by chromatic++ and merlyn++, but their points can't be emphasized enough.

    Makeshifts last the longest.