Monks, I'm still trying to make a Paypal API call behind the scenes but it's not working. I'm using the following code, but I need to be able to print the exact string that is getting sent. My print line instead prints the response I get back from their server.
my $ua = LWP::UserAgent->new; $ua->env_proxy; my $response = $ua->post($GATEWAY_URL, { # add other parameters as necessary 'USER' => 'myid', 'VENDOR' => 'myid', 'PARTNER' => 'partner', 'TRXTYPE' => 'S', 'AMT' => '$paymentamount', 'PWD' => 'mypass', 'CREATESECURETOKEN' => 'Y', 'SECURETOKENID' => $sec_token_id } ); print "Response: $response<br><br>";
Paypal cannot tell me what we're missing without the exact string that is being sent to them, and I can't figure out how to get it to them. The following is the entire routine in context. The $sec_token variable never gets set. I'm assuming they're not sending it back, or I'm not parsing it correctly. Either way I can't tell what's wrong unless I can see the exact string that is sent to them. Thanks.
sub Get_Token { use LWP::UserAgent; use LWP::Protocol::https; #my $GATEWAY_URL = 'https://payflowpro.paypal.com'; # For LIVE t +ransactions my $GATEWAY_URL = 'https://pilot-payflowpro.paypal.com'; # For TEST tr +ansactions my $random_string=&Random_String(36); $sec_token_id = $random_string; #print "Random string: ".$random_string."\n"; print "Random Token Sent: ".$sec_token_id."<br><br>"; #print "Length: ".length($random_string)."<br><br>"; # send http post request to gateway my $ua = LWP::UserAgent->new; $ua->env_proxy; my $response = $ua->post($GATEWAY_URL, { # add other parameters as necessary 'USER' => 'myid', 'VENDOR' => 'myid', 'PARTNER' => 'partner', 'TRXTYPE' => 'S', 'AMT' => '$paymentamount', 'PWD' => 'mypass', 'CREATESECURETOKEN' => 'Y', 'SECURETOKENID' => $sec_token_id } ); print "Response Unhashed: $response<br><br>"; unless ($response->is_success) { # request failed print "Error: Problem with secure token. Please contact the admin." +; } # parse server response my $resdec = $response->decoded_content; chomp $resdec; # keys and values into %reshash my @resdata = split(/\&/, $resdec); my %reshash; foreach (@resdata) { my ($key,$val) = split(/=/, $_, 2); $key =~ s/\[\d+\]//; # remove length of SECURETOKEN $reshash{$key} = $val; } # validate response unless (defined $reshash{'SECURETOKENID'} && defined $reshash{'SECURETOKEN'} && defined $reshash{'RESULT'} && defined $reshash{'RESPMSG'} && $reshash{'SECURETOKENID'} eq $sec_token_id && $reshash{'RESULT'} eq '0' && $reshash{'RESPMSG'} eq 'Approved') { # bad response print "Response from Gateway: $resdec<br><br>"; #print "Error: Cannot retrieve secure token. Please contact the adm +in.<br><br>"; } # result: secure token my $sec_token = $reshash{'SECURETOKEN'}; my $sec_token_id = $reshash{'SECURETOKENID'}; } ######## sub Random_String { my $length_of_randomstring=shift;# the length of # the random string to generate my @chars=('a'..'z','A'..'Z','0'..'9'); my $random_string; foreach (1..$length_of_randomstring) { # rand @chars will generate a random # number between 0 and scalar @chars $random_string.=$chars[rand @chars]; } return $random_string; } #Generate the random string

In reply to API Request Help by htmanning

Title:
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, details, 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, summary, 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.