public function __construct($url_link = 0)
 {
     if ($this->registration = EE_Registry::instance()->load_model('Registration')->get_registration_for_reg_url_link($url_link)) {
         $this->transaction = $this->registration->transaction();
         $payment_settings = EE_Config::instance()->gateway->payment_settings;
         //get_user_meta(EE_Registry::instance()->CFG->wp_user, 'payment_settings', TRUE);
         $this->invoice_payment_method = EEM_Payment_Method::instance()->get_one_of_type('Invoice');
     } else {
         EE_Error::add_error(__('Your request appears to be missing some required data, and no information for your transaction could be retrieved.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
     }
 }
 protected function _get_data_for_context($context, EE_Registration $registration, $id)
 {
     //receipt message type data handler is 'Gateways' and it expects a transaction object.
     $transaction = $registration->transaction();
     if ($transaction instanceof EE_Transaction) {
         return array($transaction);
     }
     return array();
 }
 protected function _get_data_for_context($context, EE_Registration $registration, $id)
 {
     //use the registration to get the transaction.
     $transaction = $registration->transaction();
     //bail early if no transaction
     if (!$transaction instanceof EE_Transaction) {
         throw new EE_Error(__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
     }
     $payment = !empty($id) ? EEM_Payment::instance()->get_one(array(array('PAY_ID' => $id, 'TXN_ID' => $transaction->ID()))) : 0;
     return array($transaction, $payment);
 }
    /**
     * 		REG_date
     */
    function column_REG_date(EE_Registration $item)
    {
        //Build row actions
        $actions = array();
        //Build row actions
        $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'event_registrations', 'event_id' => $item->event_ID()), REG_ADMIN_URL);
        $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can('ee_read_checkin', 'espresso_registrations_registration_checkins', $item->ID()) ? '
			<a href="' . $check_in_url . '" title="' . esc_attr__('The Check-In List allows you to easily toggle check-in status for this event', 'event_espresso') . '">' . __('View Check-ins', 'event_espresso') . '</a>' : __('View Check-ins', 'event_espresso');
        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $item->transaction()->ID()), TXN_ADMIN_URL);
        $REG_date = EE_Regisry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction') ? '<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Transaction Details', 'event_espresso') . '">' . $item->get_i18n_datetime('REG_date') . '</a>' : $item->get_i18n_datetime('REG_date');
        return sprintf('%1$s %2$s', $REG_date, $this->row_actions($actions));
    }
 /**
  * 		generates HTML for the Registration main meta box
  *		@access public
  *		@return void
  */
 public function _reg_details_meta_box()
 {
     EEH_Autoloader::register_line_item_display_autoloaders();
     EEH_Autoloader::register_line_item_filter_autoloaders();
     EE_Registry::instance()->load_Helper('Line_Item');
     $transaction = $this->_registration->transaction() ? $this->_registration->transaction() : EE_Transaction::new_instance();
     $this->_session = $transaction->session_data();
     $filters = new EE_Line_Item_Filter_Collection();
     $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
     $filters->add(new EE_Non_Zero_Line_Item_Filter());
     $line_item_filter_processor = new EE_Line_Item_Filter_Processor($filters, $transaction->total_line_item());
     $filtered_line_item_tree = $line_item_filter_processor->process();
     $this->_template_args['REG_ID'] = $this->_registration->ID();
     $line_item_display = new EE_Line_Item_Display('reg_admin_table', 'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
     $this->_template_args['line_item_table'] = $line_item_display->display_line_item($filtered_line_item_tree, array('EE_Registration' => $this->_registration));
     $attendee = $this->_registration->attendee();
     $this->_template_args['view_transaction_button'] = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction') ? EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $transaction->ID()), TXN_ADMIN_URL), __(' View Transaction'), 'button secondary-button right', 'dashicons dashicons-cart') : '';
     $this->_template_args['resend_registration_button'] = $attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_registrations_resend_registration') ? EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'resend_registration', '_REG_ID' => $this->_registration->ID(), 'redirect_to' => 'view_registration'), REG_ADMIN_URL), __(' Resend Registration'), 'button secondary-button right', 'dashicons dashicons-email-alt') : '';
     $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
     $payment = $transaction->get_first_related('Payment');
     $payment = !$payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment;
     $payment_method = $payment->get_first_related('Payment_Method');
     $payment_method = !$payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance() : $payment_method;
     $reg_status_class = 'status-' . $this->_registration->status_ID();
     $reg_details = array('payment_method' => $payment_method->name(), 'response_msg' => $payment->gateway_response(), 'registration_id' => $this->_registration->get('REG_code'), 'registration_session' => $this->_registration->session_ID(), 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '');
     if (isset($reg_details['registration_id'])) {
         $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
         $this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso');
         $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
     }
     if (isset($reg_details['payment_method'])) {
         $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
         $this->_template_args['reg_details']['payment_method']['label'] = __('Most Recent Payment Method', 'event_espresso');
         $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
         $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
         $this->_template_args['reg_details']['response_msg']['label'] = __('Payment method response', 'event_espresso');
         $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
     }
     $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
     $this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session', 'event_espresso');
     $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
     $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
     $this->_template_args['reg_details']['ip_address']['label'] = __('Registration placed from IP', 'event_espresso');
     $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
     $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
     $this->_template_args['reg_details']['user_agent']['label'] = __('Registrant User Agent', 'event_espresso');
     $this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
     $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'default', 'event_id' => $this->_registration->event_ID()), REG_ADMIN_URL);
     $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
     echo EEH_Template::display_template($template_path, $this->_template_args, TRUE);
 }
 /**
  * 		generates HTML for the Registration main meta box
  *		@access public
  *		@return void
  */
 public function _reg_details_meta_box()
 {
     $transaction = $this->_registration->transaction() ? $this->_registration->transaction() : EE_Transaction::new_instance();
     $this->_template_args['line_items'] = $transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item')));
     // process taxes
     if ($transaction) {
         //get all "tax" line items for this transaction and we'll use them for the tax display.
         $taxes = $transaction->get_many_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_tax)));
         $this->_template_args['taxes'] = !empty($taxes) ? $taxes : array();
     } else {
         $this->_template_args['taxes'] = array();
     }
     $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $transaction->ID()), TXN_ADMIN_URL), __(' View Transaction'), 'button secondary-button right', 'dashicons dashicons-cart');
     $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'resend_registration', '_REG_ID' => $this->_registration->ID(), 'redirect_to' => 'view_registration'), REG_ADMIN_URL), __(' Resend Registration'), 'button secondary-button right', 'dashicons dashicons-email-alt');
     $this->_template_args['grand_total'] = EEH_Template::format_currency($transaction->total());
     $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
     $reg_status_class = 'status-' . $this->_registration->status_ID();
     $payment = $transaction->get_first_related('Payment');
     $reg_details = !empty($payment) ? maybe_unserialize($payment->details()) : NULL;
     //REG_ID will NOT be retrieved from $payment!
     $reg_details['registration_id'] = $this->_registration->get('REG_code');
     if (!is_array($reg_details) || is_array($reg_details) && isset($reg_details['REDO_TXN']) && $reg_details['REDO_TXN']) {
         $reg_details = array();
         $reg_details['method'] = '';
         $reg_details['response_msg'] = '';
         $reg_details['invoice_number'] = '';
     }
     $card_type = isset($reg_details['card_type']) ? ' : ' . $reg_details['card_type'] : '';
     if (isset($reg_details['registration_id'])) {
         $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
         $this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso');
         $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
     }
     if (isset($reg_details['invoice_number'])) {
         $this->_template_args['reg_details']['invoice_number']['value'] = isset($reg_details['invoice_number']) ? $reg_details['invoice_number'] : '';
         $this->_template_args['reg_details']['invoice_number']['label'] = __('Invoice Number', 'event_espresso');
         $this->_template_args['reg_details']['invoice_number']['class'] = 'regular-text';
     }
     $this->_template_args['reg_details']['registration_session']['value'] = $this->_registration->session_ID();
     $this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session', 'event_espresso');
     $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
     $this->_template_args['reg_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '';
     $this->_template_args['reg_details']['ip_address']['label'] = __('Registration placed from IP', 'event_espresso');
     $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
     $this->_template_args['reg_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '';
     $this->_template_args['reg_details']['user_agent']['label'] = __('Registrant User Agent', 'event_espresso');
     $this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
     $this->_template_args['full_session'] = $this->_session;
     $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
     echo EEH_Template::display_template($template_path, $this->_template_args, TRUE);
 }
 /**
  * 		generates HTML for the Registration main meta box
  *		@access public
  *		@return void
  */
 public function _reg_details_meta_box()
 {
     $transaction = $this->_registration->transaction() ? $this->_registration->transaction() : EE_Transaction::new_instance();
     $this->_session = $transaction->session_data();
     $this->_template_args['REG_ID'] = $this->_registration->ID();
     $this->_template_args['line_items'] = $transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item')));
     $attendee = $this->_registration->attendee();
     // process taxes
     if ($transaction) {
         //get all "tax" line items for this transaction and we'll use them for the tax display.
         $taxes = $transaction->get_many_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_tax)));
         $this->_template_args['taxes'] = !empty($taxes) ? $taxes : array();
     } else {
         $this->_template_args['taxes'] = array();
     }
     $this->_template_args['view_transaction_button'] = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction') ? EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $transaction->ID()), TXN_ADMIN_URL), __(' View Transaction'), 'button secondary-button right', 'dashicons dashicons-cart') : '';
     $this->_template_args['resend_registration_button'] = $attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_registrations_resend_registration') ? EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'resend_registration', '_REG_ID' => $this->_registration->ID(), 'redirect_to' => 'view_registration'), REG_ADMIN_URL), __(' Resend Registration'), 'button secondary-button right', 'dashicons dashicons-email-alt') : '';
     $this->_template_args['grand_total'] = EEH_Template::format_currency($transaction->total());
     $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
     $payment = $transaction->get_first_related('Payment');
     $payment = !$payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment;
     $payment_method = $payment->get_first_related('Payment_Method');
     $payment_method = !$payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance() : $payment_method;
     $reg_status_class = 'status-' . $this->_registration->status_ID();
     $reg_details = array('payment_method' => $payment_method->name(), 'response_msg' => $payment->gateway_response(), 'registration_id' => $this->_registration->get('REG_code'), 'registration_session' => $this->_registration->session_ID(), 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '');
     if (isset($reg_details['registration_id'])) {
         $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
         $this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso');
         $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
     }
     if (isset($reg_details['payment_method'])) {
         $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
         $this->_template_args['reg_details']['payment_method']['label'] = __('Most Recent Payment Method', 'event_espresso');
         $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
         $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
         $this->_template_args['reg_details']['response_msg']['label'] = __('Payment method response', 'event_espresso');
         $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
     }
     $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
     $this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session', 'event_espresso');
     $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
     $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
     $this->_template_args['reg_details']['ip_address']['label'] = __('Registration placed from IP', 'event_espresso');
     $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
     $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
     $this->_template_args['reg_details']['user_agent']['label'] = __('Registrant User Agent', 'event_espresso');
     $this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
     $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'default', 'event_id' => $this->_registration->event_ID()), REG_ADMIN_URL);
     $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
     echo EEH_Template::display_template($template_path, $this->_template_args, TRUE);
 }
 /**
  * 		column_TXN_total
  */
 function column_TXN_total(EE_Registration $item)
 {
     $txn = $item->transaction();
     $view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL);
     if ($item->get('REG_count') == 1) {
         $line_total_obj = $txn->total_line_item();
         $txn_total = $line_total_obj instanceof EE_Line_Item ? $line_total_obj->get_pretty('LIN_total') : __('View Transaction', 'event_espresso');
         return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction') ? '<a href="' . $view_txn_url . '" title="' . esc_attr__('View Transaction', 'event_espresso') . '"><span class="reg-pad-rght">' . $txn_total . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
     } else {
         return '<span class="reg-pad-rght"></span>';
     }
 }
 /**
  * column_TXN_paid
  *
  * @access public
  * @param \EE_Registration $item
  * @return string
  */
 function column_TXN_paid(EE_Registration $item)
 {
     if ($item->count() == 1) {
         $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance();
         if ($transaction->paid() >= $transaction->total()) {
             return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
         } else {
             $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()), TXN_ADMIN_URL);
             return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction', $item->transaction_ID()) ? '<span class="reg-pad-rght"><a class="status-' . $transaction->status_ID() . '" href="' . $view_txn_lnk_url . '"  title="' . esc_attr__('View Transaction', 'event_espresso') . '">' . $item->transaction()->pretty_paid() . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
         }
     }
     return '&nbsp;';
 }
 /**
  *    registration_status_changed
  *
  * @access public
  * @param EE_Registration $registration
  * @param array 	$additional_details
  * @return void
  */
 public function trigger_registration_update_notifications($registration, $additional_details = array())
 {
     try {
         if (!$registration instanceof EE_Registration) {
             throw new EE_Error(__('An invalid registration was received.', 'event_espresso'));
         }
         EE_Registry::instance()->load_helper('Debug_Tools');
         EEH_Debug_Tools::log(__CLASS__, __FUNCTION__, __LINE__, array($registration->transaction(), $additional_details), false, 'EE_Transaction: ' . $registration->transaction()->ID());
         do_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', $registration, $additional_details);
     } catch (Exception $e) {
         EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
     }
 }
 /**
  *   toggle_registration_status_if_no_monies_owing
  * determine whether to toggle free tickets to "Approved" based on payment status (kinda sorta) of other tickets for
  * the same event. So if more than one ticket for the same event is in the cart, and one or more tickets are NOT
  * free, then free tickets will NOT be automatically toggled to "Approved"
  *
  * @access public
  * @param bool $toggle_registration_status
  * @param \EE_Registration $registration
  * @return bool
  */
 public static function toggle_registration_status_if_no_monies_owing($toggle_registration_status = false, EE_Registration $registration)
 {
     $reg_tickets = array();
     if ($registration instanceof EE_Registration && $registration->transaction() instanceof EE_Transaction) {
         // now we need to get an accurate count of registration tickets
         foreach ($registration->transaction()->registrations() as $reg) {
             if ($reg instanceof EE_Registration) {
                 if ($reg->event() instanceof EE_Event && $reg->ticket() instanceof EE_Ticket) {
                     $reg_tickets[$reg->event()->ID()][$reg->ticket()->ID()] = $reg->ticket()->is_free();
                 }
             }
         }
     }
     if ($registration->ticket() instanceof EE_Ticket && $registration->ticket()->is_free()) {
         $toggle_registration_status = true;
         if ($registration->event() instanceof EE_Event && isset($reg_tickets[$registration->event()->ID()])) {
             foreach ($reg_tickets[$registration->event()->ID()] as $free_ticket) {
                 $toggle_registration_status = $free_ticket ? $toggle_registration_status : false;
             }
         }
     }
     return $toggle_registration_status;
 }
 /**
  *    registration_status_changed
  *
  * @access public
  * @param EE_Registration $registration
  * @param array 	$additional_details
  * @return void
  */
 public function trigger_registration_update_notifications(EE_Registration $registration, $additional_details = array())
 {
     try {
         //do_action(
         //	'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
         //	$registration,
         //	apply_filters(
         //		'FHEE__EE_Registration_Processor__trigger_registration_update_notifications__additional_conditions',
         //		array_merge(
         //		// defaults
         //			array(
         //				'checkout_or_payment' => false,
         //				'manually_updated' 		=> false,
         //				'payment_updates' 		=> false,
         //				//'status_updates' 			=> $this->reg_status_updated( $registration->ID() ),
         //				'finalized' 						=> false,
         //				'revisit' 							=> false,
         //				'reg_steps' 						=> $registration->transaction()->reg_steps(),
         //				'txn_status' 						=> $registration->transaction()->status_ID(),
         //				'last_payment'				=> null,
         //				'old_reg_status' 				=> $this->old_reg_status( $registration->ID() ),
         //				'new_reg_status' 			=> $this->new_reg_status( $registration->ID() )
         //			),
         //			$additional_details
         //		)
         //	)
         //);
         EE_Registry::instance()->load_helper('Debug_Tools');
         EEH_Debug_Tools::log(__CLASS__, __FUNCTION__, __LINE__, array($registration->transaction(), $additional_details), false, 'EE_Transaction: ' . $registration->transaction()->ID());
         do_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', $registration, $additional_details);
     } catch (Exception $e) {
         EE_Error::add_error($e->getMessage(), $e->getFile(), 'function_added_from_exception', $e->getLine());
     }
 }
 /**
  * set_transaction_payment_method_based_on_registration_statuses
  *
  * sets or unsets the PMD_ID field on the TXN based on the related REG statuses
  * basically if ALL Registrations are "Not Approved", then the EE_Transaction.PMD_ID is set to null,
  * but if any Registration has a different status, then EE_Transaction.PMD_ID is set to either:
  * 		the first "default" Payment Method
  * 		the first active Payment Method
  * 	whichever is found first.
  *
  * @param  EE_Registration $edited_registration
  * @return void
  */
 public function set_transaction_payment_method_based_on_registration_statuses(EE_Registration $edited_registration)
 {
     if ($edited_registration instanceof EE_Registration) {
         $transaction = $edited_registration->transaction();
         if ($transaction instanceof EE_Transaction) {
             $all_not_approved = true;
             foreach ($transaction->registrations() as $registration) {
                 if ($registration instanceof EE_Registration) {
                     // if any REG != "Not Approved" then toggle to false
                     $all_not_approved = $registration->is_not_approved() ? $all_not_approved : false;
                 }
             }
             // if ALL Registrations are "Not Approved"
             if ($all_not_approved) {
                 $transaction->set_payment_method_ID(null);
                 $transaction->save();
             } else {
                 $available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction($transaction, EEM_Payment_Method::scope_cart);
                 if (!empty($available_payment_methods)) {
                     $PMD_ID = 0;
                     foreach ($available_payment_methods as $available_payment_method) {
                         if ($available_payment_method instanceof EE_Payment_Method && $available_payment_method->open_by_default()) {
                             $PMD_ID = $available_payment_method->ID();
                             break;
                         }
                     }
                     if (!$PMD_ID) {
                         $first_payment_method = reset($available_payment_methods);
                         if ($first_payment_method instanceof EE_Payment_Method) {
                             $PMD_ID = $first_payment_method->ID();
                         } else {
                             EE_Error::add_error(__('A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', 'event_espresso'), __FILE__, __LINE__, __FUNCTION__);
                         }
                     }
                     $transaction->set_payment_method_ID($PMD_ID);
                     $transaction->save();
                 } else {
                     EE_Error::add_error(__('Please activate at least one Payment Method in order for things to operate correctly.', 'event_espresso'), __FILE__, __LINE__, __FUNCTION__);
                 }
             }
         }
     }
 }