· 9 years ago · Jan 12, 2017, 07:36 AM
1public function postConfirmMoCo()
2 {
3
4 $tid = Input::get('tid');
5 $status = Input::get('status');
6 $message = Input::get('message');
7 $userid = Input::get('userid');
8 $mparam = Input::get('mparam');
9 $name = Input::get('name');
10 $email = Input::get('email');
11 $hash = Input::get('hash');
12 $secret_key = "s@st0";
13
14 // generate hash on merchant side using values sent by MoCo
15 $myHash = hash_hmac("md5", $tid . $status . $message . $userid . $mparam . $name . $email, $secret_key);
16
17 if($myHash == $hash)
18 {
19 if($status == 'S')
20 {
21 die('success');
22 }
23 else
24 {
25 die('failure');
26 }
27 }
28 else
29 {
30 die('hash not matched');
31
32 }
33 }
34
35
36 public function getMoCo($shippingDetails){
37
38
39 $item_price = DB::table('carts')->where('user_id', '=', Session::get('user_id') )->sum('subtotal');
40
41
42 $shipping_charge = $shippingDetails['shipping_charge'];
43
44 $total_price = $item_price + $shipping_charge;
45
46 // merchant id assigned by MoCo
47 $mid = "1006";
48
49 // amount in rupees
50 $amount = $total_price;
51
52 // any merchant required parameters
53 //$mparam = urlencode("MERCHANT-PARAMETERS");
54 $mparam = 100;
55
56 // secret key provided by MoCo
57 $secret_key = "s@st0";
58
59 // merchant defined url where the page will be redirected after the completion of
60 // transaction
61 $return_url = route('moco_payment');
62
63 // generate hmac md5 hash using secret key
64
65 $hash = hash_hmac("md5", $mid . $amount . $mparam, $secret_key);
66
67
68 $post_array = array(
69
70 'mid'=> $mid,
71 'amount' => $amount,
72 'mparam' => $mparam,
73 'hash' => $hash,
74 'return_url' => $return_url
75 );
76
77 return $post_array;
78 }