· 7 years ago · Jul 12, 2018, 07:02 AM
1<link href="css/cart.css" rel="stylesheet" type="text/css" media="all" />
2<link href="css/view_form.css" rel="stylesheet" type="text/css" media="all" />
3<?php
4/**
5 * This is a sample code for manual integration with senangPay
6 * It is so simple that you can do it in a single file
7 * Make sure that in senangPay Dashboard you have key in the return URL referring to this file for example http://myserver.com/senangpay_sample.php
8 */
9
10# please fill in the required info as below
11$merchant_id = '890151902813230';
12$secretkey = '8572-944';
13
14
15# this part is to process data from the form that user key in, make sure that all of the info is passed so that we can process the payment
16if(isset($_POST['detail']) && isset($_POST['amount']) && isset($_POST['order_id']) && isset($_POST['name']) && isset($_POST['email']) && isset($_POST['phone']))
17{
18 # assuming all of the data passed is correct and no validation required. Preferably you will need to validate the data passed
19 //echo $_POST['detail'];
20 $hashed_string = md5($secretkey.urldecode($_POST['detail']).urldecode($_POST['amount']).urldecode($_POST['order_id']));
21
22 # now we send the data to senangPay by using post method
23 ?>
24 <form name="order" method="post" action="https://app.senangpay.my/payment/<?php echo $merchant_id; ?>">
25 <input type="hidden" name="detail" value="<?php echo $_POST['detail']; ?>">
26 <input type="hidden" name="amount" value="<?php echo $_POST['amount']; ?>">
27 <input type="hidden" name="order_id" value="<?php echo $_POST['order_id']; ?>">
28 <input type="hidden" name="name" value="<?php echo $_POST['name']; ?>">
29 <input type="hidden" name="email" value="<?php echo $_POST['email']; ?>">
30 <input type="hidden" name="phone" value="<?php echo $_POST['phone']; ?>">
31
32 <input type="hidden" name="hash" value="<?php echo $hashed_string; ?>">
33 <input type="submit" value="submit">
34 </form>
35
36 <?php
37}
38# this part is to process the response received from senangPay, make sure we receive all required info
39else if(isset($_GET['status_id']) && isset($_GET['order_id']) && isset($_GET['msg']) && isset($_GET['transaction_id']) && isset($_GET['hash']))
40{
41 # verify that the data was not tempered, verify the hash
42 $hashed_string = md5($secretkey.urldecode($_GET['status_id']).urldecode($_GET['order_id']).urldecode($_GET['transaction_id']).urldecode($_GET['msg']));
43
44 # if hash is the same then we know the data is valid
45 if($hashed_string == urldecode($_GET['hash']))
46 {
47 # this is a simple result page showing either the payment was successful or failed. In real life you will need to process the order made by the customer
48 if(urldecode($_GET['status_id']) == '1')
49 echo 'Payment was successful with message: '.urldecode($_GET['msg']);
50 else
51 echo 'Payment failed with message: '.urldecode($_GET['msg']);
52 }
53 else
54 echo 'Hashed value is not correct';
55}
56# this part is to show the form where customer can key in their information
57else
58{
59 # by right the detail, amount and order ID must be populated by the system, in this example you can key in the value yourself
60?>
61
62 <!-- banner -->
63<?php
64 $sql = "SELECT
65 productbanner.productbanner_id,
66 productbanner.productbanner_img,
67 productbanner.banner_about,
68 productbanner.banner_faq,
69 productbanner.banner_mail,
70 productbanner.banner_checkout
71 FROM
72 productbanner
73 ";
74 $resultInfo = mysql_query($sql);
75 $resultTotal = mysql_num_rows($resultInfo);
76 while($rowInfo = mysql_fetch_array($resultInfo))
77 {
78 $banner_checkout = $rowInfo['banner_checkout'];
79 ?>
80 <div class="bannercheckout" id="home1" style="background:url(admin/upload/banner/<?=$banner_checkout;?>) no-repeat 0px 0px;background-size:cover;">
81 <div class="container">
82 <h2>Checkout</h2>
83 </div>
84 </div>
85 <?php } ?>
86 <!-- //banner -->
87
88 <!-- breadcrumbs -->
89 <div class="breadcrumb_dress">
90 <div class="container">
91 <ul>
92 <li><a href="index.php?task=home"><span class="glyphicon glyphicon-home" aria-hidden="true"></span> Home</a> <i>/</i></li>
93 <li>Checkout</li>
94 </ul>
95 </div>
96 </div>
97 <!-- //breadcrumbs -->
98 <div class="checkout">
99 <div class="container">
100 <form name="ePayment" id="ePayment" method="post" action="index.php?task=confirm_payment">
101 <?php $order_id = mt_rand(1000000000,99999999999); ?>
102 <div class="checkout-right">
103 <table class='timetable_sub'>
104 <thead>
105 <tr>
106 <th>No.</th>
107 <th>Product Name</th>
108 <th>Product</th>
109 <th>Quantity</th>
110 <th>Price</th>
111 <th>Remove</th>
112 </tr>
113 </thead>
114 <?php
115 $totalQuantity = 0;
116 $grandTot = "";
117 $productDesc = "";
118 $current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
119 $product = "<table>
120 <tr>
121 <th>No.</th>
122 <th>Product Name</th>
123 <th>Quantity</th>
124 <th>Price</th>
125 <th>Remove</th>
126 </tr>
127 ";
128
129 if(isset($_SESSION["products"]))
130 {
131 $cart_items = 0;
132 $no = 1;
133 foreach ($_SESSION["products"] as $cart_itm)
134 {
135 $product_name = $cart_itm["code"];
136 $product_price = $cart_itm["price"];
137 $product_img = $cart_itm["product_img"];
138 $quantity = $cart_itm["qty"];
139 $totalQuantity = $totalQuantity + $quantity;
140 $subTot = $product_price * $quantity;
141 $grandTot = $grandTot + $subTot;
142 $amount = number_format($grandTot,2);
143 $productDesc .= "Product Name : $product_name ($quantity)<br>";
144
145 $product .= "
146 <tr class='rem1'>
147 <td>$no</td>
148 <td>$product_name</td>
149 <td>".$cart_itm["qty"]."</td>
150 <td>$product_price</td>
151 <td>X</td>
152 </tr>";
153
154 echo '<tr class="rem1">';
155 echo '<td class="invert">'.$no.'</td>';
156 echo '<td class="invert"><img src="admin/upload/products/'.$product_img.'"></td> ';
157 echo '<td class="invert">'.$product_name.'</td> ';
158 echo '<td class="invert">'.$cart_itm["qty"].'</td>';
159 echo '<td class="invert">MYR '.$product_price.' / item</td>';
160 echo '<td class="invert"><a href="cart_update.php?removep='.$cart_itm["code"].'&return_url='.$current_url.'"><img src="images/close.png"></a>
161 </td> ';
162 echo '</tr>';
163
164
165
166 echo '<input type="hidden" name="item_img['.$cart_items.']" value="'.$product_img.'" />';
167 echo '<input type="hidden" name="item_code['.$cart_items.']" value="'.$product_name.'" />';
168 echo '<type="number" min="1" style="width: 70px;" name="item_qty['.$cart_items.']" value="'.$cart_itm["qty"].'" />';
169 echo '<input type="hidden" name="item_price['.$cart_items.']" value="'.$cart_itm["price"].'" />';
170
171 $cart_items ++;
172 $no++;
173 }
174 $product .= "</table>";
175 //echo '</ul>';
176 echo '<span class="check-out-txt">';
177 echo '<h3>Your shopping cart contains: <span>'.$cart_items.' Products</span></h3>';
178 echo '</span>';
179 echo '<input type="hidden" name="totalItem" value="'.$cart_items.'" />';
180 }else{
181 echo '#Your Cart is empty';
182 }
183 ?>
184 </table>
185 </div>
186 <div class="checkout-left">
187 <div class="checkout-left-basket">
188 <h4>Order Summary</h4>
189 <ul>
190 <?php
191 $subTot = 0;
192 $grandTot = 0;
193 $productDesc = "";
194 $current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
195 $product = "<table>
196 <tr>
197 <th>No.</th>
198 <th>Product Name</th>
199 <th>Quantity</th>
200 <th>Price</th>
201 <th>Remove</th>
202 </tr>
203 ";
204
205 if(isset($_SESSION["products"]))
206 {
207 $cart_items = 0;
208 $no = 1;
209 foreach ($_SESSION["products"] as $cart_itm)
210 {
211 $product_name = $cart_itm["code"];
212 $product_price = $cart_itm["price"];
213 $quantity = $cart_itm["qty"];
214 //$totalQuantity = $totalQuantity + $quantity;
215 $subTot = $product_price * $quantity;
216 $grandTot = $grandTot + $subTot;
217 $productDesc .= "Product Name : $product_name ($quantity)<br>";
218
219 $product .= "
220 <tr class='rem1'>
221 <td>$no</td>
222 <td>$product_name</td>
223 <td>".$cart_itm["qty"]."</td>
224 <td>$product_price</td>
225 <td>X</td>
226 </tr>";
227
228 echo '<li>'.$product_name.' <span>MYR '.$subTot.'</span></li>';
229
230 $cart_items ++;
231 $no++;
232 }
233 $product .= "</table>";
234 echo '<li>Total <span>MYR '.$grandTot.'</span></li>';
235 }else{
236 echo '#Your Cart is empty';
237 }
238 ?>
239 </ul>
240 <br>
241 <img src="https://app.senangpay.my/public/img/pay.png">
242 </div>
243 <div class="checkout-right-basket">
244 <div class="contact-form">
245 <h2>Order Form</h2>
246 <div>
247 <span><label>Name</label></span>
248 <span><input name="name" type="text" class="textbox" placeholder="Your name" required=""></span>
249 <input type="hidden" name="detail" value="payment for <?php echo $order_id; ?>" placeholder="Description of the transaction" size="30">
250 <input type="hidden" name="amount" value="<?php echo $amount; ?>" placeholder="Amount to pay, for example 12.20" size="30">
251 <input type="hidden" name="order_id" value="<?php echo $order_id; ?>" placeholder="Unique id to reference the transaction or order" size="30">
252
253 </div>
254 <div>
255 <span><label>Delivery Address</label></span>
256 <span><input name="address" type="text" class="textbox" placeholder="Your delivery address" required=""></span>
257 </div>
258 <div>
259 <span><label>E-mail</label></span>
260 <span><input name="email" type="email" class="textbox" placeholder="Your email" required=""></span>
261 </div>
262 <div>
263 <span><label>Mobile</label></span>
264 <span><input name="phone" type="text" class="textbox" placeholder="Your Mobile No." required=""></span>
265 </div>
266 <div>
267 <?php
268 $merchant_id = '890151902813230';
269 $secretkey = '8572-944';
270 ?>
271 <input type="hidden" name="merchant_id" value="<?php echo $merchant_id;?>">
272 <input type="hidden" name="secretkey" value="<?php echo $secretkey;?>">
273
274
275 <input type="text" name="detail" value="payment_for_order_<?php echo $order_id; ?>">
276 <input type="text" name="amount" value="<?php echo $amount; ?>">
277 <input type="text" name="order_id" value="<?php echo $order_id; ?>">
278
279 </div>
280 <div>
281 <input type="submit" class="btn item_add" value="Continue To Payment">
282 </div>
283 </div>
284 <a href="index.php?task=products"><span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span>Continue Shopping</a>
285 </div>
286 <div class="clearfix"> </div>
287 </div>
288
289 </form>
290 </div>
291 </div>
292
293<?ph
294}
295?>