I have a paypal shopping cart that works good. However, I have not found a way for at the end of an order to have my database updated for that order. Everytime someone orders a product, I must update the inventory in the databse. I will have no problems doing this besides one thing.
All i need to know is how to get those variables such as order #, cust e-mail, etc.. to my server.
Paypal gives you the following code:
#!/usr/local/bin/perl
read the 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','https://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++;
}
assign posted variables to local variables
$receiver_email = $variable{'receiver_email'};
$item_name = $variable{'item_name'};
$item_number = $variable{'item_number'};
$custom = $variable{'custom'};
$payment_status = $variable{'payment_status'};
$payment_date = $variable{'payment_date'};
$payment_gross = $variable{'payment_gross'};
$payment_fee = $variable{'payment_fee'};
$txn_id = $variable{'txn_id'};
$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'};
$payer_email = $variable{'payer_email'};
if ($res->content eq 'VERIFIED') {
check transaction for uniqueness
process payment
}
elsif ($res->content eq 'INVALID') {
possible fraud
}
else {
error
}
This is fine. However, is there a way to change this into php? Or is there a way to include a php file or a way to update a mysql db with this?
Or, if I have this as an include at the top of my page, would I be able to do that?
Thanks,
Jason