Passed
Push — master ( 5effd2...12657e )
by Emmanuel
02:22
created
src/Payant.php 2 patches
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
      */
84 84
     private function setRequestOptions()
85 85
     {       
86
-        $authorization_string = 'Bearer '. $this->private_key;
86
+        $authorization_string = 'Bearer '.$this->private_key;
87 87
 
88 88
         //Set up Guzzle
89
-        $this->client = new Client( [
89
+        $this->client = new Client([
90 90
             'base_uri' => $this->base_uri,
91 91
             'protocols' => ['https'],
92 92
             'headers' => [
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      * [getStates Get States in a country (Nigeria)]
103 103
      * @return object [list of banks and their respective bank_ids]
104 104
      */
105
-    public function getBanks(){
105
+    public function getBanks() {
106 106
         return $this->sendRequest('get', '/banks');
107 107
     }
108 108
     
@@ -113,11 +113,11 @@  discard block
 block discarded – undo
113 113
      * @param array $client_data [description]
114 114
      * Required fields - 'settlement_bank', 'account_number'
115 115
      */
116
-    public function resolveAccount( array $client_data){
116
+    public function resolveAccount(array $client_data) {
117 117
         // Mandatory fields
118 118
         $required_values = ['settlement_bank', 'account_number'];
119 119
 
120
-        if(!array_keys_exist($client_data, $required_values)){
120
+        if (!array_keys_exist($client_data, $required_values)) {
121 121
             throw new RequiredValuesMissing("Missing required values :(");
122 122
         }
123 123
 
@@ -135,11 +135,11 @@  discard block
 block discarded – undo
135 135
      * Required fields - 'first_name', 'last_name', 'email', 'phone'
136 136
      * Optional - 'address', 'company_name', 'type', 'settlement_bank', 'account_number'
137 137
      */
138
-    public function addClient( array $client_data){
138
+    public function addClient(array $client_data) {
139 139
         // Mandatory fields
140 140
         $required_values = ['first_name', 'last_name', 'email', 'phone'];
141 141
 
142
-        if(!array_keys_exist($client_data, $required_values)){
142
+        if (!array_keys_exist($client_data, $required_values)) {
143 143
             throw new RequiredValuesMissing("Missing required values :(");
144 144
         }
145 145
 
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
      * @param  string $client_id
157 157
      * @return object
158 158
      */
159
-    public function getClient($client_id = null){
160
-        if(!$client_id){
159
+    public function getClient($client_id = null) {
160
+        if (!$client_id) {
161 161
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id");
162 162
         }
163 163
 
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
      *        Required fields - 'first_name', 'last_name', 'email', 'phone'
178 178
      *        Optional - 'address', 'company_name', 'type', 'settlement_bank', 'account_number'
179 179
      */
180
-    public function editClient( $client_id, array $client_data){
181
-        if(!$client_id){
180
+    public function editClient($client_id, array $client_data) {
181
+        if (!$client_id) {
182 182
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id");
183 183
         }
184 184
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
         // Mandatory fields
188 188
         $required_values = ['first_name', 'last_name', 'email', 'phone'];
189 189
 
190
-        if(!array_keys_exist($client_data, $required_values)){
190
+        if (!array_keys_exist($client_data, $required_values)) {
191 191
                 throw new RequiredValuesMissing("Missing required values :(");
192 192
         }
193 193
 
@@ -276,8 +276,8 @@  discard block
 block discarded – undo
276 276
      * @param  string $reference_code [Mandatory - Invoice Reference Code]
277 277
      * @return object               
278 278
      */
279
-    public function getInvoice($reference_code){
280
-        if(!$reference_code){
279
+    public function getInvoice($reference_code) {
280
+        if (!$reference_code) {
281 281
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
282 282
         }
283 283
 
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
      * @param  string $reference_code [Mandatory - Invoice Reference Code]
292 292
      * @return object               
293 293
      */
294
-    public function sendInvoice($reference_code = null){
295
-        if(!$reference_code){
294
+    public function sendInvoice($reference_code = null) {
295
+        if (!$reference_code) {
296 296
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
297 297
         }
298 298
 
@@ -312,8 +312,8 @@  discard block
 block discarded – undo
312 312
      * @param  string $end    [Format - DD/MM/YYYY]
313 313
      * @return object         
314 314
      */
315
-    public function getInvoiceHistory($period, $start = null, $end = null){
316
-        if(!$period){
315
+    public function getInvoiceHistory($period, $start = null, $end = null) {
316
+        if (!$period) {
317 317
             throw new RequiredValueMissing("Error Processing Request - period Missing");
318 318
         }
319 319
 
@@ -350,8 +350,8 @@  discard block
 block discarded – undo
350 350
      * @param  string $reference_code [Mandatory - Invoice Reference Code]
351 351
      * @return object                 
352 352
      */
353
-    public function deleteInvoice($reference_code){
354
-        if(!$reference_code){
353
+    public function deleteInvoice($reference_code) {
354
+        if (!$reference_code) {
355 355
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
356 356
         }
357 357
 
@@ -402,8 +402,8 @@  discard block
 block discarded – undo
402 402
      * @param  string $reference_code [Mandatory - Transfer Reference Code]
403 403
      * @return object               
404 404
      */
405
-    public function getTransfer($reference_code){
406
-        if(!$reference_code){
405
+    public function getTransfer($reference_code) {
406
+        if (!$reference_code) {
407 407
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
408 408
         }
409 409
 
@@ -424,8 +424,8 @@  discard block
 block discarded – undo
424 424
      * @param  string $end    [Format - DD/MM/YYYY]
425 425
      * @return object         
426 426
      */
427
-    public function getTransferHistory($period, $start = null, $end = null){
428
-        if(!$period){
427
+    public function getTransferHistory($period, $start = null, $end = null) {
428
+        if (!$period) {
429 429
             throw new RequiredValueMissing("Error Processing Request - period Missing");
430 430
         }
431 431
 
@@ -462,8 +462,8 @@  discard block
 block discarded – undo
462 462
      * @param  string $reference_code [Mandatory - Invoice Reference Code]
463 463
      * @return object                 
464 464
      */
465
-    public function deleteTransfer($reference_code){
466
-        if(!$reference_code){
465
+    public function deleteTransfer($reference_code) {
466
+        if (!$reference_code) {
467 467
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
468 468
         }
469 469
 
@@ -484,22 +484,22 @@  discard block
 block discarded – undo
484 484
      * @param string $amount         [Mandatory]
485 485
      * @param string $channel        [Mandatory - valid ["Cash", "BankTransfer", "POS", "Cheque"]]
486 486
      */
487
-    public function addPayment(string $reference_code, string $date, string $amount, string $channel){
488
-        if(!$reference_code){
487
+    public function addPayment(string $reference_code, string $date, string $amount, string $channel) {
488
+        if (!$reference_code) {
489 489
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
490 490
         }
491 491
 
492
-        if(!$due_date){
492
+        if (!$due_date) {
493 493
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid date");
494 494
         }
495 495
 
496
-        if(!$amount){
496
+        if (!$amount) {
497 497
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid amount");
498 498
         }
499 499
 
500 500
         $valid_channels = ["Cash", "BankTransfer", "POS", "Cheque"];
501 501
 
502
-        if(!$channel){
502
+        if (!$channel) {
503 503
             throw new IsNull("Error Processing Request - Null/Invalid amount");
504 504
         }elseif (!in_array(ucfirst($channel), $valid_channels)) {
505 505
             throw new IsInvalid("Invalid Channel - Cash, BankTransfer, POS or Cheque");
@@ -525,8 +525,8 @@  discard block
 block discarded – undo
525 525
      * [getPayment]
526 526
      * @param string $reference_code [Mandatory - Invoice Reference Code]
527 527
      */
528
-    public function getPayment($reference_code){
529
-        if(!$reference_code){
528
+    public function getPayment($reference_code) {
529
+        if (!$reference_code) {
530 530
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
531 531
         }
532 532
 
@@ -546,8 +546,8 @@  discard block
 block discarded – undo
546 546
      * @param  string $end    [Format - DD/MM/YYYY || Optional if $period !== 'custom']
547 547
      * @return object         
548 548
      */
549
-    public function getPaymentHistory(string $period, string $start, string $end){
550
-        if(!$period){
549
+    public function getPaymentHistory(string $period, string $start, string $end) {
550
+        if (!$period) {
551 551
             throw new RequiredValueMissing("Error Processing Request - period Missing");
552 552
         }
553 553
 
@@ -586,23 +586,23 @@  discard block
 block discarded – undo
586 586
      * @param string $unit_cost   [Mandatory - Product's unit cost]
587 587
      * @param string $type        [Mandatory - Product type 'product' or 'service']
588 588
      */
589
-    public function addProduct(string $name, string $description, string $unit_cost, string $type){
590
-        if(!$name){
589
+    public function addProduct(string $name, string $description, string $unit_cost, string $type) {
590
+        if (!$name) {
591 591
             throw new IsNull("Error Processing Request - Null/Invalid name");
592 592
         }
593 593
 
594
-        if(!$description){
594
+        if (!$description) {
595 595
             throw new IsNull("Error Processing Request - Null/Invalid description");
596 596
         }
597 597
 
598
-        if(!$unit_cost){
598
+        if (!$unit_cost) {
599 599
             throw new IsNull("Error Processing Request - Null/Invalid unit_cost");
600 600
         }
601 601
 
602 602
         //Validate Product Type
603 603
         $valid_product_type = ["product", "service"];
604 604
 
605
-        if(!$type){
605
+        if (!$type) {
606 606
             throw new IsNull("Error Processing Request - Null/Invalid type");
607 607
         }elseif (!in_array(strtolower($type), $valid_product_type)) {
608 608
             throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'");
@@ -629,8 +629,8 @@  discard block
 block discarded – undo
629 629
      * @param  int $product_id [Mandatory - Product ID]
630 630
      * @return object 
631 631
      */
632
-    public function getProduct($product_id){
633
-        if(!$product_id){
632
+    public function getProduct($product_id) {
633
+        if (!$product_id) {
634 634
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid product_id");
635 635
         }
636 636
 
@@ -649,8 +649,8 @@  discard block
 block discarded – undo
649 649
      * @param  array  $product_data [description]
650 650
      * @return object               
651 651
      */
652
-    public function editProduct($product_id, array $product_data){
653
-        if(!$product_id){
652
+    public function editProduct($product_id, array $product_data) {
653
+        if (!$product_id) {
654 654
                 throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id");
655 655
         }
656 656
 
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
         // Mandatory fields
671 671
         $required_values = ['name', 'description', 'unit_cost', 'type'];
672 672
 
673
-        if(!array_keys_exist($client_data, $required_values)){
673
+        if (!array_keys_exist($client_data, $required_values)) {
674 674
                 throw new RequiredValuesMissing("Missing required values :(");
675 675
         }
676 676
 
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
      * [getProducts]
685 685
      * @return object
686 686
      */
687
-    public function getProducts(){
687
+    public function getProducts() {
688 688
         $url = "/products";
689 689
 
690 690
         return $this->sendRequest('get', $url);
@@ -698,8 +698,8 @@  discard block
 block discarded – undo
698 698
      * @param $product_id [Mandatory - Product ID]
699 699
      * @return object           
700 700
      */
701
-    public function deleteProduct($product_id){
702
-        if(!$product_id){
701
+    public function deleteProduct($product_id) {
702
+        if (!$product_id) {
703 703
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id");
704 704
         }
705 705
 
@@ -716,22 +716,22 @@  discard block
 block discarded – undo
716 716
      * @param string $url           [Mandatory - url to send request to]
717 717
      * @param array $params         [data to post to request url]
718 718
      */
719
-    public function sendRequest($method, $url, $params=[])
719
+    public function sendRequest($method, $url, $params = [])
720 720
     {
721
-        try{
722
-            if (strtolower($method) == 'get'){
721
+        try {
722
+            if (strtolower($method) == 'get') {
723 723
                 $result = $this->client->request('GET', $url);
724
-            }elseif (strtolower($method) == 'post'){
724
+            }elseif (strtolower($method) == 'post') {
725 725
                 $result = $this->client->request('POST', $url, $params);
726
-            }elseif (strtolower($method) == 'put'){
726
+            }elseif (strtolower($method) == 'put') {
727 727
                 $result = $this->client->request('PUT', $url, $params);
728
-            }elseif (strtolower($method) == 'delete'){
728
+            }elseif (strtolower($method) == 'delete') {
729 729
                 $result = $this->client->request('DELETE', $url);
730 730
             }
731 731
 
732 732
             return cleanResponse($result);
733 733
         }
734
-        catch( Exception $e){
734
+        catch (Exception $e) {
735 735
             throw $e;
736 736
         }
737 737
     }
Please login to merge, or discard this patch.
Braces   +8 added lines, -9 removed lines patch added patch discarded remove patch
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 
247 247
         if (!$fee_bearer) {
248 248
             throw new IsNull("Error Processing Request - Null Fee Bearer");
249
-        }elseif (!in_array($fee_bearer, $valid_fee_bearers)) {
249
+        } elseif (!in_array($fee_bearer, $valid_fee_bearers)) {
250 250
             throw new InvalidFeeBearer("Invalid Fee Bearer - Use either 'account' or 'client'");
251 251
         }
252 252
 
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
 
502 502
         if(!$channel){
503 503
             throw new IsNull("Error Processing Request - Null/Invalid amount");
504
-        }elseif (!in_array(ucfirst($channel), $valid_channels)) {
504
+        } elseif (!in_array(ucfirst($channel), $valid_channels)) {
505 505
             throw new IsInvalid("Invalid Channel - Cash, BankTransfer, POS or Cheque");
506 506
         }
507 507
 
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
 
605 605
         if(!$type){
606 606
             throw new IsNull("Error Processing Request - Null/Invalid type");
607
-        }elseif (!in_array(strtolower($type), $valid_product_type)) {
607
+        } elseif (!in_array(strtolower($type), $valid_product_type)) {
608 608
             throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'");
609 609
         }
610 610
 
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
 
662 662
         if (!$product_type) {
663 663
             throw new IsNull("Error Processing Request - Null/Invalid type");
664
-        }elseif (!in_array($product_type, $valid_product_type)) {
664
+        } elseif (!in_array($product_type, $valid_product_type)) {
665 665
             throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'");
666 666
         }
667 667
 
@@ -721,17 +721,16 @@  discard block
 block discarded – undo
721 721
         try{
722 722
             if (strtolower($method) == 'get'){
723 723
                 $result = $this->client->request('GET', $url);
724
-            }elseif (strtolower($method) == 'post'){
724
+            } elseif (strtolower($method) == 'post'){
725 725
                 $result = $this->client->request('POST', $url, $params);
726
-            }elseif (strtolower($method) == 'put'){
726
+            } elseif (strtolower($method) == 'put'){
727 727
                 $result = $this->client->request('PUT', $url, $params);
728
-            }elseif (strtolower($method) == 'delete'){
728
+            } elseif (strtolower($method) == 'delete'){
729 729
                 $result = $this->client->request('DELETE', $url);
730 730
             }
731 731
 
732 732
             return cleanResponse($result);
733
-        }
734
-        catch( Exception $e){
733
+        } catch( Exception $e){
735 734
             throw $e;
736 735
         }
737 736
     }
Please login to merge, or discard this patch.