Skip to content

Commit d321f5d

Browse files
committed
refactored for psr-2 compliance
1 parent cb45bc1 commit d321f5d

File tree

8 files changed

+111
-99
lines changed

8 files changed

+111
-99
lines changed

resources/config/paystack.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
*/
3636
'merchantEmail' => getenv('MERCHANT_EMAIL'),
3737

38-
];
38+
];

src/Exceptions/PaymentVerificationFailedException.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Exception;
1515

16-
class PaymentVerificationFailedException extends Exception {
16+
class PaymentVerificationFailedException extends Exception
17+
{
1718

18-
}
19+
}

src/Exceptions/isNullException.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Exception;
1515

16-
class IsNullException extends Exception {
16+
class IsNullException extends Exception
17+
{
1718

18-
}
19+
}

src/Facades/Paystack.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
use Illuminate\Support\Facades\Facade;
1515

16-
class Paystack extends Facade {
16+
class Paystack extends Facade
17+
{
1718
/**
18-
* Get the registered name of the component.
19-
*
20-
* @return string
21-
*/
19+
* Get the registered name of the component
20+
* @return string
21+
*/
2222
protected static function getFacadeAccessor()
2323
{
2424
return 'laravel-paystack';
2525
}
26-
}
26+
}

src/Paystack.php

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use GuzzleHttp\Client;
1515
use Illuminate\Support\Facades\Config;
1616

17-
class Paystack {
18-
17+
class Paystack
18+
{
1919
/**
2020
* Transaction Verification Successful
2121
*/
@@ -28,13 +28,13 @@ class Paystack {
2828

2929
/**
3030
* Issue Secret Key from your Paystack Dashboard
31-
* @var mixed
31+
* @var string
3232
*/
3333
protected $secretKey;
3434

3535
/**
3636
* Instance of Client
37-
* @var object
37+
* @var Client
3838
*/
3939
protected $client;
4040

@@ -73,7 +73,6 @@ public function setBaseUrl()
7373

7474
/**
7575
* Get secret key from Paystack config file
76-
* @return void
7776
*/
7877
public function setKey()
7978
{
@@ -82,22 +81,26 @@ public function setKey()
8281

8382
/**
8483
* Set options for making the Client request
85-
* @return void
8684
*/
8785
private function setRequestOptions()
8886
{
8987
$authBearer = 'Bearer '. $this->secretKey;
9088

91-
$this->client = new Client(['base_uri' => $this->baseUrl,
92-
'headers' => [
93-
'Authorization' => $authBearer,
94-
'Content-Type' => 'application/json',
95-
'Accept' => 'application/json'
96-
]]);
89+
$this->client = new Client(
90+
[
91+
'base_uri' => $this->baseUrl,
92+
'headers' => [
93+
'Authorization' => $authBearer,
94+
'Content-Type' => 'application/json',
95+
'Accept' => 'application/json'
96+
]
97+
]
98+
);
9799
}
98100

99101
/**
100102
* Initiate a payment request to Paystack
103+
* @return Paystack
101104
*/
102105
public function makePaymentRequest()
103106
{
@@ -110,7 +113,7 @@ public function makePaymentRequest()
110113
"last_name" => request()->last_name,
111114
"callback_url" => request()->callback_url
112115
];
113-
116+
114117
// Remove the fields which were not sent (value would be null)
115118
array_filter($data);
116119

@@ -120,18 +123,30 @@ public function makePaymentRequest()
120123
}
121124

122125

126+
/**
127+
* @param string $relativeUrl
128+
* @param string $method
129+
* @param array $body
130+
* @return Paystack
131+
* @throws IsNullException
132+
*/
123133
private function setHttpResponse($relativeUrl, $method, $body = [])
124134
{
125-
if(is_null($method)){
135+
if (is_null($method)) {
126136
throw new IsNullException("Empty method not allowed");
127137
}
128138

129-
$this->response = $this->client->{strtolower($method)}($this->baseUrl . $relativeUrl, ["body" => json_encode($body)]);
139+
$this->response = $this->client->{strtolower($method)}(
140+
$this->baseUrl . $relativeUrl,
141+
["body" => json_encode($body)]
142+
);
143+
130144
return $this;
131145
}
132146

133147
/**
134148
* Get the authorization url from the callback response
149+
* @return Paystack
135150
*/
136151
public function getAuthorizationUrl()
137152
{
@@ -144,7 +159,6 @@ public function getAuthorizationUrl()
144159

145160
/**
146161
* Hit Paystack Gateway to Verify that the transaction is valid
147-
* @return void
148162
*/
149163
private function verifyTransactionAtGateway()
150164
{
@@ -165,8 +179,7 @@ public function isTransactionVerificationValid()
165179

166180
$result = $this->getResponse()['message'];
167181

168-
switch ($result)
169-
{
182+
switch ($result) {
170183
case self::VS:
171184
$validate = true;
172185
break;
@@ -275,8 +288,8 @@ private function getData()
275288
/**
276289
* Create a plan
277290
*/
278-
public function createPlan(){
279-
291+
public function createPlan()
292+
{
280293
$data = [
281294
"name" => request()->name,
282295
"description" => request()->desc,
@@ -298,7 +311,8 @@ public function createPlan(){
298311
* @param $plan_code
299312
* @return array
300313
*/
301-
public function fetchPlan($plan_code){
314+
public function fetchPlan($plan_code)
315+
{
302316
$this->setRequestOptions();
303317
return $this->setHttpResponse('/plan/' . $plan_code, 'GET', [])->getResponse();
304318
}
@@ -308,7 +322,8 @@ public function fetchPlan($plan_code){
308322
* @param $plan_code
309323
* @return array
310324
*/
311-
public function updatePlan($plan_code){
325+
public function updatePlan($plan_code)
326+
{
312327
$data = [
313328
"name" => request()->name,
314329
"description" => request()->desc,
@@ -325,9 +340,9 @@ public function updatePlan($plan_code){
325340

326341
/**
327342
* Create a customer
328-
* @return array
329343
*/
330-
public function createCustomer(){
344+
public function createCustomer()
345+
{
331346
$data = [
332347
"email" => request()->email,
333348
"first_name" => request()->fname,
@@ -357,7 +372,8 @@ public function fetchCustomer($customer_id)
357372
* @param $customer_id
358373
* @return array
359374
*/
360-
public function updateCustomer($customer_id){
375+
public function updateCustomer($customer_id)
376+
{
361377
$data = [
362378
"email" => request()->email,
363379
"first_name" => request()->fname,
@@ -372,10 +388,11 @@ public function updateCustomer($customer_id){
372388
}
373389

374390
/**
375-
* Export tranactions in .CSV
391+
* Export transactions in .CSV
376392
* @return array
377393
*/
378-
public function exportTransactions(){
394+
public function exportTransactions()
395+
{
379396
$data = [
380397
"from" => request()->from,
381398
"to" => request()->to,
@@ -388,9 +405,9 @@ public function exportTransactions(){
388405

389406
/**
390407
* Create a subscription to a plan from a customer.
391-
* @return array
392408
*/
393-
public function createSubscription(){
409+
public function createSubscription()
410+
{
394411
$data = [
395412
"customer" => request()->customer, //Customer email or code
396413
"plan" => request()->plan,
@@ -405,7 +422,8 @@ public function createSubscription(){
405422
* Enable a subscription using the subscription code and token
406423
* @return array
407424
*/
408-
public function enableSubscription(){
425+
public function enableSubscription()
426+
{
409427
$data = [
410428
"code" => request()->code,
411429
"token" => request()->token,
@@ -419,7 +437,8 @@ public function enableSubscription(){
419437
* Disable a subscription using the subscription code and token
420438
* @return array
421439
*/
422-
public function disableSubscription(){
440+
public function disableSubscription()
441+
{
423442
$data = [
424443
"code" => request()->code,
425444
"token" => request()->token,
@@ -431,7 +450,7 @@ public function disableSubscription(){
431450

432451
/**
433452
* Fetch details about a certain subscription
434-
* @param $subscription_id
453+
* @param mixed $subscription_id
435454
* @return array
436455
*/
437456
public function fetchSubscription($subscription_id)
@@ -442,9 +461,9 @@ public function fetchSubscription($subscription_id)
442461

443462
/**
444463
* Create pages you can share with users using the returned slug
445-
* @return array
446464
*/
447-
public function createPage(){
465+
public function createPage()
466+
{
448467
$data = [
449468
"name" => request()->name,
450469
"description" => request()->description,
@@ -467,7 +486,7 @@ public function getAllPages()
467486

468487
/**
469488
* Fetch details about a certain page using its id or slug
470-
* @param $page_id
489+
* @param mixed $page_id
471490
* @return array
472491
*/
473492
public function fetchPage($page_id)
@@ -481,7 +500,8 @@ public function fetchPage($page_id)
481500
* @param $page_id
482501
* @return array
483502
*/
484-
public function updatePage($page_id){
503+
public function updatePage($page_id)
504+
{
485505
$data = [
486506
"name" => request()->name,
487507
"description" => request()->description,
@@ -491,8 +511,4 @@ public function updatePage($page_id){
491511
$this->setRequestOptions();
492512
return $this->setHttpResponse('/page/'.$page_id, 'PUT', $data)->getResponse();
493513
}
494-
495514
}
496-
497-
498-

0 commit comments

Comments
 (0)