Note: This example for sandbox only.
For this simple process we will be needed these files.
payal_transaction.html
to create the transactionipn_paypal.php
to validate the ipn request by paypal.PaypalIPN.php
to get the PaypalIPN.php please visit here.
<form style="display:none" name="0.form_iframe" id="fomreruso" method="post" action="https://securepayments.sandbox.paypal.com/cgi-bin/acquiringweb" >
<input type="hidden" name="cmd" value="_hosted-payment">
<input type="hidden" name="billing_first_name" value="Nixon">
<input type="hidden" name="billing_last_name" value="Nabulas">
<input type="hidden" name="subtotal" value="500.00">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="paymentaction" value="sale">
<input type="hidden" name="template" value="templateD">
<!-- Lets say i have placed my order id into custom variable, so that i can retrieve that in ipn-->
<input type="hidden" name="custom" value="903872f4-449a-465b-b412-184cae4e893a">
<!-- The url where paypal will send you for after a transacrtion is done/failed/lost etc.-->
<input type="hidden" name="return" value="http://somedoamin.com/confirm_page.html">
<!-- The url where paypal will send IPN request for the user to verify the order.-->
<input type="hidden" name="notify_url" value="http://somedoamin.com/ipn_paypal.php">
<input type="submit" name="METHOD" value="Pay Now">
</form>
<?php
namespace Listener;
/* to get the PaypalIPN.php please visit here
* https://github.com/paypal/ipn-code-samples/tree/master/php
* I would recommend that to place the cert folder in the same loacation where PaypalIPN.php will be placed.
*/
require('PaypalIPN.php');
use PaypalIPN;
$ipn = new PaypalIPN();
// Use the sandbox endpoint during testing.
$ipn->useSandbox();
$verified = $ipn->verifyIPN();
// if verified
if ($verified) {
/*
* Process IPN
* A list of variables is available here:
* https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/
*/
// first make the order verfied in current dbs
$order_id = $_POST['custom'];
// now use the order_id to verify the order in your system, since paypal has confiremed that this order is verfied.
}
// you can dup the reuqst into a file to investigate by yourself.
$data_text = "";
foreach ($_POST as $key => $value) {
$data_text .= $key . " = " . $value . "\r\n";
}
file_put_contents("filename.txt", $data_text . "\r\n", FILE_APPEND);
// done dumping
// Reply with an empty 200 response to indicate to paypal the IPN was received correctly.
header("HTTP/1.1 200 OK");