Passed
Push — master ( a8d879...5effd2 )
by Emmanuel
02:40
created
src/PayantServiceProvider.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
     */
41 41
     public function register()
42 42
     {
43
-        $this->app->bind('laravel-payant', function () {
43
+        $this->app->bind('laravel-payant', function() {
44 44
 
45 45
             return new Payant;
46 46
 
Please login to merge, or discard this patch.
src/Support/helpers.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 
24 24
 use \Exception as phpException;
25 25
 
26
-if (! function_exists('array_get'))
26
+if (!function_exists('array_get'))
27 27
 {
28 28
   /*
29 29
    *
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
      if (!is_array($data)) {
38 38
          return $default;
39 39
      }
40
-     return isset($data[$key]) ? $data[$key]: $default;
40
+     return isset($data[$key]) ? $data[$key] : $default;
41 41
    }
42 42
 }
43 43
 
44
-if(!function_exists('array_keys_exist')){
44
+if (!function_exists('array_keys_exist')) {
45 45
     /**
46 46
      * Checks if multiple keys exist in an array
47 47
      *
@@ -50,23 +50,23 @@  discard block
 block discarded – undo
50 50
      *
51 51
      * @return bool
52 52
      */
53
-    function array_keys_exist( array $array, $keys ) {
53
+    function array_keys_exist(array $array, $keys) {
54 54
         $count = 0;
55
-        if ( ! is_array( $keys ) ) {
55
+        if (!is_array($keys)) {
56 56
             $keys = func_get_args();
57
-            array_shift( $keys );
57
+            array_shift($keys);
58 58
         }
59
-        foreach ( $keys as $key ) {
60
-            if ( array_key_exists( $key, $array ) ) {
61
-                $count ++;
59
+        foreach ($keys as $key) {
60
+            if (array_key_exists($key, $array)) {
61
+                $count++;
62 62
             }
63 63
         }
64 64
 
65
-        return count( $keys ) === $count;
65
+        return count($keys) === $count;
66 66
     }
67 67
 }
68 68
 
69
-function cleanResponse($response){
69
+function cleanResponse($response) {
70 70
   $result = $response->getBody();
71 71
   return $result;
72 72
 }
73 73
\ No newline at end of file
Please login to merge, or discard this patch.
src/Payant.php 1 patch
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
     */
64 64
     public function setBaseUrl()
65 65
     {
66
-        if(Config::get('payant.mode') == 'LIVE')
66
+        if (Config::get('payant.mode') == 'LIVE')
67 67
         {
68 68
             $this->base_uri = "https://api.payant.ng";
69 69
         }
@@ -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
 
@@ -202,8 +202,8 @@  discard block
 block discarded – undo
202 202
      * [deleteClient]
203 203
      * @param  string $client_id [description]
204 204
      */
205
-    public function deleteClient($client_id = null){
206
-        if(!$client_id){
205
+    public function deleteClient($client_id = null) {
206
+        if (!$client_id) {
207 207
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id");
208 208
         }
209 209
 
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
      * @param string      $fee_bearer  [Mandatory]
227 227
      * @param array         $items       [Mandatory]
228 228
      */
229
-    public function addInvoice($client_id, array $client_data, $due_date, $fee_bearer, array $items){
229
+    public function addInvoice($client_id, array $client_data, $due_date, $fee_bearer, array $items) {
230 230
         // Mandatory Client fields
231 231
         $required_client_values = ['first_name', 'last_name', 'email', 'phone'];
232 232
         
@@ -236,21 +236,21 @@  discard block
 block discarded – undo
236 236
 
237 237
         
238 238
         // Either the client Id is supplied or a new client data is provided
239
-        if(!$client_id && !array_keys_exist($client_data, $required_client_values)){
239
+        if (!$client_id && !array_keys_exist($client_data, $required_client_values)) {
240 240
             throw new RequiredValuesMissing("Missing required values :( - Provide client_id or client_data");
241 241
         }
242 242
 
243
-        if(!$due_date){
243
+        if (!$due_date) {
244 244
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Due Date");
245 245
         }
246 246
 
247
-        if(!$fee_bearer){
247
+        if (!$fee_bearer) {
248 248
             throw new IsNull("Error Processing Request - Null Fee Bearer");
249 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
 
253
-        if(!is_array($items)){
253
+        if (!is_array($items)) {
254 254
             throw new IsInvalid("Error Processing Request - Invalid Items");
255 255
         }
256 256
 
@@ -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
 
@@ -328,8 +328,8 @@  discard block
 block discarded – undo
328 328
             'period' => $period
329 329
         ];
330 330
 
331
-        if ($period == 'custom'){
332
-            if (!$start || !$end){
331
+        if ($period == 'custom') {
332
+            if (!$start || !$end) {
333 333
                 throw new IsNull("Invalid custom Start or End date");
334 334
             }
335 335
             $post_data['start'] = $start;
@@ -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
 
@@ -371,15 +371,15 @@  discard block
 block discarded – undo
371 371
      * Optional - 'address', 'company_name', 'type',
372 372
      * @param string      $amount    [Mandatory]
373 373
      */
374
-    public function addTransfer(array $client_data, string $amount){
374
+    public function addTransfer(array $client_data, string $amount) {
375 375
         // Mandatory Client fields
376 376
         $required_client_values = ['first_name', 'last_name', 'email', 'phone', 'settlement_bank', 'account_number'];        
377 377
         
378
-        if(!array_keys_exist($client_data, $required_client_values)){
378
+        if (!array_keys_exist($client_data, $required_client_values)) {
379 379
             throw new RequiredValuesMissing("Missing required values :( - Provide client_data");
380 380
         }
381 381
 
382
-        if(!$amount){
382
+        if (!$amount) {
383 383
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid amount");
384 384
         }
385 385
 
@@ -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
 
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
             'period' => $period
441 441
         ];
442 442
 
443
-        if ($period == 'custom'){
444
-            if (!$start || !$end){
443
+        if ($period == 'custom') {
444
+            if (!$start || !$end) {
445 445
                 throw new IsNull("Invalid custom Start or End date");
446 446
             }
447 447
             $post_data['start'] = $start;
@@ -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
 
@@ -562,8 +562,8 @@  discard block
 block discarded – undo
562 562
             'period' => $period
563 563
         ];
564 564
 
565
-        if ($period == 'custom'){
566
-            if (!$start || !$end){
565
+        if ($period == 'custom') {
566
+            if (!$start || !$end) {
567 567
                 throw new IsNull("Invalid custom Start or End date");
568 568
             }
569 569
             $post_data['start'] = $start;
@@ -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
 
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
 
660 660
         $valid_product_type = ["product", "service"];
661 661
 
662
-        if(!$product_type){
662
+        if (!$product_type) {
663 663
             throw new IsNull("Error Processing Request - Null/Invalid type");
664 664
         }elseif (!in_array($product_type, $valid_product_type)) {
665 665
             throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'");
@@ -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.