EchoFool Posted September 22, 2008 Share Posted September 22, 2008 I am having difficulty with this....and paypal have the worst help responses ever they just keep copying and pasted me the same page that i was confused on when i read it in first place. I'm trying to get the IPN on my paypal buy script.... i have it set to go to my script: dpcomplete.php though my buying form takes the user to: ppcomplete.php when the purchase is done (paypal when i asked them do these two things suppse to be linked to same php file... i never had a reply for over 3 weeks and still waiting) Secondly.... has any one actually used the IPN script from paypal.. i don't get how i get it to retrieved the necessary infomation. I got the php example from their site...but their notes don't really explain a great deal as to what or why i need to do what it says.... could you please explain it to me if possible? This is their example, i have put my questions in brackets next to what im confused with. <?php // 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 ('ssl://www.paypal.com', 443, $errno, $errstr, 30); // assign posted variables to local variables $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 (What kind of error are we talking about here) } else { //(what is this while loop for below my current guess is if the user has purchased with a quantity greater than 1? Though i see no quantity around) fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { // check the payment_status is Completed (how ? what am i checking this against? is 1 = complete or 0 = complete? or something else..) // check that txn_id has not been previously processed (again what do i check this against?) // check that receiver_email is your Primary PayPal email (though my buy button is using a secondary email) // check that payment_amount/payment_currency are correct // process payment (thought paypal does the transaction of money automatically? or is this to give the user the item or what ever it is they bought? and if it is that... wheres the quantity value?) } else if (strcmp ($res, "INVALID") == 0) { // log for manual investigation (what am i loggin here... what is the failure if script is at this point?) } } fclose ($fp); } ?> Hope you can help explain to me my confusions. Quote Link to comment https://forums.phpfreaks.com/topic/125309-help-with-paypal-buying/ Share on other sites More sharing options...
JonnoTheDev Posted September 22, 2008 Share Posted September 22, 2008 Forget all that rubbish in the comments. What they are saying is that this line indicates a successful transaction: if (strcmp ($res, "VERIFIED") == 0) { So what you do is replace the comment block with your own transaction logging i.e. where you save the successful transaction into your own database. you can add checks to make sure that the $txn_id id has not already been processed by checking against your own database records. You would obviously store this number for customer reference. This indicates a failed transaction. You may also want to store failed transactions also else if (strcmp ($res, "INVALID") == 0) { Quote Link to comment https://forums.phpfreaks.com/topic/125309-help-with-paypal-buying/#findComment-647767 Share on other sites More sharing options...
JonnoTheDev Posted September 22, 2008 Share Posted September 22, 2008 These are the variables that contain the transaction information sent to your site from paypal. Store them in your database on successful or failed transactions. $item_name $item_number $payment_status $payment_amount $payment_currency $txn_id $receiver_email $payer_email Quote Link to comment https://forums.phpfreaks.com/topic/125309-help-with-paypal-buying/#findComment-647771 Share on other sites More sharing options...
EchoFool Posted September 22, 2008 Author Share Posted September 22, 2008 Does it not give quantity? Becuase otherwise how does my site know how many items to give to the user that they paid for? Quote Link to comment https://forums.phpfreaks.com/topic/125309-help-with-paypal-buying/#findComment-647778 Share on other sites More sharing options...
JonnoTheDev Posted September 22, 2008 Share Posted September 22, 2008 Are you not sending this value to paypal in a button to start with including the price and currency. The quantity may also be posted back in a variable. Check out the IPN docs. Possibly $_POST['qty']; Quote Link to comment https://forums.phpfreaks.com/topic/125309-help-with-paypal-buying/#findComment-647990 Share on other sites More sharing options...
EchoFool Posted September 22, 2008 Author Share Posted September 22, 2008 Well at moment you click buy then on a paypal page you set the quantity... but ill look into the docs see if i can find it. Quote Link to comment https://forums.phpfreaks.com/topic/125309-help-with-paypal-buying/#findComment-648187 Share on other sites More sharing options...
Guest Xanza Posted September 22, 2008 Share Posted September 22, 2008 Firstly don't blame paypal for your ignorance... It's very easy to search Google for this explanation - if you don't believe me; I've just done it... So shame on you, secondly the documentation on paypal.com is very nice, and well laid out... If you can't find it there - Then you really shouldn't be using paypal as a payment gateway. Sorry to be so blunt. Quote Link to comment https://forums.phpfreaks.com/topic/125309-help-with-paypal-buying/#findComment-648224 Share on other sites More sharing options...
EchoFool Posted September 23, 2008 Author Share Posted September 23, 2008 Firstly don't blame paypal for your ignorance... It's very easy to search Google for this explanation - if you don't believe me; I've just done it... So shame on you, secondly the documentation on paypal.com is very nice, and well laid out... If you can't find it there - Then you really shouldn't be using paypal as a payment gateway. Sorry to be so blunt. I don't see how im ignorant for double checking with this forums from the script i got hold of.... It doesn't claim to say that the return page of the buy form, should be the same page as where the IPN page will be, if it was why does it ask to input the page name in the first place when it should already know when i inputted the return page for the form for purchasing. Quote Link to comment https://forums.phpfreaks.com/topic/125309-help-with-paypal-buying/#findComment-648995 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.