Splitting 'Default Payment Gateway' & 'other payment gateway' based on user group?

Permalink Browser Info Environment
Hi there, I'm trying to work out a way to split the payment gateway based on user group. If a member has an 'invoice-based' agreement with the client, they access the default gateway and the invoice is handled seperately, whereas other customers pay in the usual fashion...

method.php is where this happens:

Loader::packageElement('checkout/payment/method','core_commerce', array('action' => $action, 'o'=>$order,'form'=>$form,'form_attribute'=>$form_attribute, 'akHandles'=>$akHandles));

but I'm unsure about how I can proceed from here. Any pointers would be a real help

Thanks in advance for any help :)

Type: Discussion
Status: In Progress
rc255
View Replies:
Korvin replied on at Permalink Reply
Korvin
Hi rc255,
It looks like you can simply tie into the "core_commerce_on_get_payment_methods" event and return an array with the only item being the payment method you want to be used.

Check out this guide for more info: https://www.concrete5.org/documentation/developers/5.6/system/events...
rc255 replied on at Permalink Reply
rc255
Hi Korvin, thanks for your reply. I am stumped with this one... I haven't really delved into the 'hook events' side of things - just can't get my head 'round it

Is there any chance you could give me an example of how to go about it? I'm sure that once I begin to understand hooking events, it will open a whole new world of Concrete5 development...

Cheers mate

Rob
rc255 replied on at Permalink Reply
rc255
Hi there all, can anyone point me in the right direction with this? I just can't get my head 'round the whole 'hooking' element in Concrete5. I've searched everywhere, but I'm not really coming up with anything that works...

Any help would really be appreciated.

Cheers

Rob
Korvin replied on at Permalink Reply
Korvin
Here's a working example:

class MyEventHandler
{
    public function handle($order, $methods)
    {
        $user = new User();
        $group = Group::getByName('Testers');
        if ($user->inGroup($group)) {
            // Return the paypal gateway for users in group "Testers"
            return array(CoreCommercePaymentMethod::getByHandle('paypal_website_payments_standard'));
        }
        // Return just the default gateway for everyone else
        return array(CoreCommercePaymentMethod::getByHandle('default'));
    }
}
Events::extend('core_commerce_on_get_payment_methods', 'MyEventHandler', 'handle');
rc255 replied on at Permalink Reply
rc255
This is brilliant Korvin, thanks very much. Works like a charm. This has been doing my head in for weeks now!

One quick question. I have SagePay as a payment method option. How do I get PayPal and SagePay up as options if the user is in the group?

// Return just the default gateway for everyone else
            return array(CoreCommercePaymentMethod::getByHandle('sagepay_form'));
            return array(CoreCommercePaymentMethod::getByHandle('paypal_website_payments_standard'));


...if you get what I mean...

You have made my day now that this is almost 100% there. Cheers mate!
rc255 replied on at Permalink Reply
rc255
Hi Korvin, I'm still struggling to get multiple payment systems to show up... Is there a way of doing this?

I really hope so. Thanks in advance for your help

Rob
PortlandLabs replied on at Permalink Reply
PortlandLabs
##- Please type your reply above this line -##

Your request (24) has been received and is being reviewed by our support
staff.

To add additional comments, reply to this email.

[image: concrete5]

*concrete5 Community*

Nov 14, 02:25
Korvin replied on at Permalink Reply
Korvin
Hi Rob,
In PHP you can only return from a function once. However since we're returning an array, we can simply add the payment method there:

// Return just the default gateway for everyone else
return array(
    CoreCommercePaymentMethod::getByHandle('sagepay_form'),
    CoreCommercePaymentMethod::getByHandle('paypal_website_payments_standard')
);
PortlandLabs replied on at Permalink Reply
PortlandLabs
##- Please type your reply above this line -##

Your request (46) has been received and is being reviewed by our support
staff.

To add additional comments, reply to this email.

[image: concrete5]

*concrete5 Community*

Nov 17, 09:43
rc255 replied on at Permalink Reply
rc255
doh! The answer was staring me in the face all the time!

Thanks Korvin, that's brilliant
PortlandLabs replied on at Permalink Reply
PortlandLabs
##- Please type your reply above this line -##

Your request (117) has been received and is being reviewed by our support
staff.

To add additional comments, reply to this email.

[image: concrete5]

*concrete5 Community*

Nov 22, 03:37

concrete5 Environment Information

# concrete5 Version
5.6.2.1

# concrete5 Packages
AddThis (1.0), Designer Content (3.1.1), Downloadable File Purchase (1.2.2), Easy News (1.1), eCommerce (2.8.12), PHP block by ND (1.0), Sage Pay eCommerce Payment Provider (0.9.3), Sidebar Cart (0.9).

# concrete5 Overrides
blocks/autonav, blocks/home_featured_story, blocks/sharethis, blocks/rss_events, blocks/page_list, js/slideshow.js, js/fadeslideshow.js, css/core_form.css, themes/FatMonkey

# Server Software
Apache

# Server API
apache2handler

# PHP Version
5.3.10-1ubuntu3.15

# PHP Extensions
apache2handler, apc, bcmath, bz2, calendar, Core, ctype, curl, date, dba, dom, ereg, exif, fileinfo, filter, ftp, gd, gettext, hash, iconv, imap, intl, json, libxml, mbstring, mcrypt, mhash, mysql, mysqli, openssl, pcre, PDO, pdo_mysql, Phar, posix, pspell, Reflection, session, shmop, SimpleXML, soap, sockets, SPL, standard, sysvmsg, sysvsem, sysvshm, tokenizer, wddx, xml, xmlreader, xmlwriter, zip, zlib.

# PHP Settings
max_execution_time - 30

Browser User-Agent String

Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You may not request a refund that is not currently owned by you.