Jump to content


Photo

$res->content always is HTTP::Response=HASH(0x83c1


  • This topic is locked This topic is locked
6 replies to this topic

#1 EricM

EricM

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 15 October 2003 - 04:27 PM

The values always look like this:

$res->is_error = HTTP::Response=HASH(0x83c1a6c)->is_error
$res->content = HTTP::Response=HASH(0x83c1a6c)->content
$res->response = HTTP::Response=HASH(0x83c1a6c)->response
$res->data = HTTP::Response=HASH(0x83c1a6c)->data

here is my code:

#!/usr/bin/perl

# 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.paypal.com/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++;
}

open (MAIL, "|/var/qmail/bin/sendmail -t") || die "Can't open $path_to_sendmail!\n";
print MAIL "To: ***my email address***\n";
print MAIL "Subject: IPN Payment!\n\n";
print MAIL <<to_the_end;

\$res->response = $res->response

business = $variable{'business'}
receiver_email = $variable{'receiver_email'}
item_name = $variable{'item_name'}
item_number = $variable{'item_number'}
quantity = $variable{'quantity'}
invoice = $variable{'invoice'}
custom = $variable{'custom'}
memo = $variable{'memo'}
tax = $variable{'tax'}
option_name1 = $variable{'option_name1'}
option_selection1 = $variable{'option_selection1'}
option_name2 = $variable{'option_name2'}
option_selection2 = $variable{'option_selection2'}
num_cart_items = $variable{'num_cart_items'}
payment_status = $variable{'payment_status'}
pending_reason = $variable{'pending_reason'}
payment_date = $variable{'payment_date'}
settle_amount = $variable{'settle_amount'}
settle_currency = $variable{'settle_currency'}
exchange_rate = $variable{'exchange_rate'}
mc_gross = $variable{'mc_gross'}
mc_fee = $variable{'mc_fee'}
mc_currency = $variable{'mc_currency'}
txn_id = $variable{'txn_id'}
txn_type = $variable{'txn_type'}
for_auction = $variable{'for_auction'}
first_name = $variable{'first_name'}
last_name = $variable{'last_name'}
address_street = $variable{'address_street'}
address_city = $variable{'address_city'}
address_state = $variable{'address_state'}
address_zip = $variable{'address_zip'}
address_country = $variable{'address_country'}
address_status = $variable{'address_status'}
payer_email = $variable{'payer_email'}
payer_id = $variable{'payer_id'}
payer_status = $variable{'payer_status'}
payment_type = $variable{'payment_type'}
notify_version = $variable{'notify_version'}
verify_sign = $variable{'verify_sign'}
payment_gross = $variable{'payment_gross'}
payment_fee = $variable{'payment_fee'}
subscr_date = $variable{'subscr_date'}
subscr_effective = $variable{'subscr_effective'}
period1 = $variable{'period1'}
period2 = $variable{'period2'}
period3 = $variable{'period3'}
amount1 = $variable{'amount1'}
amount2 = $variable{'amount2'}
amount3 = $variable{'amount3'}
mc_amount1 = $variable{'mc_amount1'}
mc_amount2 = $variable{'mc_amount2'}
mc_amount3 = $variable{'mc_amount3'}
mc_currency = $variable{'mc_currency'}
recurring = $variable{'recurring'}
reattempt = $variable{'reattempt'}
retry_at = $variable{'retry_at'}
recur_times = $variable{'recur_times'}
username = $variable{'username'}
password = $variable{'password'}
subscr_id = $variable{'subscr_id'}


to_the_end

close (MAIL);


#2 goingcrazy

goingcrazy

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 16 October 2003 - 05:18 PM

1st. I am also using emails to send me errors or good things based on what the handshake gives. You should send your email after everything is defined.

I am not positive but, I believe the format of your sendmail procedure is incorrect. I think you have two different ways of using sendmail combined. If you want an easier way of sending plain text and HTML's emails once the IPN handshake has been initiated, visit http://alma.ch/perl/...-FAQ.html#HTML.

2nd. I just learn this. With any testing of the handshake between PayPal and you, you MUST have their Verified/Invalid check in your script. Not only will things go wrong but the IPN will hit your script every chance it gets for 2 days and then they actually remove the script call from you PayPal profile.

Here is an Example:


#!/usr/bin/perl

# 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.paypal.com/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++;

########I HAD A PIECE OF BETA CODE HERE BUT TOOK IT OUT############
#################IT WASN'T GOING TO WORK#################

}

business = $variable{'business'}
receiver_email = $variable{'receiver_email'}
item_name = $variable{'item_name'}
item_number = $variable{'item_number'}
quantity = $variable{'quantity'}
invoice = $variable{'invoice'}
custom = $variable{'custom'}
memo = $variable{'memo'}
tax = $variable{'tax'}
option_name1 = $variable{'option_name1'}
option_selection1 = $variable{'option_selection1'}
option_name2 = $variable{'option_name2'}
option_selection2 = $variable{'option_selection2'}
num_cart_items = $variable{'num_cart_items'}
payment_status = $variable{'payment_status'}
pending_reason = $variable{'pending_reason'}
payment_date = $variable{'payment_date'}
settle_amount = $variable{'settle_amount'}
settle_currency = $variable{'settle_currency'}
exchange_rate = $variable{'exchange_rate'}
mc_gross = $variable{'mc_gross'}
mc_fee = $variable{'mc_fee'}
mc_currency = $variable{'mc_currency'}
txn_id = $variable{'txn_id'}
txn_type = $variable{'txn_type'}
for_auction = $variable{'for_auction'}
first_name = $variable{'first_name'}
last_name = $variable{'last_name'}
address_street = $variable{'address_street'}
address_city = $variable{'address_city'}
address_state = $variable{'address_state'}
address_zip = $variable{'address_zip'}
address_country = $variable{'address_country'}
address_status = $variable{'address_status'}
payer_email = $variable{'payer_email'}
payer_id = $variable{'payer_id'}
payer_status = $variable{'payer_status'}
payment_type = $variable{'payment_type'}
notify_version = $variable{'notify_version'}
verify_sign = $variable{'verify_sign'}
payment_gross = $variable{'payment_gross'}
payment_fee = $variable{'payment_fee'}
subscr_date = $variable{'subscr_date'}
subscr_effective = $variable{'subscr_effective'}
period1 = $variable{'period1'}
period2 = $variable{'period2'}
period3 = $variable{'period3'}
amount1 = $variable{'amount1'}
amount2 = $variable{'amount2'}
amount3 = $variable{'amount3'}
mc_amount1 = $variable{'mc_amount1'}
mc_amount2 = $variable{'mc_amount2'}
mc_amount3 = $variable{'mc_amount3'}
mc_currency = $variable{'mc_currency'}
recurring = $variable{'recurring'}
reattempt = $variable{'reattempt'}
retry_at = $variable{'retry_at'}
recur_times = $variable{'recur_times'}
username = $variable{'username'}
password = $variable{'password'}
subscr_id = $variable{'subscr_id'}



#This is what you are missing------------------
if ($res->is_error) {
# send error email or print to browser for your test.
}
elsif ($res->content eq 'VERIFIED') {
#ATTN ANYONE READING THIS. I confirmed this with PayPal today The example in the Perl# IPN code snipet, testing #if (payment_status eq "Completed") within this if statement is wrong! This will not be #true in every case.

#The best thing to do is just test the receiver_email, tax id if you have one or maybe #send a unique custom number through paypal which #you could test through the handshake.
if($receiver_email eq "youremail\@you.com"){
#I call a subroutine here to handle the rest but.....
# send good email or print to browser for your test, all the variables you have defined.
}else{
# send error email or print to browser for your test.
}
elsif ($res->content eq 'INVALID') {
# log for manual investigation
}
else {
# error
}
print "content-type: text/plain\n\n";
###-----------------------------------------

I hope I was of some help to you. I am still working out some kinks myself but I know your probably goingcrazy right now so feel free to contact me using my profile. This probably won’t be your last bottleneck figuring out the IPN.

Highest Regards,
Jason


#3 EricM

EricM

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 26 October 2003 - 05:35 PM

The handshake works perfect.
The post back to paypal works

The problem is with $res->content the value of it always looks like "HTTP::Response=HASH(0x83c1a6c)->content" instead of "VERIFIED" or "INVALID" so elsif ($res->content eq 'VERIFIED') { does not work!

#4 goingcrazy

goingcrazy

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 29 October 2003 - 05:07 PM

Hi Eric,

I had a post up for you already but I decided to write a mini IPN script for you. I have a busy night tonight but I am willing to help you. I am working on it now and I will have it up soon. The reason why I am taking the time to do this is because I totally understand where you are coming from!! . I technically am still there but further than you. Let me ask you a question. Have you cried yet?? Ha, ha, ha. Just kidding. I will have it up soon.

Jay


#5 goingcrazy

goingcrazy

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 29 October 2003 - 09:27 PM

Hi Eric, PLEASE TAKE TIME TO READ ALL

OK! This script is pretty straight forward. Although, I am a slow typer and it took about an hour and half to write it because I also docuemnted every step, so please at least use some of it. I am not Mr. Perl but this script should be viable. If someone sees somthing that could be revised, please let us both know.

1st. Change all variable to your own.

2nd. Because of the format used in this forum, the comment fields
may not be commented out properly. Don't forget to check them. You can get rid of all of them if you want to.

3rd. The look and feel can be changed but I have it set up so, in just about every instance you will be able to track whats going. Consider it a debugging script. I did not get a chance to run it but as far as everything checking out for formatting errors, it passed.

Once all variables are in place, just ping the script without going through PayPal. You should get a browser error that reads "The process did not get completed because of a known error". Following that you should get a plain text email which states an error that reads"The buyer is using an invalid method of purchase. Further investigation is required". This way you know the error messages are at least being sent. Then you can can test it through Paypal. I'll be back in a a day or two. Good Luck!!!

###############SCRIPT####################################
#!/usr/bin/perl

#Set mail program variable. This may have been your problem.
$mail_prog = '/usr/lib/sendmail';

# get proper modules.
use LWP::UserAgent;

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

$ua = new LWP::UserAgent;
#if you are using a SSL connection, use the line below.
#$req = new HTTP::Request 'POST','https://www.paypal.com/cgi-bin/webscr';

#if not keep the line below uncommented.
$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);

# 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++;
}

#I would use "my" to declare your variables local to the script if I were you.
#Example: my($receiver_email,$item_number,
#$item_number,$quantity,$invoice,$store_email,$memo);


$receiver_email = $variable{'receiver_email'};
$item_name = $variable{'item_name'};
$item_number = $variable{'item_number'};
$quantity = $variable{'quantity'};
$invoice = $variable{'invoice'};
$custom = $variable{'custom'};
$memo = $variable{'memo'};
#I would send them through a metacharcter filter as well.(High Security risk if not checked. #Contact me if you don't know what I mean )

#I am making an error variable to pass when a die is called so you can determine,
#where your problem is happening if there is one. You should use die(); in any
#case in this script instead of exit(). exit() doesn't kill the script properly,
#especially in subroutines.

#lets make sure its blank for now.
$eric_angry_error = "";

#set email to check against paypal.
$email_for_paypal = "your\@email2checkagainst.com";

#set email to send errors and successful transaction.
$email_2_send = "your\@email2checkagainst.com";


#If die() is called in script, automatically send to eric_error subroutine. This will
#will send YOU any error that occurs.
$SIG{__DIE__}= \&eric_error;

#This statement I put to print to browser, when we print simple messages
#(when its time) of the status of the script.
print "Content-type: text/html\n\n";

#If there is no URL the IPN can talk to(if this script is not accessible), send error.
if ($res->is_error) {
$eric_angry_error = "There is no script to talk to in my Profile or by using the notify_url hidden field.";
die($eric_angry_error);
}

elsif ($res->content eq 'VERIFIED'){
#REMEBER checking if(payment_status eq "Completed") is wrong. This will not always
#be the case. Your best off checking against your invoice or custom variables.
if($receiver_email eq $email_for_paypal){
#Its OK, do nothing. You can call a subroutine here if you wanted to.
#I figured, if it makes it past these checks, your good anyway, so I
#just set it all up below.
}else{
$eric_angry_error = "The paypal email does not match the email we use for purchases.";
die($eric_angry_error);
}
}

elsif ($res->content eq 'INVALID'){
$eric_angry_error = "The buyer is using an invalid method of purchase. Further investigation is required.";
die($eric_angry_error);
}else{
$eric_angry_error = "The problem that occurred is undetermined. Further investigation is required.";
die($eric_angry_error);
}

#At this point everything should be good-to-go! This is just set up to send an email
#with the variable in any case. When determining what you want to do next, use the
#transaction type(I think it is 'txn_type') variable for your
#conditioning NOT PAYMENT_STATUS.



# I have your\@email2checkagainst.com hardcoded in instead of the variable for the
#reply and from fields because I think there was some reason why you couldn't use the
#variable way. I am not sure, maybe I was goingcrazy that day. you can try it.
#
#set up an error incase there is a problem.
$eric_angry_error = "There was a problem sending succssful email,$Mail::Sendmail::error";

#Send successful mail.
open (MAIL, "|$mail_prog -t");
print MAIL "To:$email_2_send";
print MAIL "Reply-to:your\@email2checkagainst.com\n";
print MAIL "From:your\@email2checkagainst.com\n";
print MAIL "Subject: A smooth transaction occurred with PayPal IPN.\n";
print MAIL "\n\n";
print MAIL "This is great. I believe someone bought something. We freaking hoo.\n";
print MAIL "Receiver Email: ".$receiver_email."\n" ;
print MAIL "Item Number: ".$item_number."\n" ;
print MAIL "Item Name: ".$item_number."\n" ;
print MAIL "Quantity: ".$quantity."\n" ;
print MAIL "Invoice: ".$invoice."\n";
print MAIL "custom: ".$store_email."\n" ;
print MAIL "memo: ".$memo."\n" ;
print MAIL "\n\n";
close (MAIL) or die($eric_angry_error);


#This is just to make the browser happy. You will never see this.
print "All Transactions Complete.\n";

#exit in this case is OK because you are at the end of the script and your not
#exiting from a subroutine. You don't have to do this either. Its just makes a smoother.
#It does tell the Perl interputer to shut down making it have to reopen next
#script used. Its just takes a couple more seconds to load the next script.
exit(0);



#This subroutine sends what ever the die error is.
sub eric_error {
my ($eric_angry_error) = @_;


#If there is a problem sending this email, you won't get there error below
#because the die subroutine is this subroutine. It should still die properly.
$only_other_error = "We died while being dead,$Mail::Sendmail::error";

open (MAIL, "|$mail_prog -t");
print MAIL "To:$email_2_send";
print MAIL "Reply-to:towhoever\@towhoever.com\n";
print MAIL "From:towhoever\@towhoever.com\n";
print MAIL "Subject:There was a problem with a buyer transaction.\n";
print MAIL "\n\n";
print MAIL "There was a fatal error when processing a user's request:\n";
print MAIL "The following error occurred:\n";
print MAIL "".$eric_angry_error."\n";
print MAIL "\n\n";
close (MAIL) or die($only_other_error);

#This just makes it so, if you just ping your script without using paypal,
#you will at least see the message below in your browser or anyone who tries
#for that matter. An error message should be sent saying and the buyer used an
#INVALID method.
print "The process did not get completed because of a known error.\n";
}
################End of script############################

#6 cwspaypal

cwspaypal

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 18 December 2003 - 06:13 PM

I have just tested the PERL code you posted but it continues to come back as "Your script did not reply!"

I have only changed the email variables and am testing this code from here: http://www.eliteweav...ing/ipntest.php

If you get this soon, let me know what may be the problem... Im certain I have the LWP modules installed, as I have just done that before setting this stuff up. Is there any configuration that needs to take place for the LWP module?

Help would be appreciated. Thank you.

#7 goingcrazy

goingcrazy

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 20 December 2003 - 07:28 PM

The test you are doing at the portal is unpredictable. Some scripts it works for, some it doesn't. I believe you have to manually test your script with your own methods to really see what you are doing.

As far as the message, "Your script did not reply", what condition is giving the message? This message I assume is your own spawned message, right??? I will try and help you if you can tell me what condition this message is displayed from.
Catch you later,
goingcrazy

P.S. I am not affiliated with PayPalDev in anyway. I do come here every once in awhile to try and help people that are in the situation I once was. There should be more help with the IPN through PayPal but unfortunately there isn’t.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users