Change API key dynamically
ixperiencenl opened this issue · comments
Specifications
- API Version: "mollie/laravel-mollie": "^2.15",
Describe the issue
- Previously it was possible to change the config vars on runtime. We need this because we have several portals that belong to different API customers. Now, the API uses the .env variable and this is a problem because it's not possible to change the API key on runtime.
I see that there is a 'setApiKey' in the API but this cannot be called from within a controller.
Any solution for this?
...
Hi @ixperiencenl,
Double check:
Is this about mollie-api-php or laravel-mollie (different repo)?
What's the use case?
My bad. Should be indeed in laravel-mollie, had two tabs open... Shall I place it there? Thanks for your very fast response.
Well... if you're going to swap keys dynamically etc I'd actually recommend to use mollie-api-php instead. Consider wiring up the credentials in a service provider OR instantiate a new mollie client when you need it, set the key then. The latter ensures that you're using the right credentials when interacting with Mollie.
ALTERNATIVELY, when using the Laravel package, you should be able to use
mollie()->setApiKey(...);
Allright, thanks a lot. Yes this works (for the Laravel package). Maybe someone can use the info for the API as well in the future.