Test Failed
Push — master ( 8a0687...d273b7 )
by Olayemi
14:11
created

Paystack::recipent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Iamolayemi\Paystack;
4
5
use Iamolayemi\Paystack\Endpoints\Balance;
6
use Iamolayemi\Paystack\Endpoints\Bank;
7
use Iamolayemi\Paystack\Endpoints\Country;
8
use Iamolayemi\Paystack\Endpoints\Customer;
9
use Iamolayemi\Paystack\Endpoints\DedicatedAccount;
10
use Iamolayemi\Paystack\Endpoints\Invoice;
11
use Iamolayemi\Paystack\Endpoints\Page;
12
use Iamolayemi\Paystack\Endpoints\Plan;
13
use Iamolayemi\Paystack\Endpoints\Product;
14
use Iamolayemi\Paystack\Endpoints\Refund;
15
use Iamolayemi\Paystack\Endpoints\Resolve;
16
use Iamolayemi\Paystack\Endpoints\Settlement;
17
use Iamolayemi\Paystack\Endpoints\Split;
18
use Iamolayemi\Paystack\Endpoints\SubAccount;
19
use Iamolayemi\Paystack\Endpoints\Subscription;
20
use Iamolayemi\Paystack\Endpoints\Transaction;
21
use Iamolayemi\Paystack\Endpoints\Transfer;
22
use Iamolayemi\Paystack\Endpoints\TransferRecipient;
23
use Illuminate\Http\Client\PendingRequest;
24
use Illuminate\Support\Facades\Http;
25
26
class Paystack
27
{
28
    /**
29
     * @var string
30
     */
31
    protected string $secretKey;
32
33
    /**
34
     * @var PendingRequest|null
35
     */
36
    private ?PendingRequest $connection = null;
37
38
    /**
39
     * Paystack constructor.
40
     * @param string $secretKey
41
     */
42
    public function __construct(string $secretKey)
43
    {
44
        $this->setSecretKey($secretKey);
45
        $this->connect();
46
    }
47
48
    private function setSecretKey($secretKey): void
49
    {
50
        $this->secretKey = $secretKey;
51
    }
52
53
54
    /**
55
     * @return void
56
     */
57
    private function connect(): void
58
    {
59
        $this->connection = Http::withToken($this->secretKey);
60
    }
61
62
    /**
63
     * @return PendingRequest|null
64
     */
65
    public function getConnection(): ?PendingRequest
66
    {
67
        return $this->connection;
68
    }
69
70
    /**
71
     * Generates a unique reference
72
     *
73
     * @param  String|null  $transactionPrefix
74
     * @return string
75
     */
76
77
    public function generateReference(String $transactionPrefix = NULL): string
78
    {
79
        if ($transactionPrefix) {
80
            return $transactionPrefix . '_' . uniqid(time());
81
        }
82
        return 'PK_' . uniqid(time());
83
    }
84
85
    /**
86
     * Create a new Balance instance.
87
     *
88
     * @throws \Exception
89
     */
90
    public function balance(): Balance
91
    {
92
        return new Balance($this);
93
    }
94
95
    /**
96
     * Create a new Bank instance.
97
     *
98
     * @throws \Exception
99
     */
100
    public function bank(): Bank
101
    {
102
        return new Bank($this);
103
    }
104
105
    /**
106
     * Create a new Country instance.
107
     *
108
     * @throws \Exception
109
     */
110
    public function country(): Country
111
    {
112
        return new Country($this);
113
    }
114
115
    /**
116
     * Create a new customer instance.
117
     *
118
     * @throws \Exception
119
     */
120
    public function customer(): Customer
121
    {
122
        return new Customer($this);
123
    }
124
125
    /**
126
     * Create a new dedicated account instance.
127
     *
128
     * @throws \Exception
129
     */
130
    public function dedicatedAccount(): DedicatedAccount
131
    {
132
        return new DedicatedAccount($this);
133
    }
134
135
    /**
136
     * Create a new invoice instance.
137
     *
138
     * @throws \Exception
139
     */
140
    public function invoice(): Invoice
141
    {
142
        return new Invoice($this);
143
    }
144
145
    /**
146
     * Create a new page instance.
147
     *
148
     * @throws \Exception
149
     */
150
    public function page(): Page
151
    {
152
        return new Page($this);
153
    }
154
155
    /**
156
     * Create a new plan instance.
157
     *
158
     * @throws \Exception
159
     */
160
    public function plan(): Plan
161
    {
162
        return new Plan($this);
163
    }
164
165
    /**
166
     * Create a new Product instance.
167
     *
168
     * @throws \Exception
169
     */
170
    public function product(): Product
171
    {
172
        return new Product($this);
173
    }
174
175
    /**
176
     * Create a new TransferRecipient instance.
177
     *
178
     * @throws \Exception
179
     */
180
    public function recipient(): TransferRecipient
181
    {
182
        return new TransferRecipient($this);
183
    }
184
185
    /**
186
     * Create a new Refund instance.
187
     *
188
     * @throws \Exception
189
     */
190
    public function refund(): Refund
191
    {
192
        return new Refund($this);
193
    }
194
195
    /**
196
     * Create a new Resolve instance.
197
     *
198
     * @throws \Exception
199
     */
200
    public function resolve(): Resolve
201
    {
202
        return new Resolve($this);
203
    }
204
205
    /**
206
     * Create a new Settlement instance.
207
     *
208
     * @throws \Exception
209
     */
210
    public function settlement(): Settlement
211
    {
212
        return new Settlement($this);
213
    }
214
215
    /**
216
     * Create a new split transaction instance.
217
     *
218
     * @throws \Exception
219
     */
220
    public function split(): Split
221
    {
222
        return new Split($this);
223
    }
224
225
    /**
226
     * Create a new SubAccount instance.
227
     *
228
     * @throws \Exception
229
     */
230
    public function subAccount(): SubAccount
231
    {
232
        return new SubAccount($this);
233
    }
234
235
    /**
236
     * Create a new Subscription instance.
237
     *
238
     * @throws \Exception
239
     */
240
    public function subscription(): Subscription
241
    {
242
        return new Subscription($this);
243
    }
244
245
    /**
246
     * Create a new transaction instance.
247
     *
248
     * @throws \Exception
249
     */
250
    public function transaction(): Transaction
251
    {
252
        return new Transaction($this);
253
    }
254
255
    /**
256
     * Create a new Transfer instance.
257
     *
258
     * @throws \Exception
259
     */
260
    public function transfer(): Transfer
261
    {
262
        return new Transfer($this);
263
    }
264
}
265