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. Required fields are marked *

How to integrate Paypal API in Laravel

Are you looking to integrate Paypal API in your Laravel project for seamless payment processing? Look no further! In this […]

April 3, 2024

How to integrate Razorpay API in Laravel

Integrating payment gateways into web applications has become an essential part of e-commerce websites. In this tutorial, we will discuss […]

April 3, 2024

Laravel 11 Ajax CRUD Operation Tutorial Example

**Mastering CRUD Operations with Laravel 11 Ajax: A Comprehensive Tutorial** In the world of web development, interaction between the front-end […]

April 3, 2024

Login as Client in Laravel – Login with user id

**Unlock the Power of Laravel with Login as Client – Login with User ID** Laravel, the popular PHP framework, offers […]

April 3, 2024

Digital Marketing Toolkit

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

Get Free Access Now