public function test_save_and_clean_billing_info_for_payment_method() { $pm = EE_Payment_Method::new_instance(array('PMD_type' => 'Aim')); $pm->save(); //reset the country model because it caches its list of countries which is used when //making most billing forms EEM_Country::reset(); $form = $pm->type_obj()->billing_form(); $form_name = $form->name(); $form_values = array('first_name' => 'e', 'last_name' => 'e', 'email' => '*****@*****.**', 'address' => '123', 'address2' => '', 'city' => 'someville', 'state' => 12, 'country' => 'US', 'zip' => '1235', 'phone' => '9991231234', 'credit_card' => '4007000000027', 'exp_month' => '12', 'exp_year' => '2020', 'cvv' => '123'); $form->receive_form_submission(array($form_name => $form_values)); $this->assertTrue($form->is_valid(), 'error was: ' . $form->get_validation_error_string()); $p = $this->new_model_obj_with_dependencies('Payment', array('PMD_ID' => $pm->ID())); $reg = $this->new_model_obj_with_dependencies('Registration', array('TXN_ID' => $p->TXN_ID())); $att = $reg->attendee(); $att->save_and_clean_billing_info_for_payment_method($form, $pm); //ok so now it should ahve been saved. Let's verify that $billing_info_form = $att->billing_info_for_payment_method($pm); $this->assertInstanceOf('EE_Billing_Attendee_Info_Form', $billing_info_form); //it should ahve been cleaned too, so lets tweak teh form values ot what they should be $form_values['credit_card'] = 'XXXXXXXXX0027'; $form_values['cvv'] = 'XXX'; $form_values['exp_month'] = ''; $form_values['exp_year'] = 0; foreach ($form_values as $input_name => $value) { $input = $billing_info_form->get_input($input_name); $this->assertInstanceOf('EE_Form_Input_Base', $input); $this->assertEquals($value, $input->raw_value(), $input_name); } }
/** * 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); }
protected function _payment_methods_list() { /** * first let's ensure payment methods have been setup. We do this here because when people activate a * payment method for the first time (as an addon), it may not setup its capabilities or get registered correctly due * to the loading process. However, people MUST setup the details for the payment method so its safe to do a * recheck here. */ EE_Registry::instance()->load_lib('Payment_Method_Manager'); EEM_Payment_Method::instance()->verify_button_urls(); EE_Registry::instance()->load_helper('Tabbed_Content'); EE_Registry::instance()->load_helper('HTML'); //setup tabs, one for each payment method type $tabs = array(); $payment_methods = array(); foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) { // we don't want to show admin-only PMTs for now if ($pmt_obj instanceof EE_PMT_Admin_Only) { continue; } //check access if (!EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(), 'specific_payment_method_type_access')) { continue; } //check for any active pms of that type $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name()); if (!$payment_method instanceof EE_Payment_Method) { $payment_method = EE_Payment_Method::new_instance(array('PMD_slug' => sanitize_key($pmt_obj->system_name()), 'PMD_type' => $pmt_obj->system_name(), 'PMD_name' => $pmt_obj->pretty_name(), 'PMD_admin_name' => $pmt_obj->pretty_name())); } $payment_methods[$payment_method->slug()] = $payment_method; } $payment_methods = apply_filters('FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', $payment_methods); foreach ($payment_methods as $payment_method) { if ($payment_method instanceof EE_Payment_Method) { add_meta_box('espresso_' . $payment_method->slug() . '_payment_settings', sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()), array($this, 'payment_method_settings_meta_box'), null, 'normal', 'default', array('payment_method' => $payment_method)); //setup for tabbed content $tabs[$payment_method->slug()] = array('label' => $payment_method->admin_name(), 'class' => $payment_method->active() ? 'gateway-active' : '', 'href' => 'espresso_' . $payment_method->slug() . '_payment_settings', 'title' => __('Modify this Payment Method', 'event_espresso'), 'slug' => $payment_method->slug()); } } $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($tabs, 'payment_method_links', '|', $this->_get_active_payment_method_slug()); $this->display_admin_page_with_sidebar(); }
/** * 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); }
/** * Activates a payment method of the given type. * @global type $current_user * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' * @return EE_Payment_Method */ public function activate_a_payment_method_of_type($payment_method_type) { $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); if (!$payment_method) { global $current_user; $pm_type_class = $this->payment_method_class_from_type($payment_method_type); if (class_exists($pm_type_class)) { /** @var $pm_type_obj EE_PMT_Base */ $pm_type_obj = new $pm_type_class(); $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); if (!$payment_method) { $payment_method = EE_Payment_Method::new_instance(array('PMD_type' => $pm_type_obj->system_name(), 'PMD_name' => $pm_type_obj->pretty_name(), 'PMD_admin_name' => $pm_type_obj->pretty_name(), 'PMD_slug' => $pm_type_obj->system_name(), 'PMD_wp_user' => $current_user->ID, 'PMD_order' => EEM_Payment_Method::instance()->count(array(array('PMD_type' => array('!=', 'Admin_Only')))) * 10)); } $payment_method->set_active(); $payment_method->set_description($pm_type_obj->default_description()); //handles the goofy case where someone activates the invoice gateway which is also $payment_method->set_type($pm_type_obj->system_name()); if (!$payment_method->button_url()) { $payment_method->set_button_url($pm_type_obj->default_button_url()); } $payment_method->save(); foreach ($payment_method->get_all_usable_currencies() as $currency_obj) { $payment_method->_add_relation_to($currency_obj, 'Currency'); } //now add setup its default extra meta properties $extra_metas = $payment_method->type_obj()->settings_form()->extra_meta_inputs(); foreach ($extra_metas as $meta_name => $input) { $payment_method->update_extra_meta($meta_name, $input->raw_value()); } } } else { $payment_method->set_active(); $payment_method->save(); } if ($payment_method->type() == 'Invoice') { $messages = EE_Registry::instance()->load_lib('messages'); $messages->ensure_message_type_is_active('invoice', 'html'); $messages->ensure_messenger_is_active('pdf'); EE_Error::add_attention(sprintf(__('Note, when the invoice payment method is activated, the invoice message type, html messenger, and pdf messenger are activated as well for the %1$smessages system%2$s.', 'event_espresso'), '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', '</a>')); } return $payment_method; }
/** * Creates a payment method of the specified type. Does not save it. * * @global WP_User $current_user * @param EE_PMT_Base $pm_type_obj * @return EE_Payment_Method * @throws \EE_Error */ public function create_payment_method_of_type($pm_type_obj) { global $current_user; $payment_method = EE_Payment_Method::new_instance(array('PMD_type' => $pm_type_obj->system_name(), 'PMD_name' => $pm_type_obj->pretty_name(), 'PMD_admin_name' => $pm_type_obj->pretty_name(), 'PMD_slug' => $pm_type_obj->system_name(), 'PMD_wp_user' => $current_user->ID, 'PMD_order' => EEM_Payment_Method::instance()->count(array(array('PMD_type' => array('!=', 'Admin_Only')))) * 10)); return $payment_method; }