/**
  *    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);
 }
 /**
  * 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_payment_options
  *
  * 	@access private
  * 	@return 	void
  */
 private function _process_payment_options()
 {
     do_action('AHEE_log', __FILE__, __FUNCTION__, '');
     if ($this->_continue_reg) {
         $success = TRUE;
         if ($this->_transaction instanceof EE_Transaction) {
             // grab the saved registrations from the transaction
             foreach ($this->_transaction->registrations(array(), TRUE) as $registration) {
                 // verify object
                 if ($registration instanceof EE_Registration) {
                     // if event is sold out but this is NOT a revisit
                     if (!($this->_revisit || !$this->_revisit && !($registration->event()->is_sold_out() || $registration->event()->is_sold_out(TRUE)))) {
                         $success = FALSE;
                     }
                 } else {
                     $success = FALSE;
                 }
             }
         } else {
             $success = FALSE;
         }
         if ($success) {
             if (EE_Registry::instance()->REQ->is_set('selected_gateway') && EE_Registry::instance()->REQ->get('selected_gateway') == 'payments_closed') {
                 // requires pre-approval
                 $success_msg = __('no payment required at this time.', 'event_espresso');
                 EE_Error::add_success($success_msg, __FILE__, __FUNCTION__, __LINE__);
             } else {
                 if ($this->_transaction->total() > 0) {
                     // PAID EVENT !!!  BOO  : (
                     EE_Registry::instance()->load_model('Gateways')->process_gateway_selection();
                 } else {
                     if (!$this->_reg_url_link) {
                         // FREE EVENT !!! YEAH : )
                         $success_msg = __('no payment required.', 'event_espresso');
                         EE_Error::add_success($success_msg, __FILE__, __FUNCTION__, __LINE__);
                     }
                 }
             }
         } else {
             EE_Error::add_error(apply_filters('FHEE__Single_Page_Checkout___process_payment_options__sold_out_events_msg', __('It appears that the event you are attempting to register for has just sold out. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__);
         }
     }
     $this->go_to_next_step(__FUNCTION__);
 }
 /**
  * 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;
 }
 /**
  * Makes sure there is no rounding errors for the REG_final_prices.
  * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them,
  * they will each be for $0.99333333, which gets rounded to $1 again.
  * So the transaction total will be $2.99, but each registration will be for $1,
  * so if each registrant paid individually they will have overpaid by $0.01.
  * So in order to overcome this, we check for any difference, and if there is a difference
  * we just grab one registrant at random and make them responsible for it.
  * This should be used after setting REG_final_prices (it's done automatically as part of
  * EE_Registration_Processor::update_registration_final_prices())
  * @param EE_Transaction $transaction
  * @return boolean success verifying that there is NO difference after this method is done
  */
 public function fix_reg_final_price_rounding_issue($transaction)
 {
     $reg_final_price_sum = EEM_Registration::instance()->sum(array(array('TXN_ID' => $transaction->ID())), 'REG_final_price');
     $diff = $transaction->total() - floatval($reg_final_price_sum);
     //ok then, just grab one of the registrations
     if ($diff != 0) {
         $a_reg = EEM_Registration::instance()->get_one(array(array('TXN_ID' => $transaction->ID())));
         $success = $a_reg instanceof EE_Registration ? $a_reg->save(array('REG_final_price' => $a_reg->final_price() + $diff)) : false;
         return $success ? true : false;
     } else {
         return true;
     }
 }
 public function send_invoice($download = FALSE)
 {
     $template_args = array();
     $EE = EE_Registry::instance();
     //allow the request to override the default theme defined in the invoice settings
     $theme_requested = isset($_REQUEST['theme']) && $_REQUEST['theme'] > 0 && $_REQUEST['theme'] < 8 ? absint($_REQUEST['theme']) : null;
     $themes = array(1 => "simple.css", 2 => "bauhaus.css", 3 => "ejs.css", 4 => "horizon.css", 5 => "lola.css", 6 => "tranquility.css", 7 => "union.css");
     //Get the CSS file
     if (isset($themes[$theme_requested])) {
         $template_args['invoice_css'] = $themes[$theme_requested];
     } else {
         $template_args['invoice_css'] = $this->invoice_payment_method->get_extra_meta('legacy_invoice_css', TRUE, 'simple.css');
     }
     if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) {
         $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/';
     } else {
         $template_args['base_url'] = EE_GATEWAYS . '/Invoice/lib/templates/';
     }
     $primary_attendee = $this->transaction->primary_registration()->attendee();
     $template_args['organization'] = $EE->CFG->organization->get_pretty('name');
     $template_args['street'] = 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');
     $template_args['city'] = $EE->CFG->organization->get_pretty('city');
     $template_args['state'] = EE_Registry::instance()->load_model('State')->get_one_by_ID($EE->CFG->organization->STA_ID);
     $template_args['country'] = EE_Registry::instance()->load_model('Country')->get_one_by_ID($EE->CFG->organization->CNT_ISO);
     $template_args['zip'] = $EE->CFG->organization->get_pretty('zip');
     $template_args['email'] = $EE->CFG->organization->get_pretty('email');
     $template_args['registration_code'] = $this->registration->reg_code();
     $template_args['registration_date'] = $this->registration->date();
     $template_args['name'] = $primary_attendee->full_name();
     $template_args['attendee_address'] = $primary_attendee->address();
     $template_args['attendee_address2'] = $primary_attendee->address2();
     $template_args['attendee_city'] = $primary_attendee->city();
     $attendee_state = $primary_attendee->state_obj();
     if ($attendee_state) {
         $attendee_state_name = $attendee_state->name();
     } else {
         $attendee_state_name = '';
     }
     $template_args['attendee_state'] = $attendee_state_name;
     $template_args['attendee_zip'] = $primary_attendee->zip();
     $template_args['ship_name'] = $template_args['name'];
     $template_args['ship_address'] = $template_args['attendee_address'];
     $template_args['ship_city'] = $template_args['attendee_city'];
     $template_args['ship_state'] = $template_args['attendee_state'];
     $template_args['ship_zip'] = $template_args['attendee_zip'];
     $template_args['total_cost'] = number_format($this->transaction->total(), 2, '.', '');
     $template_args['transaction'] = $this->transaction;
     $template_args['amount_pd'] = $this->transaction->paid();
     $template_args['amount_owed'] = $this->transaction->total() - $this->transaction->paid();
     $template_args['payments'] = $this->transaction->approved_payments();
     $template_args['net_total'] = '';
     $template_args['edit_reg_info_url'] = $this->registration->edit_attendee_information_url();
     $template_args['retry_payment_url'] = $this->registration->payment_overview_url();
     $template_args['show_line_item_description'] = $this->check_if_any_line_items_have_a_description($this->transaction->total_line_item());
     if ($template_args['amount_pd'] != $template_args['total_cost']) {
         //$template_args['net_total'] = $this->espressoInvoiceTotals( __('SubTotal', 'event_espresso'), $this->transaction->total());//$this->session_data['cart']['REG']['sub_total']);
         $tax_items = $this->transaction->tax_items();
         if (!empty($tax_items)) {
             foreach ($tax_items as $tax) {
                 $template_args['net_total'] .= $this->espressoInvoiceTotals($tax->name(), $tax->total());
             }
         }
         $difference = $template_args['amount_pd'] - $template_args['total_cost'];
         if ($difference < 0) {
             $text = __('Discount', 'event_espresso');
         } else {
             $text = __('Extra', 'event_espresso');
         }
         $template_args['discount'] = $this->espressoInvoiceTotals($text, $difference);
     }
     $template_args['currency_symbol'] = $EE->CFG->currency->sign;
     $template_args['template_payment_instructions'] = wpautop(stripslashes_deep(html_entity_decode($this->invoice_payment_method->get_extra_meta('pdf_instructions', TRUE), ENT_QUOTES)));
     $template_args['shameless_plug'] = apply_filters('FHEE_Invoice__send_invoice__shameless_plug', true);
     if (isset($_GET['receipt'])) {
         //receipt-specific stuff
         $events_for_txn = EEM_Event::instance()->get_all(array(array('Registration.TXN_ID' => $this->transaction->ID())));
         $ticket_line_items_per_event = array();
         $registrations_per_line_item = array();
         $venues_for_events = array();
         foreach ($events_for_txn as $event_id => $event) {
             $line_items_for_this_event = EEM_Line_Item::instance()->get_all(array(array('Ticket.Datetime.EVT_ID' => $event_id, 'TXN_ID' => $this->transaction->ID())));
             $ticket_line_items_per_event[$event_id] = $line_items_for_this_event;
             foreach ($line_items_for_this_event as $line_item_id => $line_item) {
                 $ticket = $line_item->ticket();
                 $registrations_for_this_ticket = EEM_Registration::instance()->get_all(array(array('TKT_ID' => $ticket->ID(), 'TXN_ID' => $this->transaction->ID())));
                 $registrations_per_line_item[$line_item_id] = $registrations_for_this_ticket;
             }
             $venues_for_events = array_merge($venues_for_events, $event->venues());
         }
         $tax_total_line_item = EEM_Line_Item::instance()->get_one(array(array('TXN_ID' => $this->transaction->ID(), 'LIN_type' => EEM_Line_Item::type_tax_sub_total)));
         $questions_to_skip = array(EEM_Attendee::system_question_fname, EEM_Attendee::system_question_lname, EEM_Attendee::system_question_email);
         $template_args['events_for_txn'] = $events_for_txn;
         $template_args['ticket_line_items_per_event'] = $ticket_line_items_per_event;
         $template_args['registrations_per_line_item'] = $registrations_per_line_item;
         $template_args['venues_for_events'] = $venues_for_events;
         $template_args['tax_total_line_item'] = $tax_total_line_item;
         $template_args['questions_to_skip'] = $questions_to_skip;
         //			d($template_args);
         $template_args['download_link'] = $this->registration->receipt_url('download');
     } else {
         //it's just an invoice we're accessing
         $template_args['download_link'] = $this->registration->invoice_url('download');
     }
     //Get the HTML as an object
     $templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
     $template_header = EEH_Template::locate_template($templates_relative_path . 'invoice_header.template.php', $template_args, TRUE, TRUE);
     if (isset($_GET['receipt'])) {
         $template_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', $template_args, TRUE, TRUE);
     } else {
         $template_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', $template_args, TRUE, TRUE);
     }
     $template_footer = EEH_Template::locate_template($templates_relative_path . 'invoice_footer.template.php', $template_args, TRUE, TRUE);
     $copies = !empty($_REQUEST['copies']) ? $_REQUEST['copies'] : 1;
     $content = $this->espresso_replace_invoice_shortcodes($template_header);
     for ($x = 1; $x <= $copies; $x++) {
         $content .= $this->espresso_replace_invoice_shortcodes($template_body);
     }
     $content .= $this->espresso_replace_invoice_shortcodes($template_footer);
     //Check if debugging or mobile is set
     if (!empty($_REQUEST['html'])) {
         echo $content;
         exit(0);
     }
     $invoice_name = $template_args['organization'] . ' ' . __('Invoice #', 'event_espresso') . $template_args['registration_code'] . __(' for ', 'event_espresso') . $template_args['name'];
     $invoice_name = str_replace(' ', '_', $invoice_name);
     //Create the PDF
     if (array_key_exists('html', $_GET)) {
         echo $content;
     } else {
         //only load dompdf if nobody else has yet...
         if (!defined('DOMPDF_DIR')) {
             define('DOMPDF_ENABLE_REMOTE', TRUE);
             define('DOMPDF_ENABLE_JAVASCRIPT', FALSE);
             define('DOMPDF_ENABLE_CSS_FLOAT', TRUE);
             require_once EE_THIRD_PARTY . 'dompdf/dompdf_config.inc.php';
         }
         $dompdf = new DOMPDF();
         $dompdf->load_html($content);
         $dompdf->render();
         $dompdf->stream($invoice_name . ".pdf", array('Attachment' => $download));
     }
     exit(0);
 }