-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpayWithEasypay.php
152 lines (129 loc) · 5.46 KB
/
payWithEasypay.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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>