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

Index.php


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

    
   <label>Prodcut Name: Product 1 </label><br/>
   <label>Product Price: 100 USD</label>
    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> 

       <!-- Identify your business so that you can collect the payments. --> 
       <input type="hidden" name="business" value="<PAYPAL USERNAME>"> <!-- email@xyz.com [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="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal way to pay online"> 
        

    </form> 
    
</body> 
</html>

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)
  3. CURRENCY_CODE
  4. PAYMENT_STATUS
  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'];


if(!empty($txnId)){
	echo 'Your payment has been successful.';
}else{
	echo 'Your payment has failed.';
}

Create a new file with cancel.php.


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

Copyright 2024. All rights are reserved