Jump to content

Good php error handling involving paypal


JonnySnip3r

Recommended Posts

Hey guys i was wondering if someone could help or guide me. I have been messing around with php for quite some months now to the stage where i can code pretty much what i need to. but recently i started using paypals IPN and during testing i realised some problems arise for example when testing and people buying things say the payment failed due to a line not executing in your script for what ever reason, the person has lost their money yet you have gained it and they are lost. Take this code below for example:

 

public function insertIntoDatabase($firstName,$lastName,$emailAddress,$merchant,$code,$database,$gameNumber)
{
	$year = date("Y");
	// Check what database we need to submit too::
	$sql = "INSERT INTO playerGame (playerFirstName,
										playerLastName,
										playerEmailAddress,
										playerAccountType,
										playerCode,
										playerGameDate,
										playerGameNumber) VALUES (?,?,?,?,?,?,?)";

		$stmt = $this->conn->prepare($sql);
		$stmt->bind_param('ssssssi',$firstName,$lastName,$emailAddress,$merchant,$code,$year,$gameNumber);
		$stmt->execute();
		$stmt->close();

		return true;
}

 

this is called on success the paypal IPN script. But what happens if this fails to execute? I suppose i could wrap it in a variable on the other side and test it

 

if($task)

{

    echo "code executed";

}

 

but what happens if this fails ? of am i just being paranoid ? hope someone can help dont want to be ripping people off =] Thanks!

Link to comment
Share on other sites

I have just had some fun with PayPal's IPN myself. You use the IPN script to check if the payment is a success (if it is complete). So you use an if statement similar to:

if($payment_status == "Completed"){//do the database insertion stuff here}

 

You add further else if for payment status of failed, and all the other possible ones. From there, I can't see how a line of code wouldn't execute. You just need to make sure you test your script thoroughly using the PayPal IPN simulator in the PayPal developer section. If that is always right, then there is no reason why it would fail in real world applications...

 

Denno

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.