From 7676dc1410bdfe881a9d108479f4e1446ebac5d6 Mon Sep 17 00:00:00 2001 From: Joshua Paul Date: Fri, 21 Jul 2023 12:33:14 +0100 Subject: [PATCH] Added location API --- docs/.vitepress/config.js | 1 + docs/location/index.md | 29 +++++++++++++++++++++++++++++ src/Traits/LocationApi.php | 13 +++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 docs/location/index.md diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index bf0dd66..b17e66e 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -51,6 +51,7 @@ export default { { text: "Transactions", link: "/transaction/index.html" }, { text: "Miscellaneous", link: "/miscellaneous/index.html" }, { text: "Webhooks", link: "/webhook/index.html" }, + { text: "Location", link: "/location/index.html" }, ], } diff --git a/docs/location/index.md b/docs/location/index.md new file mode 100644 index 0000000..4cd4e11 --- /dev/null +++ b/docs/location/index.md @@ -0,0 +1,29 @@ +# Location API + +## Get Countries + +This method allows you to get list of countries. + +```php +$countries = TerminalAfrica::getCountries(); +``` + +## Get States + +This method allows you to retrieve a list of states by it's country code. + +```php + +$countryCode = 'NG'; +$states = TerminalAfrica::getStates($countryCode); +``` + +## Get Cities + +This method allows you to retrieve a list of states by it's country code and state code. + +```php +$countryCode = 'NG'; +$stateCode = 'Lagos'; +$cities = TerminalAfrica::getCities($countryCode, $stateCode); +``` diff --git a/src/Traits/LocationApi.php b/src/Traits/LocationApi.php index e425158..8be030a 100644 --- a/src/Traits/LocationApi.php +++ b/src/Traits/LocationApi.php @@ -20,10 +20,14 @@ public function getCountries(): array /** * This endpoint allows you to retrieve a list of valid states for a given country. */ - public function getStates(array $queryParams): array + public function getStates(string $countryCode): array { $endpoint = '/states'; + $queryParams = [ + 'country_code' => $countryCode, + ]; + return $this->makeRequest( method: 'GET', endpoint: $endpoint, @@ -34,10 +38,15 @@ public function getStates(array $queryParams): array /** * This endpoint allows you to retrieve a list of valid cities available in a specific country. */ - public function getCities(array $queryParams): array + public function getCities(string $countryCode, string $stateCode): array { $endpoint = '/cities'; + $queryParams = [ + 'country_code' => $countryCode, + 'state_code' => $stateCode, + ]; + return $this->makeRequest( method: 'GET', endpoint: $endpoint,