Paypal payment gateway Integration with PHP – Simple Method

Do you know how easy its to integrate the PayPal payment gateway into your website?

It is so simple. You can integrate the Paypal payment gateway into your website within a few lines of code with PHP and Javascript.

Want to know how?  Let’s do it.

First, we have to create a page to display the payment form .. Normally your checkout page.

So let’s create a checkout page.

Filename: Checkout.php

<script src=""> </script> 

<div id="paypal-button-container"> </div>

    createOrder: function(data, actions) {
      return actions.order.create({
        purchase_units: [{
          amount: {
            value: '1230'
    onApprove: function(data, actions) {
      return actions.order.capture().then(function(details) {
        alert('Transaction completed');
        // Call your server to save the transaction
        return fetch('savethepayment.php', {
          method: 'post',
          headers: {
            'content-type': 'application/json'
          body: JSON.stringify({
            orderID: data.orderID,
            amount: data.amount,
            invoice: 1242

Yes just copy and paste the codes. i will explain everything now.

<script src=""> </script>

This script tag is used to call the Paypal SDK into our website. If you dont have an api Key  Follow this link to get one

And this div tag will display the PayPal checkout button after compiling the javascript code.

<div id="paypal-button-container"> </div>

In the javascript code you can see

purchase_units: [{ amount: { value: '1230' } }]

This line of code which is refers to the amount we want to collect.. in our case it’s $1230 USD.

You can see another code return fetch('savethepayment.php',  

for submitting a post req after successful payment, which means we are sending the order id, invoice number, and amount we collected to savepayment.php file. so we can read the data in savepayment.php file and update our database with payment success status.


So simple right ..

Yeah I don’t like to make things complicated .. I need everything simple and I make everything simple..  keep your code simple. 🙂


Post Your Questions on our forum

Post a question on Forum

Ajith Jojo Joseph

Self taught, dedicated young entrepreneur with many licensed products under his sleeve. Passionate about technology, business and excellence in general.

Share with your friends:

Leave a Reply

Your email address will not be published.

How to get data from a model on all pages in Laravel – Simple Way

Do you know How to get data from a model on all pages in Laravel ? In this blog post, […]

August 5, 2022

Export html table to excel, pdf, csv format using Datatable

Do you know how to export html table to excel, pdf, CSV, or excel format using Datatable? If you don’t […]

August 4, 2022

How to create a Laravel Collection From JSON

Today i have to create a laravel collection from a JSON object. I search on the internet and I cant […]

August 3, 2022

Instagram Hashtag API PHP and JavaScript Integration with RapidAPI

Do you know how to integrate Instagram Hashtag API with your website? In this tutorial, I will show you how […]

August 2, 2022

Digital Marketing Toolkit

Get Free Access to Digital Marketing Toolkit. You can use all our tools without any limits

Get Free Access Now