TransWikia.com

Restricting Payment Gatways by User Group using Commerce Pro?

Craft CMS Asked by Owen on January 17, 2021

Is it possible to restrict payment gateways on a per user group basis?

e.g. Say you want a user group to assign users into from a certain country that cannot use PayPal, so you can offer them a different gateway instead?

Thanks

One Answer

This is really more of a Craft general thing than Commerce per se, if you're content to simply 'restrict' them by only showing them the appropriate options depends on their group.

If so, then it's as simple as some twig code to test the user group and show/not show things accordingly.

{% if currentUser.isInGroup('groupHandle') %}
   ... show something
{% else %}
   ... show something else
{% endif %}

(Of course that requires a logged in user and the bigger questions here is whether user groups is the right way to handle this scenario...)

If you want to take things further, you could listen to various Commerce events in a custom module and take action there if they should/shouldn't be allowed to do what they arte doing. You might look at:

https://craftcms.com/docs/commerce/3.x/events.html#beforeprocesspaymentevent

https://craftcms.com/docs/commerce/3.x/events.html#beforecompleteorder

...or others - they are listed here:

https://craftcms.com/docs/commerce/3.x/events.html

In reality, as usual, probably some combination of front end logic and back end verification would be the way to go.

Hopefully that is enough to get you started!

Answered by Jeremy Daalder on January 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP