| @@ -13,10 +13,7 @@ | ||
| 13 | 13 | |
| 14 | 14 | use GuzzleHttp\Client; | 
| 15 | 15 | use Illuminate\Support\Facades\Config; | 
| 16 | -use Olaoluwa98\Payant\Exceptions\ApiRequestError; | |
| 17 | -use Olaoluwa98\Payant\Exceptions\InvalidCredentials; | |
| 18 | 16 | use Olaoluwa98\Payant\Exceptions\InvalidFeeBearer; | 
| 19 | -use Olaoluwa98\Payant\Exceptions\InvalidParameterType; | |
| 20 | 17 | use Olaoluwa98\Payant\Exceptions\IsInvalid; | 
| 21 | 18 | use Olaoluwa98\Payant\Exceptions\IsNull; | 
| 22 | 19 | use Olaoluwa98\Payant\Exceptions\IsNullOrInvalid; | 
| @@ -29,7 +29,7 @@ discard block | ||
| 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 | ||
| 37 | 37 | * | 
| 38 | 38 | * @var $base_uri | 
| 39 | 39 | * | 
| 40 | - */ | |
| 40 | + */ | |
| 41 | 41 | protected $base_uri = 'https://api.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 | ||
| 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('payantng.isdemo') == 'TRUE') | 
| @@ -83,7 +83,7 @@ discard block | ||
| 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( [ | 
| @@ -100,7 +100,7 @@ discard block | ||
| 100 | 100 | /** | 
| 101 | 101 | * [getStates Get States in a country (Nigeria)] | 
| 102 | 102 | * @return [object] [list of banks and their respective bank_ids] | 
| 103 | - */ | |
| 103 | + */ | |
| 104 | 104 |      public function getBanks(){ | 
| 105 | 105 |          return $this->sendRequest('get', '/banks'); | 
| 106 | 106 | } | 
| @@ -111,13 +111,13 @@ discard block | ||
| 111 | 111 | * [resolveAccount description] | 
| 112 | 112 | * @param array $client_data [description] | 
| 113 | 113 | * Required fields - 'settlement_bank', 'account_number' | 
| 114 | - */ | |
| 114 | + */ | |
| 115 | 115 |      public function resolveAccount( array $client_data){ | 
| 116 | 116 | // Mandatory fields | 
| 117 | 117 | $required_values = ['settlement_bank', 'account_number']; | 
| 118 | 118 | |
| 119 | 119 |          if(!array_keys_exist($client_data, $required_values)){ | 
| 120 | -         throw new RequiredValuesMissing("Missing required values :("); | |
| 120 | +            throw new RequiredValuesMissing("Missing required values :("); | |
| 121 | 121 | } | 
| 122 | 122 | |
| 123 | 123 | $url = '/resolve-account'; | 
| @@ -133,13 +133,13 @@ discard block | ||
| 133 | 133 | * @param array $client_data [description] | 
| 134 | 134 | * Required fields - 'first_name', 'last_name', 'email', 'phone' | 
| 135 | 135 | * Optional - 'address', 'company_name', 'type', 'settlement_bank', 'account_number' | 
| 136 | - */ | |
| 136 | + */ | |
| 137 | 137 |      public function addClient( array $client_data){ | 
| 138 | 138 | // Mandatory fields | 
| 139 | 139 | $required_values = ['first_name', 'last_name', 'email', 'phone']; | 
| 140 | 140 | |
| 141 | 141 |          if(!array_keys_exist($client_data, $required_values)){ | 
| 142 | -         throw new RequiredValuesMissing("Missing required values :("); | |
| 142 | +            throw new RequiredValuesMissing("Missing required values :("); | |
| 143 | 143 | } | 
| 144 | 144 | |
| 145 | 145 | $url = '/clients'; | 
| @@ -154,7 +154,7 @@ discard block | ||
| 154 | 154 | * [getClient Get client Details] | 
| 155 | 155 | * @param [string] $client_id | 
| 156 | 156 | * @return [object] | 
| 157 | - */ | |
| 157 | + */ | |
| 158 | 158 |      public function getClient($client_id = null){ | 
| 159 | 159 |          if(!$client_id){ | 
| 160 | 160 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id"); | 
| @@ -170,15 +170,15 @@ discard block | ||
| 170 | 170 | |
| 171 | 171 | |
| 172 | 172 | /** | 
| 173 | - * [editClient - Edit Existing Client] | |
| 174 | - * @param [string] $client_id | |
| 175 | - * @param [array] $client_data | |
| 176 | - * Required fields - 'first_name', 'last_name', 'email', 'phone' | |
| 177 | - * Optional - 'address', 'company_name', 'type', 'settlement_bank', 'account_number' | |
| 178 | - */ | |
| 173 | + * [editClient - Edit Existing Client] | |
| 174 | + * @param [string] $client_id | |
| 175 | + * @param [array] $client_data | |
| 176 | + * Required fields - 'first_name', 'last_name', 'email', 'phone' | |
| 177 | + * Optional - 'address', 'company_name', 'type', 'settlement_bank', 'account_number' | |
| 178 | + */ | |
| 179 | 179 |      public function editClient( $client_id, array $client_data){ | 
| 180 | 180 |          if(!$client_id){ | 
| 181 | -           throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id"); | |
| 181 | +            throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id"); | |
| 182 | 182 | } | 
| 183 | 183 | |
| 184 | 184 |          $url = "/clients/{$client_id}"; | 
| @@ -187,7 +187,7 @@ discard block | ||
| 187 | 187 | $required_values = ['first_name', 'last_name', 'email', 'phone']; | 
| 188 | 188 | |
| 189 | 189 |          if(!array_keys_exist($client_data, $required_values)){ | 
| 190 | -             throw new RequiredValuesMissing("Missing required values :("); | |
| 190 | +                throw new RequiredValuesMissing("Missing required values :("); | |
| 191 | 191 | } | 
| 192 | 192 | |
| 193 | 193 |          return $this->sendRequest('put', $url, ['form_params' => $client_data]); | 
| @@ -271,10 +271,10 @@ discard block | ||
| 271 | 271 | |
| 272 | 272 | |
| 273 | 273 | /** | 
| 274 | - * [getInvoice ] | |
| 275 | - * @param [string] $reference_code [Mandatory - Invoice Reference Code] | |
| 276 | - * @return [object] | |
| 277 | - */ | |
| 274 | + * [getInvoice ] | |
| 275 | + * @param [string] $reference_code [Mandatory - Invoice Reference Code] | |
| 276 | + * @return [object] | |
| 277 | + */ | |
| 278 | 278 |      public function getInvoice($reference_code){ | 
| 279 | 279 |          if(!$reference_code){ | 
| 280 | 280 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); | 
| @@ -286,10 +286,10 @@ discard block | ||
| 286 | 286 | } | 
| 287 | 287 | |
| 288 | 288 | /** | 
| 289 | - * [sendInvoice] | |
| 290 | - * @param [type] $reference_code [Mandatory - Invoice Reference Code] | |
| 291 | - * @return [object] | |
| 292 | - */ | |
| 289 | + * [sendInvoice] | |
| 290 | + * @param [type] $reference_code [Mandatory - Invoice Reference Code] | |
| 291 | + * @return [object] | |
| 292 | + */ | |
| 293 | 293 |      public function sendInvoice($reference_code = null){ | 
| 294 | 294 |          if(!$reference_code){ | 
| 295 | 295 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); | 
| @@ -305,12 +305,12 @@ discard block | ||
| 305 | 305 | |
| 306 | 306 | |
| 307 | 307 | /** | 
| 308 | - * [getInvoiceHistory] | |
| 309 | - * @param [string] $period [Mandatory || Valid Options ["today", "week", "month", "30", "90", "year", "custom"]] | |
| 310 | - * @param [string] $start [Format - DD/MM/YYYY] | |
| 311 | - * @param [string] $end [Format - DD/MM/YYYY] | |
| 312 | - * @return [object] | |
| 313 | - */ | |
| 308 | + * [getInvoiceHistory] | |
| 309 | + * @param [string] $period [Mandatory || Valid Options ["today", "week", "month", "30", "90", "year", "custom"]] | |
| 310 | + * @param [string] $start [Format - DD/MM/YYYY] | |
| 311 | + * @param [string] $end [Format - DD/MM/YYYY] | |
| 312 | + * @return [object] | |
| 313 | + */ | |
| 314 | 314 |      public function getInvoiceHistory($period, $start = null, $end = null){ | 
| 315 | 315 |          if(!$period){ | 
| 316 | 316 |              throw new RequiredValueMissing("Error Processing Request - period Missing"); | 
| @@ -345,10 +345,10 @@ discard block | ||
| 345 | 345 | |
| 346 | 346 | |
| 347 | 347 | /** | 
| 348 | - * [deleteInvoice] | |
| 349 | - * @param [string] $reference_code [Mandatory - Invoice Reference Code] | |
| 350 | - * @return [object] | |
| 351 | - */ | |
| 348 | + * [deleteInvoice] | |
| 349 | + * @param [string] $reference_code [Mandatory - Invoice Reference Code] | |
| 350 | + * @return [object] | |
| 351 | + */ | |
| 352 | 352 |      public function deleteInvoice($reference_code){ | 
| 353 | 353 |          if(!$reference_code){ | 
| 354 | 354 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); | 
| @@ -364,12 +364,12 @@ discard block | ||
| 364 | 364 | |
| 365 | 365 | |
| 366 | 366 | /** | 
| 367 | - * [addPayment] | |
| 368 | - * @param [string] $reference_code [Mandatory - Invoice Reference Code] | |
| 369 | - * @param [string] $date [Mandatory - [Format - DD/MM/YYYY]] | |
| 370 | - * @param [string] $amount [Mandatory] | |
| 371 | - * @param [string] $channel [Mandatory - valid ["Cash", "BankTransfer", "POS", "Cheque"]] | |
| 372 | - */ | |
| 367 | + * [addPayment] | |
| 368 | + * @param [string] $reference_code [Mandatory - Invoice Reference Code] | |
| 369 | + * @param [string] $date [Mandatory - [Format - DD/MM/YYYY]] | |
| 370 | + * @param [string] $amount [Mandatory] | |
| 371 | + * @param [string] $channel [Mandatory - valid ["Cash", "BankTransfer", "POS", "Cheque"]] | |
| 372 | + */ | |
| 373 | 373 |      public function addPayment(string $reference_code, string $date, string $amount, string $channel){ | 
| 374 | 374 |          if(!$reference_code){ | 
| 375 | 375 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); | 
| @@ -408,9 +408,9 @@ discard block | ||
| 408 | 408 | |
| 409 | 409 | |
| 410 | 410 | /** | 
| 411 | - * [getPayment] | |
| 412 | - * @param [string] $reference_code [Mandatory - Invoice Reference Code] | |
| 413 | - */ | |
| 411 | + * [getPayment] | |
| 412 | + * @param [string] $reference_code [Mandatory - Invoice Reference Code] | |
| 413 | + */ | |
| 414 | 414 |      public function getPayment($reference_code){ | 
| 415 | 415 |          if(!$reference_code){ | 
| 416 | 416 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); | 
| @@ -426,12 +426,12 @@ discard block | ||
| 426 | 426 | |
| 427 | 427 | |
| 428 | 428 | /** | 
| 429 | - * [getPaymentHistory] | |
| 430 | - * @param [string] $period [Mandatory || Valid Options ["today", "week", "month", "30", "90", "year", "custom"]] | |
| 431 | - * @param [string] $start [Format - DD/MM/YYYY || Optional if $period !== 'custom'] | |
| 432 | - * @param [string] $end [Format - DD/MM/YYYY || Optional if $period !== 'custom'] | |
| 433 | - * @return [object] | |
| 434 | - */ | |
| 429 | + * [getPaymentHistory] | |
| 430 | + * @param [string] $period [Mandatory || Valid Options ["today", "week", "month", "30", "90", "year", "custom"]] | |
| 431 | + * @param [string] $start [Format - DD/MM/YYYY || Optional if $period !== 'custom'] | |
| 432 | + * @param [string] $end [Format - DD/MM/YYYY || Optional if $period !== 'custom'] | |
| 433 | + * @return [object] | |
| 434 | + */ | |
| 435 | 435 |      public function getPaymentHistory(string $period, string $start, string $end){ | 
| 436 | 436 |          if(!$period){ | 
| 437 | 437 |              throw new RequiredValueMissing("Error Processing Request - period Missing"); | 
| @@ -466,12 +466,12 @@ discard block | ||
| 466 | 466 | |
| 467 | 467 | |
| 468 | 468 | /** | 
| 469 | - * [addProduct] | |
| 470 | - * @param string $name [Mandatory - Product's name] | |
| 471 | - * @param string $description [Mandatory - Product's description] | |
| 472 | - * @param string $unit_cost [Mandatory - Product's unit cost] | |
| 473 | - * @param string $type [Mandatory - Product type 'product' or 'service'] | |
| 474 | - */ | |
| 469 | + * [addProduct] | |
| 470 | + * @param string $name [Mandatory - Product's name] | |
| 471 | + * @param string $description [Mandatory - Product's description] | |
| 472 | + * @param string $unit_cost [Mandatory - Product's unit cost] | |
| 473 | + * @param string $type [Mandatory - Product type 'product' or 'service'] | |
| 474 | + */ | |
| 475 | 475 |      public function addProduct(string $name, string $description, string $unit_cost, string $type){ | 
| 476 | 476 |          if(!$name){ | 
| 477 | 477 |              throw new IsNull("Error Processing Request - Null/Invalid name"); | 
| @@ -511,10 +511,10 @@ discard block | ||
| 511 | 511 | |
| 512 | 512 | |
| 513 | 513 | /** | 
| 514 | - * [getProduct] | |
| 515 | - * @param [int] $product_id [Mandatory - Product ID] | |
| 516 | - * @return [object] | |
| 517 | - */ | |
| 514 | + * [getProduct] | |
| 515 | + * @param [int] $product_id [Mandatory - Product ID] | |
| 516 | + * @return [object] | |
| 517 | + */ | |
| 518 | 518 |      public function getProduct($product_id){ | 
| 519 | 519 |          if(!$product_id){ | 
| 520 | 520 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid product_id"); | 
| @@ -530,14 +530,14 @@ discard block | ||
| 530 | 530 | |
| 531 | 531 | |
| 532 | 532 | /** | 
| 533 | - * [editProduct] | |
| 534 | - * @param string $product_id [Mandatory - Product ID] | |
| 535 | - * @param array $product_data [description] | |
| 536 | - * @return object | |
| 537 | - */ | |
| 533 | + * [editProduct] | |
| 534 | + * @param string $product_id [Mandatory - Product ID] | |
| 535 | + * @param array $product_data [description] | |
| 536 | + * @return object | |
| 537 | + */ | |
| 538 | 538 |      public function editProduct($product_id, array $product_data){ | 
| 539 | 539 |          if(!$product_id){ | 
| 540 | -               throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id"); | |
| 540 | +                throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id"); | |
| 541 | 541 | } | 
| 542 | 542 | |
| 543 | 543 | //Validate Type | 
| @@ -551,13 +551,13 @@ discard block | ||
| 551 | 551 |              throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'"); | 
| 552 | 552 | } | 
| 553 | 553 | |
| 554 | -       $url = "/products/{$product_id}"; | |
| 554 | +        $url = "/products/{$product_id}"; | |
| 555 | 555 | |
| 556 | - // Mandatory fields | |
| 557 | - $required_values = ['name', 'description', 'unit_cost', 'type']; | |
| 556 | + // Mandatory fields | |
| 557 | + $required_values = ['name', 'description', 'unit_cost', 'type']; | |
| 558 | 558 | |
| 559 | 559 |          if(!array_keys_exist($client_data, $required_values)){ | 
| 560 | -             throw new RequiredValuesMissing("Missing required values :("); | |
| 560 | +                throw new RequiredValuesMissing("Missing required values :("); | |
| 561 | 561 | } | 
| 562 | 562 | |
| 563 | 563 |          return $this->sendRequest('put', $url, ['form_params' => $post_data]); | 
| @@ -567,9 +567,9 @@ discard block | ||
| 567 | 567 | |
| 568 | 568 | |
| 569 | 569 | /** | 
| 570 | - * [getProducts] | |
| 571 | - * @return object | |
| 572 | - */ | |
| 570 | + * [getProducts] | |
| 571 | + * @return object | |
| 572 | + */ | |
| 573 | 573 |      public function getProducts(){ | 
| 574 | 574 | $url = "/products"; | 
| 575 | 575 | |
| @@ -580,10 +580,10 @@ discard block | ||
| 580 | 580 | |
| 581 | 581 | |
| 582 | 582 | /** | 
| 583 | - * [deleteProduct] | |
| 584 | - * @param $product_id [Mandatory - Product ID] | |
| 585 | - * @return object | |
| 586 | - */ | |
| 583 | + * [deleteProduct] | |
| 584 | + * @param $product_id [Mandatory - Product ID] | |
| 585 | + * @return object | |
| 586 | + */ | |
| 587 | 587 |      public function deleteProduct($product_id){ | 
| 588 | 588 |          if(!$product_id){ | 
| 589 | 589 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id"); | 
| @@ -597,11 +597,11 @@ discard block | ||
| 597 | 597 | |
| 598 | 598 | |
| 599 | 599 | /** | 
| 600 | - * [addPayment] | |
| 601 | - * @param [string] $method [Mandatory - request method <get | post | put | delete> ] | |
| 602 | - * @param [string] $url [Mandatory - url to send request to] | |
| 603 | - * @param [array] $params [data to post to request url] | |
| 604 | - */ | |
| 600 | + * [addPayment] | |
| 601 | + * @param [string] $method [Mandatory - request method <get | post | put | delete> ] | |
| 602 | + * @param [string] $url [Mandatory - url to send request to] | |
| 603 | + * @param [array] $params [data to post to request url] | |
| 604 | + */ | |
| 605 | 605 | public function sendRequest($method, $url, $params=[]) | 
| 606 | 606 |      { | 
| 607 | 607 |          try{ | 
| @@ -63,7 +63,7 @@ discard block | ||
| 63 | 63 | */ | 
| 64 | 64 | public function setBaseUrl() | 
| 65 | 65 |      { | 
| 66 | -        if(Config::get('payantng.isdemo') == 'TRUE') | |
| 66 | +        if (Config::get('payantng.isdemo') == 'TRUE') | |
| 67 | 67 |          { | 
| 68 | 68 | $this->base_uri = "https://api.demo.payant.ng"; | 
| 69 | 69 | } | 
| @@ -83,10 +83,10 @@ discard block | ||
| 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' => [ | 
| @@ -101,7 +101,7 @@ discard block | ||
| 101 | 101 | * [getStates Get States in a country (Nigeria)] | 
| 102 | 102 | * @return [object] [list of banks and their respective bank_ids] | 
| 103 | 103 | */ | 
| 104 | -    public function getBanks(){ | |
| 104 | +    public function getBanks() { | |
| 105 | 105 |          return $this->sendRequest('get', '/banks'); | 
| 106 | 106 | } | 
| 107 | 107 | |
| @@ -112,11 +112,11 @@ discard block | ||
| 112 | 112 | * @param array $client_data [description] | 
| 113 | 113 | * Required fields - 'settlement_bank', 'account_number' | 
| 114 | 114 | */ | 
| 115 | -    public function resolveAccount( array $client_data){ | |
| 115 | +    public function resolveAccount(array $client_data) { | |
| 116 | 116 | // Mandatory fields | 
| 117 | 117 | $required_values = ['settlement_bank', 'account_number']; | 
| 118 | 118 | |
| 119 | -        if(!array_keys_exist($client_data, $required_values)){ | |
| 119 | +        if (!array_keys_exist($client_data, $required_values)) { | |
| 120 | 120 |           throw new RequiredValuesMissing("Missing required values :("); | 
| 121 | 121 | } | 
| 122 | 122 | |
| @@ -134,11 +134,11 @@ discard block | ||
| 134 | 134 | * Required fields - 'first_name', 'last_name', 'email', 'phone' | 
| 135 | 135 | * Optional - 'address', 'company_name', 'type', 'settlement_bank', 'account_number' | 
| 136 | 136 | */ | 
| 137 | -    public function addClient( array $client_data){ | |
| 137 | +    public function addClient(array $client_data) { | |
| 138 | 138 | // Mandatory fields | 
| 139 | 139 | $required_values = ['first_name', 'last_name', 'email', 'phone']; | 
| 140 | 140 | |
| 141 | -        if(!array_keys_exist($client_data, $required_values)){ | |
| 141 | +        if (!array_keys_exist($client_data, $required_values)) { | |
| 142 | 142 |           throw new RequiredValuesMissing("Missing required values :("); | 
| 143 | 143 | } | 
| 144 | 144 | |
| @@ -155,8 +155,8 @@ discard block | ||
| 155 | 155 | * @param [string] $client_id | 
| 156 | 156 | * @return [object] | 
| 157 | 157 | */ | 
| 158 | -    public function getClient($client_id = null){ | |
| 159 | -        if(!$client_id){ | |
| 158 | +    public function getClient($client_id = null) { | |
| 159 | +        if (!$client_id) { | |
| 160 | 160 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id"); | 
| 161 | 161 | } | 
| 162 | 162 | |
| @@ -176,8 +176,8 @@ discard block | ||
| 176 | 176 | * Required fields - 'first_name', 'last_name', 'email', 'phone' | 
| 177 | 177 | * Optional - 'address', 'company_name', 'type', 'settlement_bank', 'account_number' | 
| 178 | 178 | */ | 
| 179 | -    public function editClient( $client_id, array $client_data){ | |
| 180 | -        if(!$client_id){ | |
| 179 | +    public function editClient($client_id, array $client_data) { | |
| 180 | +        if (!$client_id) { | |
| 181 | 181 |             throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id"); | 
| 182 | 182 | } | 
| 183 | 183 | |
| @@ -186,7 +186,7 @@ discard block | ||
| 186 | 186 | // Mandatory fields | 
| 187 | 187 | $required_values = ['first_name', 'last_name', 'email', 'phone']; | 
| 188 | 188 | |
| 189 | -        if(!array_keys_exist($client_data, $required_values)){ | |
| 189 | +        if (!array_keys_exist($client_data, $required_values)) { | |
| 190 | 190 |               throw new RequiredValuesMissing("Missing required values :("); | 
| 191 | 191 | } | 
| 192 | 192 | |
| @@ -201,8 +201,8 @@ discard block | ||
| 201 | 201 | * [deleteClient] | 
| 202 | 202 | * @param [string] $client_id [description] | 
| 203 | 203 | */ | 
| 204 | -    public function deleteClient($client_id = null){ | |
| 205 | -        if(!$client_id){ | |
| 204 | +    public function deleteClient($client_id = null) { | |
| 205 | +        if (!$client_id) { | |
| 206 | 206 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id"); | 
| 207 | 207 | } | 
| 208 | 208 | |
| @@ -225,7 +225,7 @@ discard block | ||
| 225 | 225 | * @param [string] $fee_bearer [Mandatory] | 
| 226 | 226 | * @param array $items [Mandatory] | 
| 227 | 227 | */ | 
| 228 | -    public function addInvoice($client_id, array $client_data, $due_date, $fee_bearer, array $items){ | |
| 228 | +    public function addInvoice($client_id, array $client_data, $due_date, $fee_bearer, array $items) { | |
| 229 | 229 | // Mandatory Client fields | 
| 230 | 230 | $required_client_values = ['first_name', 'last_name', 'email', 'phone']; | 
| 231 | 231 | |
| @@ -235,21 +235,21 @@ discard block | ||
| 235 | 235 | |
| 236 | 236 | |
| 237 | 237 | // Either the client Id is supplied or a new client data is provided | 
| 238 | -        if(!$client_id && !array_keys_exist($client_data, $required_client_values)){ | |
| 238 | +        if (!$client_id && !array_keys_exist($client_data, $required_client_values)) { | |
| 239 | 239 |              throw new RequiredValuesMissing("Missing required values :( - Provide client_id or client_data"); | 
| 240 | 240 | } | 
| 241 | 241 | |
| 242 | -        if(!$due_date){ | |
| 242 | +        if (!$due_date) { | |
| 243 | 243 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Due Date"); | 
| 244 | 244 | } | 
| 245 | 245 | |
| 246 | -        if(!$fee_bearer){ | |
| 246 | +        if (!$fee_bearer) { | |
| 247 | 247 |              throw new IsNull("Error Processing Request - Null Fee Bearer"); | 
| 248 | 248 |          }elseif (!in_array($fee_bearer, $valid_fee_bearers)) { | 
| 249 | 249 |              throw new InvalidFeeBearer("Invalid Fee Bearer - Use either 'account' or 'client'"); | 
| 250 | 250 | } | 
| 251 | 251 | |
| 252 | -        if(!is_array($items)){ | |
| 252 | +        if (!is_array($items)) { | |
| 253 | 253 |              throw new IsInvalid("Error Processing Request - Invalid Items"); | 
| 254 | 254 | } | 
| 255 | 255 | |
| @@ -275,8 +275,8 @@ discard block | ||
| 275 | 275 | * @param [string] $reference_code [Mandatory - Invoice Reference Code] | 
| 276 | 276 | * @return [object] | 
| 277 | 277 | */ | 
| 278 | -    public function getInvoice($reference_code){ | |
| 279 | -        if(!$reference_code){ | |
| 278 | +    public function getInvoice($reference_code) { | |
| 279 | +        if (!$reference_code) { | |
| 280 | 280 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); | 
| 281 | 281 | } | 
| 282 | 282 | |
| @@ -290,8 +290,8 @@ discard block | ||
| 290 | 290 | * @param [type] $reference_code [Mandatory - Invoice Reference Code] | 
| 291 | 291 | * @return [object] | 
| 292 | 292 | */ | 
| 293 | -    public function sendInvoice($reference_code = null){ | |
| 294 | -        if(!$reference_code){ | |
| 293 | +    public function sendInvoice($reference_code = null) { | |
| 294 | +        if (!$reference_code) { | |
| 295 | 295 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); | 
| 296 | 296 | } | 
| 297 | 297 | |
| @@ -311,8 +311,8 @@ discard block | ||
| 311 | 311 | * @param [string] $end [Format - DD/MM/YYYY] | 
| 312 | 312 | * @return [object] | 
| 313 | 313 | */ | 
| 314 | -    public function getInvoiceHistory($period, $start = null, $end = null){ | |
| 315 | -        if(!$period){ | |
| 314 | +    public function getInvoiceHistory($period, $start = null, $end = null) { | |
| 315 | +        if (!$period) { | |
| 316 | 316 |              throw new RequiredValueMissing("Error Processing Request - period Missing"); | 
| 317 | 317 | } | 
| 318 | 318 | |
| @@ -327,8 +327,8 @@ discard block | ||
| 327 | 327 | 'period' => $period | 
| 328 | 328 | ]; | 
| 329 | 329 | |
| 330 | -        if ($period == 'custom'){ | |
| 331 | -            if (!$start || !$end){ | |
| 330 | +        if ($period == 'custom') { | |
| 331 | +            if (!$start || !$end) { | |
| 332 | 332 |                  throw new IsNull("Invalid custom Start or End date"); | 
| 333 | 333 | } | 
| 334 | 334 | $post_data['start'] = $start; | 
| @@ -349,8 +349,8 @@ discard block | ||
| 349 | 349 | * @param [string] $reference_code [Mandatory - Invoice Reference Code] | 
| 350 | 350 | * @return [object] | 
| 351 | 351 | */ | 
| 352 | -    public function deleteInvoice($reference_code){ | |
| 353 | -        if(!$reference_code){ | |
| 352 | +    public function deleteInvoice($reference_code) { | |
| 353 | +        if (!$reference_code) { | |
| 354 | 354 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); | 
| 355 | 355 | } | 
| 356 | 356 | |
| @@ -370,22 +370,22 @@ discard block | ||
| 370 | 370 | * @param [string] $amount [Mandatory] | 
| 371 | 371 | * @param [string] $channel [Mandatory - valid ["Cash", "BankTransfer", "POS", "Cheque"]] | 
| 372 | 372 | */ | 
| 373 | -    public function addPayment(string $reference_code, string $date, string $amount, string $channel){ | |
| 374 | -        if(!$reference_code){ | |
| 373 | +    public function addPayment(string $reference_code, string $date, string $amount, string $channel) { | |
| 374 | +        if (!$reference_code) { | |
| 375 | 375 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); | 
| 376 | 376 | } | 
| 377 | 377 | |
| 378 | -        if(!$due_date){ | |
| 378 | +        if (!$due_date) { | |
| 379 | 379 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid date"); | 
| 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 | |
| 386 | 386 | $valid_channels = ["Cash", "BankTransfer", "POS", "Cheque"]; | 
| 387 | 387 | |
| 388 | -        if(!$channel){ | |
| 388 | +        if (!$channel) { | |
| 389 | 389 |              throw new IsNull("Error Processing Request - Null/Invalid amount"); | 
| 390 | 390 |          }elseif (!in_array(ucfirst($channel), $valid_channels)) { | 
| 391 | 391 |              throw new IsInvalid("Invalid Channel - Cash, BankTransfer, POS or Cheque"); | 
| @@ -411,8 +411,8 @@ discard block | ||
| 411 | 411 | * [getPayment] | 
| 412 | 412 | * @param [string] $reference_code [Mandatory - Invoice Reference Code] | 
| 413 | 413 | */ | 
| 414 | -    public function getPayment($reference_code){ | |
| 415 | -        if(!$reference_code){ | |
| 414 | +    public function getPayment($reference_code) { | |
| 415 | +        if (!$reference_code) { | |
| 416 | 416 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); | 
| 417 | 417 | } | 
| 418 | 418 | |
| @@ -432,8 +432,8 @@ discard block | ||
| 432 | 432 | * @param [string] $end [Format - DD/MM/YYYY || Optional if $period !== 'custom'] | 
| 433 | 433 | * @return [object] | 
| 434 | 434 | */ | 
| 435 | -    public function getPaymentHistory(string $period, string $start, string $end){ | |
| 436 | -        if(!$period){ | |
| 435 | +    public function getPaymentHistory(string $period, string $start, string $end) { | |
| 436 | +        if (!$period) { | |
| 437 | 437 |              throw new RequiredValueMissing("Error Processing Request - period Missing"); | 
| 438 | 438 | } | 
| 439 | 439 | |
| @@ -448,8 +448,8 @@ discard block | ||
| 448 | 448 | 'period' => $period | 
| 449 | 449 | ]; | 
| 450 | 450 | |
| 451 | -        if ($period == 'custom'){ | |
| 452 | -            if (!$start || !$end){ | |
| 451 | +        if ($period == 'custom') { | |
| 452 | +            if (!$start || !$end) { | |
| 453 | 453 |                  throw new IsNull("Invalid custom Start or End date"); | 
| 454 | 454 | } | 
| 455 | 455 | $post_data['start'] = $start; | 
| @@ -472,23 +472,23 @@ discard block | ||
| 472 | 472 | * @param string $unit_cost [Mandatory - Product's unit cost] | 
| 473 | 473 | * @param string $type [Mandatory - Product type 'product' or 'service'] | 
| 474 | 474 | */ | 
| 475 | -    public function addProduct(string $name, string $description, string $unit_cost, string $type){ | |
| 476 | -        if(!$name){ | |
| 475 | +    public function addProduct(string $name, string $description, string $unit_cost, string $type) { | |
| 476 | +        if (!$name) { | |
| 477 | 477 |              throw new IsNull("Error Processing Request - Null/Invalid name"); | 
| 478 | 478 | } | 
| 479 | 479 | |
| 480 | -        if(!$description){ | |
| 480 | +        if (!$description) { | |
| 481 | 481 |              throw new IsNull("Error Processing Request - Null/Invalid description"); | 
| 482 | 482 | } | 
| 483 | 483 | |
| 484 | -        if(!$unit_cost){ | |
| 484 | +        if (!$unit_cost) { | |
| 485 | 485 |              throw new IsNull("Error Processing Request - Null/Invalid unit_cost"); | 
| 486 | 486 | } | 
| 487 | 487 | |
| 488 | 488 | //Validate Product Type | 
| 489 | 489 | $valid_product_type = ["product", "service"]; | 
| 490 | 490 | |
| 491 | -        if(!$type){ | |
| 491 | +        if (!$type) { | |
| 492 | 492 |              throw new IsNull("Error Processing Request - Null/Invalid type"); | 
| 493 | 493 |          }elseif (!in_array(strtolower($type), $valid_product_type)) { | 
| 494 | 494 |              throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'"); | 
| @@ -515,8 +515,8 @@ discard block | ||
| 515 | 515 | * @param [int] $product_id [Mandatory - Product ID] | 
| 516 | 516 | * @return [object] | 
| 517 | 517 | */ | 
| 518 | -    public function getProduct($product_id){ | |
| 519 | -        if(!$product_id){ | |
| 518 | +    public function getProduct($product_id) { | |
| 519 | +        if (!$product_id) { | |
| 520 | 520 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid product_id"); | 
| 521 | 521 | } | 
| 522 | 522 | |
| @@ -535,8 +535,8 @@ discard block | ||
| 535 | 535 | * @param array $product_data [description] | 
| 536 | 536 | * @return object | 
| 537 | 537 | */ | 
| 538 | -    public function editProduct($product_id, array $product_data){ | |
| 539 | -        if(!$product_id){ | |
| 538 | +    public function editProduct($product_id, array $product_data) { | |
| 539 | +        if (!$product_id) { | |
| 540 | 540 |                 throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id"); | 
| 541 | 541 | } | 
| 542 | 542 | |
| @@ -545,7 +545,7 @@ discard block | ||
| 545 | 545 | |
| 546 | 546 | $valid_product_type = ["product", "service"]; | 
| 547 | 547 | |
| 548 | -        if(!$product_type){ | |
| 548 | +        if (!$product_type) { | |
| 549 | 549 |              throw new IsNull("Error Processing Request - Null/Invalid type"); | 
| 550 | 550 |          }elseif (!in_array($product_type, $valid_product_type)) { | 
| 551 | 551 |              throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'"); | 
| @@ -556,7 +556,7 @@ discard block | ||
| 556 | 556 | // Mandatory fields | 
| 557 | 557 | $required_values = ['name', 'description', 'unit_cost', 'type']; | 
| 558 | 558 | |
| 559 | -        if(!array_keys_exist($client_data, $required_values)){ | |
| 559 | +        if (!array_keys_exist($client_data, $required_values)) { | |
| 560 | 560 |               throw new RequiredValuesMissing("Missing required values :("); | 
| 561 | 561 | } | 
| 562 | 562 | |
| @@ -570,7 +570,7 @@ discard block | ||
| 570 | 570 | * [getProducts] | 
| 571 | 571 | * @return object | 
| 572 | 572 | */ | 
| 573 | -    public function getProducts(){ | |
| 573 | +    public function getProducts() { | |
| 574 | 574 | $url = "/products"; | 
| 575 | 575 | |
| 576 | 576 |          return $this->sendRequest('get', $url); | 
| @@ -584,8 +584,8 @@ discard block | ||
| 584 | 584 | * @param $product_id [Mandatory - Product ID] | 
| 585 | 585 | * @return object | 
| 586 | 586 | */ | 
| 587 | -    public function deleteProduct($product_id){ | |
| 588 | -        if(!$product_id){ | |
| 587 | +    public function deleteProduct($product_id) { | |
| 588 | +        if (!$product_id) { | |
| 589 | 589 |              throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id"); | 
| 590 | 590 | } | 
| 591 | 591 | |
| @@ -602,22 +602,22 @@ discard block | ||
| 602 | 602 | * @param [string] $url [Mandatory - url to send request to] | 
| 603 | 603 | * @param [array] $params [data to post to request url] | 
| 604 | 604 | */ | 
| 605 | - public function sendRequest($method, $url, $params=[]) | |
| 605 | + public function sendRequest($method, $url, $params = []) | |
| 606 | 606 |      { | 
| 607 | -        try{ | |
| 608 | -            if (strtolower($method) == 'get'){ | |
| 607 | +        try { | |
| 608 | +            if (strtolower($method) == 'get') { | |
| 609 | 609 |                  $result = $this->client->request('GET', $url); | 
| 610 | -            }elseif (strtolower($method) == 'post'){ | |
| 610 | +            }elseif (strtolower($method) == 'post') { | |
| 611 | 611 |                  $result = $this->client->request('POST', $url, $params); | 
| 612 | -            }elseif (strtolower($method) == 'put'){ | |
| 612 | +            }elseif (strtolower($method) == 'put') { | |
| 613 | 613 |                  $result = $this->client->request('PUT', $url, $params); | 
| 614 | -            }elseif (strtolower($method) == 'delete'){ | |
| 614 | +            }elseif (strtolower($method) == 'delete') { | |
| 615 | 615 |                  $result = $this->client->request('DELETE', $url); | 
| 616 | 616 | } | 
| 617 | 617 | |
| 618 | 618 | return cleanResponse($result); | 
| 619 | 619 | } | 
| 620 | -        catch( Exception $e){ | |
| 620 | +        catch (Exception $e) { | |
| 621 | 621 | throw $e; | 
| 622 | 622 | } | 
| 623 | 623 | } | 
| @@ -245,7 +245,7 @@ discard block | ||
| 245 | 245 | |
| 246 | 246 |          if(!$fee_bearer){ | 
| 247 | 247 |              throw new IsNull("Error Processing Request - Null Fee Bearer"); | 
| 248 | -        }elseif (!in_array($fee_bearer, $valid_fee_bearers)) { | |
| 248 | +        } elseif (!in_array($fee_bearer, $valid_fee_bearers)) { | |
| 249 | 249 |              throw new InvalidFeeBearer("Invalid Fee Bearer - Use either 'account' or 'client'"); | 
| 250 | 250 | } | 
| 251 | 251 | |
| @@ -387,7 +387,7 @@ discard block | ||
| 387 | 387 | |
| 388 | 388 |          if(!$channel){ | 
| 389 | 389 |              throw new IsNull("Error Processing Request - Null/Invalid amount"); | 
| 390 | -        }elseif (!in_array(ucfirst($channel), $valid_channels)) { | |
| 390 | +        } elseif (!in_array(ucfirst($channel), $valid_channels)) { | |
| 391 | 391 |              throw new IsInvalid("Invalid Channel - Cash, BankTransfer, POS or Cheque"); | 
| 392 | 392 | } | 
| 393 | 393 | |
| @@ -490,7 +490,7 @@ discard block | ||
| 490 | 490 | |
| 491 | 491 |          if(!$type){ | 
| 492 | 492 |              throw new IsNull("Error Processing Request - Null/Invalid type"); | 
| 493 | -        }elseif (!in_array(strtolower($type), $valid_product_type)) { | |
| 493 | +        } elseif (!in_array(strtolower($type), $valid_product_type)) { | |
| 494 | 494 |              throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'"); | 
| 495 | 495 | } | 
| 496 | 496 | |
| @@ -547,7 +547,7 @@ discard block | ||
| 547 | 547 | |
| 548 | 548 |          if(!$product_type){ | 
| 549 | 549 |              throw new IsNull("Error Processing Request - Null/Invalid type"); | 
| 550 | -        }elseif (!in_array($product_type, $valid_product_type)) { | |
| 550 | +        } elseif (!in_array($product_type, $valid_product_type)) { | |
| 551 | 551 |              throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'"); | 
| 552 | 552 | } | 
| 553 | 553 | |
| @@ -607,17 +607,16 @@ discard block | ||
| 607 | 607 |          try{ | 
| 608 | 608 |              if (strtolower($method) == 'get'){ | 
| 609 | 609 |                  $result = $this->client->request('GET', $url); | 
| 610 | -            }elseif (strtolower($method) == 'post'){ | |
| 610 | +            } elseif (strtolower($method) == 'post'){ | |
| 611 | 611 |                  $result = $this->client->request('POST', $url, $params); | 
| 612 | -            }elseif (strtolower($method) == 'put'){ | |
| 612 | +            } elseif (strtolower($method) == 'put'){ | |
| 613 | 613 |                  $result = $this->client->request('PUT', $url, $params); | 
| 614 | -            }elseif (strtolower($method) == 'delete'){ | |
| 614 | +            } elseif (strtolower($method) == 'delete'){ | |
| 615 | 615 |                  $result = $this->client->request('DELETE', $url); | 
| 616 | 616 | } | 
| 617 | 617 | |
| 618 | 618 | return cleanResponse($result); | 
| 619 | - } | |
| 620 | -        catch( Exception $e){ | |
| 619 | +        } catch( Exception $e){ | |
| 621 | 620 | throw $e; | 
| 622 | 621 | } | 
| 623 | 622 | } | 
| @@ -15,7 +15,7 @@ discard block | ||
| 15 | 15 | |
| 16 | 16 |  if (! function_exists('array_get')) | 
| 17 | 17 |  { | 
| 18 | - /* | |
| 18 | + /* | |
| 19 | 19 | * | 
| 20 | 20 | * @param array $data | 
| 21 | 21 | * @param string $key | 
| @@ -23,12 +23,12 @@ discard block | ||
| 23 | 23 | * | 
| 24 | 24 | * @return mixed | 
| 25 | 25 | */ | 
| 26 | -   function array_get($data, $key, $default = false) { | |
| 27 | -     if (!is_array($data)) { | |
| 28 | - return $default; | |
| 29 | - } | |
| 30 | - return isset($data[$key]) ? $data[$key]: $default; | |
| 31 | - } | |
| 26 | +    function array_get($data, $key, $default = false) { | |
| 27 | +        if (!is_array($data)) { | |
| 28 | + return $default; | |
| 29 | + } | |
| 30 | + return isset($data[$key]) ? $data[$key]: $default; | |
| 31 | + } | |
| 32 | 32 | } | 
| 33 | 33 | |
| 34 | 34 |  if(!function_exists('array_keys_exist')){ | 
| @@ -57,6 +57,6 @@ discard block | ||
| 57 | 57 | } | 
| 58 | 58 | |
| 59 | 59 |  function cleanResponse($response){ | 
| 60 | - $result = $response->getBody(); | |
| 61 | - return json_decode($result); | |
| 60 | + $result = $response->getBody(); | |
| 61 | + return json_decode($result); | |
| 62 | 62 | } | 
| 63 | 63 | \ No newline at end of file | 
| @@ -13,7 +13,7 @@ discard block | ||
| 13 | 13 | |
| 14 | 14 | use \Exception as phpException; | 
| 15 | 15 | |
| 16 | -if (! function_exists('array_get')) | |
| 16 | +if (!function_exists('array_get')) | |
| 17 | 17 |  { | 
| 18 | 18 | /* | 
| 19 | 19 | * | 
| @@ -27,11 +27,11 @@ discard block | ||
| 27 | 27 |       if (!is_array($data)) { | 
| 28 | 28 | return $default; | 
| 29 | 29 | } | 
| 30 | - return isset($data[$key]) ? $data[$key]: $default; | |
| 30 | + return isset($data[$key]) ? $data[$key] : $default; | |
| 31 | 31 | } | 
| 32 | 32 | } | 
| 33 | 33 | |
| 34 | -if(!function_exists('array_keys_exist')){ | |
| 34 | +if (!function_exists('array_keys_exist')) { | |
| 35 | 35 | /** | 
| 36 | 36 | * Checks if multiple keys exist in an array | 
| 37 | 37 | * | 
| @@ -40,23 +40,23 @@ discard block | ||
| 40 | 40 | * | 
| 41 | 41 | * @return bool | 
| 42 | 42 | */ | 
| 43 | -    function array_keys_exist( array $array, $keys ) { | |
| 43 | +    function array_keys_exist(array $array, $keys) { | |
| 44 | 44 | $count = 0; | 
| 45 | -        if ( ! is_array( $keys ) ) { | |
| 45 | +        if (!is_array($keys)) { | |
| 46 | 46 | $keys = func_get_args(); | 
| 47 | - array_shift( $keys ); | |
| 47 | + array_shift($keys); | |
| 48 | 48 | } | 
| 49 | -        foreach ( $keys as $key ) { | |
| 50 | -            if ( array_key_exists( $key, $array ) ) { | |
| 51 | - $count ++; | |
| 49 | +        foreach ($keys as $key) { | |
| 50 | +            if (array_key_exists($key, $array)) { | |
| 51 | + $count++; | |
| 52 | 52 | } | 
| 53 | 53 | } | 
| 54 | 54 | |
| 55 | - return count( $keys ) === $count; | |
| 55 | + return count($keys) === $count; | |
| 56 | 56 | } | 
| 57 | 57 | } | 
| 58 | 58 | |
| 59 | -function cleanResponse($response){ | |
| 59 | +function cleanResponse($response) { | |
| 60 | 60 | $result = $response->getBody(); | 
| 61 | 61 | return json_decode($result); | 
| 62 | 62 | } | 
| 63 | 63 | \ No newline at end of file |