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.
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!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community