Support the ongoing development of →
IOC Architecture
Last updated 1 year ago.

Hi harhoo,

I think you could use a config file with all country codes and depends on those you put any implementation class.

Then in your ServiceProvider you may use a conditional statement to evaluate the country code selected for the user and populate the class implementation of that Payment Interface.


return [
    'AF' => 'OnePaymentClass',
    'AL' => 'SecondPaymentOptionClass',
    'DZ' => 'OnePaymentClass',
    'AS' => 'OnePaymentClass',


class PaymentServiceProvider extends ServiceProvider {

    public function register(){
        $app->bind('Path\To\Your\PaymentInterface', function(){
              //Set the condition for the selected config value
              //Don't forget this service provider may be deferred

Hope it helps you.

Last updated 1 year ago.

Thanks - I actually had been trying a variation of that but I don't think it works in register() - as am not sure the auth user exists then. Shifting it to boot(), however, worked. Thanks for the prompt!

Last updated 1 year ago.

Great work!

Best regards.

Last updated 1 year ago.

Sign in to participate in this thread!


Your banner here too?

harhoo harhoo Joined 3 Feb 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.