function ticket_checkin($echo = true)
 {
     if ($this->get_api_key_id()) {
         $api_key_id = $this->get_api_key_id();
         $ticket_id = ticket_code_to_id($this->ticket_code);
         if ($ticket_id) {
             $ticket_instance = new TC_Ticket_Instance($ticket_id);
             $ticket_type_id = apply_filters('tc_ticket_type_id', $ticket_instance->details->ticket_type_id);
             $ticket_type = new TC_Ticket($ticket_type_id);
             $order = new TC_Order($ticket_instance->details->post_parent);
             if ($order->details->post_status == 'order_paid') {
                 $order_is_paid = true;
             } else {
                 $order_is_paid = false;
             }
             $order_is_paid = apply_filters('tc_order_is_paid', $order_is_paid, $order->details->ID);
             if ($order_is_paid) {
                 //all good, continue with check-in process
             } else {
                 _e('Ticket does not exist', 'tc');
                 exit;
             }
             $ticket_event_id = $ticket_type->get_ticket_event($ticket_type_id);
         } else {
             _e('Ticket does not exist', 'tc');
             exit;
         }
         if ($this->get_api_event() != $ticket_event_id) {
             //Only API key for the parent event can check-in this ticket
             if ($this->get_api_event() !== 'all') {
                 if ($echo) {
                     _e('Insufficient permissions. This API key cannot check-in this ticket.', 'tc');
                 } else {
                     return 403;
                     //error code for incufficient persmissions
                 }
                 exit;
             }
         }
         $check_ins = $ticket_instance->get_ticket_checkins();
         $num_of_check_ins = apply_filters('tc_num_of_checkins', is_array($check_ins) ? count($check_ins) : 0);
         $available_checkins = get_post_meta($ticket_type_id, 'available_checkins_per_ticket', true);
         $alternate_available_checkins = get_post_meta($ticket_type_id, '_available_checkins_per_ticket', true);
         $available_checkins = !empty($available_checkins) ? $available_checkins : $alternate_available_checkins;
         $available_checkins = is_numeric($available_checkins) ? $available_checkins : 9999;
         //9999 means unlimited check-ins but it's set for easier comparation
         if ($available_checkins > $num_of_check_ins) {
             $check_in_status = apply_filters('tc_checkin_status_name', true);
             $check_in_status_bool = true;
             do_action('tc_check_in_notification', $ticket_id);
         } else {
             $check_in_status = apply_filters('tc_checkin_status_name', false);
             $check_in_status_bool = false;
         }
         $new_checkins = array();
         if (is_array($check_ins)) {
             foreach ($check_ins as $check_in) {
                 $new_checkins[] = $check_in;
             }
         }
         $new_checkin = array("date_checked" => time(), "status" => $check_in_status ? apply_filters('tc_checkin_status_name', 'Pass') : apply_filters('tc_checkin_status_name', 'Fail'), "api_key_id" => $api_key_id);
         $new_checkins[] = apply_filters('tc_new_checkin_array', $new_checkin);
         do_action('tc_before_checkin_array_update');
         update_post_meta($ticket_id, "tc_checkins", $new_checkins);
         do_action('tc_after_checkin_array_update');
         $payment_date = apply_filters('tc_checkin_payment_date', tc_format_date(apply_filters('tc_ticket_checkin_order_date', $order->details->tc_order_date, $order->details->ID)));
         //date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $order->details->tc_order_date, false )
         if ($payment_date == '') {
             $payment_date = 'N/A';
         }
         $name = apply_filters('tc_checkin_owner_name', $ticket_instance->details->first_name . ' ' . $ticket_instance->details->last_name);
         if (trim($name) == '') {
             $name = 'N/A';
         }
         $address = apply_filters('tc_checkin_owner_address', $ticket_instance->details->address);
         if ($address == '') {
             $address = 'N/A';
         }
         $city = apply_filters('tc_checkin_owner_city', $ticket_instance->details->city);
         if ($city == '') {
             $city = 'N/A';
         }
         $state = apply_filters('tc_checkin_owner_state', $ticket_instance->details->state);
         if ($state == '') {
             $state = 'N/A';
         }
         $country = apply_filters('tc_checkin_owner_country', $ticket_instance->details->country);
         if ($country == '') {
             $country = 'N/A';
         }
         $data = array('status' => $check_in_status_bool, 'previous_status' => '', 'pass' => true, 'name' => $name, 'payment_date' => $payment_date, 'address' => $address, 'city' => $city, 'state' => $state, 'country' => $country, 'checksum' => $this->ticket_code);
         $buyer_full_name = isset($order->details->tc_cart_info['buyer_data']['first_name_post_meta']) ? $order->details->tc_cart_info['buyer_data']['first_name_post_meta'] . ' ' . $order->details->tc_cart_info['buyer_data']['last_name_post_meta'] : '';
         $buyer_email = isset($order->details->tc_cart_info['buyer_data']['email_post_meta']) ? $order->details->tc_cart_info['buyer_data']['email_post_meta'] : '';
         $data['custom_fields'] = array(array(apply_filters('tc_ticket_checkin_custom_field_title', 'Ticket Type'), apply_filters('tc_checkout_owner_info_ticket_title', $ticket_type->details->post_title, $ticket_type->details->ID)), array(apply_filters('tc_ticket_checkin_custom_field_title', 'Buyer Name'), apply_filters('tc_ticket_checkin_buyer_full_name', $buyer_full_name, $order->details->ID)), array(apply_filters('tc_ticket_checkin_custom_field_title', 'Buyer E-mail'), apply_filters('tc_ticket_checkin_buyer_email', $buyer_email, $order->details->ID)));
         $data['custom_fields'] = apply_filters('tc_checkin_custom_fields', $data['custom_fields'], $ticket_instance->details->ID, $ticket_event_id, $order, $ticket_type);
         apply_filters('tc_checkin_output_data', $data);
         if ($echo === true || $echo == 'echo') {
             echo json_encode($data);
             exit;
         } else {
             return $data;
         }
     }
 }
 $ticket_instance = new TC_Ticket_Instance((int) $_GET['ID']);
 $ticket_type = new TC_Ticket($ticket_instance->details->ticket_type_id);
 $ticket_event_id = $ticket_type->get_ticket_event($ticket_instance->details->ticket_type_id);
 if (isset($_POST['api_key'])) {
     $api_key = new TC_API_Key($_POST['api_key']);
     $checkin = new TC_Checkin_API($api_key->details->api_key, apply_filters('tc_checkin_request_name', 'tickera_scan'), 'return', $ticket_instance->details->ticket_code, false);
     $checkin_result = $checkin->ticket_checkin(false);
     if ($checkin_result['status'] == 1) {
         $message_type = 'updated';
         $message = __('Ticket checked in successfully.', 'tc');
     } else {
         $message_type = 'error';
         $message = __('Ticket expired.', 'tc');
     }
 }
 $ticket_checkins = $ticket_instance->get_ticket_checkins();
 if (isset($_GET['checkin_action']) && $_GET['checkin_action'] == 'delete_checkin' && check_admin_referer('delete_checkin') && !isset($_POST['api_key'])) {
     $entry_to_delate = $_GET['checkin_entry'];
     $checkin_row = 0;
     if ($ticket_checkins) {
         foreach ($ticket_checkins as $ticket_key => $ticket_checkin) {
             if ($ticket_checkin['date_checked'] == $entry_to_delate) {
                 unset($ticket_checkins[$ticket_key]);
             }
             $checkin_row++;
         }
         update_post_meta($ticket_instance->details->ID, 'tc_checkins', $ticket_checkins);
         $message_type = 'updated';
         $message = __('Check-in record deleted successfully.', 'tc');
     }
 }