16
16
use Unicodeveloper \Paystack \Exceptions \IsNullException ;
17
17
use Unicodeveloper \Paystack \Exceptions \PaymentVerificationFailedException ;
18
18
19
- class Paystack {
20
-
19
+ class Paystack
20
+ {
21
21
/**
22
22
* Transaction Verification Successful
23
23
*/
@@ -30,13 +30,13 @@ class Paystack {
30
30
31
31
/**
32
32
* Issue Secret Key from your Paystack Dashboard
33
- * @var mixed
33
+ * @var string
34
34
*/
35
35
protected $ secretKey ;
36
36
37
37
/**
38
38
* Instance of Client
39
- * @var object
39
+ * @var Client
40
40
*/
41
41
protected $ client ;
42
42
@@ -75,7 +75,6 @@ public function setBaseUrl()
75
75
76
76
/**
77
77
* Get secret key from Paystack config file
78
- * @return void
79
78
*/
80
79
public function setKey ()
81
80
{
@@ -84,22 +83,26 @@ public function setKey()
84
83
85
84
/**
86
85
* Set options for making the Client request
87
- * @return void
88
86
*/
89
87
private function setRequestOptions ()
90
88
{
91
89
$ authBearer = 'Bearer ' . $ this ->secretKey ;
92
90
93
- $ this ->client = new Client (['base_uri ' => $ this ->baseUrl ,
94
- 'headers ' => [
95
- 'Authorization ' => $ authBearer ,
96
- 'Content-Type ' => 'application/json ' ,
97
- 'Accept ' => 'application/json '
98
- ]]);
91
+ $ this ->client = new Client (
92
+ [
93
+ 'base_uri ' => $ this ->baseUrl ,
94
+ 'headers ' => [
95
+ 'Authorization ' => $ authBearer ,
96
+ 'Content-Type ' => 'application/json ' ,
97
+ 'Accept ' => 'application/json '
98
+ ]
99
+ ]
100
+ );
99
101
}
100
102
101
103
/**
102
104
* Initiate a payment request to Paystack
105
+ * @return Paystack
103
106
*/
104
107
public function makePaymentRequest ()
105
108
{
@@ -112,7 +115,7 @@ public function makePaymentRequest()
112
115
"last_name " => request ()->last_name ,
113
116
"callback_url " => request ()->callback_url
114
117
];
115
-
118
+
116
119
// Remove the fields which were not sent (value would be null)
117
120
array_filter ($ data );
118
121
@@ -122,18 +125,30 @@ public function makePaymentRequest()
122
125
}
123
126
124
127
128
+ /**
129
+ * @param string $relativeUrl
130
+ * @param string $method
131
+ * @param array $body
132
+ * @return Paystack
133
+ * @throws IsNullException
134
+ */
125
135
private function setHttpResponse ($ relativeUrl , $ method , $ body = [])
126
136
{
127
- if (is_null ($ method )){
137
+ if (is_null ($ method )) {
128
138
throw new IsNullException ("Empty method not allowed " );
129
139
}
130
140
131
- $ this ->response = $ this ->client ->{strtolower ($ method )}($ this ->baseUrl . $ relativeUrl , ["body " => json_encode ($ body )]);
141
+ $ this ->response = $ this ->client ->{strtolower ($ method )}(
142
+ $ this ->baseUrl . $ relativeUrl ,
143
+ ["body " => json_encode ($ body )]
144
+ );
145
+
132
146
return $ this ;
133
147
}
134
148
135
149
/**
136
150
* Get the authorization url from the callback response
151
+ * @return Paystack
137
152
*/
138
153
public function getAuthorizationUrl ()
139
154
{
@@ -146,7 +161,6 @@ public function getAuthorizationUrl()
146
161
147
162
/**
148
163
* Hit Paystack Gateway to Verify that the transaction is valid
149
- * @return void
150
164
*/
151
165
private function verifyTransactionAtGateway ()
152
166
{
@@ -167,8 +181,7 @@ public function isTransactionVerificationValid()
167
181
168
182
$ result = $ this ->getResponse ()['message ' ];
169
183
170
- switch ($ result )
171
- {
184
+ switch ($ result ) {
172
185
case self ::VS :
173
186
$ validate = true ;
174
187
break ;
@@ -277,8 +290,8 @@ private function getData()
277
290
/**
278
291
* Create a plan
279
292
*/
280
- public function createPlan (){
281
-
293
+ public function createPlan ()
294
+ {
282
295
$ data = [
283
296
"name " => request ()->name ,
284
297
"description " => request ()->desc ,
@@ -300,7 +313,8 @@ public function createPlan(){
300
313
* @param $plan_code
301
314
* @return array
302
315
*/
303
- public function fetchPlan ($ plan_code ){
316
+ public function fetchPlan ($ plan_code )
317
+ {
304
318
$ this ->setRequestOptions ();
305
319
return $ this ->setHttpResponse ('/plan/ ' . $ plan_code , 'GET ' , [])->getResponse ();
306
320
}
@@ -310,7 +324,8 @@ public function fetchPlan($plan_code){
310
324
* @param $plan_code
311
325
* @return array
312
326
*/
313
- public function updatePlan ($ plan_code ){
327
+ public function updatePlan ($ plan_code )
328
+ {
314
329
$ data = [
315
330
"name " => request ()->name ,
316
331
"description " => request ()->desc ,
@@ -327,9 +342,9 @@ public function updatePlan($plan_code){
327
342
328
343
/**
329
344
* Create a customer
330
- * @return array
331
345
*/
332
- public function createCustomer (){
346
+ public function createCustomer ()
347
+ {
333
348
$ data = [
334
349
"email " => request ()->email ,
335
350
"first_name " => request ()->fname ,
@@ -359,7 +374,8 @@ public function fetchCustomer($customer_id)
359
374
* @param $customer_id
360
375
* @return array
361
376
*/
362
- public function updateCustomer ($ customer_id ){
377
+ public function updateCustomer ($ customer_id )
378
+ {
363
379
$ data = [
364
380
"email " => request ()->email ,
365
381
"first_name " => request ()->fname ,
@@ -374,10 +390,11 @@ public function updateCustomer($customer_id){
374
390
}
375
391
376
392
/**
377
- * Export tranactions in .CSV
393
+ * Export transactions in .CSV
378
394
* @return array
379
395
*/
380
- public function exportTransactions (){
396
+ public function exportTransactions ()
397
+ {
381
398
$ data = [
382
399
"from " => request ()->from ,
383
400
"to " => request ()->to ,
@@ -390,9 +407,9 @@ public function exportTransactions(){
390
407
391
408
/**
392
409
* Create a subscription to a plan from a customer.
393
- * @return array
394
410
*/
395
- public function createSubscription (){
411
+ public function createSubscription ()
412
+ {
396
413
$ data = [
397
414
"customer " => request ()->customer , //Customer email or code
398
415
"plan " => request ()->plan ,
@@ -407,7 +424,8 @@ public function createSubscription(){
407
424
* Enable a subscription using the subscription code and token
408
425
* @return array
409
426
*/
410
- public function enableSubscription (){
427
+ public function enableSubscription ()
428
+ {
411
429
$ data = [
412
430
"code " => request ()->code ,
413
431
"token " => request ()->token ,
@@ -421,7 +439,8 @@ public function enableSubscription(){
421
439
* Disable a subscription using the subscription code and token
422
440
* @return array
423
441
*/
424
- public function disableSubscription (){
442
+ public function disableSubscription ()
443
+ {
425
444
$ data = [
426
445
"code " => request ()->code ,
427
446
"token " => request ()->token ,
@@ -433,7 +452,7 @@ public function disableSubscription(){
433
452
434
453
/**
435
454
* Fetch details about a certain subscription
436
- * @param $subscription_id
455
+ * @param mixed $subscription_id
437
456
* @return array
438
457
*/
439
458
public function fetchSubscription ($ subscription_id )
@@ -444,9 +463,9 @@ public function fetchSubscription($subscription_id)
444
463
445
464
/**
446
465
* Create pages you can share with users using the returned slug
447
- * @return array
448
466
*/
449
- public function createPage (){
467
+ public function createPage ()
468
+ {
450
469
$ data = [
451
470
"name " => request ()->name ,
452
471
"description " => request ()->description ,
@@ -469,7 +488,7 @@ public function getAllPages()
469
488
470
489
/**
471
490
* Fetch details about a certain page using its id or slug
472
- * @param $page_id
491
+ * @param mixed $page_id
473
492
* @return array
474
493
*/
475
494
public function fetchPage ($ page_id )
@@ -483,7 +502,8 @@ public function fetchPage($page_id)
483
502
* @param $page_id
484
503
* @return array
485
504
*/
486
- public function updatePage ($ page_id ){
505
+ public function updatePage ($ page_id )
506
+ {
487
507
$ data = [
488
508
"name " => request ()->name ,
489
509
"description " => request ()->description ,
@@ -493,8 +513,4 @@ public function updatePage($page_id){
493
513
$ this ->setRequestOptions ();
494
514
return $ this ->setHttpResponse ('/page/ ' .$ page_id , 'PUT ' , $ data )->getResponse ();
495
515
}
496
-
497
516
}
498
-
499
-
500
-
0 commit comments