Support

Home Forums Event Espresso Premium Invoice Payment method for Admin only

Invoice Payment method for Admin only

Posted: January 2, 2020 at 7:41 pm

Viewing 4 reply threads


Daniel

January 2, 2020 at 7:41 pm

I want to provide an Invoice Payment method but only for logged-in admin users.

I found this in another support thread so it seems possible:
https://gist.github.com/Pebblo/f952f806aec55df5f8a1

However, when I install this code the payment method radio button for Invoice does not render on the first load of the payment page. It only shows up when I refresh (registration_checkout) payment page. And then when I choose it as the payment method and hit submit there is an error saying “Invalid Input” which I traced to the validation base class.

It looks like this filter is not operable anymore.
Can you confirm that this code should still load the Invoice Payment Method for Admins and correctly process payment?

Thank you!
D


Tony

  • Support Staff

January 3, 2020 at 7:09 am

Hi Daniel,

The filter is still working otherwise the payment method wouldn’t load at all, why it’s not firing on the initial page load I’m not sure yet but just wanted to confirm I can reproduce this so will be investigating further to see what is happening.


Daniel

January 8, 2020 at 8:54 pm

Hi.

Any luck on discovering the root of this issue?

Thx!


Tony

  • Support Staff

January 9, 2020 at 5:42 am

Yeah, I’ve found the cause and its painfully obvious now I know what it is (as they usually are).

Checkout now loads the payment methods over ajax and ajax requests return true for is_admin(), meaning the !is_admin() check that was on line 10:

https://gist.github.com/Pebblo/f952f806aec55df5f8a1#file-ee-site-specific-plugin-php-L10

prevented the invoice payment method from being loaded on the list of available payment methods when loaded over ajax, the validation then checks the submitted value against the available payment methods (which again at that point does not include ‘Invoice’) and returns an invalid input has been set.

The ‘refresh’ view of checkout isn’t loading them over ajax, it’s loading directly over the request which is why it shows when you refresh, but you get the same issue when you submit.

I’ve updated my snippet and simply removed that check, the Invoice payment method now loads and submits as expected for me. I can’t recall why I added that admin check originally but the section that loads payment methods in the admin, doesn’t use that filter as it just loads all payment methods anyway so this should cause any issues but it would be a good idea to confirm (I did some testing and didn’t run into anything).


Daniel

January 9, 2020 at 12:37 pm

Thank you! I have updated my code to remove that is_admin() call and it seems to be working as described now.

Viewing 4 reply threads

The support post ‘Invoice Payment method for Admin only’ 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.

Event Espresso