public function setUp() { parent::setUp(); //make sure caf payment methods are registered new EE_Brewing_Regular(); EE_Payment_Method_Manager::reset(); }
/** * Method for registering new EE_PMT_Base children * * @since 4.5.0 * @param string $payment_method_id a unique identifier for this set of modules Required. * @param array $setup_args an array of arguments provided for registering modules Required.{ * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains the files * EE_PMT_Payomatic.pm.php) * } * @throws EE_Error * @internal param string payment_method_paths an array of full server paths to folders containing any EE_PMT_Base children, or to the EED_Module files themselves * @return void */ public static function register($payment_method_id = NULL, $setup_args = array()) { //required fields MUST be present, so let's make sure they are. if (empty($payment_method_id) || !is_array($setup_args) || empty($setup_args['payment_method_paths'])) { throw new EE_Error(__('In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)', 'event_espresso')); } //make sure we don't register twice if (isset(self::$_settings[$payment_method_id])) { return; } //make sure this was called in the right place! if (!did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')) { EE_Error::doing_it_wrong(__METHOD__, __('An attempt to register modules has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.', 'event_espresso'), '4.3.0'); } //setup $_settings array from incoming values. self::$_settings[$payment_method_id] = array('payment_method_paths' => isset($setup_args['payment_method_paths']) ? (array) $setup_args['payment_method_paths'] : array()); // add to list of modules to be registered add_filter('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', array('EE_Register_Payment_Method', 'add_payment_methods')); /** * If EE_Payment_Method_Manager::register_payment_methods has already been called, we need it to be called again * (because it's missing the paymetn method we JUST registered here). We are assuming EE_Register_payment_method::register() * will be called only once per payment method from an addon, so going with that assumption we should always do this. * If that assumption is false, we should verify this newly-registered paymetn method isn't on the EE_Payment_Method_Manager::_payment_method_types array before calling this (this code should be changed to improve performance) */ if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) { EE_Registry::instance()->load_lib('Payment_Method_Manager'); EE_Payment_Method_Manager::instance()->maybe_register_payment_methods(TRUE); } }
/** * unit tests inherited from parent */ public function setUp() { parent::setUp(); $this->_pretend_addon_hook_time(); EE_Register_Payment_Method::register('onsite', array('payment_method_paths' => array(EE_TESTS_DIR . 'mocks' . DS . 'payment_methods' . DS . 'Mock_Onsite'))); EE_Register_Payment_Method::register('offsite', array('payment_method_paths' => array(EE_TESTS_DIR . 'mocks' . DS . 'payment_methods' . DS . 'Mock_Offsite'))); EE_Payment_Method_Manager::instance()->reset(); //unlike EE_Payment_Processor_With_Messages, this is integration testing //and so we want to leave messages hooks in-place }
/** * setUp */ public function setUp() { $return_value = parent::setUp(); //EEG_Paypal_Pro uses $_SERVER at some point, so we need to pretend this is a regular request $this->go_to('http://localhost/'); //just set a random address $_SERVER['REMOTE_ADDR'] = '192.0.0.1'; add_filter('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', '__return_false'); //make sure caf payment methods are registered new EE_Brewing_Regular(); EE_Payment_Method_Manager::reset(); return $return_value; }
public function test_register__success() { EE_Register_Payment_Method::deregister($this->_pmt_name); $this->_pretend_addon_hook_time(); //double-check no one else is filtering payment method types remove_all_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register'); //first verify it doesn't already exists $pmt_exists = EE_Payment_Method_Manager::reset()->payment_method_type_exists($this->_pmt_name); $this->assertFalse($pmt_exists); EE_Register_Payment_Method::register($this->_pmt_name, $this->_pmt_args); //now check it does exist $pmt_exists = EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->_pmt_name, TRUE); $this->assertTrue($pmt_exists); }
public function setUp() { parent::setUp(); $this->_pretend_addon_hook_time(); EE_Register_Payment_Method::register('onsite', array('payment_method_paths' => array(EE_TESTS_DIR . 'mocks' . DS . 'payment_methods' . DS . 'Mock_Onsite'))); EE_Register_Payment_Method::register('offsite', array('payment_method_paths' => array(EE_TESTS_DIR . 'mocks' . DS . 'payment_methods' . DS . 'Mock_Offsite'))); EE_Payment_Method_Manager::instance()->reset(); //remove all actions that have been added by messages because we aren't testing them here. remove_all_actions('AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'); remove_all_actions('AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'); remove_all_actions('AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'); remove_all_actions('AHEE__EE_Payment_Processor__update_txn_based_on_payment'); }
/** * Makes sure the default payment method (Invoice) is active. * This used to be done automatically as part of constructing the old gateways config */ public static function insert_default_payment_methods() { if (!EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { EE_Registry::instance()->load_lib('Payment_Method_Manager'); EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); } else { EEM_Payment_Method::instance()->verify_button_urls(); } }
/** * Processes the payment method form that was submitted. This is slightly trickier than usual form * processing because we first need to identify WHICH form was processed and which payment method * it corresponds to. Once we have done that, we see if the form is valid. If it is, the * form's data is saved and we redirect to the default payment methods page, setting the updated payment method * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the * subsequently called 'headers_sent_func' which is _payment_methods_list) * @return void */ protected function _update_payment_method() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { //ok let's find which gateway form to use based on the form input EE_Registry::instance()->load_lib('Payment_Method_Manager'); /** @var $correct_pmt_form_to_use EE_Payment_Method_Form */ $correct_pmt_form_to_use = NULL; $pmt_obj = NULL; foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) { /** @var $pmt_obj EE_PMT_Base */ //get the form and simplify it, like what we do when we display it $pmt_form = $pmt_obj->settings_form(); $this->_simplify_form($pmt_form); if ($pmt_form->form_data_present_in($this->_req_data)) { $correct_pmt_form_to_use = $pmt_form; break; } } //if we couldn't find the correct payment method type... if (!$correct_pmt_form_to_use) { EE_Error::add_error(__("We could not find which payment method type your form submission related to. Please contact support", 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); $this->_redirect_after_action(FALSE, 'Payment Method', 'activated', array('action' => 'default')); } $correct_pmt_form_to_use->receive_form_submission($this->_req_data); if ($correct_pmt_form_to_use->is_valid()) { $correct_pmt_form_to_use->save(); $pm = $correct_pmt_form_to_use->get_model_object(); /** @var $pm EE_Payment_Method */ $this->_redirect_after_action(TRUE, 'Payment Method', 'updated', array('action' => 'default', 'payment_method' => $pm->slug())); } else { EE_Error::add_error(sprintf(__('Payment method of type %s was not saved because there were validation errors. They have been marked in the form', 'event_espresso'), $pmt_obj instanceof EE_PMT_Base ? $pmt_obj->pretty_name() : __('"(unknown)"', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__); } } return; }
/** * Gets the payment method type for this payment method instance * @return EE_PMT_Base * @throws EE_Error */ public function type_obj() { if (!$this->_type_obj) { EE_Registry::instance()->load_lib('Payment_Method_Manager'); if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); if (!class_exists($class_name)) { throw new EE_Error(sprintf(__('An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', 'event_espresso'), $class_name, '<br />', '<a href="' . admin_url('plugins.php') . '">', '</a>')); } $r = new ReflectionClass($class_name); $this->_type_obj = $r->newInstanceArgs(array($this)); } else { throw new EE_Error(sprintf(__('A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', 'event_espresso'), $this->type(), implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()))); } } return $this->_type_obj; }
/** * This just updates the active_messengers usermeta field when a messenger or message type is activated/deactivated. * NOTE: deactivating will remove the messenger (or message type) from the active_messengers wp_options field so all saved settings WILL be lost for the messenger AND message_types associated with that messenger (or message type). * * @param string $messenger What messenger we're toggling * @param boolean $deactivate if true then we deactivate * @param mixed $message_type if present what message type we're toggling * @return void */ protected function _activate_messenger($messenger, $deactivate = FALSE, $message_type = FALSE) { global $espresso_wp_user; $templates = TRUE; $this->_set_m_mt_settings(); if (!$deactivate) { //we are activating. we can use $this->_m_mt_settings to get all the installed messengers $this->_active_messengers[$messenger]['settings'] = !isset($this->_active_messengers[$messenger]['settings']) ? array() : $this->_active_messengers[$messenger]['settings']; $this->_active_messengers[$messenger]['obj'] = $this->_m_mt_settings['messenger_tabs'][$messenger]['obj']; //get has_active so we can sure its kept up to date. $has_activated = get_option('ee_has_activated_messages'); if (empty($has_activated[$messenger])) { $has_activated[$messenger] = array(); } //k we need to get what default message types are to be associated with the messenger that's been activated. $default_types = $message_type ? (array) $message_type : $this->_active_messengers[$messenger]['obj']->get_default_message_types(); foreach ($default_types as $type) { $settings_fields = $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'][$type]['obj']->get_admin_settings_fields(); if (!empty($settings_fields)) { //we have fields for this message type so let's get the defaults for saving. foreach ($settings_fields as $field => $values) { $settings[$field] = $values['default']; } //let's set the data for reloading this message type form in ajax $this->_template_args['data']['mt_reload'][] = $type; } else { $settings = array(); } $this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'][$type]['settings'] = $settings; if (!in_array($type, $has_activated[$messenger])) { $has_activated[$messenger][] = $type; } } //any default settings for the messenger? $msgr_settings = $this->_active_messengers[$messenger]['obj']->get_admin_settings_fields(); if (!empty($msgr_settings)) { foreach ($msgr_settings as $field => $value) { $this->_active_messengers[$messenger]['settings'][$field] = $value; } } //update settings in database EEH_MSG_Template::update_active_messengers_in_db($this->_active_messengers); update_option('ee_has_activated_messages', $has_activated); //generate new templates (if necessary) $templates = $this->_generate_new_templates($messenger, $default_types, 0, TRUE); EE_Error::overwrite_success(); //if generation failed then we need to remove the active messenger. if (!$templates) { unset($this->_active_messengers[$messenger]); EEH_MSG_Template::update_active_messengers_in_db($this->_active_messengers); } else { //all is good let's do a success message if ($message_type) { EE_Error::add_success(sprintf(__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), ucwords($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'][$message_type]['obj']->label['singular']), ucwords($this->_active_messengers[$messenger]['obj']->label['singular']))); //if message type was invoice then let's make sure we activate the invoice payment method. if ($message_type == 'invoice') { EE_Registry::instance()->load_lib('Payment_Method_Manager'); $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); if ($pm instanceof EE_Payment_Method) { EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', 'event_espresso')); } } } else { EE_Error::add_success(sprintf(__('%s messenger has been successfully activated', 'event_espresso'), ucwords($this->_active_messengers[$messenger]['obj']->label['singular']))); } } $this->_template_args['data']['active_mts'] = $default_types; } else { //we're deactivating $MTP = EEM_Message_Template_Group::instance(); //okay let's update the message templates that match this messenger so that they are deactivated in the database as well. $update_array = array('MTP_messenger' => $messenger); if ($message_type) { $update_array['MTP_message_type'] = $message_type; } $success = $MTP->update(array('MTP_is_active' => 0), array($update_array)); $messenger_obj = $this->_active_messengers[$messenger]['obj']; //if this is a message type deactivation then we're only unsetting the message type otherwise unset the messenger if ($message_type) { unset($this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'][$message_type]); } else { unset($this->_active_messengers[$messenger]); } EEH_MSG_Template::update_active_messengers_in_db($this->_active_messengers); EE_Error::overwrite_success(); if ($message_type) { EE_Error::add_success(sprintf(__('%s message type has been successfully deactivated', 'event_espresso'), ucwords($this->_m_mt_settings['message_type_tabs'][$messenger]['active'][$message_type]['obj']->label['singular']))); } else { EE_Error::add_success(sprintf(__('%s messenger has been successfully deactivated', 'event_espresso'), ucwords($messenger_obj->label['singular']))); } //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. if ($messenger == 'html' || $message_type == 'invoice') { EE_Registry::instance()->load_lib('Payment_Method_Manager'); $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); if ($count_updated > 0) { $msg = $message_type == 'invoice' ? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then vist the payment methods admin page to reactivate the invoice payment method.', 'event_espresso') : __('Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', 'event_espresso'); EE_Error::add_attention($msg); } } } return true; }
/** * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, * but also verifies the payment method type of each is a usable object. If not, * deactivate it, sets a notification, and deactivates it * @param array $rows * @return EE_Payment_Method[] */ protected function _create_objects($rows = array()) { EE_Registry::instance()->load_lib('Payment_Method_Manager'); $payment_methods = parent::_create_objects($rows); /* @var $payment_methods EE_Payment_Method[] */ $usable_payment_methods = array(); foreach ($payment_methods as $key => $payment_method) { if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { $usable_payment_methods[$key] = $payment_method; //some payment methods enqueue their scripts in EE_PMT_*::__construct //which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue //its scripts). but for backwards-compat we should continue to do that $payment_method->type_obj(); } elseif ($payment_method->active()) { //only deactivate and notify the admin if the payment is active somewhere $payment_method->deactivate(); $payment_method->save(); EE_Error::add_persistent_admin_notice('auto-deactivated-' . $payment_method->type(), sprintf(__('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', 'event_espresso'), $payment_method->admin_name(), '<br />', '<a href="' . admin_url('plugins.php') . '">', '</a>'), true); } } return $usable_payment_methods; }
/** * This sets up the appropriate response for deactivating a messenger and/or message type. * * @param EE_messenger $messenger * @param EE_message_type|null $message_type * * @return bool */ protected function _setup_response_message_for_deactivating_messenger_with_message_types($messenger, EE_message_type $message_type = null) { EE_Error::overwrite_success(); //if $messenger isn't a valid messenger object then get out. if (!$messenger instanceof EE_Messenger) { EE_Error::add_error(__('The messenger being deactivated is not a valid messenger', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); return false; } if ($message_type instanceof EE_message_type) { $message_type_name = $message_type->name; EE_Error::add_success(sprintf(__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), ucwords($message_type->label['singular']), ucwords($messenger->label['singular']))); } else { $message_type_name = ''; EE_Error::add_success(sprintf(__('%s messenger has been successfully deactivated.', 'event_espresso'), ucwords($messenger->label['singular']))); } //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. if ($messenger->name == 'html' || $message_type_name == 'invoice') { EE_Registry::instance()->load_lib('Payment_Method_Manager'); $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); if ($count_updated > 0) { $msg = $message_type_name == 'invoice' ? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', 'event_espresso') : __('Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', 'event_espresso'); EE_Error::add_attention($msg); } } return true; }
/** * Resets the instance and returns a new one * @return EE_Payment_Method_Manager */ public static function reset() { self::$_instance = NULL; return self::instance(); }
/** * Gets the payment method type for this payment method instance * @return EE_PMT_Base * @throws EE_Error */ public function type_obj() { if (!$this->_type_obj) { EE_Registry::instance()->load_lib('Payment_Method_Manager'); if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); if (!class_exists($class_name)) { throw new EE_Error(sprintf(__("There is no payment method type of class '%s', did you deactivate an EE addon?", "event_espresso"), $class_name)); } $r = new ReflectionClass($class_name); $this->_type_obj = $r->newInstanceArgs(array($this)); } else { throw new EE_Error(sprintf(__('A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', 'event_espresso'), $this->type(), implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()))); } } return $this->_type_obj; }