Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shaan360 committed Jul 16, 2017
1 parent c882cf4 commit fd05a2c
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 0 deletions.
28 changes: 28 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

define('DB_NAME', 'uexel');

/** MySQL database username */
define('DB_USER', 'uexel');

/** MySQL database password */
define('DB_PASSWORD', 'XTAL');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Easypay Details */
define('HOST', 'https://uexel.com'); // your host
define('URL', 'https://uexel.com'); // url
define('STORE_ID', '1234'); // your store id
define('HASH_KEY', '23222sdfsafsf'); // your hash key
define('STORE_NAME', 'storename'); ///your store name
define('EXPIRY_DATE', '10'); /// days to expire
define('ORDER_PREFIX', 'cd');
define('LIVE', 'no');
define('PAYMENT_METHOD', ''); // null for all payment methods
define('AUTO_REDIRECT','0'); //



?>
23 changes: 23 additions & 0 deletions confirmEasypay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

require 'config.php';
$merchantStatusPage = HOST.'/easypay/statusEasypay.php';


$easypayConfirmPage = '';
$live = LIVE;
if ($live == 'no') {
$easypayConfirmPage = 'https://easypaystg.easypaisa.com.pk/easypay/Confirm.jsf';
} else {
$easypayConfirmPage = 'https://easypay.easypaisa.com.pk/easypay/Confirm.jsf';
}
?>

<form name="easypayconfirmform" action="<?php echo $easypayConfirmPage ?>" method="POST">
<input name="auth_token" value="<?php echo $_GET['auth_token'] ?>" hidden = "true"/>
<input name="postBackURL" value="<?php echo $merchantStatusPage ?>" hidden = "true"/>
</form>

<script data-cfasync="false" type="text/javascript">
document.easypayconfirmform.submit();
</script>
38 changes: 38 additions & 0 deletions easypayIPN.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
require 'config.php';

$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$con) {
die('Could not connect: ' . mysqli_errno());
}
mysqli_select_db($con, DB_NAME);

if (isset($_GET["url"])) {

$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, $_GET["url"]);
$output=curl_exec($curl);
$table_name ='easypay_order';

if($output != null) {

$orderRefNumber = substr($_GET['url'], strrpos($_GET['url'], '/') + 1);
$query = "UPDATE ".$table_name." SET ipn_attr='".$output."' WHERE easypay_order_id='".$orderRefNumber."'";

try {
mysqli_query($con, $query);
echo "Response is saved ";
} catch (Exception $ex) {
error_log($ex->getMessage());
}
}
curl_close($curl);
}
else {
echo "Welcome!! Enter url to get data :";
}



Binary file added images/easy-pay-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
152 changes: 152 additions & 0 deletions payWithEasypay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php
require 'config.php';

$storeId = STORE_ID;
$daysToExpire = EXPIRY_DATE;
$orderId = ORDER_PREFIX;

$live = LIVE;
$easypayIndexPage = '';
if ($live == 'no') {
$easypayIndexPage = 'https://easypaystg.easypaisa.com.pk/easypay/Index.jsf';
} else {
$easypayIndexPage = 'https://easypay.easypaisa.com.pk/easypay/Index.jsf';
}

$merchantConfirmPage = HOST.'/easypay/confirmEasypay.php';

$autoRedirect = AUTO_REDIRECT;
//$autoRedirect = checked( isset( $options['autoRedirectCb'] ) );
// $autoRedirect = isset( $options['autoRedirectCb']);
if($autoRedirect) {
$autoRedirect = 1;
} else {
$autoRedirect = 0;
}

$orderId .= $_GET['orderId'];
if (strpos($_GET['amount'], '.') !== false) {
$amount = $_GET['amount'];
} else {
$amount = sprintf("%0.1f",$_GET['amount']);
}

$custEmail = $_GET['custEmail'];
$custCell = $_GET['custCell'];
$hashKey = HASH_KEY;

$currentDate = new DateTime();
$currentDate->modify('+ 10 day');
$expiryDate = $currentDate->format('Ymd His');

$paymentMethods = PAYMENT_METHOD;
$paymentMethodVal = $paymentMethods['methods'];

$hashRequest = '';
if(strlen($hashKey) > 0 && (strlen($hashKey) == 16 || strlen($hashKey) == 24 || strlen($hashKey) == 32 )) {
// Create Parameter map
$paramMap = array();
$paramMap['amount'] = $amount ;
$paramMap['autoRedirect'] = $autoRedirect ;
if($custEmail != null && $custEmail != '') {
$paramMap['emailAddr'] = $custEmail ;
}
if($expiryDate != null && $expiryDate != '') {
$paramMap['expiryDate'] = $expiryDate;
}
if($custCell != null && $custCell != '') {
$paramMap['mobileNum'] = $custCell;
}
$paramMap['orderRefNum'] = $orderId ;

if($paymentMethodVal != null && $paymentMethodVal != '') {
$paramMap['paymentMethod'] = $paymentMethodVal ;
}
$paramMap['postBackURL'] = $merchantConfirmPage;
$paramMap['storeId'] = $storeId ;

//Creating string to be encoded
$mapString = '';
foreach ($paramMap as $key => $val) {
$mapString .= $key.'='.$val.'&';
}
$mapString = substr($mapString , 0, -1);

// Encrypting mapString
function pkcs5_pad($text, $blocksize) {

$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);

}

$alg = MCRYPT_RIJNDAEL_128; // AES
$mode = MCRYPT_MODE_ECB; // ECB

$iv_size = mcrypt_get_iv_size($alg, $mode);
$block_size = mcrypt_get_block_size($alg, $mode);
$iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM);

$mapString = pkcs5_pad($mapString, $block_size);
$crypttext = mcrypt_encrypt($alg, $hashKey, $mapString, $mode, $iv);
$hashRequest = base64_encode($crypttext);
}

$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$con) {
die('Could not connect: ' . mysqli_errno());
}
mysqli_select_db($con, DB_NAME);
$table_name = 'easypay_order';

// mysql inserting an order with pending status
$query = "INSERT INTO ".$table_name."( easypay_order_id, easypay_order_info, easypay_order_status, ipn_attr ) VALUES ('$orderId' ,'null', 'pending', 'null')";
try {
mysqli_query($con, $query);
} catch (Exception $ex) {
error_log($ex->getMessage());
}

?>
<form name="easypayform" action="https://easypaystg.easypaisa.com.pk/easypay/Index.jsf" method="POST">
<! -- Store Id Provided by Easypay-->
<input name="storeId" value="3223" hidden = "true"/>
<! -- Amount of Transaction from merchant’s website -->
<input name="amount" value="1033" hidden = "true"/>
<! – Post back URL from merchant’s website -- >
<input name="postBackURL" value=" https://www.consuldents.com/easypay/confirmEasypay.php" hidden = "true"/>
<! – Order Reference Number from merchant’s website -- >
<input name="orderRefNum" value="1101" hidden = "true"/>
<! – Expiry Date from merchant’s website (Optional) -- >
<input type ="hidden" name="expiryDate" value="20170720 201521">
<! – Merchant Hash Value (Optional) -- >
<input type ="hidden" name="merchantHashedReq" value="askldjflaksdjflkasdf======asdfas dfkjaskdf">
<! – If Merchant wants to redirect to Merchant website after payment completion (Optional) -- >
<input type ="hidden" name="autoRedirect" value="0">
<! – If merchant wants to post specific Payment Method (Optional) -- >
<input type ="hidden" name="paymentMethod" value="">
<! – If merchant wants to post specific Payment Method (Optional) -- >
<input type ="hidden" name="emailAddr" value="[email protected]">
<! – If merchant wants to post specific Payment Method (Optionl) -- >
<input type ="hidden" name="mobileNum" value="03345385426">

<!-- <input type = "submit" value="Submit"> -->
</form>
<!-- <form name="easypayformx" method="post" action="<?php echo $easypayIndexPage ?>">
<input name="storeId" value="<?php echo $storeId ?>" />
<input name="amount" value="<?php echo $amount ?>" />
<input name="postBackURL" value="<?php echo $merchantConfirmPage ?>" />
<input name="orderRefNum" value="<?php echo $orderId ?>"/>
<input name="expiryDate" value="<?php echo $expiryDate ?>" />
<input name="autoRedirect" value="<?php echo $autoRedirect ?>" />
<input name="emailAddr" value="<?php echo $custEmail ?>" />
<input name="mobileNum" value="<?php echo $custCell ?>" />
<input name="merchantHashedReq" value="<?php echo $hashRequest ?>" />
<input name="paymentMethod" value="<?php echo $paymentMethodVal ?>" />
<input type = "submit" value="Submit">
</form> -->


<script data-cfasync="false" type="text/javascript">
document.easypayform.submit();
</script>
27 changes: 27 additions & 0 deletions statusEasypay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
require 'config.php';

$status = $_GET['status'];
$orderRefNumber = $_GET ['orderRefNumber'];

$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$con) {
die('Could not connect: ' . mysqli_errno());
}
mysqli_select_db($con, DB_NAME);

$table_name = 'easypay_order';

if ($status == '0000') {
$query = "UPDATE ".$table_name." SET easypay_order_status='success' WHERE easypay_order_id='".$orderRefNumber."'";
} else {
$query = "UPDATE ".$table_name." SET easypay_order_status='failed' WHERE easypay_order_id='".$orderRefNumber."'";
}

try {
mysqli_query($con, $query);
header("Location: ".HOST);
die();
} catch (Exception $ex) {
error_log($ex->getMessage());
}

0 comments on commit fd05a2c

Please sign in to comment.