ONLINE PAYMENT USING PAYPAL IPN WITH PHP.
(SESSION CAN BE USED IF DATABASE IS NOT INVOLVED IN THE PAYMENT PROCESS )Introducing Instant Payment Notification (IPN)
Instant Payment Notification (IPN) is a message service that automatically notifies merchants of events related to PayPal transactions. Merchants can use it to automate back-office and administrative functions, including automatically fulfilling orders and providing customers with order status.
Why use Instant Payment Notification
Instant Payment Notification (IPN) notifies merchants almost instantly about transaction events, such as:
How it works
Merchants create an Instant Payment Notification(IPN) listener page on their website and then specify the URL of the listener page in their PayPal account profile. PayPal then sends notifications of all transaction-related events to that URL. When customers pay for goods or services, PayPal sends a secure FORM POST containing payment information (IPN messages) to the URL. The Instant Payment Notification(IPN )listener detects and processes Instant Payment Notification(IPN) messages using the merchant backend processes. The Instant Payment Notification (IPN) listener page contains a custom script or program that waits for the messages, validates them with PayPal, and then passes them to various backend applications for processing.
Referral to this link for paypal (IPN) Instant Payment Notification
I will share with you integration of PayPal gateway payment without database in PHP. In this blog you will learn how to integrate Paypal payment gateway without database in Codeigniter. This blog will give you full example of the PayPal payment gateway integration in the PHP.
In this example, I will show you easy and simple way to integrate paypal payment gateway in PHP . I will show you step by step to integrate paypal payment gateway in PHP as follow.
Referral to this link for paypal (IPN) Instant Payment Notification
Step 1: Set link in paypal after IPN file is ready
Step 2: Create a Payment Form payment_form.php.
payment_form.php
<form id="contactform" action="payment_confirmation.php" method="post"
class="validateform" name="send-contact" >
<lablel>Email </lablel>
<input type="text" name="email" id="email" data-rule="maxlen:4" data-msg="Please enter at least 4 chars" maxlength="100" class="form-control form-control-email"/>
<lable>Amount To Paid</lable>
<input type="text" name="amount" id="amount" data-rule="maxlen:2" data-msg="Please enter at least 2 length of Amount paid" maxlength="10" class="form-control form-control-name"/>
<input type="submit" name="submit" value="Submit" class="theme-btn btn-style-one" style="cursor: pointer;">
</form>
Step 3: : Take data from form to payment_confirmation.php page and store in to a Session. And Process data for Paypal.
<table>
<lablel>Email </lablel>
<?php if(isset($_POST['email'])){echo $_POST['email'];$_SESSION['email1'] = $_POST['email'];}?>
<lable>Amount To Paid</lable>
<?php if(isset($_POST['amount'])){echo $_POST['amount'];$_SESSION['amt'] = $_POST['amount'];}?>
</table>
<h4 style="margin-right:20%;">Check Your Payment Details Before Payment</h4>
<form action="<?php echo PAYPAL_URL; ?>" method="post">
//Identify your business so that you can collect the payments.
<input type="hidden" name="business" value="<php echo PAYPAL_ID; ?>">"
//Specify a Buy Now button.
<input type="hidden" name="cmd" value="_xclick">
//Specify details about the item that buyers will purchase.
<input type="hidden" name="item_name" value="<php echo $_POST['fname']. ",". $_POST['lname']. ",". $_POST['phone']. ",". $_POST['email']. ",".$_POST['amount'];?>">
<input type="hidden" name="item_number" value="<php echo $_POST['referance']; ?>">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="txn_id" value="Transaction id">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="cbt" value="Please Click Here to Complete Payment">
//Specify URLs
<input type='hidden' name='cancel_return' value="<php echo cancel_return.php; ?>" />
<input type='hidden' name='return' value="<php echo success_return.php; ?>"/>
<input type='hidden' name='notify_url' value=" <php echo listener.php; ?>" />
//Display the payment button
<input type="image" style = "margin-right: 25%" name="submit" src="https://www.paypal.com/en_GB/i/btn/btn_paynowCC_LG.gif" alt="Check out with PayPal" />
</form>
Step 4: : Create listener.php file and process data from paypal.
<?php
header('HTTP/1.1 200 OK');
$resp = 'cmd=_notify-validate';
foreach ($_POST as $parm => $var) {
$var = urlencode(stripslashes($var));
$resp .= "&$parm=$var";
}
$item_name = $_POST['item_name'];
list( $email, $payment_amount) = explode(",", "$item_name");
$todayis = date("l, F j, Y") ;
$headers = "From: info@mylearner.co.uk \r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$subject = "ABCD Payment confirmation";
$message = " <img src='logo.jpg' > <hr width='50%' align='left'> <h3>PAYMENT CONFIRMATION FROM ABCD </h3>
$todayis<hr width='50%' align='left'>
<table border='0'>
<tr><th align='left'>Amount Paid: </th><td>$payment_amount </td></tr>
<tr><th align='left'>Customer Email: </th><td>$email </td></tr>
</table>
$company_message = "<img src='logo.jpg' ><hr width='50%' align='left'><h3>ONLINE PAYMENT RECEIVED FROM <font color='#4a9fcc'>$fname $lname</font></h3>
$todayis<hr width='50%' align='left'>
<tr><th align='left'>Amount Paid: </th><td>$payment_amount </td></tr>
<tr><th align='left'>Customer Email: </th><td>$email </td></tr>
$to = $email;
mail($to, $subject, $message, $headers);
mail("test@abcd.co.in", $subject, $company_message, $headers);
/?>
Step 5: Create a Success Page success_return.php where your payment success message and details will be display.
<?php
//paypal data
$paypalId = $_GET['tx'];
$email = $_SESSION['email1'];
$amt = $_SESSION['amt'];
?>
//paypal data
<table>
<lablel>Email </lablel>
<?php if(isset($_SESSION['email1'])){echo $_SESSION['email1'];}?>
<lable>Amount To Paid</lable>
<?php if(isset($_SESSION['amt'])){echo $_SESSION['amt'];}?>
<lable>Paypal Id</lable>
<?php echo $paypalId; ?>
<lable> Payment Date </lable>
<?php echo date('Y-m-d'); ?>
</table>
Paypal returns all transaction details in an array and verify all details and shoots the mail through IPN and this process will work in background.