Google trends Public Holidays Coupon Code Code Compiler

Paypal Payment Gateway Integration in PHP

Jan 13, 2019

Paypal payment gateway is allows people to make money transfer through internet. And most of the eCommerce stores integrate Paypal payment gateway to provide online payment option. This Paypal tutorial will explain about the complete process of Paypal payment gateway integration in PHP.

Let's Start Code Integration In PHP

Here, we’ll need following files to integrate Paypal Payment Gateway

  1. Index.php
  2. success.php
  3. cancel.php


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Paypal Payment Gateway Integration</title> 

   <label>Prodcut Name: Product 1 </label><br/>
   <label>Product Price: 100 USD</label>
    <form action="" method="post"> 

       <!-- Identify your business so that you can collect the payments. --> 
       <input type="hidden" name="business" value="<PAYPAL USERNAME>"> <!-- [Business Email]-->
       <input type="hidden" name="cmd" value="_xclick">
        <!-- Specify details about the item that buyers will purchase. --> 
        <input type="hidden" name="item_name" value="product1"> 
        <input type="hidden" name="item_number" value="item_123"> 
        <input type="hidden" name="amount" value="100"> 
        <input type="hidden" name="currency_code" value="USD"> 
        <!-- Specify URLs --> 
        <input type='hidden' name='cancel' value='http://localhost/paypal/cancel.php'> 
        <input type='hidden' name='success' value='http://localhost/paypal/success.php'> 

        <!-- payment button. --> 
        <input type="image" name="submit" border="0" 
        src="" alt="PayPal way to pay online"> 


Create a new file with success.php.

When your transaction is successful, then at that time Paypal will return you following transaction details.

  1. Item_number
  2. AMT (Amount)
  5. Transaction_ID

//save Trasaction information form PayPal
$itemNumber = $_GET['item_number']; 
$txnId = $_GET['Trasaction_ID'];
$amount = $_GET['AMT'];
$currencyCode = $_GET['CURRENCY_CODE'];
$paymentStatus = $_GET['PAYMENT_STATUS'];

	echo 'Your payment has been successful.';
	echo 'Your payment has failed.';

Create a new file with cancel.php.

   <title>PayPal Transaction Cancel</title>
	<h1>Your transaction has been canceled.</h1>

Copyright 2024. All rights are reserved