Jump to content

Two little problems with Paypal IPN,


dezkit

Recommended Posts

hey guys I got this code

	<?php $txn_id = $_POST["txn_id"];
	echo $txn_id;
		$query4 = mysql_query("SELECT * FROM soldpins WHERE transaction='".$txn_id."'") or die(mysql_error());
		$row4 = mysql_fetch_array( $query4 );
		echo "<i>This is a receipt of your purchase</i><br/><br/>";
		echo "Your PIN Number: <b>".$row4["pin"]."</b><br/>";
		echo "The Paypal Username that you had used: <b>".$row4["paypal"]."</b><br/>";
		echo "Your Username: <b>".$row4["name"]."</b><br/>";
		echo "Transaction ID: <b>".$row4["transaction"]."</b><br/><br/>";
		echo "A receipt of the purchase had been sent to your paypal email.<br/>";
		echo "We hope to see you as a customer again soon!<br/><br/>";
		echo "This page will expire as soon as your session expires, <br/>your browser closes, or you buy another PIN Number.<br/><br/>";
		echo "<u>Please save the PIN in a safe place.</u><br/><br/>";
		echo "Click <a href=\"".$this_script."\">here</a> to go back to the main page."; ?>

And almost everytime when i get redirected from paypal after a successful payment, I always get the query blank, after I refresh the page then the query works, for example,

I buy something and get redirected to the page, then Pin number is blank, username is blank, etc, but when i refresh the page it all goes back, by the way, echo $txn_id; SHOWS the id even if the query is blank.

 

oh and need a quick tip, when somebody is in the middle of buying a pin from the database, somebody else buys the last pin, what can i do so that if this happens the person will get an error and get their money refunded instead of actually paying the price and not receiving a pin, thanks guys.

Link to comment
Share on other sites

As for the query being blank, it may be best to setup some logging to try notice a pattern as to when the database doesn't return a response for a $txn_id.  Log the query string (including the dynamic $txn_id) and the number of rows that MySQL returns.  You can use a tool like phpMyAdmin to re-run any suspect queries.  Usually something like this might happen if the database is queried for a txn_id before it has had a chance to finish writing that txn_id to the database.  But this seems unlikely since the user would have gone through an entire payment process at paypal by then...  It's a bit weird.

 

oh and need a quick tip, when somebody is in the middle of buying a pin from the database, somebody else buys the last pin, what can i do so that if this happens the person will get an error and get their money refunded instead of actually paying the price and not receiving a pin, thanks guys.

 

Usually it would be better to generate the pin when the user returns from making payment - but if you are sticking to doing it this way, your best bet is probably to have an additional tinyint(1) field in the pin table called 'busy' or something.  Then when you send someone off to paypal to pay for a pin, set busy to 1 for that pin.  If another person comes along to buy a pin, only let them buy a pin where busy = 0 in the database.  You'd then have to run an additiontal query to change 'busy' back to 0 if the customer's payment doesn't complete etc.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.