|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Korobovn\CloudPayments; |
|
6
|
|
|
|
|
7
|
|
|
use GuzzleHttp\ClientInterface as GuzzleHttpClientInterface; |
|
8
|
|
|
use Illuminate\Contracts\Config\Repository; |
|
9
|
|
|
use Illuminate\Support\ServiceProvider; |
|
10
|
|
|
use Illuminate\Contracts\Container\Container; |
|
11
|
|
|
use Korobovn\CloudPayments\Client\Client; |
|
12
|
|
|
use Korobovn\CloudPayments\Client\ClientInterface; |
|
13
|
|
|
|
|
14
|
|
|
class CloudPaymentsServiceProvider extends ServiceProvider |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Register package services. |
|
18
|
|
|
* |
|
19
|
|
|
* @return void |
|
20
|
|
|
*/ |
|
21
|
|
|
public function register(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$this->initializeConfigs(); |
|
24
|
|
|
|
|
25
|
|
|
$this->app->bind(Client::class, function (Container $app) { |
|
26
|
|
|
$http_client = $app->make(GuzzleHttpClientInterface::class); |
|
27
|
|
|
/** @var Repository $config */ |
|
28
|
|
|
$config = $app->make(Repository::class); |
|
29
|
|
|
|
|
30
|
|
|
return new Client( |
|
31
|
|
|
$http_client, |
|
32
|
|
|
$config->get(static::getConfigRootKeyName() . '.cloud_payments.public_key', ''), |
|
33
|
|
|
$config->get(static::getConfigRootKeyName() . '.cloud_payments.private_key', '') |
|
34
|
|
|
); |
|
35
|
|
|
}); |
|
36
|
|
|
|
|
37
|
|
|
$this->app->bind(ClientInterface::class, Client::class); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Returns path to the configuration file. |
|
42
|
|
|
* |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
|
|
public static function getConfigPath() |
|
46
|
|
|
{ |
|
47
|
|
|
return __DIR__ . '/../config/services.php'; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Get config root key name. |
|
52
|
|
|
* |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
|
|
public static function getConfigRootKeyName() |
|
56
|
|
|
{ |
|
57
|
|
|
return \basename(static::getConfigPath(), '.php'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Initialize configs. |
|
62
|
|
|
* |
|
63
|
|
|
* @return void |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function initializeConfigs(): void |
|
66
|
|
|
{ |
|
67
|
|
|
$this->mergeConfigFrom(static::getConfigPath(), static::getConfigRootKeyName()); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|