htmanning has asked for the wisdom of the Perl Monks concerning the following question:
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.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>";
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: API Request Help
by Anonymous Monk on Nov 13, 2012 at 10:00 UTC |