PDA

View Full Version : PayPal IPN (instant Payment Notification


gtroll
July 2nd, 2002, 12:27 AM
Can you incorporate the PayPal IPN function to confirm orders http://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/pp-solutions-ipn-outside
There's a new PHP routine posted
[code:1:f46a697b24]<?php

// read post from PayPal system and add 'cmd'
$postvars = array();
while (list ($key, $value) = each ($HTTP_POST_VARS)) {
$postvars[] = $key;
}
$req = 'cmd=_notify-validate';
for ($var = 0; $var < count ($postvars); $var++) {
$postvar_key = $postvars[$var];
$postvar_value = $$postvars[$var];
$req .= "&" . $postvar_key . "=" . urlencode ($postvar_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
// note: additional IPN variables also available -- see IPN documentation
$item_name = $HTTP_POST_VARS['item_name'];
$receiver_email = $HTTP_POST_VARS['receiver_email'];
$item_number = $HTTP_POST_VARS['item_number'];
$invoice = $HTTP_POST_VARS['invoice'];
$payment_status = $HTTP_POST_VARS['payment_status'];
$payment_gross = $HTTP_POST_VARS['payment_gross'];
$txn_id = $HTTP_POST_VARS['txn_id'];
$payer_email = $HTTP_POST_VARS['payer_email'];

if (!$fp) {
// HTTP ERROR
echo "$errstr ($errno)";
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status=Completed
// check that txn_id has not been previously processed
// check that receiver_email is an email address in your PayPal account
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>[/code:1:f46a697b24]

Jamie
July 3rd, 2002, 06:54 PM
We will see what we can do to get it in the next version. Thanks for the code. 8)

gtroll
July 21st, 2002, 11:00 PM
I changed the form paypal.php to the below code so that a persons
Paypal application is prepopulated.
[code:1:1504e31223]<?
$paypal_email = get_field_val("Payment_Methods","PayPal_Email","Na me = 'PayPal'");
$store_info = get_records("Store_Information",0,"record_number = \"1\"",0,0);
$item_name = $store_info[0][Company_Name]." order # ".$order['number'];
$url = $store_info[0][URL];
?>
<span class="header"><?=$Final_Payment_Image?></span><br><br>
Your order has been placed, and is in our database. <br>
To continue, click the button below to submit payment via PayPal. <br>

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_ext-enter">
<input type="hidden" name="redirect_cmd" value="_xclick">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="email" value="<?=$SESSION[order][Bill_Email_Address]?>">
<input type=HIDDEN name="first_name" TYPE="text" VALUE="<?=$Bill_First_Name?>">
<input type=HIDDEN name="last_name" TYPE="text" VALUE="<?=$Bill_Last_Name?>">
<input type="hidden" name="address1" value="<?=$Bill_Street?>">
<input type="hidden" name="address2" value="<?=$Bill_Street_2?>">
<input type="hidden" name="city" value="<?=$Bill_City?>">
<input type="hidden" name="state" value="<?=$Bill_State_or_Province?>">
<input type="hidden" name="zip" value="<?=$Bill_Postal_Code?>">
<input type="hidden" name="night_phone_a" value="<?=$Bill_Phone?>">
<input type="hidden" name="business" value="<?=$paypal_email ?>">
<input type="hidden" name="item_name" value="<?=$item_name?>">
<input type="hidden" name="amount" value="<?=$SESSION[order][grand_total] ?>">
<input type="hidden" name="shipping" value="">
<input type="hidden" name="return" value="<?=$url ?>">
<input type="hidden" name="cancel_return" value="<?=$url ?>">
<input type="hidden" name="no_note" value="1">
<input type="image" src="<?=$PayPal_Button?>" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>[/code:1:1504e31223]
This doesn't seen to be getting the variables from the cart I tried changing one to <?=$SESSION[order][Bill_Email_Address]?> and that does not seem to work either

Jamie
July 22nd, 2002, 02:29 PM
Sorry for the delay. I will check this out soon. Are you trying to get IPN to work? I need to research this some more and check out PayPal's reference material. Check out the payment gateway file for Authorize.net:
squirrelcart/payment_gateways/authorizenet.php. This will probably help. The way you would access the info is the same as in that file. Something like this:
[code:1:a93f855ef1]<?=$order[Bill_Addr][Email_Address] ?>[/code:1:a93f855ef1]

-Jamie

gtroll
July 22nd, 2002, 02:45 PM
I haven't worked on the IPN yet hoping you could... https://www.paypal.com/html/ipn.pdf
I'll try the method you suggest <?=$order[Bill_Addr][Email_Address] ?>
Thanks
Scott

Jamie
July 22nd, 2002, 04:14 PM
I will definitely be working on it as a new feature soon.

gtroll
October 4th, 2002, 12:10 AM
This might work best integrated into the order tracking as mentioned in http://www.squirrelcart.com/forums/viewtopic.php?t=250
http://www.squirrelcart.com/forums/viewtopic.php?t=47
Each order would have a status received,paid,shipped with a interface to allow one to enter status manually for gateways that do not support a confirmation.

Jamie
October 4th, 2002, 09:48 AM
I will check it out. Thanks for the idea!