Simple PayPal integration on your website

paypal-banner

Online payment is the hype of today’s web world. For getting any service or product we prefer to online payment method and PayPal is the most secure payment gateway. If you have a very basic knowledge of PHP, you can easily implement the simple PayPal gateway in your site.

The Process to implement PayPal on your website:

We can simplify the process into 3 steps – PayPal button, PDT and confirmation. 

PayPal button

Put this code in the PHP file template where the payment button will appear.

You have to change the respective values like  email, item name, item number, amount, currency, success page link, cancel page link and form action live link.

PDT function

Create a PHP file called ‘paypal-pdt-functions.php’ and put the following code in that file. PDT means payment data transfer. When any payment made successfully, PayPal returns all the payment related info to the return URL so that you can get all those values in your application process.

You have to enable PDT from your PayPal account profile and you will get a PDT identity token, just copy that token and put the token value in this file.

Confirmation

You have a confirmation page, say success URL. Just put the following code on that page template. It will return the array values to show what you will get when any payment made successfully.

This tutorial shows the process using sandbox mode. So, it is recommended to test everything on sandbox mode first and after successful testing you can put the total payment process on live mode.

Demo | Source code

You may also like

3 Comments

  1. Hi Sanjay

    Thanks for the script.
    I have tried following instructions exactly and have changed all the settings to my own account’s and uploaded to my host’s server, but when I try with my own sandbox account, everything comes back blank on the success page.

    There’s nothing to get from the url, and the page is completely blank.
    Also, when I try without PDT, the url comes back with no tx id, etc either.

    I have set my return address under PDT under my main PayPal account (can’t find anywhere to do this for my sandbox account)
    and have used the identity token from there.
    I also tried just for chance, the signature from the sandbox account from the token, but with no luck.

    I have tried with the account details from this tutorial and it shows the data in the url and gets the data in the page, but nothing shows under PDT.

    Is there anything you could please suggest?
    Is this possibly a problem with my sandbox account? I read somewhere that sandbox accounts created after 2012 don’t show the info in the url, not sure how true this is, sure they would have fixed this by now.

    Please help

    Many thanks
    Brad

  2. Hello Sanjay, thank you for this tutorial, i actually using your demo and works great.
    I tried to use it in my website, replace my token and my sandbox account and the auto return is not working anymore, can you please explain to me your sandbox account configuration?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.