Forum Home
Press F1
 
Thread ID: 59123 2005-06-22 04:40:00 paypal help ipn script and everything else Morgenmuffel (187) Press F1
Post ID Timestamp Content User
366033 2005-06-22 04:40:00 Greeting all

1st) yes I have RTFM, but it left me more confused than when i began

2nd) The website i am working on had a paypal hosted cart, and when a successful sale happened they got an email to that effect (there was no working backend database), as they wanted to add a direct credit option and Credit card gateway we had to replace the paypal hosted cart, so we built a new cart for them, and got the direct credit and credit card end working . Now all i need to do is get the paypal side working and that is where I run into problems .

3rd) I am looking at using the buy now option, to send the aggregate amount through to paypal, the problem is i have no idea how to go about testing etc what is this 'sandbox' I hear mentioned on the paypal forums, is it free to sign up to?

Is there a step by step illustrated guide to setting up the process (a little more indepth than the paypal guides) that use a a realistic setup

Lets put it this way - the credit card gateway setup was a 3 page pdf written in plain english that was a snap to follow, whereas the paypal setup is 110 pages and I am still not 100% sure what i need to know


Firstly here is an ipn script i got from paypal i have a few queries they are prefixed within the code by a
//>>>>>




// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req . = "&$key=$value";
}

// post back to PayPal system to validate
$header . = "POST /cgi-bin/webscr HTTP/1 . 0\r\n";
$header . = "Content-Type: application/x-www-form-urlencoded\r\n";
$header . = "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www . paypal . com', 80, $errno, $errstr, 30);

// assign posted variables to local variables
//>>>>>>I assume these are the variables posted to me by paypal?
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

// check the payment_status is Completed


// check that txn_id has not been previously processed
//>>>>>>> Now as i understand it e-checks can take 3 days to clear, so technically the first email i would have received would say 'pending' and this would write the txn_id into the database, which would cause an error when i get a second e-mail saying the transaction was 'completed' ?

// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct


// process payment
//>>>>>> I ASSUME THIS MEANS THAT I UPDATE MY ORDERS DATABASE


}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>



Is it simplly a case of sending everything through on the button and then having it return to a page containing the above code, or is there way more to it

Thanks for reading this far, any help would be greatly appreciated especially about the testing aspects thanks

Nigel
Morgenmuffel (187)
1