@@ -590,7 +590,7 @@ |
||
| 590 | 590 | |
| 591 | 591 | /** |
| 592 | 592 | * [addPayment] |
| 593 | - * @param [string] $method [Mandatory - request method <get | post | put | delete> ] |
|
| 593 | + * @param string $method [Mandatory - request method <get | post | put | delete> ] |
|
| 594 | 594 | * @param [string] $url [Mandatory - url to send request to] |
| 595 | 595 | * @param [array] $params [data to post to request url] |
| 596 | 596 | */ |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function setBaseUrl() |
| 57 | 57 | { |
| 58 | - if(Config::get('payantng.isdemo') == 'TRUE') |
|
| 58 | + if (Config::get('payantng.isdemo') == 'TRUE') |
|
| 59 | 59 | { |
| 60 | 60 | $this->base_uri = "https://api.demo.payant.ng"; |
| 61 | 61 | } |
@@ -75,10 +75,10 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | private function setRequestOptions() |
| 77 | 77 | { |
| 78 | - $authorization_string = 'Bearer '. $this->private_key; |
|
| 78 | + $authorization_string = 'Bearer '.$this->private_key; |
|
| 79 | 79 | |
| 80 | 80 | //Set up Guzzle |
| 81 | - $this->client = new Client( [ |
|
| 81 | + $this->client = new Client([ |
|
| 82 | 82 | 'base_uri' => $this->base_uri, |
| 83 | 83 | 'protocols' => ['https'], |
| 84 | 84 | 'headers' => [ |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * [getStates Get States in a country (Nigeria)] |
| 94 | 94 | * @return [object] [list of banks and their respective bank_ids] |
| 95 | 95 | */ |
| 96 | - public function getBanks(){ |
|
| 96 | + public function getBanks() { |
|
| 97 | 97 | return $this->sendRequest('get', '/banks'); |
| 98 | 98 | } |
| 99 | 99 | |
@@ -104,11 +104,11 @@ discard block |
||
| 104 | 104 | * @param array $client_data [description] |
| 105 | 105 | * Required fields - 'settlement_bank', 'account_number' |
| 106 | 106 | */ |
| 107 | - public function resolveAccount( array $client_data){ |
|
| 107 | + public function resolveAccount(array $client_data) { |
|
| 108 | 108 | // Mandatory fields |
| 109 | 109 | $required_values = ['settlement_bank', 'account_number']; |
| 110 | 110 | |
| 111 | - if(!array_keys_exist($client_data, $required_values)){ |
|
| 111 | + if (!array_keys_exist($client_data, $required_values)) { |
|
| 112 | 112 | throw new Exception\RequiredValuesMissing("Missing required values :("); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -126,11 +126,11 @@ discard block |
||
| 126 | 126 | * Required fields - 'first_name', 'last_name', 'email', 'phone' |
| 127 | 127 | * Optional - 'address', 'company_name', 'type', 'settlement_bank', 'account_number' |
| 128 | 128 | */ |
| 129 | - public function addClient( array $client_data){ |
|
| 129 | + public function addClient(array $client_data) { |
|
| 130 | 130 | // Mandatory fields |
| 131 | 131 | $required_values = ['first_name', 'last_name', 'email', 'phone']; |
| 132 | 132 | |
| 133 | - if(!array_keys_exist($client_data, $required_values)){ |
|
| 133 | + if (!array_keys_exist($client_data, $required_values)) { |
|
| 134 | 134 | throw new Exception\RequiredValuesMissing("Missing required values :("); |
| 135 | 135 | } |
| 136 | 136 | |
@@ -147,8 +147,8 @@ discard block |
||
| 147 | 147 | * @param [string] $client_id |
| 148 | 148 | * @return [object] |
| 149 | 149 | */ |
| 150 | - public function getClient($client_id = null){ |
|
| 151 | - if(!$client_id){ |
|
| 150 | + public function getClient($client_id = null) { |
|
| 151 | + if (!$client_id) { |
|
| 152 | 152 | throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id"); |
| 153 | 153 | } |
| 154 | 154 | |
@@ -168,8 +168,8 @@ discard block |
||
| 168 | 168 | * Required fields - 'first_name', 'last_name', 'email', 'phone' |
| 169 | 169 | * Optional - 'address', 'company_name', 'type', 'settlement_bank', 'account_number' |
| 170 | 170 | */ |
| 171 | - public function editClient( $client_id, array $client_data){ |
|
| 172 | - if(!$client_id){ |
|
| 171 | + public function editClient($client_id, array $client_data) { |
|
| 172 | + if (!$client_id) { |
|
| 173 | 173 | throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id"); |
| 174 | 174 | } |
| 175 | 175 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | // Mandatory fields |
| 179 | 179 | $required_values = ['first_name', 'last_name', 'email', 'phone']; |
| 180 | 180 | |
| 181 | - if(!array_keys_exist($client_data, $required_values)){ |
|
| 181 | + if (!array_keys_exist($client_data, $required_values)) { |
|
| 182 | 182 | throw new Exception\RequiredValuesMissing("Missing required values :("); |
| 183 | 183 | } |
| 184 | 184 | |
@@ -193,8 +193,8 @@ discard block |
||
| 193 | 193 | * [deleteClient] |
| 194 | 194 | * @param [string] $client_id [description] |
| 195 | 195 | */ |
| 196 | - public function deleteClient($client_id = null){ |
|
| 197 | - if(!$client_id){ |
|
| 196 | + public function deleteClient($client_id = null) { |
|
| 197 | + if (!$client_id) { |
|
| 198 | 198 | throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid Client Id"); |
| 199 | 199 | } |
| 200 | 200 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @param [string] $fee_bearer [Mandatory] |
| 218 | 218 | * @param array $items [Mandatory] |
| 219 | 219 | */ |
| 220 | - public function addInvoice($client_id, array $client_data, $due_date, $fee_bearer, array $items){ |
|
| 220 | + public function addInvoice($client_id, array $client_data, $due_date, $fee_bearer, array $items) { |
|
| 221 | 221 | // Mandatory Client fields |
| 222 | 222 | $required_client_values = ['first_name', 'last_name', 'email', 'phone']; |
| 223 | 223 | |
@@ -227,21 +227,21 @@ discard block |
||
| 227 | 227 | |
| 228 | 228 | |
| 229 | 229 | // Either the client Id is supplied or a new client data is provided |
| 230 | - if(!$client_id && !array_keys_exist($client_data, $required_client_values)){ |
|
| 230 | + if (!$client_id && !array_keys_exist($client_data, $required_client_values)) { |
|
| 231 | 231 | throw new Exception\RequiredValuesMissing("Missing required values :( - Provide client_id or client_data"); |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - if(!$due_date){ |
|
| 234 | + if (!$due_date) { |
|
| 235 | 235 | throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid Due Date"); |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - if(!$fee_bearer){ |
|
| 238 | + if (!$fee_bearer) { |
|
| 239 | 239 | throw new Exception\IsNull("Error Processing Request - Null Fee Bearer"); |
| 240 | 240 | }elseif (!in_array($fee_bearer, $valid_fee_bearers)) { |
| 241 | 241 | throw new Exception\InvalidFeeBearer("Invalid Fee Bearer - Use either 'account' or 'client'"); |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - if(!is_array($items)){ |
|
| 244 | + if (!is_array($items)) { |
|
| 245 | 245 | throw new Exception\IsInvalid("Error Processing Request - Invalid Items"); |
| 246 | 246 | } |
| 247 | 247 | |
@@ -267,8 +267,8 @@ discard block |
||
| 267 | 267 | * @param [string] $reference_code [Mandatory - Invoice Reference Code] |
| 268 | 268 | * @return [object] |
| 269 | 269 | */ |
| 270 | - public function getInvoice($reference_code){ |
|
| 271 | - if(!$reference_code){ |
|
| 270 | + public function getInvoice($reference_code) { |
|
| 271 | + if (!$reference_code) { |
|
| 272 | 272 | throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); |
| 273 | 273 | } |
| 274 | 274 | |
@@ -282,8 +282,8 @@ discard block |
||
| 282 | 282 | * @param [type] $reference_code [Mandatory - Invoice Reference Code] |
| 283 | 283 | * @return [object] |
| 284 | 284 | */ |
| 285 | - public function sendInvoice($reference_code = null){ |
|
| 286 | - if(!$reference_code){ |
|
| 285 | + public function sendInvoice($reference_code = null) { |
|
| 286 | + if (!$reference_code) { |
|
| 287 | 287 | throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); |
| 288 | 288 | } |
| 289 | 289 | |
@@ -303,8 +303,8 @@ discard block |
||
| 303 | 303 | * @param [string] $end [Format - DD/MM/YYYY] |
| 304 | 304 | * @return [object] |
| 305 | 305 | */ |
| 306 | - public function getInvoiceHistory($period, $start = null, $end = null){ |
|
| 307 | - if(!$period){ |
|
| 306 | + public function getInvoiceHistory($period, $start = null, $end = null) { |
|
| 307 | + if (!$period) { |
|
| 308 | 308 | throw new Exception\RequiredValueMissing("Error Processing Request - period Missing"); |
| 309 | 309 | } |
| 310 | 310 | |
@@ -319,8 +319,8 @@ discard block |
||
| 319 | 319 | 'period' => $period |
| 320 | 320 | ]; |
| 321 | 321 | |
| 322 | - if ($period == 'custom'){ |
|
| 323 | - if (!$start || !$end){ |
|
| 322 | + if ($period == 'custom') { |
|
| 323 | + if (!$start || !$end) { |
|
| 324 | 324 | throw new Exception\IsNull("Invalid custom Start or End date"); |
| 325 | 325 | } |
| 326 | 326 | $post_data['start'] = $start; |
@@ -341,8 +341,8 @@ discard block |
||
| 341 | 341 | * @param [string] $reference_code [Mandatory - Invoice Reference Code] |
| 342 | 342 | * @return [object] |
| 343 | 343 | */ |
| 344 | - public function deleteInvoice($reference_code){ |
|
| 345 | - if(!$reference_code){ |
|
| 344 | + public function deleteInvoice($reference_code) { |
|
| 345 | + if (!$reference_code) { |
|
| 346 | 346 | throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); |
| 347 | 347 | } |
| 348 | 348 | |
@@ -362,22 +362,22 @@ discard block |
||
| 362 | 362 | * @param [string] $amount [Mandatory] |
| 363 | 363 | * @param [string] $channel [Mandatory - valid ["Cash", "BankTransfer", "POS", "Cheque"]] |
| 364 | 364 | */ |
| 365 | - public function addPayment(string $reference_code, string $date, string $amount, string $channel){ |
|
| 366 | - if(!$reference_code){ |
|
| 365 | + public function addPayment(string $reference_code, string $date, string $amount, string $channel) { |
|
| 366 | + if (!$reference_code) { |
|
| 367 | 367 | throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - if(!$due_date){ |
|
| 370 | + if (!$due_date) { |
|
| 371 | 371 | throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid date"); |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - if(!$amount){ |
|
| 374 | + if (!$amount) { |
|
| 375 | 375 | throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid amount"); |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | $valid_channels = ["Cash", "BankTransfer", "POS", "Cheque"]; |
| 379 | 379 | |
| 380 | - if(!$channel){ |
|
| 380 | + if (!$channel) { |
|
| 381 | 381 | throw new Exception\IsNull("Error Processing Request - Null/Invalid amount"); |
| 382 | 382 | }elseif (!in_array(ucfirst($channel), $valid_channels)) { |
| 383 | 383 | throw new Exception\IsInvalid("Invalid Channel - Cash, BankTransfer, POS or Cheque"); |
@@ -403,8 +403,8 @@ discard block |
||
| 403 | 403 | * [getPayment] |
| 404 | 404 | * @param [string] $reference_code [Mandatory - Invoice Reference Code] |
| 405 | 405 | */ |
| 406 | - public function getPayment($reference_code){ |
|
| 407 | - if(!$reference_code){ |
|
| 406 | + public function getPayment($reference_code) { |
|
| 407 | + if (!$reference_code) { |
|
| 408 | 408 | throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); |
| 409 | 409 | } |
| 410 | 410 | |
@@ -424,8 +424,8 @@ discard block |
||
| 424 | 424 | * @param [string] $end [Format - DD/MM/YYYY || Optional if $period !== 'custom'] |
| 425 | 425 | * @return [object] |
| 426 | 426 | */ |
| 427 | - public function getPaymentHistory(string $period, string $start, string $end){ |
|
| 428 | - if(!$period){ |
|
| 427 | + public function getPaymentHistory(string $period, string $start, string $end) { |
|
| 428 | + if (!$period) { |
|
| 429 | 429 | throw new Exception\RequiredValueMissing("Error Processing Request - period Missing"); |
| 430 | 430 | } |
| 431 | 431 | |
@@ -440,8 +440,8 @@ discard block |
||
| 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 Exception\IsNull("Invalid custom Start or End date"); |
| 446 | 446 | } |
| 447 | 447 | $post_data['start'] = $start; |
@@ -464,23 +464,23 @@ discard block |
||
| 464 | 464 | * @param string $unit_cost [Mandatory - Product's unit cost] |
| 465 | 465 | * @param string $type [Mandatory - Product type 'product' or 'service'] |
| 466 | 466 | */ |
| 467 | - public function addProduct(string $name, string $description, string $unit_cost, string $type){ |
|
| 468 | - if(!$name){ |
|
| 467 | + public function addProduct(string $name, string $description, string $unit_cost, string $type) { |
|
| 468 | + if (!$name) { |
|
| 469 | 469 | throw new Exception\IsNull("Error Processing Request - Null/Invalid name"); |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | - if(!$description){ |
|
| 472 | + if (!$description) { |
|
| 473 | 473 | throw new Exception\IsNull("Error Processing Request - Null/Invalid description"); |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | - if(!$unit_cost){ |
|
| 476 | + if (!$unit_cost) { |
|
| 477 | 477 | throw new Exception\IsNull("Error Processing Request - Null/Invalid unit_cost"); |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | //Validate Product Type |
| 481 | 481 | $valid_product_type = ["product", "service"]; |
| 482 | 482 | |
| 483 | - if(!$type){ |
|
| 483 | + if (!$type) { |
|
| 484 | 484 | throw new Exception\IsNull("Error Processing Request - Null/Invalid type"); |
| 485 | 485 | }elseif (!in_array(strtolower($type), $valid_product_type)) { |
| 486 | 486 | throw new Exception\IsInvalid("Invalid Type - Available options: 'product' or 'service'"); |
@@ -507,8 +507,8 @@ discard block |
||
| 507 | 507 | * @param [int] $product_id [Mandatory - Product ID] |
| 508 | 508 | * @return [object] |
| 509 | 509 | */ |
| 510 | - public function getProduct($product_id){ |
|
| 511 | - if(!$product_id){ |
|
| 510 | + public function getProduct($product_id) { |
|
| 511 | + if (!$product_id) { |
|
| 512 | 512 | throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid product_id"); |
| 513 | 513 | } |
| 514 | 514 | |
@@ -527,8 +527,8 @@ discard block |
||
| 527 | 527 | * @param array $product_data [description] |
| 528 | 528 | * @return object |
| 529 | 529 | */ |
| 530 | - public function editProduct($product_id, array $product_data){ |
|
| 531 | - if(!$product_id){ |
|
| 530 | + public function editProduct($product_id, array $product_data) { |
|
| 531 | + if (!$product_id) { |
|
| 532 | 532 | throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id"); |
| 533 | 533 | } |
| 534 | 534 | |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | |
| 538 | 538 | $valid_product_type = ["product", "service"]; |
| 539 | 539 | |
| 540 | - if(!$product_type){ |
|
| 540 | + if (!$product_type) { |
|
| 541 | 541 | throw new Exception\IsNull("Error Processing Request - Null/Invalid type"); |
| 542 | 542 | }elseif (!in_array($product_type, $valid_product_type)) { |
| 543 | 543 | throw new Exception\IsInvalid("Invalid Type - Available options: 'product' or 'service'"); |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | // Mandatory fields |
| 549 | 549 | $required_values = ['name', 'description', 'unit_cost', 'type']; |
| 550 | 550 | |
| 551 | - if(!array_keys_exist($client_data, $required_values)){ |
|
| 551 | + if (!array_keys_exist($client_data, $required_values)) { |
|
| 552 | 552 | throw new Exception\RequiredValuesMissing("Missing required values :("); |
| 553 | 553 | } |
| 554 | 554 | |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | * [getProducts] |
| 563 | 563 | * @return object |
| 564 | 564 | */ |
| 565 | - public function getProducts(){ |
|
| 565 | + public function getProducts() { |
|
| 566 | 566 | $url = "/products"; |
| 567 | 567 | |
| 568 | 568 | return $this->sendRequest('get', $url); |
@@ -576,8 +576,8 @@ discard block |
||
| 576 | 576 | * @param $product_id [Mandatory - Product ID] |
| 577 | 577 | * @return object |
| 578 | 578 | */ |
| 579 | - public function deleteProduct($product_id){ |
|
| 580 | - if(!$product_id){ |
|
| 579 | + public function deleteProduct($product_id) { |
|
| 580 | + if (!$product_id) { |
|
| 581 | 581 | throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id"); |
| 582 | 582 | } |
| 583 | 583 | |
@@ -594,22 +594,22 @@ discard block |
||
| 594 | 594 | * @param [string] $url [Mandatory - url to send request to] |
| 595 | 595 | * @param [array] $params [data to post to request url] |
| 596 | 596 | */ |
| 597 | - public function sendRequest($method, $url, $params=[]) |
|
| 597 | + public function sendRequest($method, $url, $params = []) |
|
| 598 | 598 | { |
| 599 | - try{ |
|
| 600 | - if (strtolower($method) == 'get'){ |
|
| 599 | + try { |
|
| 600 | + if (strtolower($method) == 'get') { |
|
| 601 | 601 | $result = $this->client->request('GET', $url); |
| 602 | - }elseif (strtolower($method) == 'post'){ |
|
| 602 | + }elseif (strtolower($method) == 'post') { |
|
| 603 | 603 | $result = $this->client->request('POST', $url, $params); |
| 604 | - }elseif (strtolower($method) == 'put'){ |
|
| 604 | + }elseif (strtolower($method) == 'put') { |
|
| 605 | 605 | $result = $this->client->request('PUT', $url, $params); |
| 606 | - }elseif (strtolower($method) == 'delete'){ |
|
| 606 | + }elseif (strtolower($method) == 'delete') { |
|
| 607 | 607 | $result = $this->client->request('DELETE', $url); |
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | return cleanResponse($result); |
| 611 | 611 | } |
| 612 | - catch( Exception $e){ |
|
| 612 | + catch (Exception $e) { |
|
| 613 | 613 | throw $e; |
| 614 | 614 | } |
| 615 | 615 | } |
@@ -40,7 +40,7 @@ |
||
| 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 | |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use \Exception as phpException; |
| 5 | 5 | use Olaoluwa98\Payant\Exception; |
| 6 | 6 | |
| 7 | -if (! function_exists('array_get')) |
|
| 7 | +if (!function_exists('array_get')) |
|
| 8 | 8 | { |
| 9 | 9 | /* |
| 10 | 10 | * |
@@ -18,11 +18,11 @@ discard block |
||
| 18 | 18 | if (!is_array($data)) { |
| 19 | 19 | return $default; |
| 20 | 20 | } |
| 21 | - return isset($data[$key]) ? $data[$key]: $default; |
|
| 21 | + return isset($data[$key]) ? $data[$key] : $default; |
|
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | -if(!function_exists('array_keys_exist')){ |
|
| 25 | +if (!function_exists('array_keys_exist')) { |
|
| 26 | 26 | /** |
| 27 | 27 | * Checks if multiple keys exist in an array |
| 28 | 28 | * |
@@ -31,23 +31,23 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @return bool |
| 33 | 33 | */ |
| 34 | - function array_keys_exist( array $array, $keys ) { |
|
| 34 | + function array_keys_exist(array $array, $keys) { |
|
| 35 | 35 | $count = 0; |
| 36 | - if ( ! is_array( $keys ) ) { |
|
| 36 | + if (!is_array($keys)) { |
|
| 37 | 37 | $keys = func_get_args(); |
| 38 | - array_shift( $keys ); |
|
| 38 | + array_shift($keys); |
|
| 39 | 39 | } |
| 40 | - foreach ( $keys as $key ) { |
|
| 41 | - if ( array_key_exists( $key, $array ) ) { |
|
| 42 | - $count ++; |
|
| 40 | + foreach ($keys as $key) { |
|
| 41 | + if (array_key_exists($key, $array)) { |
|
| 42 | + $count++; |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - return count( $keys ) === $count; |
|
| 46 | + return count($keys) === $count; |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | -function cleanResponse($response){ |
|
| 50 | +function cleanResponse($response) { |
|
| 51 | 51 | $result = $response->getBody(); |
| 52 | 52 | return json_decode($result); |
| 53 | 53 | } |