@@ -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 | } |
@@ -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 |