How to Set Up PayPal Integration with PHP & MySQL Faster

PayPal are the most pop payment service of process about the World Wide Web so beingness able to incorporate your website with PayPal’s insistent Payment Notification Service (IPN) personifies essential if you ask to process payments through with your website.

There are 3 main parts to the PayPal IPN system of rules.

  1. A webpage that beginners an request to PayPal to make an payment.
  2. A PHP page on your webserver that PayPal calls in to notify you that payment accepts been made.
  3. A webpage that confirms the above payment and keeps going about to the next phase of your World Wide Webapplication, such as a ‘thanks’ page.

Parts 1 and 3 is approachable along buyers on your website. Part 2 is only available to PayPal.  The diagram below illustrates the fundamental interaction between your client, PayPal and your website.

The following abuses break down each part by the action into easy to conform to chunks, it is assumed that you have knowledge by PHP and MySQL.


  • If you are not receiving the correct response from Paypal ensure that you are using the main test account (Verified Business Account) from your Paypal Sandbox account.
  • Also ensure that you are testing the Paypal IPN Script on an online webserver (Not MAMP, Xampp etc..) as Paypal requires a reachable ‘return url’, ‘cancel url’ and ‘notify url’.


Sign on for a PayPal account if you do not already accept one. In order to apply IPN, the Paypal account you are passing out from must be a Business Account.

At one time you have a registered PayPal account your account mustiness be setup aright to use IPN.

Take ‘edit profile’ from your PayPal account and check the following settings.

  • Under ‘My Selling Preferences’ >> ‘Getting paid and managing risk’ >> ‘Instant Payment Notification Preferences’
    Set the IPN value to ‘On’
    Set the IPN URL to the PHP page containing the IPN code shown in steps 3 & 4 of this tutorial. (
  • Under ‘My Selling Preferences’ >> ‘Getting paid and managing risk’ >> ‘Block payments’Block payments from users who pay with eCheque. (This is because these will not be instant payments)
  • Under ‘account information’ >> ’email’Note down your primary email address. This email will be visible to users so make it a professional one. Drug user* may feeling apprehensive about sending money to an e-mail address with the domain ‘’ or ‘’ etc…


Your website must now send all the required values to PayPal so that the payment can be processed.

The following code example demonstrates a basic form that we’ll use to send the values:

The business name, price, submit type, notify URL and other sensitive values will be sent during the next step.

A full list of the values to send can be found at the PayPal website under the title “A Sample IPN Message and Response”.


The payment.php page will be used to handle the outgoing request to PayPal and also to handle the incoming response after the payment has been processed.

The following sample code shows the querystring being constructed before it is posted to PayPal. Here you can specify the following values:

  • Business ($paypal_email) – Enter the email address of your PayPal account.
  • Item name ($item_name) – The name of the item being purchased.
  • Amount ($item_amount) – The price of the item.
  • Return ($return_url) – The address to return to after a successful payment.
  • Cancel Return ($cancel_url) – the address to return to after a cancelled payment.
  • Notify URL ($notify_url) – The address of the payments.php page on your website.
  • Custom – Any other data to be sent and returned with the PayPal request.


The succeeding part from the payments.php paginate handles the answer of PayPal. The response is re-assigned to variable star* and so posted back up to PayPal as confirmation using fsockopen.

Whenever the answer is VERIFIED then a validation check into can be performed. The check_txnid and agree_price affairs are called to check that the correct dealing ID and Price accept been returned. The updatePayments function can at last be called to store the inside information of the payment in the payments table (Step



The payments.php page calls upon a number of functions used to validate the returned data and store the response in the database.

That’s it; you’re ready to start taking payments online through your website.


%d bloggers like this: