/**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton(MangoPayApi::class, function (Application $app) {
         // Load the configuration and instantiate the API
         $config = $app['config']['services.mangopay'];
         $api = new MangoPayApi();
         // Set the client id and password
         if (!($clientId = array_get($config, 'key'))) {
             throw new InvalidArgumentException('Mangopay key not configured');
         }
         if (!($clientPassword = array_get($config, 'secret'))) {
             throw new InvalidArgumentException('Mangopay secret not configured');
         }
         if (!($env = array_get($config, 'env'))) {
             throw new InvalidArgumentException('Mangopay environment not configured');
         }
         $api->Config->ClientId = $clientId;
         $api->Config->ClientPassword = $clientPassword;
         // Set the base URL based on the environment defined in config
         $api->Config->BaseUrl = $this->getURL($env);
         // Use the Laravel logger
         $api->setLogger($app['log']);
         // Set a custom storage strategy if set in config
         if ($storageClass = array_get($app['config'], 'mangopay.StorageClass', null)) {
             $storageClass = $app->make($storageClass);
             $api->OAuthTokenManager->RegisterCustomStorageStrategy($storageClass);
         }
         // Set a default temp folder (can be overridden in the config,
         // but should be different for each environment according to
         // the Mangopay SDK specifications)
         $path = storage_path('mangopay' . DIRECTORY_SEPARATOR . $env . DIRECTORY_SEPARATOR);
         $api->Config->TemporaryFolder = $path;
         // Set any extra options specified in the configuration
         $extras = array_get($app['config'], 'mangopay', []);
         foreach ($extras as $property => $value) {
             if ($property === 'StorageClass') {
                 $storageClass = $app->make($value);
                 $api->OAuthTokenManager->RegisterCustomStorageStrategy($storageClass);
             } else {
                 $api->Config->{$property} = $value;
             }
         }
         // Return the configured API client
         return $api;
     });
     $this->app->bind('command.mangopay:mkdir', CreateDirectories::class);
     $this->commands(['command.mangopay:mkdir']);
 }
 public function __construct($clientId, $clientPassword, $baseUrl, EventDispatcherInterface $dispatcher, EntityManager $entityManager, $debug = false)
 {
     parent::__construct();
     $this->Config->ClientId = $clientId;
     $this->Config->ClientPassword = $clientPassword;
     $this->Config->TemporaryFolder = sys_get_temp_dir();
     $this->Config->BaseUrl = $baseUrl;
     $this->Config->DebugMode = $debug;
     $this->dispatcher = $dispatcher;
     $this->entityManager = $entityManager;
 }