gopal-g / payment

A laravel package for integrating payment gateways
MIT License
8 stars 9 forks source link

multiple merchant accounts of ccavenue on one site #2

Closed hardevine closed 5 years ago

hardevine commented 6 years ago

we have multiple merchants accounts on single site, how can i make separate instance with different merchants id,credentials etc. ?

gopal-g commented 6 years ago

I think you can change the merchant credentials on the fly using Config Facade.

I would just do this before returning Payment::process($orderData)

\Config::set('payment.ccavenue.merchantId','CURRENT_MERCHANT_ID');

This will change the merchant id only for that instance like this you can switch between all other merchant details.

I think this should do the trick... let me know. 👍

hardevine commented 6 years ago

how about

class CCAvenueCompany1 extends CCAvenueGateway implements PaymentGatewayInterface
{
 public function __construct() {
        $this->workingKey = Config::get('payment.ccavenue.company1.workingKey');
        $this->accessCode = Config::get('payment.ccavenue.company1.accessCode');
        // and so on
     }
}

then in controller

$gw = new Payment(new CCAvenueCompany1());
// now you're good to go

$gw->prepare($parameters);
gopal-g commented 6 years ago

Did u try what i suggested ? Why is that not good. Laravel by itself provides a easy way to change the configuration on the runtime depending on certain requirement. Not using that would defy its purpose altogether.

And what you are suggesting doesn't look right CCAvenue is the payment gateway i don't see the logic behind initialising multiple instances while u can just change the configuration and deal with it.

hardevine commented 6 years ago

needed a way to keep it at one place and also little code to get the instance, but as you have pointed its essentially change of configs not a different gateway, will be trying with config, yeah it worked with config, though.

gopal-g commented 5 years ago

Closing this as this question was answered with a working solution. Thanks.