How to integration Paypal payment gateway in php source code

Today now in this post i will give you an example of how to integrate the payment Paypal gateway in php application with demo. So it is very simple to use the paypal payment method in our native php application because we don’t need to use here any api for paypal payment gateway for integration. Here the paypal provide us very a simple way to do this and paypal also provide the developer console. Here i mean Sandbox account on that way we can check this better. So now In this example i will give you this example step by step payment integration of paypal.

Step 1: Create Sendbox Account

Now in this step we need to create a sendbox account for the test if we don’t have any account. So need to create click here to create new account in Sendbox :

Paypal payment gateway in php

Ok,after the register new account, and need to successfully created a new account need to Click on Accounts. We can create the multiple buyer account and merchant account.

Step 2: Create Index File

Okay now in this step we have to create the index.php file for write the bellow code, so just we can copy the bellow code and paste on the bellow file. So in this file we have to change $paypalId, so it should our own. We should also change the input type return and cancel_return URL path.


<html lang="en">
    <title>PHP - Paypal Payment Gateway Integration</title>
<body style="background:#E1E1E1">
<link rel="stylesheet" type="text/css" href="//" />
<style type="text/css">
		.price.panel-red>.panel-heading {
			color: #fff;
			background-color: #D04E50;
			border-color: #FF6062;
			border-bottom: 1px solid #FF6062;
		.price.panel-red>.panel-body {
			color: #fff;
			background-color: #EF5A5C;
		.price .list-group-item{
			border-bottom-:1px solid rgba(250,250,250, .5);
		.panel.price .list-group-item:last-child {
			border-bottom-right-radius: 0px;
			border-bottom-left-radius: 0px;
		.panel.price .list-group-item:first-child {
			border-top-right-radius: 0px;
			border-top-left-radius: 0px;
		.price .panel-footer {
			color: #fff;
			background-color:  rgba(0,0,0, .1);
			box-shadow: 0px 3px 0px rgba(0,0,0, .3);
		.panel.price .btn{
			box-shadow: 0 -1px 0px rgba(50,50,50, .2) inset;
<div class="container text-center">
	<h2><strong>PHP - Paypal Payment Gateway Integration</strong></h2>
	<div class="row">
		<div class="col-xs-6 col-sm-6 col-md-3 col-md-offset-4 col-lg-3">
			<!-- PRICE ITEM -->
    			<form action="<?php echo $paypalUrl; ?>" method="post" name="frmPayPal1">
					<div class="panel price panel-red">
						    <input type="hidden" name="business" value="<?php echo $paypalId; ?>">
						    <input type="hidden" name="cmd" value="_xclick">
						    <input type="hidden" name="item_name" value="It Solution Stuff">
						    <input type="hidden" name="item_number" value="2">
						    <input type="hidden" name="amount" value="20">
						    <input type="hidden" name="no_shipping" value="1">
						    <input type="hidden" name="currency_code" value="USD">
						    <input type="hidden" name="cancel_return" value="">
						    <input type="hidden" name="return" value="">  
						<div class="panel-heading  text-center">
						<h3>PRO PLAN</h3>
						<div class="panel-body text-center">
							<p class="lead" style="font-size:40px"><strong>$20 / month</strong></p>
						<ul class="list-group list-group-flush text-center">
							<li class="list-group-item"><i class="icon-ok text-danger"></i> Personal use</li>
							<li class="list-group-item"><i class="icon-ok text-danger"></i> Unlimited projects</li>
							<li class="list-group-item"><i class="icon-ok text-danger"></i> 27/7 support</li>
						<div class="panel-footer">
							<button class="btn btn-lg btn-block btn-danger" href="#">BUY NOW!</button>
			<!-- /PRICE ITEM -->
Step 3: Create Success File

Okay now we need to create a success.php file for get the Paypal transaction with ID when payment will successfully then it will be return here. On that way we can identify the payment is done or not so, need to create a new file as name success.php.


$itemNo            = $_REQUEST['item_number'];
$itemTransaction   = $_REQUEST['tx']; // Paypal transaction ID
$itemPrice         = $_REQUEST['amt']; // Paypal received amount
$itemCurrency      = $_REQUEST['cc']; // Paypal received currency type
$price = '20.00';
if($itemPrice==$price && $itemCurrency==$currency)
    echo "Payment Successful";
    echo "Payment Failed";
Step 4: Create Cancel File

Here we also need to create others file name cancel.php file because when the paypal transaction will be cancel then it will be redirect on this file.


echo "Payment Canceled";
Step 5: Paypal URL

Okay it is complete for the our sendbox with paypal integration but when we will live this then we need to change the $paypalId and also $paypalUrl.


Read Also : Laravel 8 Mobile Number Verification Tutorial

Thanks for read. I hope it help you. For more you can follow us on facebook


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →