/**
  *	get_cart_from_reg_url_link
  *	@access public
  *	@return class instance
  */
 public static function get_cart_from_txn(EE_Transaction $transaction)
 {
     $grand_total = $transaction->total_line_item();
     $grand_total->get_items();
     $grand_total->tax_descendants();
     return EE_Cart::instance($grand_total);
 }
 /**
  * Updates the transaction in the session to acknowledge the registrant is done
  * the registration process, all that remains is for them ot make the offline
  * payment. Was renamed from 'set_transaction_details' to 'thank_you_page()', because it served the same purpose
  * as it's parent's 'thank_you_page()', which is to update the transaction (but not the payment
  * because in this case no payment has been made)
  * @global type $EE_Session
  * @param EE_Transaction
  * @return void
  */
 public function thank_you_page_logic(EE_Transaction $transaction)
 {
     do_action('AHEE_log', __FILE__, __FUNCTION__, '');
     //check for an existing payment from this gateway
     $payments = $this->_PAY->get_all(array(array('PAY_gateway' => $this->gateway(), 'TXN_ID' => $transaction->ID())));
     //if it already exists, short-circuit updating the transaction
     if (empty($payments)) {
         $this->update_transaction_with_payment($transaction, null);
         $transaction->save();
     }
     //createa hackey payment object, but dont save it
     $payment = EE_Payment::new_instance(array('TXN_ID' => $transaction->ID(), 'STS_ID' => EEM_Payment::status_id_pending, 'PAY_timestamp' => current_time('timestamp'), 'PAY_amount' => $transaction->total(), 'PAY_gateway' => $this->_gateway_name));
     do_action('AHEE_EE_Gateway__update_transaction_with_payment__done', $transaction, $payment);
     parent::thank_you_page_logic($transaction);
 }
 /**
  * debug
  *
  * @param string $class
  * @param string $func
  * @param string $line
  * @param \EE_Transaction $transaction
  * @param array $info
  * @param bool $display_request
  */
 protected function log($class = '', $func = '', $line = '', EE_Transaction $transaction, $info = array(), $display_request = false)
 {
     if (WP_DEBUG && false) {
         if ($transaction instanceof EE_Transaction) {
             // don't serialize objects
             $info = EEH_Debug_Tools::strip_objects($info);
             if ($transaction->ID()) {
                 $info['TXN_status'] = $transaction->status_ID();
                 $info['TXN_reg_steps'] = $transaction->reg_steps();
                 $index = 'EE_Transaction: ' . $transaction->ID();
                 EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
             }
         }
     }
 }
 /**
  * generate_ONE_registration_from_line_item
  *
  * Although a ticket line item may have a quantity greater than 1,
  * this method will ONLY CREATE ONE REGISTRATION !!!
  * Regardless of the ticket line item quantity.
  * This means that any code calling this method is responsible for ensuring
  * that the final registration count matches the ticket line item quantity.
  * This was done to make it easier to match the number of registrations
  * to the number of tickets in the cart, when the cart has been edited
  * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass
  * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets.
  *
  * @param EE_Line_Item $line_item
  * @param \EE_Transaction $transaction
  * @param int $att_nmbr
  * @param int $total_ticket_count
  * @return \EE_Registration | null
  * @throws \EE_Error
  */
 public function generate_ONE_registration_from_line_item(EE_Line_Item $line_item, EE_Transaction $transaction, $att_nmbr = 1, $total_ticket_count = 1)
 {
     // grab the related ticket object for this line_item
     $ticket = $line_item->ticket();
     if (!$ticket instanceof EE_Ticket) {
         EE_Error::add_error(sprintf(__("Line item %s did not contain a valid ticket", "event_espresso"), $line_item->ID()), __FILE__, __FUNCTION__, __LINE__);
         return null;
     }
     $first_datetime = $ticket->get_first_related('Datetime');
     if (!$first_datetime instanceof EE_Datetime) {
         EE_Error::add_error(sprintf(__("The ticket (%s) is not associated with any valid datetimes.", "event_espresso"), $ticket->name()), __FILE__, __FUNCTION__, __LINE__);
         return null;
     }
     $event = $first_datetime->get_first_related('Event');
     if (!$event instanceof EE_Event) {
         EE_Error::add_error(sprintf(__("The ticket (%s) is not associated with a valid event.", "event_espresso"), $ticket->name()), __FILE__, __FUNCTION__, __LINE__);
         return null;
     }
     $reg_url_link = $this->generate_reg_url_link($att_nmbr, $line_item);
     // now create a new registration for the ticket
     $registration = EE_Registration::new_instance(array('EVT_ID' => $event->ID(), 'TXN_ID' => $transaction->ID(), 'TKT_ID' => $ticket->ID(), 'STS_ID' => EEM_Registration::status_id_incomplete, 'REG_date' => $transaction->datetime(), 'REG_final_price' => $ticket->get_ticket_total_with_taxes(), 'REG_session' => EE_Registry::instance()->SSN->id(), 'REG_count' => $att_nmbr, 'REG_group_size' => $total_ticket_count, 'REG_url_link' => $reg_url_link));
     $registration->set_reg_code($this->generate_reg_code($registration));
     $registration->save();
     $registration->_add_relation_to($event, 'Event', array(), $event->ID());
     $registration->_add_relation_to($line_item->ticket(), 'Ticket', array(), $line_item->ticket()->ID());
     $transaction->_add_relation_to($registration, 'Registration');
     return $registration;
 }
 function espresso_replace_invoice_shortcodes($content)
 {
     $EE = EE_Registry::instance();
     //Create the logo
     if (!empty($this->invoice_settings['invoice_logo_url'])) {
         $invoice_logo_url = $this->invoice_settings['invoice_logo_url'];
     } else {
         $invoice_logo_url = $EE->CFG->organization->logo_url;
     }
     if (!empty($invoice_logo_url)) {
         $image_size = getimagesize($invoice_logo_url);
         $invoice_logo_image = '<img class="logo screen" src="' . $invoice_logo_url . '" ' . $image_size[3] . ' alt="logo" /> ';
     } else {
         $invoice_logo_image = '';
     }
     $SearchValues = array("[organization]", "[registration_code]", "[transaction_id]", "[name]", "[base_url]", "[download_link]", "[invoice_logo_image]", "[street]", "[city]", "[state]", "[zip]", "[email]", "[vat]", "[registration_date]", "[instructions]");
     $primary_attendee = $this->transaction->primary_registration()->attendee();
     $org_state = EE_Registry::instance()->load_model('State')->get_one_by_ID($EE->CFG->organization->STA_ID);
     if ($org_state) {
         $org_state_name = $org_state->name();
     } else {
         $org_state_name = '';
     }
     $ReplaceValues = array(stripslashes($EE->CFG->organization->name), $this->registration->reg_code(), $this->transaction->ID(), $primary_attendee->full_name(), is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice') ? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/' : EE_GATEWAYS_URL . 'Invoice/lib/templates/', $this->registration->invoice_url(), $invoice_logo_image, empty($EE->CFG->organization->address_2) ? $EE->CFG->organization->address_1 : $EE->CFG->organization->address_1 . '<br>' . $EE->CFG->organization->address_2, $EE->CFG->organization->city, $org_state_name, $EE->CFG->organization->zip, $EE->CFG->organization->email, $EE->CFG->organization->vat, date_i18n(get_option('date_format'), strtotime($this->registration->date())), $this->invoice_settings['pdf_instructions']);
     return str_replace($SearchValues, $ReplaceValues, $content);
 }
 /**
  * test_registration_payment_data_array
  * @since    4.8
  * @group    8620
  */
 public function test_registration_payment_data_array()
 {
     $this->_admin_page = new Transactions_Admin_Page_Mock();
     $this->_setup_standard_transaction_and_payment(40.0, 4, 25.0);
     $registrations = $this->_transaction->registrations();
     $this->_apply_payment_to_registrations($registrations);
     $registration_payment_data_array = $this->_admin_page->registration_payment_data_array(array_keys($registrations));
     // format the payment values
     EE_Registry::instance()->load_helper('Template');
     $ten_dollars = EEH_Template::format_currency(10.0);
     $five_dollars = EEH_Template::format_currency(5.0);
     $no_dollars = EEH_Template::format_currency(0.0);
     // reg # 1 paid $10, owes 0
     $registration_payment_data = reset($registration_payment_data_array);
     $this->assertEquals($ten_dollars, $registration_payment_data['paid']);
     $this->assertEquals($no_dollars, $registration_payment_data['owing']);
     // reg # 2 paid $10, owes 0
     $registration_payment_data = next($registration_payment_data_array);
     $this->assertEquals($ten_dollars, $registration_payment_data['paid']);
     $this->assertEquals($no_dollars, $registration_payment_data['owing']);
     // reg # 3 paid $5, owes $5
     $registration_payment_data = next($registration_payment_data_array);
     $this->assertEquals($five_dollars, $registration_payment_data['paid']);
     $this->assertEquals($five_dollars, $registration_payment_data['owing']);
     // reg # 4 paid $0, owes $10
     $registration_payment_data = next($registration_payment_data_array);
     $this->assertEquals($no_dollars, $registration_payment_data['paid']);
     $this->assertEquals($ten_dollars, $registration_payment_data['owing']);
 }
 function test_generate_code()
 {
     $t = EE_Transaction::new_instance();
     $t->save();
     $l = EE_Line_Item::new_instance(array('OBJ_type' => 'Transaction', 'OBJ_ID' => $t->ID()));
     $this->assertNotNull($l->generate_code());
 }
 /**
  *    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);
 }
 /**
  * 	process_shortcode - EES_Espresso_Txn_Page
  *
  *  @access 	public
  *  @param		array 	$attributes
  *  @return 	void
  */
 public function process_shortcode($attributes = array())
 {
     if ($this->_current_txn) {
         printf(__("IPN successfully received for Transaction with ID '%d'", "event_espresso"), $this->_current_txn->ID());
     } else {
         printf(__("No IPN (or incomplete IPN) received.", "event_espresso"));
     }
 }
 /**
  * Callback for transaction list table column action for new events column.
  *
  * @param EE_Transaction $transaction
  * @return string
  */
 public function transaction_list_table_events_column_content($transaction)
 {
     if (!$transaction instanceof EE_Transaction) {
         return;
     }
     //get event ids
     $registrations = $transaction->registrations();
     $event_IDs = array();
     foreach ($registrations as $registration) {
         if ($registration instanceof EE_Registration) {
             if ($registration->event_ID() && !in_array($registration->event_ID(), $event_IDs)) {
                 $event_IDs[] = $registration->event_ID();
             }
         }
     }
     if (!empty($event_IDs)) {
         $count = count($event_IDs);
         $event_IDs = implode(',', $event_IDs);
         $url = add_query_arg(array('EVT_IDs' => $event_IDs, 'TXN_ID' => $transaction->ID(), 'page' => 'espresso_events', 'action' => 'default'), admin_url('admin.php'));
         echo '<a href="' . $url . '">' . sprintf(_n('1 Event', '%d Events', $count, 'event_espresso'), $count) . '</a>';
     }
 }
 /**
  * Get items
  *
  * @see Pronamic_Pay_PaymentDataInterface::get_items()
  * @return Pronamic_IDeal_Items
  */
 public function get_items()
 {
     // Items
     $items = new Pronamic_IDeal_Items();
     // Item
     // We only add one total item, because iDEAL cant work with negative price items (discount)
     $item = new Pronamic_IDeal_Item();
     $item->setNumber($this->get_order_id());
     $item->setDescription($this->get_description());
     $item->setPrice($this->transaction->total());
     $item->setQuantity(1);
     $items->addItem($item);
     return $items;
 }
 /**
  * 	_process_finalize_registration
  *
  * 	@access private
  * 	@return 	void
  */
 private function _process_finalize_registration()
 {
     do_action('AHEE_log', __FILE__, __FUNCTION__, '');
     // save everything
     if ($this->_continue_reg && $this->_save_all_registration_information()) {
         //			echo '<h2 style="color:#E76700;">_process_finalize_registration<br/><span style="font-size:9px;font-weight:normal;color:#666">' . __FILE__ . '</span>    <b style="font-size:10px;color:#333">  ' . __LINE__ . ' </b></h2>';
         // save TXN data to the cart
         $this->_cart->get_grand_total()->save_this_and_descendants_to_txn($this->_transaction->ID());
         do_action('AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', $this->_transaction);
         // if Default REG Status is set to REQUIRES APPROVAL... then payments are NOT allowed
         if (EE_Registry::instance()->REQ->is_set('selected_gateway') && EE_Registry::instance()->REQ->get('selected_gateway') == 'payments_closed') {
             //				echo '<h2 style="color:#E76700;">payments_closed<br/><span style="font-size:9px;font-weight:normal;color:#666">' . __FILE__ . '</span>    <b style="font-size:10px;color:#333">  ' . __LINE__ . ' </b></h2>';
             // set TXN Status to Open
             $this->_transaction->set_status(EEM_Transaction::incomplete_status_code);
             $this->_transaction->save();
             $this->_transaction->finalize();
             $notices = EE_Error::get_notices(FALSE);
             $response = array('msg' => array('success' => isset($notices['success']) ? $notices['success'] : '', 'errors' => isset($notices['errors']) ? $notices['errors'] : ''));
             $this->_thank_you_page_url = add_query_arg(array('e_reg_url_link' => $this->_transaction->primary_registration()->reg_url_link()), get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
             // Default REG Status is set to PENDING PAYMENT OR APPROVED, and payments are allowed
         } else {
             // attempt to perform transaction via payment gateway
             $response = EE_Registry::instance()->load_model('Gateways')->process_payment_start($this->_cart->get_grand_total(), $this->_transaction);
             $this->_thank_you_page_url = $response['forward_url'];
         }
         if (isset($response['msg']['success'])) {
             $response_data = array('success' => $response['msg']['success'], 'return_data' => array('redirect-to-thank-you-page' => $this->_thank_you_page_url));
             $response_data = apply_filters('FHEE__EE_Single_Page_Checkout__JSON_response', $response_data);
             //				printr( $response_data, '$response_data  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
             //				echo '<h4>thank_you_page_url : ' . $this->_thank_you_page_url . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
             if (EE_Registry::instance()->REQ->front_ajax) {
                 echo json_encode($response_data);
                 die;
             } else {
                 wp_safe_redirect($this->_thank_you_page_url);
                 exit;
             }
         } else {
             EE_Error::add_error($response['msg']['error'], __FILE__, __FUNCTION__, __LINE__);
         }
         //			printr( $response, '$response  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
     }
     $this->go_to_next_step(__FUNCTION__);
 }
 function test_finalize()
 {
     $t = EE_Transaction::new_instance(array('STS_ID' => EEM_Transaction::complete_status_code));
     $t->save();
     $e = EE_Event::new_instance();
     $e->save();
     $tkt = EE_Ticket::new_instance();
     $tkt->save();
     $d = EE_Datetime::new_instance(array('EVT_ID' => $e->ID()));
     $d->save();
     $tkt->_add_relation_to($d, 'Datetime');
     /** @type EE_Registration_Processor $registration_processor */
     $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
     $reg_url = $registration_processor->generate_reg_url_link(1, EE_Line_Item::new_instance(array('LIN_name' => $tkt->name(), 'LIN_desc' => $tkt->description(), 'LIN_unit_price' => $tkt->price(), 'LIN_quantity' => 1, 'LIN_is_taxable' => $tkt->taxable(), 'LIN_order' => 0, 'LIN_total' => $tkt->price(), 'LIN_type' => EEM_Line_Item::type_line_item, 'OBJ_ID' => $tkt->ID(), 'OBJ_type' => 'Ticket')));
     $r = EE_REgistration::new_instance(array('EVT_ID' => $e->ID(), 'TXN_ID' => $t->ID(), 'TKT_ID' => $tkt->ID(), 'STS_ID' => EEM_Registration::status_id_pending_payment, 'REG_url_link' => $reg_url));
     $r->set_reg_code($registration_processor->generate_reg_code($r));
     $registration_processor->update_registration_after_checkout_or_payment($r);
     $this->assertNotNull($r->reg_code());
     $this->assertEquals(EEM_Registration::status_id_approved, $r->status_ID());
 }
 function espresso_replace_invoice_shortcodes($content)
 {
     $EE = EE_Registry::instance();
     //Create the logo
     $invoice_logo_url = $this->invoice_payment_method->get_extra_meta('pdf_logo_image', TRUE, $EE->CFG->organization->logo_url);
     if (!empty($invoice_logo_url)) {
         $image_size = getimagesize($invoice_logo_url);
         $invoice_logo_image = '<img class="logo screen" src="' . $invoice_logo_url . '" ' . $image_size[3] . ' alt="logo" /> ';
     } else {
         $invoice_logo_image = '';
     }
     $SearchValues = array("[organization]", "[registration_code]", "[transaction_id]", "[name]", "[base_url]", "[download_link]", "[invoice_logo_image]", "[street]", "[city]", "[state]", "[zip]", "[email]", "[vat]", "[registration_date]", "[instructions]");
     $primary_attendee = $this->transaction->primary_registration()->attendee();
     $org_state = EE_Registry::instance()->load_model('State')->get_one_by_ID($EE->CFG->organization->STA_ID);
     if ($org_state) {
         $org_state_name = $org_state->name();
     } else {
         $org_state_name = '';
     }
     $ReplaceValues = array($EE->CFG->organization->get_pretty('name'), $this->registration->reg_code(), $this->transaction->ID(), $primary_attendee->full_name(), is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice') ? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/' : EE_GATEWAYS_URL . 'Invoice/lib/templates/', $this->registration->invoice_url(), $invoice_logo_image, empty($EE->CFG->organization->address_2) ? $EE->CFG->organization->get_pretty('address_1') : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty('address_2'), $EE->CFG->organization->get_pretty('city'), $org_state_name, $EE->CFG->organization->get_pretty('zip'), $EE->CFG->organization->get_pretty('email'), $EE->CFG->organization->vat, $this->registration->get_i18n_datetime('REG_date', get_option('date_format')), $this->invoice_payment_method->get_extra_meta('pdf_instructions', TRUE));
     return str_replace($SearchValues, $ReplaceValues, $content);
 }
 /**
  * 		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);
 }
 /**
  * debug
  *
  * @param string $class
  * @param string $func
  * @param string $line
  * @param array $info
  * @param bool $display_request
  */
 function log($class = '', $func = '', $line = '', $info = array(), $display_request = false)
 {
     if (WP_DEBUG && false) {
         $debug_data = get_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array());
         $default_data = array($class => $func . '() : ' . $line, 'request->step' => $this->step, 'request->action' => $this->action, 'current_step->slug' => $this->current_step instanceof EE_SPCO_Reg_Step ? $this->current_step->slug() : '', 'current_step->completed' => $this->current_step instanceof EE_SPCO_Reg_Step ? $this->current_step->completed() : '', 'txn_status_updated' => $this->txn_status_updated, 'reg_status_updated' => $this->reg_status_updated, 'reg_url_link' => $this->reg_url_link, 'REQ' => $display_request ? $_REQUEST : '');
         if ($this->transaction instanceof EE_Transaction) {
             $default_data['TXN_status'] = $this->transaction->status_ID();
             $default_data['TXN_reg_steps'] = $this->transaction->reg_steps();
             foreach ($this->transaction->registrations($this->reg_cache_where_params) as $REG_ID => $registration) {
                 $default_data['registrations'][$REG_ID] = $registration->status_ID();
             }
             if ($this->transaction->ID()) {
                 $TXN_ID = 'EE_Transaction: ' . $this->transaction->ID();
                 // don't serialize objects
                 $info = $this->_strip_objects($info);
                 if (!isset($debug_data[$TXN_ID])) {
                     $debug_data[$TXN_ID] = array();
                 }
                 $debug_data[$TXN_ID][microtime()] = array_merge($default_data, $info);
                 update_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data);
             }
         }
     }
 }
 /**
  * update registrations REG_paid field after successful payment and link registrations with payment
  *
  * @param EE_Transaction $transaction
  * @param EE_Payment $payment
  * @param EE_Registration[] $registrations
  * @throws \EE_Error
  */
 public function process_registration_payments(EE_Transaction $transaction, EE_Payment $payment, $registrations = array())
 {
     // only process if payment was successful
     if ($payment->status() !== EEM_Payment::status_id_approved) {
         return;
     }
     //EEM_Registration::instance()->show_next_x_db_queries();
     if (empty($registrations)) {
         // find registrations with monies owing that can receive a payment
         $registrations = $transaction->registrations(array(array('STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), 'REG_final_price' => array('!=', 0), 'REG_final_price*' => array('!=', 'REG_paid', true))));
     }
     // still nothing ??!??
     if (empty($registrations)) {
         return;
     }
     // todo: break out the following logic into a separate strategy class
     // todo: named something like "Sequential_Reg_Payment_Strategy"
     // todo: which would apply payments using the capitalist "first come first paid" approach
     // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
     // todo: which would be the socialist "everybody gets a piece of pie" approach,
     // todo: which would be better for deposits, where you want a bit of the payment applied to each registration
     $refund = $payment->is_a_refund();
     // how much is available to apply to registrations?
     $available_payment_amount = abs($payment->amount());
     foreach ($registrations as $registration) {
         if ($registration instanceof EE_Registration) {
             // nothing left?
             if ($available_payment_amount <= 0) {
                 break;
             }
             if ($refund) {
                 $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount);
             } else {
                 $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount);
             }
         }
     }
     if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) {
         EE_Error::add_attention(sprintf(__('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', 'event_espresso'), EEH_Template::format_currency($available_payment_amount), implode(', ', array_keys($registrations)), '<br/>', EEH_Template::format_currency($payment->amount())), __FILE__, __FUNCTION__, __LINE__);
     }
 }
 /**
  * _get_registrations
  *
  * @access private
  * @param EE_Transaction $transaction
  * @return EE_Cart
  */
 private function _get_registrations(EE_Transaction $transaction)
 {
     // first step: grab the registrants  { : o
     $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true);
     // verify registrations have been set
     if (empty($registrations)) {
         // if no cached registrations, then check the db
         $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
         // still nothing ? well as long as this isn't a revisit
         if (empty($registrations) && !$this->checkout->revisit) {
             // generate new registrations from scratch
             $registrations = $this->_initialize_registrations($transaction);
         }
     }
     // sort by their original registration order
     usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
     // then loop thru the array
     foreach ($registrations as $registration) {
         // verify each registration
         if ($registration instanceof EE_Registration) {
             // we display all attendee info for the primary registrant
             if ($this->checkout->reg_url_link == $registration->reg_url_link() && $registration->is_primary_registrant()) {
                 $this->checkout->primary_revisit = TRUE;
                 break;
             } else {
                 if ($this->checkout->revisit && $this->checkout->reg_url_link != $registration->reg_url_link()) {
                     // but hide info if it doesn't belong to you
                     $transaction->clear_cache('Registration', $registration->ID());
                 }
             }
             $this->checkout->set_reg_status_updated($registration->ID(), false);
         }
     }
 }
 /**
  * _process_updated_registration_payments
  *
  * this applies the payments to the selected registrations
  * but only if they have not already been paid for
  *
  * @param  EE_Transaction $transaction
  * @param \EE_Payment $payment
  * @param array $registration_query_where_params
  * @return bool
  */
 protected function _process_updated_registration_payments(EE_Transaction $transaction, EE_Payment $payment, $registration_query_where_params = array())
 {
     // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
     // so let's do that using our set of REG_IDs from the form, but add in some conditions regarding payment
     // so that we don't apply payments to registrations that are free or have already been paid for
     // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
     if (!$payment->is_a_refund()) {
         $registration_query_where_params = array_merge($registration_query_where_params, array('REG_final_price' => array('!=', 0), 'REG_final_price*' => array('!=', 'REG_paid', true)));
     }
     $registrations = $transaction->registrations(array($registration_query_where_params));
     //EEH_Debug_Tools::printr( $registrations, '$registrations', __FILE__, __LINE__ );
     if (!empty($registrations)) {
         /** @type EE_Payment_Processor $payment_processor */
         $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
         $payment_processor->process_registration_payments($transaction, $payment, $registrations);
     }
 }
 /**
  * simulate six sales for an event's ticket, which will also increase sold qty for D1 & D2
  *
  * @param \EE_Ticket $ticket
  * @param int $qty
  * @throws \EE_Error
  */
 protected function _sell_tickets(EE_Ticket $ticket, $qty = 1)
 {
     if ($ticket instanceof EE_Ticket) {
         $transaction = EE_Transaction::new_instance(array('STS_ID' => EEM_Transaction::complete_status_code, 'TXN_timestamp' => time() - DAY_IN_SECONDS, 'TXN_total' => 0, 'TXN_paid' => 0));
         $transaction->save();
         for ($x = 1; $x <= $qty; $x++) {
             $registration = EE_Registration::new_instance(array('STS_ID' => EEM_Registration::status_id_approved, 'REG_date' => time() - DAY_IN_SECONDS, 'REG_code' => $transaction->ID() . "-" . $ticket->ID() . "-{$x}-test", 'TXN_ID' => $transaction->ID(), 'EVT_ID' => $ticket->get_event_ID(), 'TKT_ID' => $ticket->ID()));
             $registration->save();
         }
     }
 }
 /**
  * This sets up an empty EE_Payment object for the purpose of shortcode parsing.  Note that this doesn't actually get saved to the db.
  * @param \EE_Transaction $txn
  * @return \EE_Payment
  */
 private function _get_empty_payment_obj(EE_Transaction $txn)
 {
     $PMT = EE_Payment::new_instance(array('STS_ID' => EEM_Payment::status_id_pending, 'PAY_timestamp' => time(), 'PMD_ID' => $txn->payment_method_ID(), 'PAY_gateway_response' => $txn->gateway_response_on_transaction()));
     return $PMT;
 }
 protected function _setup_data()
 {
     //need to figure out the running total for test purposes so... we're going to create a temp cart and add the tickets to it!
     EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
     $cart = EE_Cart::reset();
     //add tickets to cart
     foreach ($this->tickets as $ticket) {
         $cart->add_ticket_to_cart($ticket['ticket']);
     }
     //setup txn property
     $this->txn = EE_Transaction::new_instance(array('TXN_timestamp' => time(), 'TXN_total' => 0, 'TXN_paid' => 0, 'STS_ID' => EEM_Transaction::incomplete_status_code, 'TXN_session_data' => NULL, 'TXN_hash_salt' => NULL, 'TXN_ID' => 999999));
     //setup reg_objects
     //note we're setting up a reg object for each attendee in each event but ALSO adding to the reg_object array.
     $this->reg_objs = array();
     $regid = 9999990;
     foreach ($this->_attendees as $key => $attendee) {
         //note we need to setup reg_objects for each event this attendee belongs to
         $regatt = $attendee['att_obj']->ID();
         $regtxn = $this->txn->ID();
         $regcnt = 1;
         foreach ($attendee['line_ref'] as $evtid) {
             foreach ($this->_events[$evtid]['tkt_objs'] as $ticket) {
                 $reg_array = array('EVT_ID' => $evtid, 'ATT_ID' => $regatt, 'TXN_ID' => $regtxn, 'TKT_ID' => $ticket->ID(), 'STS_ID' => EEM_Registration::status_id_pending_payment, 'REG_date' => time(), 'REG_final_price' => $ticket->get('TKT_price'), 'REG_session' => 'dummy_session_id', 'REG_code' => $regid . '-dummy-generated-code', 'REG_url_link' => $regcnt . '-daafpapasdlfakasdfpqasdfasdf', 'REG_count' => $regcnt, 'REG_group_size' => $this->_events[$evtid]['total_attendees'], 'REG_att_is_going' => TRUE, 'REG_ID' => $regid);
                 $REG_OBJ = EE_Registration::new_instance($reg_array);
                 $this->_attendees[$key]['reg_objs'][$regid] = $REG_OBJ;
                 $this->_events[$evtid]['reg_objs'][] = $REG_OBJ;
                 $this->reg_objs[] = $REG_OBJ;
                 $this->tickets[$ticket->ID()]['reg_objs'][$regid] = $REG_OBJ;
                 $regcnt++;
                 $regid++;
             }
         }
     }
     //setup line items!
     EE_Registry::instance()->load_helper('Line_Item');
     $line_item_total = EEH_Line_Item::create_total_line_item($this->txn);
     //add tickets
     foreach ($this->tickets as $tktid => $item) {
         $qty = $item['count'];
         $ticket = $item['ticket'];
         EEH_Line_Item::add_ticket_purchase($line_item_total, $ticket, $qty);
     }
     $shipping_line_item = EE_Line_Item::new_instance(array('LIN_name' => __('Shipping Surcharge', 'event_espresso'), 'LIN_desc' => __('Sent via Millenium Falcon', 'event_espresso'), 'LIN_unit_price' => 20, 'LIN_quantity' => 1, 'LIN_is_taxable' => TRUE, 'LIN_total' => 20, 'LIN_type' => EEM_Line_Item::type_line_item));
     EEH_Line_Item::add_item($line_item_total, $shipping_line_item);
     $this->additional_line_items = array($shipping_line_item);
     //now let's add taxes
     EEH_Line_Item::apply_taxes($line_item_total);
     //now we should be able to get the items we need from this object
     $event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children();
     $line_items = array();
     foreach ($event_line_items as $line_id => $line_item) {
         if (!$line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') {
             continue;
         }
         $ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item);
         foreach ($ticket_line_items as $ticket_line_id => $ticket_line_item) {
             if (!$ticket_line_item instanceof EE_Line_Item) {
                 continue;
             }
             $this->tickets[$ticket_line_item->OBJ_ID()]['line_item'] = $ticket_line_item;
             $this->tickets[$ticket_line_item->OBJ_ID()]['sub_line_items'] = $ticket_line_item->children();
             $line_items[$ticket_line_item->ID()]['children'] = $ticket_line_item->children();
             $line_items[$ticket_line_item->ID()]['EE_Ticket'] = $this->tickets[$ticket_line_item->OBJ_ID()]['ticket'];
         }
     }
     $this->line_items_with_children = $line_items;
     $this->tax_line_items = $line_item_total->tax_descendants();
     //add proper total to transaction object.
     $grand_total = $line_item_total->recalculate_total_including_taxes();
     $this->grand_total_line_item = $line_item_total;
     $this->txn->set_total($grand_total);
     //add additional details for each registration
     foreach ($this->reg_objs as $reg) {
         $this->_registrations[$reg->ID()]['tkt_obj'] = $this->tickets[$reg->get('TKT_ID')]['ticket'];
         $this->_registrations[$reg->ID()]['evt_obj'] = $this->_events[$reg->get('EVT_ID')]['event'];
         $this->_registrations[$reg->ID()]['reg_obj'] = $reg;
         $this->_registrations[$reg->ID()]['ans_objs'] = $this->_attendees[$reg->get('ATT_ID')]['ans_objs'];
         $this->_registrations[$reg->ID()]['att_obj'] = $this->_attendees[$reg->get('ATT_ID')]['att_obj'];
         $this->_registrations[$reg->ID()]['dtt_objs'] = $this->tickets[$reg->get('TKT_ID')]['dtt_objs'];
     }
     //events and attendees
     $this->events = $this->_events;
     $this->attendees = $this->_attendees;
     $this->registrations = $this->_registrations;
     $attendees_to_shift = $this->_attendees;
     //setup primary attendee property
     $this->primary_attendee_data = array('fname' => $this->_attendees[999999991]['att_obj']->fname(), 'lname' => $this->_attendees[999999991]['att_obj']->lname(), 'email' => $this->_attendees[999999991]['att_obj']->email(), 'att_obj' => $this->_attendees[999999991]['att_obj'], 'reg_obj' => array_shift($attendees_to_shift[999999991]['reg_objs']));
     //reg_info property
     //note this isn't referenced by any shortcode parsers so we'll ignore for now.
     $this->reg_info = array();
     //let's set a reg_obj for messengers expecting one.
     $this->reg_obj = array_pop($this->_attendees[999999991]['reg_objs']);
     //the below are just dummy items.
     $this->user_id = 1;
     $this->ip_address = '192.0.2.1';
     $this->user_agent = '';
     $this->init_access = time();
     $this->last_access = time();
 }
 /**
  * Logic to be accomplished when the payment attempt is complete.
  * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
  * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from
  * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
  * of the payment). Fed a transaction because it's always assumed to be the last payment that
  * we're dealing with. Returns that last payment (if there is one)
  *
  * @param EE_Transaction $transaction
  * @return EE_Payment
  */
 public function finalize_payment_for($transaction)
 {
     return $transaction->last_payment();
 }
 /**
  * @group 7151
  */
 function test_fresh_entity_map_with()
 {
     $p = $this->new_model_obj_with_dependencies('Payment', array('PAY_amount' => 25));
     $p->save();
     $this->assertEquals($p, EEM_Payment::instance()->get_from_entity_map($p->ID()));
     //now purposefully make a naughty payment which isn't in the entity map
     $p2 = clone $p;
     $this->assertFalse($p2->in_entity_map());
     //make the two EE_Payments diverge
     $p2->set('PAY_amount', 99);
     $t = EE_Transaction::new_instance();
     $p2->cache('Transaction', $t);
     $this->assertEquals(25, $p->get('PAY_amount'));
     $this->assertEquals(99, $p2->get('PAY_amount'));
     $this->assertNotEquals($p->get_all_from_cache('Transaction'), $p2->get_all_from_cache('Transaction'));
     //now update the payment in the entity map with the other
     EEM_Payment::instance()->refresh_entity_map_with($p->ID(), $p2);
     $this->assertEquals(99, $p->get('PAY_amount'));
     //make sure p hasn't changed into p2. that's not what we wanted to do...
     $this->assertFalse($p2 === $p);
     //We wanted to just UPDATE p with p2's values
     $this->assertEquals($p, EEM_Payment::instance()->get_from_entity_map($p->ID()));
     //and make sure p's cache was updated to be the same as p2's
     $this->assertEquals($p2->get_all_from_cache('Transaction'), $p->get_all_from_cache('Transaction'));
 }
 /**
  * This helper method can be used by any incoming data handlers to setup the data correctly.  All that is required is that $this->reg_objs be set.
  * @throws \EE_Error
  */
 protected function _assemble_data()
 {
     //verify that reg_objs is set
     if (!is_array($this->reg_objs) && !reset($this->reg_objs) instanceof EE_Registration) {
         throw new EE_Error(__('In order to assemble the data correctly, the "reg_objs" property must be an array of EE_Registration objects', 'event_espresso'));
     }
     //get all attendee and events associated with the registrations in this transaction
     $events = $event_setup = $evtcache = $tickets = $datetimes = array();
     $answers = $questions = $attendees = $line_items = $registrations = array();
     $total_ticket_count = 0;
     if (!empty($this->reg_objs)) {
         $event_attendee_count = array();
         foreach ($this->reg_objs as $reg) {
             //account for filtered registrations by status.
             if (!empty($this->filtered_reg_status) && $this->filtered_reg_status !== $reg->status_ID()) {
                 continue;
             }
             $evt_id = $reg->event_ID();
             /** @type EE_Ticket $ticket */
             $ticket = $reg->get_first_related('Ticket');
             $relateddatetime = $ticket->datetimes();
             $total_ticket_count++;
             $tickets[$ticket->ID()]['ticket'] = $ticket;
             $tickets[$ticket->ID()]['count'] = is_array($tickets[$ticket->ID()]) && isset($tickets[$ticket->ID()]['count']) ? $tickets[$ticket->ID()]['count'] + 1 : 1;
             $tickets[$ticket->ID()]['att_objs'][$reg->attendee_ID()] = $reg->attendee();
             $tickets[$ticket->ID()]['dtt_objs'] = $relateddatetime;
             $tickets[$ticket->ID()]['reg_objs'][$reg->ID()] = $reg;
             $event = $reg->event();
             $tickets[$ticket->ID()]['EE_Event'] = $event;
             $evtcache[$evt_id] = $event;
             $eventsetup[$evt_id]['reg_objs'][$reg->ID()] = $reg;
             $eventsetup[$evt_id]['tkt_objs'][$ticket->ID()] = $ticket;
             $eventsetup[$evt_id]['att_objs'][$reg->attendee_ID()] = $reg->attendee();
             $event_attendee_count[$evt_id] = isset($event_attendee_count[$evt_id]) ? $event_attendee_count[$evt_id] + 1 : 0;
             $attendees[$reg->attendee_ID()]['line_ref'][] = $evt_id;
             $attendees[$reg->attendee_ID()]['att_obj'] = $reg->attendee();
             $attendees[$reg->attendee_ID()]['reg_objs'][$reg->ID()] = $reg;
             //$attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID();
             $attendees[$reg->attendee_ID()]['attendee_email'] = $reg->attendee() instanceof EE_Attendee ? $reg->attendee()->email() : '';
             $attendees[$reg->attendee_ID()]['tkt_objs'][$ticket->ID()] = $ticket;
             $attendees[$reg->attendee_ID()]['evt_objs'][$evt_id] = $event;
             //registrations
             $registrations[$reg->ID()]['tkt_obj'] = $ticket;
             $registrations[$reg->ID()]['evt_obj'] = $event;
             $registrations[$reg->ID()]['reg_obj'] = $reg;
             $registrations[$reg->ID()]['att_obj'] = $reg->attendee();
             //set up answer objects
             $rel_ans = $reg->get_many_related('Answer');
             foreach ($rel_ans as $ansid => $answer) {
                 if (!isset($questions[$ansid])) {
                     $questions[$ansid] = $answer->get_first_related('Question');
                 }
                 $answers[$ansid] = $answer;
                 $registrations[$reg->ID()]['ans_objs'][$ansid] = $answer;
             }
             foreach ($relateddatetime as $dtt_id => $datetime) {
                 $eventsetup[$evt_id]['dtt_objs'][$dtt_id] = $datetime;
                 $registrations[$reg->ID()]['dtt_objs'][$dtt_id] = $datetime;
                 if (isset($datetimes[$dtt_id])) {
                     continue;
                     //already have this info in the datetimes array.
                 }
                 $datetimes[$dtt_id]['tkt_objs'][] = $ticket;
                 $datetimes[$dtt_id]['datetime'] = $datetime;
                 $datetimes[$dtt_id]['evt_objs'][$evt_id] = $event;
                 $datetimes[$dtt_id]['reg_objs'][$reg->ID()] = $reg;
             }
         }
         //let's loop through the unique event=>reg items and setup data on them
         if (!empty($eventsetup)) {
             foreach ($eventsetup as $evt_id => $items) {
                 if ($this->txn instanceof EE_Transaction) {
                     $ticket_line_items_for_event = EEM_Line_Item::instance()->get_all(array(array('Ticket.Datetime.EVT_ID' => $evt_id, 'TXN_ID' => $this->txn->ID()), 'default_where_conditions' => 'none'));
                 } else {
                     $ticket_line_items_for_event = array();
                 }
                 $events[$evt_id] = array('ID' => $evt_id, 'event' => $evtcache[$evt_id], 'name' => $evtcache[$evt_id] instanceof EE_Event ? $evtcache[$evt_id]->name() : '', 'total_attendees' => $event_attendee_count[$evt_id], 'reg_objs' => $items['reg_objs'], 'tkt_objs' => $items['tkt_objs'], 'att_objs' => $items['att_objs'], 'dtt_objs' => isset($items['dtt_objs']) ? $items['dtt_objs'] : array(), 'line_items' => $ticket_line_items_for_event);
                 //make sure the tickets have the line items setup for them.
                 foreach ($ticket_line_items_for_event as $line_id => $line_item) {
                     if ($line_item instanceof EE_Line_Item) {
                         $tickets[$line_item->ticket()->ID()]['line_item'] = $line_item;
                         $tickets[$line_item->ticket()->ID()]['sub_line_items'] = $line_item->children();
                         $line_items[$line_item->ID()]['children'] = $line_item->children();
                         $line_items[$line_item->ID()]['EE_Ticket'] = $line_item->ticket();
                     }
                 }
             }
         }
         $this->grand_total_line_item = $this->txn instanceof EE_Transaction ? $this->txn->total_line_item() : null;
     }
     //lets set the attendees and events properties
     $this->attendees = $attendees;
     $this->events = $events;
     $this->tickets = $tickets;
     $this->line_items_with_children = $line_items;
     $this->datetimes = $datetimes;
     $this->questions = $questions;
     $this->answers = $answers;
     $this->total_ticket_count = $total_ticket_count;
     $this->registrations = $registrations;
     if ($this->txn instanceof EE_Transaction) {
         $this->tax_line_items = $this->txn->tax_items();
         $this->additional_line_items = $this->txn->non_ticket_line_items();
         $this->payments = $this->txn->payments();
         //setup primary registration if we have a single transaction object to work with
         //let's get just the primary_attendee_data!  First we get the primary registration object.
         $primary_reg = $this->txn->primary_registration();
         // verify
         if ($primary_reg instanceof EE_Registration) {
             // get attendee object
             if ($primary_reg->attendee() instanceof EE_Attendee) {
                 //now we can setup the primary_attendee_data array
                 $this->primary_attendee_data = array('registration_id' => $primary_reg->ID(), 'att_obj' => $primary_reg->attendee(), 'reg_obj' => $primary_reg, 'primary_att_obj' => $primary_reg->attendee(), 'primary_reg_obj' => $primary_reg);
             } else {
                 EE_Error::add_error(__('Incoming data does not have a valid Attendee object for the primary registrant.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
             }
         } else {
             EE_Error::add_error(__('Incoming data does not have a valid Registration object for the primary registrant.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         }
     }
 }
 /**
  * @param \EE_Transaction $transaction
  * @return bool
  */
 public function set_transaction(EE_Transaction $transaction)
 {
     // first remove the session from the transaction before we save the transaction in the session
     $transaction->set_txn_session_data(NULL);
     $this->_session_data['transaction'] = $transaction;
     return TRUE;
 }
 /**
  * Handle IPN for transaction
  */
 public function handle_ipn_for_transaction(EE_Transaction $transaction)
 {
     global $pronamic_payment, $pronamic_url;
     // Transaction ID
     $transaction_id = $transaction->ID();
     // Payment
     $payment = $this->_PAY->get_payment_by_txn_id_chq_nmbr($transaction_id);
     if (empty($payment)) {
         $payment = EE_Payment::new_instance(array('TXN_ID' => $transaction_id, 'STS_ID' => EEM_Payment::status_id_approved, 'PAY_timestamp' => $transaction->datetime(), 'PAY_amount' => $pronamic_payment->amount, 'PAY_gateway' => __('iDEAL', 'pronamic_ideal'), 'PAY_txn_id_chq_nmbr' => $transaction_id));
     } else {
         $payment->set_status(EEM_Payment::status_id_approved);
     }
     // Save
     $payment->save();
     // URL
     $registration = $transaction->primary_registration();
     $pronamic_url = $this->_get_return_url($registration);
     // Return update
     return $this->update_transaction_with_payment($transaction, $payment);
 }
 /**
  * Returns what a simple summing of items and taxes for this transaction. This
  * can be used to determine if some more complex line items, like promotions,
  * surcharges, or cancellations occurred (in which case we might want to forget
  * about creating an itemized list of purchases and instead only send the total due)
  * @param EE_Transaction  $transaction
  * @return float
  */
 protected function _sum_items_and_taxes(EE_Transaction $transaction)
 {
     $total_line_item = $transaction->total_line_item();
     $total = 0;
     foreach ($total_line_item->get_items() as $item_line_item) {
         $total += max($item_line_item->total(), 0);
     }
     foreach ($total_line_item->tax_descendants() as $tax_line_item) {
         $total += max($tax_line_item->total(), 0);
     }
     return $total;
 }
 /**
  * @param \EE_Transaction $transaction
  * @param \EE_Ticket $ticket
  * @param \EE_Event $event
  * @param float $REG_final_price
  * @return \EE_Registration
  * @throws \EE_Error
  */
 public function get_registration_mock(EE_Transaction $transaction, EE_Ticket $ticket, EE_Event $event, $REG_final_price = 10.0)
 {
     return $this->new_model_obj_with_dependencies('Registration', array('TXN_ID' => $transaction->ID(), 'TKT_ID' => $ticket->ID(), 'EVT_ID' => $event->ID(), 'REG_final_price' => $REG_final_price, 'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT));
 }
 /**
  * possibly toggles TXN status
  *
  * @param EE_Transaction $transaction
  * @param 	boolean $update_txn  	whether to save the TXN
  * @return 	boolean 	 	whether the TXN was saved
  * @throws \EE_Error
  */
 public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = TRUE)
 {
     // verify transaction
     if (!$transaction instanceof EE_Transaction) {
         EE_Error::add_error(__('Please provide a valid EE_Transaction object.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         return FALSE;
     }
     // set incoming TXN_Status
     $this->set_old_txn_status($transaction->status_ID());
     // set transaction status based on comparison of TXN_paid vs TXN_total
     if (EEH_Money::compare_floats($transaction->paid(), $transaction->total(), '>')) {
         $new_txn_status = EEM_Transaction::overpaid_status_code;
     } else {
         if (EEH_Money::compare_floats($transaction->paid(), $transaction->total())) {
             $new_txn_status = EEM_Transaction::complete_status_code;
         } else {
             if (EEH_Money::compare_floats($transaction->paid(), $transaction->total(), '<')) {
                 $new_txn_status = EEM_Transaction::incomplete_status_code;
             } else {
                 EE_Error::add_error(__('The total paid calculation for this transaction is inaccurate.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
                 return FALSE;
             }
         }
     }
     if ($new_txn_status !== $transaction->status_ID()) {
         // set incoming TXN_Status
         $this->set_new_txn_status($new_txn_status);
         $transaction->set_status($new_txn_status);
         if ($update_txn) {
             return $transaction->save() ? TRUE : FALSE;
         }
     }
     return FALSE;
 }