I created a custom service provider for paypal. When I try to access config from inside the provider, it returns null.
Below is the code I wrote.
public function register()
{
$this->app->singleton(ApiContext::class, function($app){
$paypalConf = $app['config']->get('paypal');
$apiContext = new ApiContext(new OAuthTokenCredential(
$paypalConf['client_id'],$paypalConf['client_secret']
));
$apiContext->setConfig($paypalConf['settings']);
return $apiContext;
});
}
But it throws following error
if (empty($credObj)) {
throw new PayPalInvalidCredentialException("Credential not found for " . ($userId ? $userId : " default user") .
". Please make sure your configuration/APIContext has credential information");
}
"Credential not found for default user. Please make sure your configuration/APIContext has credential information
Which is certainly because my config file is returning null.
Here is my paypal.php
return [
'client_id' => env('PAYPAL_CLIENT_ID', ''),
'client_secret' => env('PAYPAL_SECRET', ''),
'settings' => [
'mode' => env('PAYPAL_MODE', ''),
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => storage_path().'/logs/paypal.log',
'log.LogLevel' => 'ERROR'
]];
and the PAYPAL credentials exists in .env file.
I have tried clearing the config and caching it again, but it didn't work.
Update
Seems like the register method isn't working in the service provider. But I have registered the provider in config/app.php
dd($paypalConf, $app['config']->get('app.name'))
, in the service provider after first line? I smell a typo kind of error. – Kyslikconfig/app.php
? – Kyslik