Guest User

Untitled

a guest
Nov 18th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.04 KB | None | 0 0
  1. function result_cc(){
  2.     $m = explode("?", $_SERVER['REQUEST_URI'] );
  3.         $m = count($m)>0?explode("&",$m[1]):$m[0];
  4.         $arr = array();
  5.         if( count($m) > 0 ){
  6.                 foreach($m as $r){
  7.                         $t = explode("=",$r);
  8.                         $arr[$t[0]] = urldecode($t[1]);
  9.                 }
  10.         }
  11.         $px = get_cd_from_order($this->jCfg['trans']['order_id']);
  12.         $SECURE_SECRET =  $px->security_key;
  13.         $accessCode    =  $px->access_code;
  14.         $merchantId    =  $px->merchant_id;        
  15.                
  16.         $md5HashData = $SECURE_SECRET;
  17.        
  18.         foreach($arr as $key => $value) {
  19.             if (trim($key) != "vpc_SecureHash" && strlen($value) > 0) {
  20.                 $md5HashData .= urldecode($value);
  21.             }
  22.         }
  23.            
  24.         $signature = strtoupper(md5($md5HashData));
  25.         $order_id = "0";
  26.         $status = 0;
  27.         $pesan = isset($arr['vpc_Message'])?$arr['vpc_Message']:'';
  28.         if( isset($arr['vpc_SecureHash']) && $arr['vpc_SecureHash']== $signature){
  29.            
  30.             if( $arr['vpc_TxnResponseCode'] == 0 && strtolower($arr['vpc_Message'])=="approved" ){
  31.                
  32.                 //$order_id = isset($arr['vpc_MerchTxnRef'])?$arr['vpc_MerchTxnRef']:'';
  33.                 $order_id = trim($this->jCfg['trans']['order_id'])?$this->jCfg['trans']['order_id']:'';
  34.  
  35.                 //if success.... cek API Payable..
  36.                 $paycode = $arr['vpc_ReceiptNo'];
  37.                 $partner_key = get_cfg_app('blitz_partner_key');
  38.                 $partner_code = get_cfg_app('blitz_partner_code');
  39.                 $bookingcode = $order_id;
  40.                 $paytype = get_cfg_app('blitz_paytype');
  41.                 $signature = sha1($bookingcode.$paytype.$paycode.$partner_code.$partner_key);          
  42.                
  43.                     $data_insert = array(
  44.                                 "cc_status"             => isset($arr['vpc_TxnResponseCode'])?$arr['vpc_TxnResponseCode']:'',
  45.                                 "cc_message"            => isset($arr['vpc_Message'])?$arr['vpc_Message']:'',
  46.                                 "cc_hash"               => isset($arr['vpc_SecureHash'])?$arr['vpc_SecureHash']:'',
  47.                                 "cc_booking_id"         => $order_id ,
  48.                                 "cc_paycode"            => $paycode,
  49.                                 "cc_date"               => date("Y-m-d H:i:s")
  50.                         );
  51.                 $this->db->insert("blitz_result_cc",$data_insert);
  52.                
  53.                
  54.                 // get email…
  55.                 $em = $this->db->get_where("blitz_trans",array(
  56.                     'order_id'  => $bookingcode
  57.                 ))->row();
  58.                 $email_order = '';
  59.                 if(count($m)>0 && isset($em->order_email) && trim($em->order_email)!=''){
  60.                     $email_order = $em->order_email;
  61.                 }
  62.                 // post booking..
  63.                 $arr_data =  array(
  64.                                 'bookingcode'   => $bookingcode,
  65.                                 'paytype'       => $paytype,
  66.                                 'paycode'       => $paycode,
  67.                                 'customeremail' => $email_order,
  68.                                 'partnercode'   => $partner_code,
  69.                                 'signature'     => $signature
  70.                             );
  71.    
  72.                 $post_data = http_build_query($arr_data);
  73.                 $opts = array('http' =>
  74.                                     array(
  75.                                         'method'  => 'POST',
  76.                                         'header'  => 'Content-type: application/x-www-form-urlencoded',
  77.                                         'content' => $post_data
  78.                                     )
  79.                                 );
  80.    
  81.                 $context        = stream_context_create($opts);
  82.                 $result         = file_get_contents(get_cfg_app('blitz_url_payable'), false, $context);
  83.                
  84.                 $payable_result = json_decode(xml2json($result));
  85.    
  86.                 if(!isset($payable_result->{'@attributes'}->bookingcode)){
  87.                         $msg = "";
  88.                         if(count($payable_result) > 0){
  89.                                 foreach($payable_result as $k=>$v){
  90.                                         $msg = isset($v)?$v:'';
  91.                                 }
  92.                         }
  93.                         $this->setMessage(array(
  94.                                         "class" =>"error",
  95.                                         "msg"   => $msg
  96.                                 ));
  97.                 }
  98.                
  99.                
  100.                 //insert payable…..
  101.                 //debug($payable_result);
  102.                 if( isset($payable_result->{'@attributes'}->bookingcode) ){
  103.                     $data_payable = array(
  104.                         'pay_bookingcode'   => $payable_result->{'@attributes'}->bookingcode,
  105.                         'pay_passkey'       => $payable_result->{'@attributes'}->passkey,
  106.                         'pay_paytype'       => $payable_result->{'@attributes'}->paytype,
  107.                         'pay_paycode'       => $payable_result->{'@attributes'}->paycode,
  108.                         'pay_total'         => $payable_result->{'@attributes'}->total - $px->order_price_discount,
  109.                         'pay_time'          => date("Y-m-d H:i:s"),
  110.                         'pay_status'        => 'SUCCESS'
  111.                     );
  112.                     $this->db->insert('blitz_payable',$data_payable);
  113.                 }
  114.    
  115.             }else{
  116.                     //echo "Access Denied!";
  117.                     //insert error to db cc_result..
  118.                     $order_id = trim($this->jCfg['trans']['order_id'])?$this->jCfg['trans']['order_id']:'';
  119.                    
  120.                     $this->db->insert("blitz_result_cc",array(
  121.                         "cc_status" => 'ERROR',
  122.                         "cc_date"   => date("Y-m-d H:i:s"),
  123.                         "cc_booking_id" => $order_id,
  124.                         "cc_error"  => json_encode($arr)
  125.                     ));
  126.                    
  127.                     _go_to_error_page();
  128.             }
  129.         }else{
  130.             //insert error to db cc_result..
  131.             $order_id = trim($this->jCfg['trans']['order_id'])?$this->jCfg['trans']['order_id']:'';
  132.            
  133.             $this->db->insert("blitz_result_cc",array(
  134.                 "cc_status" => 'ERROR',
  135.                 "cc_date"   => date("Y-m-d H:i:s"),
  136.                 "cc_booking_id" => $order_id,
  137.                 "cc_error"  => json_encode($arr)
  138.             ));
  139.            
  140.             _go_to_error_page();
  141.         }
  142.         // confirm to cek API….
  143.         redirect(base_url()."multilang/".$this->LANG."/blitz/confirm-cc/");
  144.     }
Add Comment
Please, Sign In to add comment