@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function setBaseUrl() |
64 | 64 | { |
65 | - if(Config::get('payant.mode') == 'LIVE') |
|
65 | + if (Config::get('payant.mode') == 'LIVE') |
|
66 | 66 | { |
67 | 67 | $this->base_uri = "https://api.payant.ng"; |
68 | 68 | } |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | */ |
83 | 83 | private function setRequestOptions() |
84 | 84 | { |
85 | - $authorization_string = 'Bearer '. $this->private_key; |
|
85 | + $authorization_string = 'Bearer '.$this->private_key; |
|
86 | 86 | |
87 | 87 | //Set up Guzzle |
88 | - $this->client = new Client( [ |
|
88 | + $this->client = new Client([ |
|
89 | 89 | 'base_uri' => $this->base_uri, |
90 | 90 | 'protocols' => ['https'], |
91 | 91 | '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 string $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 | |
@@ -332,8 +332,8 @@ discard block |
||
332 | 332 | * @param string $reference_code [Mandatory - Invoice Reference Code] |
333 | 333 | * @return object |
334 | 334 | */ |
335 | - public function deleteInvoice($reference_code){ |
|
336 | - if(!$reference_code){ |
|
335 | + public function deleteInvoice($reference_code) { |
|
336 | + if (!$reference_code) { |
|
337 | 337 | throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); |
338 | 338 | } |
339 | 339 | |
@@ -353,15 +353,15 @@ discard block |
||
353 | 353 | * Optional - 'address', 'company_name', 'type', |
354 | 354 | * @param string $amount [Mandatory] |
355 | 355 | */ |
356 | - public function addTransfer(array $client_data, string $amount){ |
|
356 | + public function addTransfer(array $client_data, string $amount) { |
|
357 | 357 | // Mandatory Client fields |
358 | 358 | $required_client_values = ['first_name', 'last_name', 'email', 'phone', 'settlement_bank', 'account_number']; |
359 | 359 | |
360 | - if(!array_keys_exist($client_data, $required_client_values)){ |
|
360 | + if (!array_keys_exist($client_data, $required_client_values)) { |
|
361 | 361 | throw new RequiredValuesMissing("Missing required values :( - Provide client_data"); |
362 | 362 | } |
363 | 363 | |
364 | - if(!$amount){ |
|
364 | + if (!$amount) { |
|
365 | 365 | throw new IsNullOrInvalid("Error Processing Request - Null/Invalid amount"); |
366 | 366 | } |
367 | 367 | |
@@ -384,8 +384,8 @@ discard block |
||
384 | 384 | * @param string $reference_code [Mandatory - Transfer Reference Code] |
385 | 385 | * @return object |
386 | 386 | */ |
387 | - public function getTransfer($reference_code){ |
|
388 | - if(!$reference_code){ |
|
387 | + public function getTransfer($reference_code) { |
|
388 | + if (!$reference_code) { |
|
389 | 389 | throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); |
390 | 390 | } |
391 | 391 | |
@@ -406,8 +406,8 @@ discard block |
||
406 | 406 | * @param string $end [Format - DD/MM/YYYY] |
407 | 407 | * @return object |
408 | 408 | */ |
409 | - public function getTransferHistory($period, $start = null, $end = null){ |
|
410 | - if(!$period){ |
|
409 | + public function getTransferHistory($period, $start = null, $end = null) { |
|
410 | + if (!$period) { |
|
411 | 411 | throw new RequiredValueMissing("Error Processing Request - period Missing"); |
412 | 412 | } |
413 | 413 | |
@@ -428,8 +428,8 @@ discard block |
||
428 | 428 | * @param string $reference_code [Mandatory - Invoice Reference Code] |
429 | 429 | * @return object |
430 | 430 | */ |
431 | - public function deleteTransfer($reference_code){ |
|
432 | - if(!$reference_code){ |
|
431 | + public function deleteTransfer($reference_code) { |
|
432 | + if (!$reference_code) { |
|
433 | 433 | throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); |
434 | 434 | } |
435 | 435 | |
@@ -450,22 +450,22 @@ discard block |
||
450 | 450 | * @param string $amount [Mandatory] |
451 | 451 | * @param string $channel [Mandatory - valid ["Cash", "BankTransfer", "POS", "Cheque"]] |
452 | 452 | */ |
453 | - public function addPayment(string $reference_code, string $due_date, string $amount, string $channel){ |
|
454 | - if(!$reference_code){ |
|
453 | + public function addPayment(string $reference_code, string $due_date, string $amount, string $channel) { |
|
454 | + if (!$reference_code) { |
|
455 | 455 | throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); |
456 | 456 | } |
457 | 457 | |
458 | - if(!$due_date){ |
|
458 | + if (!$due_date) { |
|
459 | 459 | throw new IsNullOrInvalid("Error Processing Request - Null/Invalid date"); |
460 | 460 | } |
461 | 461 | |
462 | - if(!$amount){ |
|
462 | + if (!$amount) { |
|
463 | 463 | throw new IsNullOrInvalid("Error Processing Request - Null/Invalid amount"); |
464 | 464 | } |
465 | 465 | |
466 | 466 | $valid_channels = ["Cash", "BankTransfer", "POS", "Cheque"]; |
467 | 467 | |
468 | - if(!$channel){ |
|
468 | + if (!$channel) { |
|
469 | 469 | throw new IsNull("Error Processing Request - Null/Invalid amount"); |
470 | 470 | }elseif (!in_array(ucfirst($channel), $valid_channels)) { |
471 | 471 | throw new IsInvalid("Invalid Channel - Cash, BankTransfer, POS or Cheque"); |
@@ -491,8 +491,8 @@ discard block |
||
491 | 491 | * [getPayment] |
492 | 492 | * @param string $reference_code [Mandatory - Invoice Reference Code] |
493 | 493 | */ |
494 | - public function getPayment($reference_code){ |
|
495 | - if(!$reference_code){ |
|
494 | + public function getPayment($reference_code) { |
|
495 | + if (!$reference_code) { |
|
496 | 496 | throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); |
497 | 497 | } |
498 | 498 | |
@@ -512,8 +512,8 @@ discard block |
||
512 | 512 | * @param string $end [Format - DD/MM/YYYY || Optional if $period !== 'custom'] |
513 | 513 | * @return object |
514 | 514 | */ |
515 | - public function getPaymentHistory(string $period, string $start, string $end){ |
|
516 | - if(!$period){ |
|
515 | + public function getPaymentHistory(string $period, string $start, string $end) { |
|
516 | + if (!$period) { |
|
517 | 517 | throw new RequiredValueMissing("Error Processing Request - period Missing"); |
518 | 518 | } |
519 | 519 | |
@@ -536,23 +536,23 @@ discard block |
||
536 | 536 | * @param string $unit_cost [Mandatory - Product's unit cost] |
537 | 537 | * @param string $type [Mandatory - Product type 'product' or 'service'] |
538 | 538 | */ |
539 | - public function addProduct(string $name, string $description, string $unit_cost, string $type){ |
|
540 | - if(!$name){ |
|
539 | + public function addProduct(string $name, string $description, string $unit_cost, string $type) { |
|
540 | + if (!$name) { |
|
541 | 541 | throw new IsNull("Error Processing Request - Null/Invalid name"); |
542 | 542 | } |
543 | 543 | |
544 | - if(!$description){ |
|
544 | + if (!$description) { |
|
545 | 545 | throw new IsNull("Error Processing Request - Null/Invalid description"); |
546 | 546 | } |
547 | 547 | |
548 | - if(!$unit_cost){ |
|
548 | + if (!$unit_cost) { |
|
549 | 549 | throw new IsNull("Error Processing Request - Null/Invalid unit_cost"); |
550 | 550 | } |
551 | 551 | |
552 | 552 | //Validate Product Type |
553 | 553 | $valid_product_type = ["product", "service"]; |
554 | 554 | |
555 | - if(!$type){ |
|
555 | + if (!$type) { |
|
556 | 556 | throw new IsNull("Error Processing Request - Null/Invalid type"); |
557 | 557 | }elseif (!in_array(strtolower($type), $valid_product_type)) { |
558 | 558 | throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'"); |
@@ -579,8 +579,8 @@ discard block |
||
579 | 579 | * @param int $product_id [Mandatory - Product ID] |
580 | 580 | * @return object |
581 | 581 | */ |
582 | - public function getProduct($product_id){ |
|
583 | - if(!$product_id){ |
|
582 | + public function getProduct($product_id) { |
|
583 | + if (!$product_id) { |
|
584 | 584 | throw new IsNullOrInvalid("Error Processing Request - Null/Invalid product_id"); |
585 | 585 | } |
586 | 586 | |
@@ -599,8 +599,8 @@ discard block |
||
599 | 599 | * @param array $product_data [description] |
600 | 600 | * @return object |
601 | 601 | */ |
602 | - public function editProduct($product_id, array $product_data){ |
|
603 | - if(!$product_id){ |
|
602 | + public function editProduct($product_id, array $product_data) { |
|
603 | + if (!$product_id) { |
|
604 | 604 | throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id"); |
605 | 605 | } |
606 | 606 | |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | |
610 | 610 | $valid_product_type = ["product", "service"]; |
611 | 611 | |
612 | - if(!$product_type){ |
|
612 | + if (!$product_type) { |
|
613 | 613 | throw new IsNull("Error Processing Request - Null/Invalid type"); |
614 | 614 | }elseif (!in_array($product_type, $valid_product_type)) { |
615 | 615 | throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'"); |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | // Mandatory fields |
621 | 621 | $required_values = ['name', 'description', 'unit_cost', 'type']; |
622 | 622 | |
623 | - if(!array_keys_exist($product_data, $required_values)){ |
|
623 | + if (!array_keys_exist($product_data, $required_values)) { |
|
624 | 624 | throw new RequiredValuesMissing("Missing required values :("); |
625 | 625 | } |
626 | 626 | |
@@ -634,7 +634,7 @@ discard block |
||
634 | 634 | * [getProducts] |
635 | 635 | * @return object |
636 | 636 | */ |
637 | - public function getProducts(){ |
|
637 | + public function getProducts() { |
|
638 | 638 | $url = "/products"; |
639 | 639 | |
640 | 640 | return $this->sendRequest('get', $url); |
@@ -648,8 +648,8 @@ discard block |
||
648 | 648 | * @param $product_id [Mandatory - Product ID] |
649 | 649 | * @return object |
650 | 650 | */ |
651 | - public function deleteProduct($product_id){ |
|
652 | - if(!$product_id){ |
|
651 | + public function deleteProduct($product_id) { |
|
652 | + if (!$product_id) { |
|
653 | 653 | throw new IsNullOrInvalid("Error Processing Request - Null/Invalid Product Id"); |
654 | 654 | } |
655 | 655 | |
@@ -666,22 +666,22 @@ discard block |
||
666 | 666 | * @param string $url [Mandatory - url to send request to] |
667 | 667 | * @param array $params [data to post to request url] |
668 | 668 | */ |
669 | - public function sendRequest($method, $url, $params=[]) |
|
669 | + public function sendRequest($method, $url, $params = []) |
|
670 | 670 | { |
671 | - try{ |
|
672 | - if (strtolower($method) == 'get'){ |
|
671 | + try { |
|
672 | + if (strtolower($method) == 'get') { |
|
673 | 673 | $result = $this->client->request('GET', $url); |
674 | - }elseif (strtolower($method) == 'post'){ |
|
674 | + }elseif (strtolower($method) == 'post') { |
|
675 | 675 | $result = $this->client->request('POST', $url, $params); |
676 | - }elseif (strtolower($method) == 'put'){ |
|
676 | + }elseif (strtolower($method) == 'put') { |
|
677 | 677 | $result = $this->client->request('PUT', $url, $params); |
678 | - }elseif (strtolower($method) == 'delete'){ |
|
678 | + }elseif (strtolower($method) == 'delete') { |
|
679 | 679 | $result = $this->client->request('DELETE', $url); |
680 | 680 | } |
681 | 681 | |
682 | 682 | return cleanResponse($result); |
683 | 683 | } |
684 | - catch( Exception $e){ |
|
684 | + catch (Exception $e) { |
|
685 | 685 | throw $e; |
686 | 686 | } |
687 | 687 | } |
@@ -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 checkHistory($period, $start, $end){ |
|
69 | +function checkHistory($period, $start, $end) { |
|
70 | 70 | //Validate Period |
71 | 71 | $valid_period_options = ["today", "week", "month", "30", "90", "year", "custom"]; |
72 | 72 | |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | 'period' => $period |
79 | 79 | ]; |
80 | 80 | |
81 | - if ($period == 'custom'){ |
|
82 | - if (!$start || !$end){ |
|
81 | + if ($period == 'custom') { |
|
82 | + if (!$start || !$end) { |
|
83 | 83 | throw new IsNull("Invalid custom Start or End date"); |
84 | 84 | } |
85 | 85 | $post_data['start'] = $start; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | -function cleanResponse($response){ |
|
90 | +function cleanResponse($response) { |
|
91 | 91 | $result = $response->getBody(); |
92 | 92 | return $result; |
93 | 93 | } |
94 | 94 | \ No newline at end of file |