@@ -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 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | use \Exception as phpException; |
| 25 | 25 | |
| 26 | -if (! function_exists('array_get')) |
|
| 26 | +if (!function_exists('array_get')) |
|
| 27 | 27 | { |
| 28 | 28 | /* |
| 29 | 29 | * |
@@ -37,11 +37,11 @@ discard block |
||
| 37 | 37 | if (!is_array($data)) { |
| 38 | 38 | return $default; |
| 39 | 39 | } |
| 40 | - return isset($data[$key]) ? $data[$key]: $default; |
|
| 40 | + return isset($data[$key]) ? $data[$key] : $default; |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | -if(!function_exists('array_keys_exist')){ |
|
| 44 | +if (!function_exists('array_keys_exist')) { |
|
| 45 | 45 | /** |
| 46 | 46 | * Checks if multiple keys exist in an array |
| 47 | 47 | * |
@@ -50,23 +50,23 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return bool |
| 52 | 52 | */ |
| 53 | - function array_keys_exist( array $array, $keys ) { |
|
| 53 | + function array_keys_exist(array $array, $keys) { |
|
| 54 | 54 | $count = 0; |
| 55 | - if ( ! is_array( $keys ) ) { |
|
| 55 | + if (!is_array($keys)) { |
|
| 56 | 56 | $keys = func_get_args(); |
| 57 | - array_shift( $keys ); |
|
| 57 | + array_shift($keys); |
|
| 58 | 58 | } |
| 59 | - foreach ( $keys as $key ) { |
|
| 60 | - if ( array_key_exists( $key, $array ) ) { |
|
| 61 | - $count ++; |
|
| 59 | + foreach ($keys as $key) { |
|
| 60 | + if (array_key_exists($key, $array)) { |
|
| 61 | + $count++; |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - return count( $keys ) === $count; |
|
| 65 | + return count($keys) === $count; |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | -function cleanResponse($response){ |
|
| 69 | +function cleanResponse($response) { |
|
| 70 | 70 | $result = $response->getBody(); |
| 71 | 71 | return $result; |
| 72 | 72 | } |
| 73 | 73 | \ No newline at end of file |
@@ -63,7 +63,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |