Completed
Push — master ( 9759f5...9cb7ff )
by Emmanuel
04:57
created
src/Payant.php 2 patches
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 
30 30
     /**
31 31
      * @var $private_key
32
-    */
32
+     */
33 33
     protected $private_key;
34 34
     
35 35
 
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
37 37
      *
38 38
      * @var $base_uri
39 39
      *
40
-    */
40
+     */
41 41
     protected $base_uri = 'https://api.demo.payant.ng';
42 42
     
43 43
     
44 44
     /**
45 45
      * @var $client
46 46
      *
47
-    */
47
+     */
48 48
     protected $client;
49 49
 
50 50
     
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
     }
60 60
 
61 61
     /**
62
-    * Get Base Url from Payant config file
63
-    */
62
+     * Get Base Url from Payant config file
63
+     */
64 64
     public function setBaseUrl()
65 65
     {
66 66
         if(Config::get('payant.mode') == 'LIVE')
@@ -83,7 +83,7 @@  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 89
         $this->client = new Client( [
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     /**
102 102
      * [getStates Get States in a country (Nigeria)]
103 103
      * @return [object] [list of banks and their respective bank_ids]
104
-    */
104
+     */
105 105
     public function getBanks(){
106 106
         return $this->sendRequest('get', '/banks');
107 107
     }
@@ -112,13 +112,13 @@  discard block
 block discarded – undo
112 112
      * [resolveAccount description]
113 113
      * @param array $client_data [description]
114 114
      * Required fields - 'settlement_bank', 'account_number'
115
-    */
115
+     */
116 116
     public function resolveAccount( array $client_data){
117 117
         // Mandatory fields
118 118
         $required_values = ['settlement_bank', 'account_number'];
119 119
 
120 120
         if(!array_keys_exist($client_data, $required_values)){
121
-         throw new RequiredValuesMissing("Missing required values :(");
121
+            throw new RequiredValuesMissing("Missing required values :(");
122 122
         }
123 123
 
124 124
         $url = '/resolve-account';
@@ -134,13 +134,13 @@  discard block
 block discarded – undo
134 134
      * @param array $client_data [description]
135 135
      * Required fields - 'first_name', 'last_name', 'email', 'phone'
136 136
      * Optional - 'address', 'company_name', 'type', 'settlement_bank', 'account_number'
137
-    */
137
+     */
138 138
     public function addClient( array $client_data){
139 139
         // Mandatory fields
140 140
         $required_values = ['first_name', 'last_name', 'email', 'phone'];
141 141
 
142 142
         if(!array_keys_exist($client_data, $required_values)){
143
-         throw new RequiredValuesMissing("Missing required values :(");
143
+            throw new RequiredValuesMissing("Missing required values :(");
144 144
         }
145 145
 
146 146
         $url = '/clients';
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
      * [getClient Get client Details]
156 156
      * @param  [string] $client_id
157 157
      * @return [object]
158
-    */
158
+     */
159 159
     public function getClient($client_id = null){
160 160
         if(!$client_id){
161 161
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id");
@@ -171,15 +171,15 @@  discard block
 block discarded – undo
171 171
 
172 172
 
173 173
     /**
174
-    * [editClient - Edit Existing Client]
175
-    * @param [string] $client_id
176
-    * @param [array] $client_data
177
-    *        Required fields - 'first_name', 'last_name', 'email', 'phone'
178
-    *        Optional - 'address', 'company_name', 'type', 'settlement_bank', 'account_number'
179
-    */
174
+     * [editClient - Edit Existing Client]
175
+     * @param [string] $client_id
176
+     * @param [array] $client_data
177
+     *        Required fields - 'first_name', 'last_name', 'email', 'phone'
178
+     *        Optional - 'address', 'company_name', 'type', 'settlement_bank', 'account_number'
179
+     */
180 180
     public function editClient( $client_id, array $client_data){
181 181
         if(!$client_id){
182
-           throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id");
182
+            throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id");
183 183
         }
184 184
 
185 185
         $url = "/clients/{$client_id}";
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
         $required_values = ['first_name', 'last_name', 'email', 'phone'];
189 189
 
190 190
         if(!array_keys_exist($client_data, $required_values)){
191
-             throw new RequiredValuesMissing("Missing required values :(");
191
+                throw new RequiredValuesMissing("Missing required values :(");
192 192
         }
193 193
 
194 194
         return $this->sendRequest('put', $url, ['form_params' => $client_data]);
@@ -272,10 +272,10 @@  discard block
 block discarded – undo
272 272
 
273 273
 
274 274
     /**
275
-    * [getInvoice ]
276
-    * @param  [string] $reference_code [Mandatory - Invoice Reference Code]
277
-    * @return [object]               
278
-    */
275
+     * [getInvoice ]
276
+     * @param  [string] $reference_code [Mandatory - Invoice Reference Code]
277
+     * @return [object]               
278
+     */
279 279
     public function getInvoice($reference_code){
280 280
         if(!$reference_code){
281 281
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
@@ -287,10 +287,10 @@  discard block
 block discarded – undo
287 287
     }
288 288
 
289 289
     /**
290
-    * [sendInvoice]
291
-    * @param  [type] $reference_code [Mandatory - Invoice Reference Code]
292
-    * @return [object]               
293
-    */
290
+     * [sendInvoice]
291
+     * @param  [type] $reference_code [Mandatory - Invoice Reference Code]
292
+     * @return [object]               
293
+     */
294 294
     public function sendInvoice($reference_code = null){
295 295
         if(!$reference_code){
296 296
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
@@ -306,12 +306,12 @@  discard block
 block discarded – undo
306 306
 
307 307
 
308 308
     /**
309
-    * [getInvoiceHistory]
310
-    * @param  [string] $period [Mandatory || Valid Options ["today", "week", "month", "30", "90", "year", "custom"]]
311
-    * @param  [string] $start  [Format - DD/MM/YYYY]
312
-    * @param  [string] $end    [Format - DD/MM/YYYY]
313
-    * @return [object]         
314
-    */
309
+     * [getInvoiceHistory]
310
+     * @param  [string] $period [Mandatory || Valid Options ["today", "week", "month", "30", "90", "year", "custom"]]
311
+     * @param  [string] $start  [Format - DD/MM/YYYY]
312
+     * @param  [string] $end    [Format - DD/MM/YYYY]
313
+     * @return [object]         
314
+     */
315 315
     public function getInvoiceHistory($period, $start = null, $end = null){
316 316
         if(!$period){
317 317
             throw new RequiredValueMissing("Error Processing Request - period Missing");
@@ -346,10 +346,10 @@  discard block
 block discarded – undo
346 346
 
347 347
 
348 348
     /**
349
-    * [deleteInvoice]
350
-    * @param  [string] $reference_code [Mandatory - Invoice Reference Code]
351
-    * @return [object]                 
352
-    */
349
+     * [deleteInvoice]
350
+     * @param  [string] $reference_code [Mandatory - Invoice Reference Code]
351
+     * @return [object]                 
352
+     */
353 353
     public function deleteInvoice($reference_code){
354 354
         if(!$reference_code){
355 355
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
@@ -365,12 +365,12 @@  discard block
 block discarded – undo
365 365
 
366 366
 
367 367
     /**
368
-    * [addPayment]
369
-    * @param [string] $reference_code [Mandatory - Invoice Reference Code]
370
-    * @param [string] $date           [Mandatory - [Format - DD/MM/YYYY]]
371
-    * @param [string] $amount         [Mandatory]
372
-    * @param [string] $channel        [Mandatory - valid ["Cash", "BankTransfer", "POS", "Cheque"]]
373
-    */
368
+     * [addPayment]
369
+     * @param [string] $reference_code [Mandatory - Invoice Reference Code]
370
+     * @param [string] $date           [Mandatory - [Format - DD/MM/YYYY]]
371
+     * @param [string] $amount         [Mandatory]
372
+     * @param [string] $channel        [Mandatory - valid ["Cash", "BankTransfer", "POS", "Cheque"]]
373
+     */
374 374
     public function addPayment(string $reference_code, string $date, string $amount, string $channel){
375 375
         if(!$reference_code){
376 376
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
@@ -409,9 +409,9 @@  discard block
 block discarded – undo
409 409
 
410 410
 
411 411
     /**
412
-    * [getPayment]
413
-    * @param [string] $reference_code [Mandatory - Invoice Reference Code]
414
-    */
412
+     * [getPayment]
413
+     * @param [string] $reference_code [Mandatory - Invoice Reference Code]
414
+     */
415 415
     public function getPayment($reference_code){
416 416
         if(!$reference_code){
417 417
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
@@ -427,12 +427,12 @@  discard block
 block discarded – undo
427 427
 
428 428
 
429 429
     /**
430
-    * [getPaymentHistory]
431
-    * @param  [string] $period [Mandatory || Valid Options ["today", "week", "month", "30", "90", "year", "custom"]]
432
-    * @param  [string] $start  [Format - DD/MM/YYYY || Optional if $period !== 'custom']
433
-    * @param  [string] $end    [Format - DD/MM/YYYY || Optional if $period !== 'custom']
434
-    * @return [object]         
435
-    */
430
+     * [getPaymentHistory]
431
+     * @param  [string] $period [Mandatory || Valid Options ["today", "week", "month", "30", "90", "year", "custom"]]
432
+     * @param  [string] $start  [Format - DD/MM/YYYY || Optional if $period !== 'custom']
433
+     * @param  [string] $end    [Format - DD/MM/YYYY || Optional if $period !== 'custom']
434
+     * @return [object]         
435
+     */
436 436
     public function getPaymentHistory(string $period, string $start, string $end){
437 437
         if(!$period){
438 438
             throw new RequiredValueMissing("Error Processing Request - period Missing");
@@ -467,12 +467,12 @@  discard block
 block discarded – undo
467 467
 
468 468
 
469 469
     /**
470
-    * [addProduct]
471
-    * @param string $name        [Mandatory - Product's name]
472
-    * @param string $description [Mandatory - Product's description]
473
-    * @param string $unit_cost   [Mandatory - Product's unit cost]
474
-    * @param string $type        [Mandatory - Product type 'product' or 'service']
475
-    */
470
+     * [addProduct]
471
+     * @param string $name        [Mandatory - Product's name]
472
+     * @param string $description [Mandatory - Product's description]
473
+     * @param string $unit_cost   [Mandatory - Product's unit cost]
474
+     * @param string $type        [Mandatory - Product type 'product' or 'service']
475
+     */
476 476
     public function addProduct(string $name, string $description, string $unit_cost, string $type){
477 477
         if(!$name){
478 478
             throw new IsNull("Error Processing Request - Null/Invalid name");
@@ -512,10 +512,10 @@  discard block
 block discarded – undo
512 512
 
513 513
 
514 514
     /**
515
-    * [getProduct]
516
-    * @param  [int] $product_id [Mandatory - Product ID]
517
-    * @return [object] 
518
-    */
515
+     * [getProduct]
516
+     * @param  [int] $product_id [Mandatory - Product ID]
517
+     * @return [object] 
518
+     */
519 519
     public function getProduct($product_id){
520 520
         if(!$product_id){
521 521
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid product_id");
@@ -531,14 +531,14 @@  discard block
 block discarded – undo
531 531
 
532 532
 
533 533
     /**
534
-    * [editProduct]
535
-    * @param  string $product_id   [Mandatory - Product ID]
536
-    * @param  array  $product_data [description]
537
-    * @return object               
538
-    */
534
+     * [editProduct]
535
+     * @param  string $product_id   [Mandatory - Product ID]
536
+     * @param  array  $product_data [description]
537
+     * @return object               
538
+     */
539 539
     public function editProduct($product_id, array $product_data){
540 540
         if(!$product_id){
541
-               throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id");
541
+                throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id");
542 542
         }
543 543
 
544 544
         //Validate Type
@@ -552,13 +552,13 @@  discard block
 block discarded – undo
552 552
             throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'");
553 553
         }
554 554
 
555
-       $url = "/products/{$product_id}";
555
+        $url = "/products/{$product_id}";
556 556
 
557
-       // Mandatory fields
558
-       $required_values = ['name', 'description', 'unit_cost', 'type'];
557
+        // Mandatory fields
558
+        $required_values = ['name', 'description', 'unit_cost', 'type'];
559 559
 
560 560
         if(!array_keys_exist($client_data, $required_values)){
561
-             throw new RequiredValuesMissing("Missing required values :(");
561
+                throw new RequiredValuesMissing("Missing required values :(");
562 562
         }
563 563
 
564 564
         return $this->sendRequest('put', $url, ['form_params' => $post_data]);
@@ -568,9 +568,9 @@  discard block
 block discarded – undo
568 568
 
569 569
 
570 570
     /**
571
-    * [getProducts]
572
-    * @return object
573
-    */
571
+     * [getProducts]
572
+     * @return object
573
+     */
574 574
     public function getProducts(){
575 575
         $url = "/products";
576 576
 
@@ -581,10 +581,10 @@  discard block
 block discarded – undo
581 581
 
582 582
 
583 583
     /**
584
-    * [deleteProduct]
585
-    * @param $product_id [Mandatory - Product ID]
586
-    * @return object           
587
-    */
584
+     * [deleteProduct]
585
+     * @param $product_id [Mandatory - Product ID]
586
+     * @return object           
587
+     */
588 588
     public function deleteProduct($product_id){
589 589
         if(!$product_id){
590 590
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id");
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
 
599 599
 
600 600
     /**
601
-    * [addPayment]
602
-    * @param [string] $method       [Mandatory - request method <get | post | put | delete> ]
603
-    * @param [string] $url           [Mandatory - url to send request to]
604
-    * @param [array] $params         [data to post to request url]
605
-    */
601
+     * [addPayment]
602
+     * @param [string] $method       [Mandatory - request method <get | post | put | delete> ]
603
+     * @param [string] $url           [Mandatory - url to send request to]
604
+     * @param [array] $params         [data to post to request url]
605
+     */
606 606
     public function sendRequest($method, $url, $params=[])
607 607
     {
608 608
         try{
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 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  [type] $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,22 +371,22 @@  discard block
 block discarded – undo
371 371
     * @param [string] $amount         [Mandatory]
372 372
     * @param [string] $channel        [Mandatory - valid ["Cash", "BankTransfer", "POS", "Cheque"]]
373 373
     */
374
-    public function addPayment(string $reference_code, string $date, string $amount, string $channel){
375
-        if(!$reference_code){
374
+    public function addPayment(string $reference_code, string $date, string $amount, string $channel) {
375
+        if (!$reference_code) {
376 376
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
377 377
         }
378 378
 
379
-        if(!$due_date){
379
+        if (!$due_date) {
380 380
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid date");
381 381
         }
382 382
 
383
-        if(!$amount){
383
+        if (!$amount) {
384 384
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid amount");
385 385
         }
386 386
 
387 387
         $valid_channels = ["Cash", "BankTransfer", "POS", "Cheque"];
388 388
 
389
-        if(!$channel){
389
+        if (!$channel) {
390 390
             throw new IsNull("Error Processing Request - Null/Invalid amount");
391 391
         }elseif (!in_array(ucfirst($channel), $valid_channels)) {
392 392
             throw new IsInvalid("Invalid Channel - Cash, BankTransfer, POS or Cheque");
@@ -412,8 +412,8 @@  discard block
 block discarded – undo
412 412
     * [getPayment]
413 413
     * @param [string] $reference_code [Mandatory - Invoice Reference Code]
414 414
     */
415
-    public function getPayment($reference_code){
416
-        if(!$reference_code){
415
+    public function getPayment($reference_code) {
416
+        if (!$reference_code) {
417 417
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
418 418
         }
419 419
 
@@ -433,8 +433,8 @@  discard block
 block discarded – undo
433 433
     * @param  [string] $end    [Format - DD/MM/YYYY || Optional if $period !== 'custom']
434 434
     * @return [object]         
435 435
     */
436
-    public function getPaymentHistory(string $period, string $start, string $end){
437
-        if(!$period){
436
+    public function getPaymentHistory(string $period, string $start, string $end) {
437
+        if (!$period) {
438 438
             throw new RequiredValueMissing("Error Processing Request - period Missing");
439 439
         }
440 440
 
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
             'period' => $period
450 450
         ];
451 451
 
452
-        if ($period == 'custom'){
453
-            if (!$start || !$end){
452
+        if ($period == 'custom') {
453
+            if (!$start || !$end) {
454 454
                 throw new IsNull("Invalid custom Start or End date");
455 455
             }
456 456
             $post_data['start'] = $start;
@@ -473,23 +473,23 @@  discard block
 block discarded – undo
473 473
     * @param string $unit_cost   [Mandatory - Product's unit cost]
474 474
     * @param string $type        [Mandatory - Product type 'product' or 'service']
475 475
     */
476
-    public function addProduct(string $name, string $description, string $unit_cost, string $type){
477
-        if(!$name){
476
+    public function addProduct(string $name, string $description, string $unit_cost, string $type) {
477
+        if (!$name) {
478 478
             throw new IsNull("Error Processing Request - Null/Invalid name");
479 479
         }
480 480
 
481
-        if(!$description){
481
+        if (!$description) {
482 482
             throw new IsNull("Error Processing Request - Null/Invalid description");
483 483
         }
484 484
 
485
-        if(!$unit_cost){
485
+        if (!$unit_cost) {
486 486
             throw new IsNull("Error Processing Request - Null/Invalid unit_cost");
487 487
         }
488 488
 
489 489
         //Validate Product Type
490 490
         $valid_product_type = ["product", "service"];
491 491
 
492
-        if(!$type){
492
+        if (!$type) {
493 493
             throw new IsNull("Error Processing Request - Null/Invalid type");
494 494
         }elseif (!in_array(strtolower($type), $valid_product_type)) {
495 495
             throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'");
@@ -516,8 +516,8 @@  discard block
 block discarded – undo
516 516
     * @param  [int] $product_id [Mandatory - Product ID]
517 517
     * @return [object] 
518 518
     */
519
-    public function getProduct($product_id){
520
-        if(!$product_id){
519
+    public function getProduct($product_id) {
520
+        if (!$product_id) {
521 521
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid product_id");
522 522
         }
523 523
 
@@ -536,8 +536,8 @@  discard block
 block discarded – undo
536 536
     * @param  array  $product_data [description]
537 537
     * @return object               
538 538
     */
539
-    public function editProduct($product_id, array $product_data){
540
-        if(!$product_id){
539
+    public function editProduct($product_id, array $product_data) {
540
+        if (!$product_id) {
541 541
                throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id");
542 542
         }
543 543
 
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
 
547 547
         $valid_product_type = ["product", "service"];
548 548
 
549
-        if(!$product_type){
549
+        if (!$product_type) {
550 550
             throw new IsNull("Error Processing Request - Null/Invalid type");
551 551
         }elseif (!in_array($product_type, $valid_product_type)) {
552 552
             throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'");
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
        // Mandatory fields
558 558
        $required_values = ['name', 'description', 'unit_cost', 'type'];
559 559
 
560
-        if(!array_keys_exist($client_data, $required_values)){
560
+        if (!array_keys_exist($client_data, $required_values)) {
561 561
              throw new RequiredValuesMissing("Missing required values :(");
562 562
         }
563 563
 
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
     * [getProducts]
572 572
     * @return object
573 573
     */
574
-    public function getProducts(){
574
+    public function getProducts() {
575 575
         $url = "/products";
576 576
 
577 577
         return $this->sendRequest('get', $url);
@@ -585,8 +585,8 @@  discard block
 block discarded – undo
585 585
     * @param $product_id [Mandatory - Product ID]
586 586
     * @return object           
587 587
     */
588
-    public function deleteProduct($product_id){
589
-        if(!$product_id){
588
+    public function deleteProduct($product_id) {
589
+        if (!$product_id) {
590 590
             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id");
591 591
         }
592 592
 
@@ -603,22 +603,22 @@  discard block
 block discarded – undo
603 603
     * @param [string] $url           [Mandatory - url to send request to]
604 604
     * @param [array] $params         [data to post to request url]
605 605
     */
606
-    public function sendRequest($method, $url, $params=[])
606
+    public function sendRequest($method, $url, $params = [])
607 607
     {
608
-        try{
609
-            if (strtolower($method) == 'get'){
608
+        try {
609
+            if (strtolower($method) == 'get') {
610 610
                 $result = $this->client->request('GET', $url);
611
-            }elseif (strtolower($method) == 'post'){
611
+            }elseif (strtolower($method) == 'post') {
612 612
                 $result = $this->client->request('POST', $url, $params);
613
-            }elseif (strtolower($method) == 'put'){
613
+            }elseif (strtolower($method) == 'put') {
614 614
                 $result = $this->client->request('PUT', $url, $params);
615
-            }elseif (strtolower($method) == 'delete'){
615
+            }elseif (strtolower($method) == 'delete') {
616 616
                 $result = $this->client->request('DELETE', $url);
617 617
             }
618 618
 
619 619
             return cleanResponse($result);
620 620
         }
621
-        catch( Exception $e){
621
+        catch (Exception $e) {
622 622
             throw $e;
623 623
         }
624 624
     }
Please login to merge, or discard this patch.