Support

Home Forums Event Espresso Premium Filter payment methods

Filter payment methods

Posted: November 18, 2018 at 1:01 pm


ARAGATO

November 18, 2018 at 1:01 pm

I am trying to filter the shown payments methods based on some user metrics.
Some users get those payment methods, while other users get other payment methods.
http://uploads.aragato-server.net/screenshots/201811173e73eb9b50.png

I am trying to use the debug tool that Tony mentioned, but I struggle to find the correct hook/filter in the sea of filters. I found these filters/hooks

AHEE__Single_Page_Checkout___initialize_reg_step__payment_options
AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment
AHEE__Form_Section_Layout__ee_spco_payment_options_reg_step_form_payment_options_before_payment_options
AHEE__Form_Section_Layout__ee_available_payment_method_inputs
AHEE__Form_Section_Layout__spco_payment_method_info_invoice
AHEE__Form_Section_Layout__spco_payment_method_info_check
AHEE__Form_Section_Layout__spco_available_methods_of_payment_dv
AHEE__Form_Section_Layout__ee_spco_payment_options_reg_step_form_payment_options_after_payment_options
AHEE__registration_page_payment_options__payment_info_table_thead_row_end
AHEE__registration_page_payment_options__payment_info_table_tbody_end
AHEE__Form_Section_Layout__ee_payment_options_hidden_inputs
AHEE__Form_Section_Layout__ee_payment_options_extra_hidden_inputs
AHEE__Form_Section_Layout__ee_spco_payment_options_reg_step_form
FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form

None of them are for my intentions. Any hints which one might be the correct one and how to proceed?

I also struggle to find out, once I found a hook, which and how many parameters it takes. Any tips on that?


Tony

  • Support Staff

November 18, 2018 at 2:08 pm

I am trying to use the debug tool that Tony mentioned, but I struggle to find the correct hook/filter in the sea of filters. I found these filters/hooks

Sometimes, Debug bar doesn’t list all of the hooks used so you need to do a little more within the code itself.

I can tell you, that the hook you want to use is:

FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods

I have some examples of using that hook here:

https://gist.github.com/Pebblo/f952f806aec55df5f8a1
https://gist.github.com/Pebblo/c87f5bf42f18380fa6b218dbc5734a34

Those snippets add an additional payment method based on various factors.

EE will have already have pulled in your payment methods are that point and pass them to the hook as an array of EE_Payment_Method objects on the first parameter, so you can unset whichever one you don’t want that specific user to see.

I also struggle to find out, once I found a hook, which and how many parameters it takes. Any tips on that?

The code within the plugin never lies so use the code 🙂

By that I mean we will eventually have some better documentation for all of our hooks, however, things change quickly, so the best place to look is in the code.

Open up Event Espresso in a text editor/IDE (Sublime Text/PHPStorm) and search for the hook, in this case we’ll use the above – http://take.ms/zuqA2

Looking at the docs for apply_filters() it’s:

apply_filters('{filter_name}', [additional params]);

There are multiple options for additional params, they can be passed within an array or individually, EE usually passes each param individually, as is the case here.

Line 371 shows the filter name.

Line 372 is whatever is actually being filtered (in this case an array of EE_Paymnt_Methods)

Lines 373 – 374 are the additional params used to help with filtering (for example you’ll need the transaction object to know what your filtering for).

Meaning for this filter there are 3 parameters.

Does that help?

Our models usually return an array, so this:

$this->get_all_active($scope, array( 'group_by' => 'PMD_type' )),

Is an array of payment methods and this is what is ‘filtered’, you must return the first parameter with your chose value(s) in the same format is was passed.

The doc block above the function adds some details on what is returned and what the function does.


ARAGATO

November 19, 2018 at 9:52 am

Hey, Tony, that was exactly the hook I was looking for. Thanks for the samples. I implemented the needed function on my side and it works.

Back to the proper approach to actually find the correct hook. I do not have any problems getting messy and search through the core code. In fact, I did just that my whole saturday. 😀
However, I obviously was not looking for the right thing. The thing is that I

By that I mean we will eventually have some better documentation for all of our hooks, however, things change quickly, so the best place to look is in the code.

Open up Event Espresso in a text editor/IDE (Sublime Text/PHPStorm) and search for the hook, in this case we’ll use the above – http://take.ms/zuqA2

That is exactly my point, where or how do I get the name of the hook I am searching for in the first place. Do you just grep search all files in the core plugin dir that contain ‘payment’? Or is there another approach/rule that can help to find the hook I am looking for?


Tony

  • Support Staff

November 20, 2018 at 7:52 am

The way I would do it is to log all of the hooks fired on the request and look through those, for that you can use a function like this:

https://gist.github.com/Pebblo/5cef7b7b004b83f527360494f55a162c

Lots of different ways to do this tbh, it depends on what output you want to use, but point being you log all of the hooks and then search through them to see if one is suitable.

So in this example run a registration and search through the hooks when finished, or better yet, open the payment options, enable the function and then refresh the page, now you’ll get the hook specifically for the current request.

Your filtering payment methods so I’d start with within for ‘payment_method’ and see what was available, then ‘payment’ if nothing stood out and so on. Find anything that looks like it handles payment methods and you have a rough idea on where to look in the code by searching for that hook.

Note, don’t leave that function enabled all of the time, EE fires a LOT of hooks, my function logs them once and its still over 300 hooks without duplicates. Your log file is going to fill up quickly if you leave that enabled.


ARAGATO

November 24, 2018 at 4:18 pm

Tony, that is epic.
I wrote a small plugin where I can turn the debug log on and off.

So far I have used this process for two more developments already.
If there is a hook name that sounds promising I just do a grep -rwn -e through ee core dir and it shows me all the files where it is used or applied.

Thanks. Resolved.


Tony

  • Support Staff

November 26, 2018 at 3:00 am

Great, I’m glad that helped 🙂

The support post ‘Filter payment methods’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Tony 9 months ago ago

Topic Tags

Tagged: , , ,

Notifications

This topic is: resolved
Do NOT follow this link or you will be banned from the site!