/**
  *    get_payment_details
  *
  * @access    public
  * @param    array $payments
  * @return    string
  */
 public function get_payment_details($payments = array())
 {
     //prepare variables for displaying
     $template_args = array();
     $template_args['transaction'] = $this->_current_txn;
     $template_args['reg_url_link'] = $this->_reg_url_link;
     $template_args['payments'] = array();
     foreach ($payments as $payment) {
         $template_args['payments'][] = $this->get_payment_row_html($payment);
     }
     //create a hacky payment object, but dont save it
     $payment = EE_Payment::new_instance(array('TXN_ID' => $this->_current_txn->ID(), 'STS_ID' => EEM_Payment::status_id_pending, 'PAY_timestamp' => time(), 'PAY_amount' => $this->_current_txn->total(), 'PMD_ID' => $this->_current_txn->payment_method_ID()));
     $payment_method = $this->_current_txn->payment_method();
     if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) {
         $template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment);
     } else {
         $template_args['gateway_content'] = '';
     }
     // link to SPCO payment_options
     $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link;
     $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url;
     // verify template arguments
     EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
     EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments');
     EEH_Template_Validator::verify_isnt_null($template_args['show_try_pay_again_link'], '$show_try_pay_again_link');
     EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content');
     EEH_Template_Validator::verify_isnt_null($template_args['SPCO_payment_options_url'], '$SPCO_payment_options_url');
     return EEH_Template::locate_template(THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php', $template_args, TRUE, TRUE);
 }
 /**
  * Saves the billing info onto the attendee of the primary registrant on this transaction, and
  * cleans it first.
  * @param EE_Billing_Attendee_Info_Form $billing_form
  * @param EE_Transaction $transaction
  * @return boolean success
  */
 protected function _save_billing_info_to_attendee($billing_form, $transaction)
 {
     if (!$transaction || !$transaction instanceof EE_Transaction) {
         EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
         return false;
     }
     $primary_reg = $transaction->primary_registration();
     if (!$primary_reg) {
         EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
         return false;
     }
     $attendee = $primary_reg->attendee();
     if (!$attendee) {
         EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
         return false;
     }
     return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
 }
 /**
  * 	_transaction_details
  * generates HTML for the View Transaction Details Admin page
  *
  * @access protected
  *	@return void
  */
 protected function _transaction_details()
 {
     do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
     EE_Registry::instance()->load_helper('MSG_Template');
     $this->_set_transaction_status_array();
     $this->_template_args = array();
     $this->_template_args['transactions_page'] = $this->_wp_page_slug;
     $this->_set_transaction_object();
     $primary_registration = $this->_transaction->primary_registration();
     $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : NULL;
     $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
     $this->_template_args['txn_nmbr']['label'] = __('Transaction Number', 'event_espresso');
     $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_datetime('TXN_timestamp', 'l F j, Y', 'g:i:s a');
     $this->_template_args['txn_datetime']['label'] = __('Date', 'event_espresso');
     $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
     $this->_template_args['txn_status']['label'] = __('Transaction Status', 'event_espresso');
     $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
     $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
     $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid');
     if ($attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_transactions_send_payment_reminder')) {
         EE_Registry::instance()->load_helper('MSG_Template');
         $this->_template_args['send_payment_reminder_button'] = EEH_MSG_Template::is_mt_active('payment_reminder') && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code ? EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'send_payment_reminder', 'TXN_ID' => $this->_transaction->ID(), 'redirect_to' => 'view_transaction'), TXN_ADMIN_URL), __(' Send Payment Reminder'), 'button secondary-button right', 'dashicons dashicons-email-alt') : '';
     } else {
         $this->_template_args['send_payment_reminder_button'] = '';
     }
     $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
     $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, TRUE);
     if (EE_Registry::instance()->CFG->currency->sign_b4) {
         $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due'];
     } else {
         $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign;
     }
     $this->_template_args['amount_due_class'] = '';
     if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
         // paid in full
         $this->_template_args['amount_due'] = FALSE;
     } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
         // overpaid
         $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') > 0 && $this->_transaction->get('TXN_paid') > 0) {
         // monies owing
         $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') > 0 && $this->_transaction->get('TXN_paid') == 0) {
         // no payments made yet
         $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') == 0) {
         // free event
         $this->_template_args['amount_due'] = FALSE;
     }
     $payment_method = $this->_transaction->payment_method();
     $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() : __('Unknown', 'event_espresso');
     $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
     // link back to overview
     $this->_template_args['txn_overview_url'] = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : TXN_ADMIN_URL;
     //next and previous links
     $next_txn = $this->_transaction->next(null, array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), 'TXN_ID');
     $this->_template_args['next_transaction'] = $next_txn ? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), TXN_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : '';
     $previous_txn = $this->_transaction->previous(null, array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), 'TXN_ID');
     $this->_template_args['previous_transaction'] = $previous_txn ? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), TXN_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : '';
     // grab messages at the last second
     $this->_template_args['notices'] = EE_Error::get_notices();
     // path to template
     $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
     $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, $this->_template_args, TRUE);
     // the details template wrapper
     $this->display_admin_page_with_sidebar();
 }
 /**
  * 	column_TXN_paid
  * @param \EE_Transaction $item
  * @return mixed|string
  */
 function column_TXN_paid(EE_Transaction $item)
 {
     $transaction_total = $item->get('TXN_total');
     $transaction_paid = $item->get('TXN_paid');
     if ($transaction_total > 0 && $transaction_paid >= $transaction_total) {
         // paid in full
         $span_class = 'txn-overview-full-payment-spn';
     } elseif ($transaction_total > 0 && $transaction_paid > 0) {
         // monies owing
         $span_class = 'txn-overview-part-payment-spn';
     } elseif ($transaction_total > 0 && $transaction_paid == 0) {
         // no payments made
         $span_class = 'txn-overview-no-payment-spn';
     } else {
         $span_class = 'txn-overview-free-event-spn';
         $transaction_paid = 0;
     }
     $payment_method = $item->payment_method();
     $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() : __('Unknown', 'event_espresso');
     $content = '<span class="' . $span_class . ' txn-pad-rght">' . $transaction_paid !== 0 ? $item->get_pretty('TXN_paid') : $transaction_paid . '</span>';
     if ($transaction_paid > 0) {
         $content .= '<br><span class="ee-status-text-small">' . sprintf(__('...via %s', 'event_espresso'), $payment_method_name) . '</span>';
     }
     return $content;
 }
 /**
  * 	_transaction_details
  * generates HTML for the View Transaction Details Admin page
  *
  * @access protected
  *	@return void
  */
 protected function _transaction_details()
 {
     do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
     $this->_set_transaction_status_array();
     $this->_template_args = array();
     $this->_template_args['transactions_page'] = $this->_wp_page_slug;
     $this->_set_transaction_object();
     $primary_registration = $this->_transaction->primary_registration();
     $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : NULL;
     $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
     $this->_template_args['txn_nmbr']['label'] = __('Transaction Number', 'event_espresso');
     $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
     $this->_template_args['txn_datetime']['label'] = __('Date', 'event_espresso');
     $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
     $this->_template_args['txn_status']['label'] = __('Transaction Status', 'event_espresso');
     $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
     $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
     $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid');
     if ($attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_transactions_send_payment_reminder')) {
         $this->_template_args['send_payment_reminder_button'] = EEH_MSG_Template::is_mt_active('payment_reminder') && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code ? EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'send_payment_reminder', 'TXN_ID' => $this->_transaction->ID(), 'redirect_to' => 'view_transaction'), TXN_ADMIN_URL), __(' Send Payment Reminder', 'event_espresso'), 'button secondary-button right', 'dashicons dashicons-email-alt') : '';
     } else {
         $this->_template_args['send_payment_reminder_button'] = '';
     }
     $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
     $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, TRUE);
     if (EE_Registry::instance()->CFG->currency->sign_b4) {
         $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due'];
     } else {
         $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign;
     }
     $this->_template_args['amount_due_class'] = '';
     if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
         // paid in full
         $this->_template_args['amount_due'] = FALSE;
     } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
         // overpaid
         $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') > 0 && $this->_transaction->get('TXN_paid') > 0) {
         // monies owing
         $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') > 0 && $this->_transaction->get('TXN_paid') == 0) {
         // no payments made yet
         $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') == 0) {
         // free event
         $this->_template_args['amount_due'] = FALSE;
     }
     $payment_method = $this->_transaction->payment_method();
     $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() : __('Unknown', 'event_espresso');
     $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
     // link back to overview
     $this->_template_args['txn_overview_url'] = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : TXN_ADMIN_URL;
     // next link
     $next_txn = $this->_transaction->next(null, array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), 'TXN_ID');
     $this->_template_args['next_transaction'] = $next_txn ? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), TXN_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : '';
     // previous link
     $previous_txn = $this->_transaction->previous(null, array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), 'TXN_ID');
     $this->_template_args['previous_transaction'] = $previous_txn ? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), TXN_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : '';
     // were we just redirected here after adding a new registration ???
     if (isset($this->_req_data['redirect_from'], $this->_req_data['EVT_ID'], $this->_req_data['event_name'])) {
         if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations', 'espresso_registrations_new_registration', $this->_req_data['EVT_ID'])) {
             $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
             $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_registrations', 'action' => 'new_registration', 'return' => 'default', 'TXN_ID' => $this->_transaction->ID(), 'event_id' => $this->_req_data['EVT_ID']), REG_ADMIN_URL);
             $this->_admin_page_title .= '">';
             $this->_admin_page_title .= sprintf(__('Add Another New Registration to Event: "%1$s" ?'), htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8'));
             $this->_admin_page_title .= '</a>';
         }
         EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
     }
     // grab messages at the last second
     $this->_template_args['notices'] = EE_Error::get_notices();
     // path to template
     $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
     $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, $this->_template_args, TRUE);
     // the details template wrapper
     $this->display_admin_page_with_sidebar();
 }