Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/rabbithabit.com/public_html/application/controllers/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Midtrans extends Public_controller { private $id_order = NULL; function __construct() { parent::__construct(); $this->load->model('order_m'); $this->load->model('order_detail_m'); $this->load->model('configuration_m'); } //when payment is success public function receive_veritrans_notification() { //Midtrans IP address allowed only /* $allowlist = array( '103.208.23.0/24', '182.253.221.152/32', '103.58.103.177' ); if(!in_array($_SERVER['REMOTE_ADDR'], $allowlist)){ show_404(); } */ require_once APPPATH . 'third_party/Veritrans.php'; $this->db->select('veritrans_server_key, veritrans_sandbox_server_key, veritrans_production_mode')->from('configuration')->where('id_configuration', 1); $veritrans = $this->db->get()->row(); $production_mode = $veritrans->veritrans_production_mode; if($production_mode == 'true') { Veritrans_Config::$isProduction = true; Veritrans_Config::$serverKey = $veritrans->veritrans_server_key; } else { Veritrans_Config::$isProduction = false; Veritrans_Config::$serverKey = $veritrans->veritrans_sandbox_server_key; } $notif = new Veritrans_Notification(); $transaction = $notif->transaction_status; $type = $notif->payment_type; $order_id_array = explode('-', $notif->order_id); $order_id = (int) trim($order_id_array[0]); $this->id_order = $order_id; $fraud = $notif->fraud_status; $data = array( 'log' => serialize($notif), 'order_id' => $order_id ); if($notif->va_numbers[0]->va_number) { $data['va_number'] = $notif->va_numbers[0]->va_number; } elseif($notif->permata_va_number) { $data['va_number'] = $notif->permata_va_number; } $this->db->insert('midtrans_log', $data); //insert va_number into orders table if($notif->va_numbers[0]->va_number || $notif->permata_va_number) { if($notif->va_numbers[0]->va_number) { $va_data['va_number'] = $notif->va_numbers[0]->va_number; $va_data['payment_method'] = 'Bank Transfer BNI'; } elseif($notif->permata_va_number) { $va_data['va_number'] = $notif->permata_va_number; $va_data['payment_method'] = 'Bank Transfer Permata'; } $this->db->where('id_orders', $order_id); $this->db->update('orders', $va_data); } switch($transaction) { case 'capture': // For credit card transaction, we need to check whether transaction is challenge by FDS or not if ($type == 'credit_card') { if($fraud == 'challenge') { // TODO set payment status in merchant's database to 'Challenge by FDS' // TODO merchant should decide whether this transaction is authorized or not in MAP $data = array( 'payment_status_message' => ucwords($transaction) . '. Fraud Status:' . $fraud, 'payment_method' => $type ); $this->db->where('id_orders', (int) $order_id); $this->db->update('orders', $data); echo "Transaction order_id: " . $order_id ." is challenged by FDS"; } else { //Fraud status accept and transaction capture. Means payment is success //check payment status must not be 4 (process) or 5 (delivered) $this->db->select('payment_status')->from('orders')->where('id_orders', (int) $order_id); $current_payment_status = $this->db->get()->row()->payment_status; if($current_payment_status != 4 && $current_payment_status != 5) { // TODO set payment status in merchant's database to 'Success' $data = array( 'payment_status_message' => $transaction, 'payment_confirm' => 1, 'payment_date' => $notif->transaction_time, 'payment_method' => $type, 'payment_type' => 'midtrans' ); //check if indent_remaining is > 0, yes means has indent payment $indent_remaining = $this->db->select('indent_remaining')->from('orders')->where('id_orders', $order_id)->get()->row()->indent_remaining; if($indent_remaining > 0) { $data['payment_status'] = 6; //partially paid of indent product } else { $data['payment_status'] = 3; //fully paid } $this->db->where('id_orders', (int) $order_id); $this->db->update('orders', $data); //prevent adding point reward twice. Get midtrans_midtrans_already_process_status $this->db->select('midtrans_process_finish')->from('orders')->where('id_orders', $order_id); $midtrans_process_finish = $this->db->get()->row()->midtrans_process_finish; if($midtrans_process_finish == 'no') { //update current point rewards //get customer_id $this->db->select('customer_id')->from('orders')->where('id_orders', $order_id); $customer_id = (int) $this->db->get()->row()->customer_id; //get customer current point $this->db->select('current_pointreward')->from('customers')->where('id_customers', $customer_id); $current_point = (int) $this->db->get()->row()->current_pointreward; //get add point from order $this->db->select('plus_reward')->from('orders')->where('id_orders', $order_id); $rewards = $this->db->get()->row(); $plus_point = (int) $rewards->plus_reward; $updated_point = $current_point + $plus_point; //update point reward $data = array( 'current_pointreward' => $updated_point ); $this->db->where('id_customers', $customer_id); $this->db->update('customers', $data); //change status of midtrans_process_finish to yes $order_data = array( 'midtrans_process_finish' => 'yes' ); $this->db->where('id_orders', $order_id); $this->db->update('orders', $order_data); $this->process_send_email($order_id); } echo "Transaction order_id: " . $order_id ." successfully captured using " . $type; } } } break; case 'settlement': if ($type != 'credit_card') { //prevent adding point reward twice. Get midtrans_midtrans_already_process_status $this->db->select('midtrans_process_finish')->from('orders')->where('id_orders', $order_id); $midtrans_process_finish = $this->db->get()->row()->midtrans_process_finish; if($midtrans_process_finish == 'no') { //check payment status must not be 4 (process) or 5 (delivered) $this->db->select('payment_status')->from('orders')->where('id_orders', (int) $order_id); $current_payment_status = $this->db->get()->row()->payment_status; if($current_payment_status != 4 && $current_payment_status != 5) { $data = array( 'payment_status_message' => $transaction, 'payment_confirm' => 1, 'payment_date' => $notif->transaction_time, 'payment_type' => 'midtrans', ); //check if indent_remaining is > 0, yes means has indent payment $indent_remaining = $this->db->select('indent_remaining')->from('orders')->where('id_orders', $order_id)->get()->row()->indent_remaining; if($indent_remaining > 0) { $data['payment_status'] = 6; //partially paid of indent product } else { $data['payment_status'] = 3; //fully paid } $this->db->where('id_orders', (int) $order_id); $this->db->update('orders', $data); //update current point rewards //get customer_id $this->db->select('customer_id')->from('orders')->where('id_orders', $order_id); $customer_id = (int) $this->db->get()->row()->customer_id; //get customer current point $this->db->select('current_pointreward')->from('customers')->where('id_customers', $customer_id); $current_point = (int) $this->db->get()->row()->current_pointreward; //get add point from order $this->db->select('plus_reward')->from('orders')->where('id_orders', $order_id); $rewards = $this->db->get()->row(); $plus_point = (int) $rewards->plus_reward; $updated_point = $current_point + $plus_point; //update point reward $data = array( 'current_pointreward' => $updated_point ); $this->db->where('id_customers', $customer_id); $this->db->update('customers', $data); //change status of midtrans_process_finish to yes $order_data = array( 'midtrans_process_finish' => 'yes' ); $this->db->where('id_orders', $order_id); $this->db->update('orders', $order_data); $this->process_send_email($order_id); echo "Transaction order_id: " . $order_id ." successfully transfered using " . $type; } } } break; case 'pending': // TODO set payment status in merchant's database to 'Pending' $data = array( 'payment_status' => 1, //not paid 'payment_status_message' => $transaction, 'payment_confirm' => 0, 'payment_type' => 'midtrans' ); $this->db->where('id_orders', (int) $order_id); $this->db->update('orders', $data); echo "Transaction order_id: " . $order_id ." pending using " . $type; break; case 'deny': //check payment status must not be 4 (process) or 5 (delivered) $this->db->select('payment_status')->from('orders')->where('id_orders', (int) $order_id); $current_payment_status = $this->db->get()->row()->payment_status; switch ($current_payment_status) { case 1: //not paid case 2: //cancel case 5: //delivered $data = array( 'payment_status_message' => $transaction, ); $this->db->where('id_orders', (int) $order_id); $this->db->update('orders', $data); break; case 3: //paid $data = array( 'payment_status_message' => $transaction, ); $this->db->where('id_orders', (int) $order_id); $this->db->update('orders', $data); break; case 4: //process $data = array( //'payment_status' => 1, //not paid 'payment_status_message' => $transaction, //'payment_confirm' => 0 ); $this->db->where('id_orders', (int) $order_id); $this->db->update('orders', $data); break; } break; case 'expired': case 'cancel': $data = array( 'payment_status_message' => ucwords($transaction), 'payment_method' => $type ); $this->db->where('id_orders', (int) $order_id); $this->db->update('orders', $data); echo "order_id: " . $order_id . " Method " . $type . " status " . $transaction; break; } } public function veritrans_payment_success() { $this->data['order_id'] = $this->session->userdata('midtrans_order_id'); $this->data['order'] = $this->db->select('*')->from('orders')->where('id_orders',$this->data['order_id'])->get()->row(); $this->data['order_info'] = $this->data['order']; $orders_detail = $this->db->select('*')->from('orders_detail')->where('orders_id', $this->data['order']->id_orders)->get()->result(); if($this->session->userdata('site_lang') == 'english') { $this->lang->load('order_history', 'english'); } else { $this->lang->load('order_history', 'indonesian'); } $finalshippingfee = 0; $calculate_finalshippingfee = $this->data['order']->shipping_fee - $this->data['order']->free_shipping_fee; if($calculate_finalshippingfee > 0){ $finalshippingfee = $calculate_finalshippingfee; } $this->data['grand_total'] = $this->data['order']->grand_total_amount - $this->data['order']->indent_remaining - $this->data['order']->indent_shipping_fee; //get customer email $this->data['email'] = $this->db->select('customers.email')->from('customers')->join('orders', 'customers.id_customers = orders.customer_id')->where('orders.id_orders', $this->data['order_id'])->get()->row()->email; //get SEO $this->data_header['browser_title'] = 'Midtrans Payment Success'; $this->data_header['meta_description'] = 'Midtrans Payment Success'; $this->data_header['meta_keywords'] = 'Midtrans Payment Success'; $this->cart->destroy(); $this->load->view("themes/$this->theme_no/header", $this->data_header); $this->load->view('veritrans_result/success',$this->data); $this->load->view("themes/$this->theme_no/footer", $this->data_footer); } public function veritrans_payment_pending() { $order_id = $this->session->userdata('midtrans_order_id'); $this->db->select('*'); $this->db->from('orders'); $this->db->where('id_orders',$order_id); $this->data['order'] = $this->db->get()->row(); $this->db->select('*'); $this->db->from('orders_detail'); $this->db->where('orders_id', $this->data['order']->id_orders); $orders_detail = $this->db->get()->result(); //get va number $this->db->select('va_number')->from('midtrans_log')->where('order_id', $order_id); $this->data['va_number'] = $this->db->get()->row()->va_number; $this->process_send_email($order_id); if($this->session->userdata('site_lang') == 'english') { $this->lang->load('order_history', 'english'); } else { $this->lang->load('order_history', 'indonesian'); } $this->cart->destroy(); //get SEO $this->data_header['browser_title'] = 'Midtrans Payment Pending'; $this->data_header['meta_description'] = 'Midtrans Payment Pending'; $this->data_header['meta_keywords'] = 'Midtrans Payment Pending'; $this->load->view("themes/$this->theme_no/header", $this->data_header); $this->load->view('veritrans_result/pending_english',$this->data); $this->load->view("themes/$this->theme_no/footer", $this->data_footer); } private function process_send_email($order_id) { //----SEND EMAIL TO CUSTOMER //get customer name if($this->session->userdata('customer')['customer_id'] != null){ $customer_id = (int) $this->session->userdata('customer')['customer_id']; } else{ $customer_id = $this->db->select('customer_id')->from('orders')->where('id_orders',$order_id)->get()->row()->customer_id; } $this->db->select('name,phone,type,email')->from('customers')->where('id_customers', $customer_id); $email_data['customer'] = $this->db->get()->row(); $email_data['email'] = $email_data['customer']->email; $cek_customer = ''; if ($this->session->userdata('customer')['customer_type'] == 'guest') { $cek_customer = 1; } else { $cek_customer = 0; } $email_data['cek_customer'] = $cek_customer; $email_data['emails'] = $this->configuration_m->get_emails(); $email_data['subject'] = 'Order Confirmation'; //get order detail and customer detail $email_data['order'] = $this->order_m->get_order($order_id); $email_data['order_details'] = $this->order_detail_m->get_orders_detail($order_id); //get vouchers detail if ($this->session->userdata('chosen_voucher_code')) { $email_data['chosen_voucher_code'] = $this->session->userdata('chosen_voucher_code'); $email_data['chosen_voucher_type'] = $this->session->userdata('chosen_voucher_type'); $email_data['chosen_voucher_discount'] = $this->session->userdata('chosen_voucher_discount'); $email_data['redeemed_voucher_amount'] = $this->session->userdata('redeemed_voucher_amount'); } //get shipping fee total $email_data['carrier_name'] = $this->session->userdata('carrier_name'); $email_data['total_shipping_fee'] = $this->session->userdata('total_shipping_fee'); //add tax to email, if exist.. if($this->session->userdata('tax')) { $email_data['tax'] = $this->session->userdata('tax'); } //add point reward to email, if exist.. if($this->session->userdata('chosen_point')) { $email_data['chosen_point'] = $this->session->userdata('chosen_point'); $email_data['chosen_point_discount'] = $this->session->userdata('chosen_point_discount'); } $view_file = 'email/indonesian/midtrans-new'; $this->send_email($view_file, $email_data); //function in My_Controller } public function veritrans_payment_unfinish() { $this->cart->destroy(); //get SEO $this->data_header['browser_title'] = 'Midtrans Payment Unfinish'; $this->data_header['meta_description'] = 'Midtrans Payment Unfinish'; $this->data_header['meta_keywords'] = 'Midtrans Payment Unfinish'; $this->load->view("themes/$this->theme_no/header", $this->data_header); $this->load->view('veritrans_result/unfinish'); $this->load->view("themes/$this->theme_no/footer", $this->data_footer); } public function veritrans_payment_error() { $this->cart->destroy(); //get SEO $this->data_header['browser_title'] = 'Midtrans Payment Error'; $this->data_header['meta_description'] = 'Midtrans Payment Error'; $this->data_header['meta_keywords'] = 'Midtrans Payment Error'; $this->load->view("themes/$this->theme_no/header", $this->data_header); $this->load->view('veritrans_result/error'); $this->load->view("themes/$this->theme_no/footer", $this->data_footer); } private function destroy_session_data() { if($this->session->userdata('customer')['customer_type'] == 'guest') { $this->session->unset_userdata('customer'); } //DESTROY CART AND UNSET SOME SESSION, BUT NOT CUSTOMER SESSION $this->cart->destroy(); $this->session->unset_userdata('midtrans_order_id'); $this->session->unset_userdata('grand_total'); $this->session->unset_userdata('recipient_name'); $this->session->unset_userdata('address'); $this->session->unset_userdata('id_district'); $this->session->unset_userdata('id_subdistrict'); $this->session->unset_userdata('id_province'); $this->session->unset_userdata('district'); $this->session->unset_userdata('subdistrict'); $this->session->unset_userdata('province'); $this->session->unset_userdata('country'); $this->session->unset_userdata('postcode'); $this->session->unset_userdata('phone'); $this->session->unset_userdata('order_id'); $this->session->unset_userdata('is_from_cart'); $this->session->unset_userdata('chosen_voucher_type'); $this->session->unset_userdata('chosen_voucher_discount'); $this->session->unset_userdata('chosen_voucher_code'); $this->session->unset_userdata('total_categoryproduct_promo'); $this->session->unset_userdata('redeemed_voucher_amount'); $this->session->unset_userdata('total_shipping_fee'); $this->session->unset_userdata('carrier'); $this->session->unset_userdata('carrier_name'); $this->session->unset_userdata('summary_message'); $this->session->unset_userdata('add_point_reward'); $this->session->unset_userdata('minus_point_reward'); $this->session->unset_userdata('chosen_point'); $this->session->unset_userdata('chosen_point_discount'); $this->session->unset_userdata('chosen_payment_type'); $this->session->unset_userdata('tax'); $this->session->unset_userdata('productpage_to_cart'); $this->session->unset_userdata('choose_dropship_status'); $this->session->unset_userdata('destination_latitude'); $this->session->unset_userdata('destination_longitude'); $this->session->unset_userdata('current_viewed_category_id'); $this->session->unset_userdata('shipping_cart'); $this->session->unset_userdata('prescription_uniqid'); } }