· 9 years ago · Jan 29, 2017, 01:42 AM
1<?php
2/*
3SenangPay Callback Processing
4*/
5
6$senangpay = new Payment_senangpay();
7if ( $senangpay->validate_callback() ) {
8 /*
9 Callback is true and payment status is successful.
10
11 What to do next?
12
13 Process $_POST data and check if order is already processed.
14 -- Process order if it hasn't been process.
15 -- Log if sale is already processed.
16 */
17} else {
18 // log invalid callback attempt -- maybe hacker trying to get free stuffs
19}
20
21
22class Payment_senangpay {
23
24 var $secret_key = '';
25
26 function validate_callback() {
27 // Unlike a return URL, callback uses POST data.
28
29 $this->order_id = $_POST['order_id'];
30
31 if(isset($_POST['status_id']) && isset($_POST['order_id']) && isset($_POST['msg']) && isset($_POST['transaction_id']) && isset($_POST['hash']))
32 {
33 // verify that the data was not tempered, verify the hash
34 $hashed_string = md5($this->secret_key.urldecode($_POST['status_id']).urldecode($_POST['order_id']).urldecode($_POST['transaction_id']).urldecode($_POST['msg']));
35
36 // if hash is the same then we know the data is valid
37 if($hashed_string == urldecode($_POST['hash']))
38 {
39 if(urldecode($_POST['status_id']) == '1') {
40 // payment was successful
41 $this->message = 'Payment was successful with message: '.urldecode($_POST['msg']);
42 $this->status = true;
43 return true;
44 } else {
45 // payment failed or cancelled
46= $this->message = 'Payment failed with message: '.urldecode($_POST['msg']);
47 $this->status = false;
48 return false;
49 }
50 }
51 else {
52 // echo 'Hashed value is not correct';
53 $this->message = 'Hashed value is not correct';
54 $this->status = false;
55 return false;
56 }
57 }
58 $this->message = 'Data incomplete';
59 $this->status = false;
60 return false;
61 }
62}
63?>