1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Laravel Paystack package. |
5
|
|
|
* |
6
|
|
|
* (c) Prosper Otemuyiwa <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Unicodeveloper\Paystack; |
13
|
|
|
|
14
|
|
|
use GuzzleHttp\Client; |
15
|
|
|
use Illuminate\Support\ServiceProvider; |
16
|
|
|
|
17
|
|
|
class PaystackServiceProvider extends ServiceProvider |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/* |
21
|
|
|
* Indicates if loading of the provider is deferred. |
22
|
|
|
* |
23
|
|
|
* @var bool |
24
|
|
|
*/ |
25
|
|
|
protected $defer = false; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Placeholder for base URL. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $baseUrl; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Placeholder for secret key. |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $secretKey; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Placeholder for GuzzleHttp\Client. |
43
|
|
|
* |
44
|
|
|
* @var \GuzzleHttp\Cient |
45
|
|
|
*/ |
46
|
|
|
protected $client; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Publishes all the config file this package needs to function |
50
|
|
|
*/ |
51
|
|
|
public function boot() |
52
|
|
|
{ |
53
|
|
|
$config = realpath(__DIR__.'/../resources/config/paystack.php'); |
54
|
|
|
|
55
|
|
|
$this->publishes([ |
56
|
|
|
$config => config_path('paystack.php') |
57
|
|
|
]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Register the application services. |
62
|
|
|
*/ |
63
|
|
|
public function register() |
64
|
|
|
{ |
65
|
|
|
$this->bootstrapConfig(); |
66
|
|
|
|
67
|
|
|
$this->app->singleton('laravel-paystack', function ($app) { |
|
|
|
|
68
|
|
|
|
69
|
|
|
return new Paystack($this->client); |
70
|
|
|
|
71
|
|
|
}); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get the services provided by the provider |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
public function provides() |
79
|
|
|
{ |
80
|
|
|
return ['laravel-paystack']; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Bootstraps configuration if configuration file exists. |
85
|
|
|
* |
86
|
|
|
* @return void |
87
|
|
|
*/ |
88
|
|
|
protected function bootstrapConfig() |
89
|
|
|
{ |
90
|
|
|
$this->setDependencies(); |
91
|
|
|
$this->setClient(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Called upon to set required meta dependencies. |
96
|
|
|
*/ |
97
|
|
|
protected function setDependencies() |
98
|
|
|
{ |
99
|
|
|
$this->setBaseUrl(); |
100
|
|
|
|
101
|
|
|
$this->setSecretToken(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Set the base url from conig. |
106
|
|
|
*/ |
107
|
|
|
protected function setBaseUrl() |
108
|
|
|
{ |
109
|
|
|
$this->baseUrl = $this->app["config"]->get("paystack.paymentUrl"); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Set the base url from conig. |
114
|
|
|
*/ |
115
|
|
|
protected function setSecretToken() |
116
|
|
|
{ |
117
|
|
|
$this->secretKey = $this->app["config"]->get("paystack.secretKey"); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Set guzzle client. |
122
|
|
|
*/ |
123
|
|
|
protected function setClient() |
124
|
|
|
{ |
125
|
|
|
$this->client = new Client([ |
|
|
|
|
126
|
|
|
"base_uri" => $this->baseUrl, |
127
|
|
|
'headers' => [ |
128
|
|
|
'Authorization' => "Bearer {$this->secretKey}", |
129
|
|
|
'Content-Type' => 'application/json', |
130
|
|
|
'Accept' => 'application/json' |
131
|
|
|
], |
132
|
|
|
]); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.