PHP 7 Script to Integrate eSewa Payment Gateway of Nepal in Browser Using HTML5 & Javascript Full Project For Beginners

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments

 

 

index.php

 

 

<?php
require_once 'config.php';
?>
<p>See source HTML of this page to see sample form for eSewa payment.</p>
<form action = "<?php echo $esewa_url; ?>" method="POST">
<input value="20" name="tAmt" type="hidden">
<input value="10" name="amt" type="hidden">
<input value="5" name="txAmt" type="hidden">
<input value="2" name="psc" type="hidden">
<input value="3" name="pdc" type="hidden">
<input value="<?php echo $merchant_id; ?>" name="scd" type="hidden">
<input value="PRD-01" name="pid" type="hidden">
<input value="<?php echo $site_url; ?>success.php/?q=su" type="hidden" name="su">
<input value="<?php echo $site_url; ?>failure.php/?q=fu" type="hidden" name="fu">
<input value="Pay Now" type="submit">
</form>

 

 

success.php

 

 

<?php
require_once 'config.php';

//create array of data to be posted
$post_data['amt'] = 20;
$post_data['scd'] = $merchant_id;
$post_data['pid'] = 'PRD-01';
$post_data['rid'] = $_REQUEST['refId'];

//traverse array and prepare data for posting (key1=value1)
foreach ($post_data as $key => $value) {
    $post_items[] = $key . '=' . $value;
}

//create the final string to be posted using implode()
$post_string = implode('&', $post_items);

//create cURL connection
$curl_connection =
        curl_init($esewa_verfication_url);

//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

//perform our request
$result = curl_exec($curl_connection);
//close the connection
curl_close($curl_connection);


$verification_response  = strtoupper( trim( strip_tags( $result ) ) ) ;

if('SUCCESS' == $verification_response){
    echo '<h2><strong>SUCCESS:</strong> Transaction is successful !!!</h2>';
}
else{
    echo '<h2><strong>ERROR:</strong> Transaction could not be verified</h2>';
}
?>
<br/>
<a href="<?php echo $site_url; ?>">Go to homepage</a>

 

See also  Build a PHP 7 Image Converter,Compressor,Edit Image Using iLoveIMG API in Browser Full Project For Beginners

 

failure.php

 

 

<?php
    require_once 'config.php';
?>
<h2><strong>ERROR:</strong> Payment cannot not be done.</h2>
<br/>
<a href="<?php echo $site_url; ?>">Go to homepage</a>

 

 

 

config.php

 

 

<?php
$site_url = 'http://esewademo.nilambar.com.np/';
$esewa_url = 'http://dev.esewa.com.np/epay/main';
$esewa_verfication_url = 'http://dev.esewa.com.np/epay/transrec';
$merchant_id = "0000ETM";
?>

 

 

DOWNLOAD FULL SOURCE CODE

 

Leave a Reply