PHP PayPal Integration Script

This post belongs to newbie PHP developer who wants to integrate paypal payment gateway in his website using PHP. This post will show you the very basic and quick method to integrate paypal using core PHP.

First of all need to create paypal developer account.

After that you’ll see two test email ids one for business type and other one for personal type. Where You’ll receive your paypal payment in your business account and you can purchase any item from your personal account. Both the account just for testing purpose you can use them for buying and selling items.

Time to start coding part.

create your project config file where you can set all configuration of your project like paypal url, paypal id etc.




DEFINE('PAYPAL_ID', 'YOUR_PAYPAL_ID');  // you can find thuis in your developer account it look like "[email protected]"


Create your payment page this is just for demonstration purpose you can change it according to your need.


<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
<div class="panel panel-primary" style="width:50%;margin:0 auto; margin-top:2%">
<div class="panel-heading"><h3>Paypal Payment Gateway in PHP</h3></div>
<div class="panel-body" style="height:40%; text-align:center;" >
<p class="bg-info" id="msg"></p>
 <form class="form-horizontal" role="form" id="paypalForm" method="post" action="<?php echo PAYPAL_URL; ?>">
    <input type="hidden" name="business" value="<?php echo PAYPAL_ID; ?>">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="credits" value="510">
    <input type="hidden" name="userid" value="1">
    <input type="hidden" name="cpp_header_image" value="">
    <input type="hidden" name="no_shipping" value="1">
    <input type="hidden" name="handling" value="0">
    <input type="hidden" name="cancel_return" value="">
    <input type="hidden" name="return" value="">
  <div class="form-group">
    <label class="control-label col-sm-2" for="amount">Amount:</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name="amount" placeholder="Enter Amount" required="required" value="10">
     <div class="form-group">
    <label class="control-label col-sm-2" for="currency">Quantity:</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name="quantity" placeholder="Enter Quantity" value="1" required="required">
  <div class="form-group">
    <label class="control-label col-sm-2" for="currency">Currency:</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name="currency" placeholder="Enter Currency Type" value="<?php echo CURRENCY; ?>" required="required">
  <div class="form-group">
    <label class="control-label col-sm-2" for="description">Description:</label>
    <div class="col-sm-10">
      <textarea class="form-control" name="item_name" placeholder="Enter Description">My First Payment</textarea>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <input type="image" src="" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="" width="1" height="1">
 <script src=""></script>

Create request.php file which will handle all your paypal requests like success or cancel.


$type = $_GET['type'];
if($type == 'success') {
  echo "<pre>";
  echo "<h1>Payment Successful</h1>";
if($type == 'cancel') {
  echo "<h1>Payment Canceled</h1>";

In payment success case you can see all your sent data by $_REQUEST variable and cross check in your side before showing success message.

See the working demo and you can also download source code form my github repository.

Hope this simple paypal integration tutorial will help you to integrate paypal payment gateway in your website.

20+ PHP Paypal Integration Script

Are you looking for PHP Paypal Integration Script for your web based application. If yes then in this post I am going to share hand picked top rated PHP Paypal Integration Script. You can use these popular PHP Paypal Integration Script to make your web application more awesome.

PHP Paypal Integration Script

Following are the list of popular top rated hand picked PHP Paypal Integration Script.

I Hope you liked Hand-picked list of PHP Paypal Integration Script, Don’t forget to Subscribe My Public Notebook for more useful Hand-picked PHP and MySql code examples, tutorials and articles.