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

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.

//app/config/countryPayment.php

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

//app/Providers/PaymentServiceProvider.php

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.
0

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.
0

Great work!

Best regards.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

harhoo harhoo Joined 3 Feb 2014

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.