Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nixon1333/ea886bb95179bea52d18eaba84fcff84 to your computer and use it in GitHub Desktop.
Save nixon1333/ea886bb95179bea52d18eaba84fcff84 to your computer and use it in GitHub Desktop.

How to make a paypal transaction with IPN integrations using php

Note: This example for sandbox only.

For this simple process we will be needed these files.

  • payal_transaction.html to create the transaction
  • ipn_paypal.php to validate the ipn request by paypal.
  • PaypalIPN.php to get the PaypalIPN.php please visit here.

payal_transaction.html

<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="paypal_business-account@somedoamin.com">
    <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>

ipn_paypal.php

<?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");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment