paypal payment gateway integration in php

Today, We want to share with you paypal payment gateway integration in php.In this post we will show you payment gateway in php and mysql, hear for paypal integration in php with sandbox we will give you demo and example for implement.In this post, we will learn about PayPal Payment Gateway with PHP MySQL Database with an example.

paypal integration in php Source Code

There are the Following The simple About paypal payment gateway api integration in php Full Information With Example and source code.

As I will cover this Post with live Working example to develop REST API Code Samples – PayPal Demo, so the paypal payment gateway integration in php codeigniter is used for this example is following below.

files structure for integrate PayPal payment gateway API in PHP

paypal_integration_php/
├── config.php
├── databaseconnection.php
├── index.php
├── success.php
├── cancel.php
├── ipn.php
├── css/
│   └── style.css
└── images/

Create PayPal Sandbox Account

Go to the https://developer.paypal.com/

Create Database Tables

SQL creates a products table in the MySQL database

CREATE TABLE `products` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `name` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
 `image` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `price` float(10,2) NOT NULL,
 `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1=Active | 0=Inactive',
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

SQL creates a paypalpayments table in the MySQL database

CREATE TABLE `paypalpayments` (
 `paypalpayment_id` int(11) NOT NULL AUTO_INCREMENT,
 `item_number` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
 `txn_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
 `paypalpayment_gross` float(10,2) NOT NULL,
 `currency_code` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
 `paypalpayment_status` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
 PRIMARY KEY (`paypalpayment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

PayPal Settings and Database Configuration

config.php


Database Connection

databaseconnection.php

connect_errno) { 
    printf("Connect failed: %s\n", $db->connect_error); 
    exit(); 
}

Products Page

index.php



query("SELECT * FROM products WHERE status = 1"); while($row = $results->fetch_assoc()){ ?>
Price:

paypalpayment Success

success.php

query("SELECT * FROM products WHERE id = ".$item_number); 
    $productRow = $productResult->fetch_assoc(); 
     

    $prevpaypalpaymentResult = $db->query("SELECT * FROM paypalpayments WHERE txn_id = '".$txn_id."'"); 
 
    if($prevpaypalpaymentResult->num_rows > 0){ 
        $paypalpaymentRow = $prevpaypalpaymentResult->fetch_assoc(); 
        $paypalpayment_id = $paypalpaymentRow['paypalpayment_id']; 
        $paypalpayment_gross = $paypalpaymentRow['paypalpayment_gross']; 
        $paypalpayment_status = $paypalpaymentRow['paypalpayment_status']; 
    }else{ 

        $insert = $db->query("INSERT INTO paypalpayments(item_number,txn_id,paypalpayment_gross,currency_code,paypalpayment_status) VALUES('".$item_number."','".$txn_id."','".$paypalpayment_gross."','".$currency_code."','".$paypalpayment_status."')"); 
        $paypalpayment_id = $db->insert_id; 
    } 
} 
?>

Your paypalpayment has been Successful

paypalpayment Information

Reference Number:

Transaction ID:

Paid Amount:

paypalpayment Status:

Product Information

Name:

Price:

Your paypalpayment has Failed

Back to Products

paypalpayment Cancellation

cancel.php

Your PayPal Transaction has been Canceled

Back to Products

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about paypal integration in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment