Share this article


This tutorial aims to introducing how to make registration process work properly with PayPal system.
  1. Explain how PayPal works (IPN and PDT process). Chapter One
  2. Give a good example to show how register work with PayPal, containing database, controller and front end form with jQuery functionalities. And explain how to setup a PayPal account (Sandbox and real PayPal business account example). Chapter Two
  3. Give detailed comments in code. Chapter Three
This tutorial gives a big picture of PayPal process (PDT and IPN), and a real project from starting point to the end. Good explanation and pictures, detailed comments in code line. Hopefully, it will be useful for all readers.

Chapter One

PayPal PDT (Payment Data Transfers)

PDT is enables buyer redirect from merchant’s website to PayPal website, and pay the payment, then redirect back to merchant’s website.

Step 1:

Client clicks on the button and goes to PayPal website, show payment form.

Step 2:

After client filling the payment form, and clicking ‘Pay Now’ button in PayPal, the PayPal will redirect to PayPal Result page, showing : During this step, PayPal is calling your own PDT handler function, and passing parameters via URL, the most important variable is ‘tx’, which is transaction token. e.g.:

Step 3:

This step is processed invisibly. After PayPal call your own PDT handler function, your PDT handler function will POST tx and auth_token back to PayPal. PayPal will identify your merchant account auth_token and tx token. Then, your own PDT handler function, the fsock get data from PayPal.
The payment data from PayPal is a string like: step-3-2

Step 4:

The last step is simple and easy. Your PDT handler function can render success page or fail page to the buyer’s screen.

Conclusion Overview:

So let’s have an overall view about all those four steps.

PayPal IPN (Instance Payment Notification)

IPN is a backup plan for buyers close browser after payment, PDT cannot redirect back to the merchant’s site. If buyers close browser or stop PDT redirect, your PDT handler function cannot $_GET[‘tx’], then you cannot POST back tx and auth_token, then PayPal cannot send payment data to your handler, then result page cannot be shown. Luckily, PayPal provides a backup plan IPN which is more reliable, because PayPal will POST payment data to your IPN handler function.

Step 1:

PayPal POST payment details to your IPN handler function. POST data is similar like: IPN-POST POST data should be an array, but I encoded by json_encode, so now it displays in json format.

Step 2:

Your IPN handler function POST payment data back to PayPal via cURL, and wait for PayPal confirmation.

Step 3:

PayPal confirmed payment data from your IPN handler function, and return confirmation result. Something like: So, you can see, the POST data was verified by PayPal.

Conclusion Overview:

From the diagram above, you can see, PayPal and your IPN handler function, have a “Handshake Protocol” for the confirmation of payment details. Then, your IPN handler function receives result string from PayPal, then, your function can process different action according to the result.

PayPal IPN & PDT Working Together

Hopefully, you have a clear understanding about PayPal PDT and IPN. The next, we should make the two tools work together, in order to make sure payment processed correctly. The key thing is to handle duplication handlers. For example, we have a payment record named payment_1. PDT processed payment_1, and IPN also tries to process payment_1, (if user did NOT close the browser).  One method to solve this problem is, in your database, you can mark the payment has been processed, which means, pre-check payment_1 has been processed already or not.  

Frequently Asked Questions about Registering and Using PayPal

How can I set up a PayPal account?

Setting up a PayPal account is a straightforward process. First, visit the PayPal website and click on the ‘Sign Up’ button. You will be asked to choose between a personal and business account. After selecting the appropriate option, you will need to provide some personal information, including your legal name, address, and phone number. You will also be asked to enter and confirm your email address and create a password. Once you’ve completed these steps, you will need to confirm your email address and link a bank account or credit card to your PayPal account.

What is a Payment Data Transfer (PDT) token and how do I enable it?

A Payment Data Transfer (PDT) token is a unique identifier that is used to retrieve transaction details from PayPal. To enable it, you need to log into your PayPal account, go to ‘Profile’ and then ‘Profile and Settings’. From there, click on ‘My Selling Tools’, then ‘Website Preferences’, and finally ‘Update’. In the PDT section, choose ‘On’ and then save your changes. PayPal will then provide you with a PDT identity token, which you should keep secure.

How can I use PayPal to make payments?

To make payments using PayPal, you first need to ensure that your PayPal account is linked to a bank account or credit card. When making a purchase online, select PayPal as your payment method at checkout. You will be redirected to the PayPal login page, where you will need to enter your email address and password. After logging in, you will be able to review your payment details before confirming the transaction.

What is the NVP/SOAP API and how can I use it?

The NVP/SOAP API is a set of protocols used by PayPal to enable online transactions. To use it, you need to have a basic understanding of programming and web development. You can access the API through the PayPal Developer website, where you will find detailed documentation and guides on how to use it.

How can I link my bank account to my PayPal account?

To link your bank account to your PayPal account, log into your PayPal account and click on ‘Wallet’ at the top of the page. From there, click on ‘Link a bank’ and follow the prompts to enter your bank details. Once you’ve entered your details, PayPal will make two small deposits into your bank account. You will need to confirm these amounts in your PayPal account to verify your bank account.

How can I ensure my PayPal account is secure?

There are several steps you can take to ensure your PayPal account is secure. These include creating a strong, unique password, enabling two-factor authentication, regularly updating your account information, and monitoring your account for any suspicious activity.

Can I use PayPal in any country?

PayPal is available in more than 200 countries and regions around the world. However, the services available may vary depending on your location. You can check the PayPal website for more information about the services available in your country.

How can I resolve a dispute with a seller?

If you have a dispute with a seller, you can use PayPal’s Resolution Center to report the issue. You will need to provide details about the transaction and the problem you’re experiencing. PayPal will then work with you and the seller to resolve the dispute.

What fees does PayPal charge?

PayPal charges different fees depending on the type of transaction. For personal transactions, there is usually no fee unless the transaction involves a currency conversion. For business transactions, PayPal charges a fee based on the amount of the transaction.

How can I close my PayPal account?

To close your PayPal account, log into your account and click on ‘Settings’. From there, click on ‘Close your account’ at the bottom of the page. You will need to confirm your decision to close your account. Please note that once your account is closed, you will not be able to reopen it.

Sam DeeringSam Deering
View Author

Sam Deering has 15+ years of programming and website development experience. He was a website consultant at Console, ABC News, Flight Centre, Sapient Nitro, and the QLD Government and runs a tech blog with over 1 million views per month. Currently, Sam is the Founder of Crypto News, Australia.

Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week
Loading form