|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sebdesign\VivaPayments; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Client as GuzzleClient; |
|
6
|
|
|
use Illuminate\Contracts\Support\DeferrableProvider; |
|
7
|
|
|
use Illuminate\Support\ServiceProvider; |
|
8
|
|
|
use Sebdesign\VivaPayments\Enums\Environment; |
|
9
|
|
|
|
|
10
|
|
|
class VivaPaymentsServiceProvider extends ServiceProvider implements DeferrableProvider |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Register the application services. |
|
14
|
|
|
* |
|
15
|
|
|
* @return void |
|
16
|
|
|
*/ |
|
17
|
78 |
|
public function register() |
|
18
|
|
|
{ |
|
19
|
78 |
|
$this->mergeConfigFrom(__DIR__.'/../config/services.php', 'services'); |
|
20
|
|
|
|
|
21
|
78 |
|
$this->app->singleton(Client::class, function ($app) { |
|
22
|
51 |
|
return new Client( |
|
23
|
51 |
|
$this->buildGuzzleClient(), |
|
24
|
51 |
|
Environment::from($app->make('config')->get('services.viva.environment')), |
|
25
|
51 |
|
merchantId: strval($app->make('config')->get('services.viva.merchant_id')), |
|
26
|
51 |
|
apiKey: strval($app->make('config')->get('services.viva.api_key')), |
|
27
|
51 |
|
clientId: strval($app->make('config')->get('services.viva.client_id')), |
|
28
|
51 |
|
clientSecret: strval($app->make('config')->get('services.viva.client_secret')), |
|
29
|
|
|
); |
|
30
|
|
|
}); |
|
31
|
|
|
|
|
32
|
78 |
|
$this->app->bind(OAuth::class, function ($app) { |
|
33
|
3 |
|
return new OAuth( |
|
34
|
3 |
|
client: $app->make(Client::class), |
|
35
|
3 |
|
clientId: strval($app->make('config')->get('services.viva.client_id')), |
|
36
|
3 |
|
clientSecret: strval($app->make('config')->get('services.viva.client_secret')), |
|
37
|
|
|
); |
|
38
|
|
|
}); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Build the Guzzlehttp client. |
|
43
|
|
|
*/ |
|
44
|
51 |
|
protected function buildGuzzleClient(): GuzzleClient |
|
45
|
|
|
{ |
|
46
|
51 |
|
return new GuzzleClient([ |
|
47
|
51 |
|
'curl' => $this->curlDoesntUseNss() |
|
48
|
51 |
|
? [CURLOPT_SSL_CIPHER_LIST => 'TLSv1.2'] |
|
49
|
|
|
: [], |
|
50
|
|
|
]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Check if cURL doens't use NSS. |
|
55
|
|
|
*/ |
|
56
|
51 |
|
protected function curlDoesntUseNss(): bool |
|
57
|
|
|
{ |
|
58
|
51 |
|
$curl = curl_version(); |
|
59
|
|
|
|
|
60
|
|
|
// @codeCoverageIgnoreStart |
|
61
|
|
|
if (! isset($curl['ssl_version'])) { |
|
62
|
|
|
return true; |
|
63
|
|
|
} |
|
64
|
|
|
// @codeCoverageIgnoreEnd |
|
65
|
|
|
|
|
66
|
51 |
|
return preg_match('/NSS/', $curl['ssl_version']) !== 1; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get the services provided by the provider. |
|
71
|
|
|
* |
|
72
|
|
|
* @return array<int,string> |
|
73
|
|
|
*/ |
|
74
|
3 |
|
public function provides() |
|
75
|
|
|
{ |
|
76
|
3 |
|
return [Client::class, OAuth::class]; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|