/**
  * Saved by ajax the order information.
  *
  * @return void
  */
 public function transparent_checkout_ajax()
 {
     $settings = get_option('woocommerce_gerencianet_settings');
     if ('tc' != $settings['api']) {
         die;
     }
     check_ajax_referer('woocommerce_gerencianet_transparent_checkout', 'security');
     $method = $_POST['method'];
     $order_id = (int) $_POST['order_id'];
     $order = new WC_Order($order_id);
     if (function_exists('WC')) {
         $mailer = WC()->mailer();
     } else {
         global $woocommerce;
         $mailer = $woocommerce->mailer();
     }
     if ('cartao-credito' == $method) {
         // Add payment information.
         $status = esc_attr(WC_gerencianet_Messages::translate_status($_POST['status']));
         update_post_meta($order_id, 'woocommerce_gerencianet_method', esc_attr($_POST['method']));
         update_post_meta($order_id, 'woocommerce_gerencianet_code', esc_attr($_POST['code']));
         update_post_meta($order_id, 'woocommerce_gerencianet_status', $status);
         // Send email with payment information.
         $message_body = '<p>';
         $message_body .= WC_gerencianet_Messages::credit_cart_message($status, $_POST['code']);
         $message_body .= '</p>';
         $message = $mailer->wrap_message(sprintf(__('Order %s received', 'woo-gerencianet'), $order->get_order_number()), apply_filters('woocommerce_gerencianet_thankyou_creditcard_email_message', $message_body, $order_id));
         $mailer->send($order->billing_email, sprintf(__('Order %s received', 'woo-gerencianet'), $order->get_order_number()), $message);
     } else {
         // Add payment information.
         update_post_meta($order_id, 'woocommerce_gerencianet_method', esc_attr($_POST['method']));
         update_post_meta($order_id, 'woocommerce_gerencianet_url', esc_url($_POST['url']));
         // Send email with payment information.
         $url = sprintf('<p><a class="button" href="%1$s" target="_blank">%1$s</a></p>', esc_url($_POST['url']));
         $message_body = '<p>';
         $message_body .= WC_gerencianet_Messages::billet_email_message();
         $message_body .= '</p>';
         $message = $mailer->wrap_message(sprintf(__('Order %s received', 'woo-gerencianet'), $order->get_order_number()), apply_filters('woocommerce_gerencianet_thankyou_billet_email_message', $message_body, $order_id) . $url);
         $mailer->send($order->billing_email, sprintf(__('Order %s received', 'woo-gerencianet'), $order->get_order_number()), $message);
     }
     die;
 }
 /**
  * Transparent checkout custom Thank You message.
  *
  * @return void
  */
 public function transparent_checkout_thankyou_page()
 {
     $order_id = woocommerce_get_order_id_by_order_key(esc_attr($_GET['key']));
     $method = get_post_meta($order_id, 'woocommerce_gerencianet_method', true);
     switch ($method) {
         case 'cartao-credito':
             $html = '<div class="woocommerce-message">';
             $message = WC_gerencianet_Messages::credit_cart_message(get_post_meta($order_id, 'woocommerce_gerencianet_status', true), get_post_meta($order_id, 'woocommerce_gerencianet_code', true));
             $html .= apply_filters('woocommerce_gerencianet_thankyou_creditcard_message', $message, $order_id);
             $html .= '</div>';
             break;
         case 'boleto':
             $html = '<div class="woocommerce-message">';
             $html .= sprintf('<a class="button" href="%s" target="_blank">%s</a>', get_post_meta($order_id, 'woocommerce_gerencianet_url', true), __('Print the billet &rarr;', 'woo-gerencianet'));
             $message = WC_gerencianet_Messages::billet_message();
             $html .= apply_filters('woocommerce_gerencianet_thankyou_billet_message', $message, $order_id);
             $html .= '</div>';
             break;
         default:
             $html = '';
             break;
     }
     echo $html;
 }