Skip to content

Commit

Permalink
added list all states
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahdeyyy committed Apr 18, 2024
1 parent 6a6fb11 commit 14804ec
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
9 changes: 9 additions & 0 deletions lib/miscellaneous/miscellaneous.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ test("list countries", async () => {
expect(response.data).toBeInstanceOf(Array)
}
})

test("list states", async () => {
const response = await paystack().miscellaneous.list_states("US")
expect(response.status).toBe(true)

if (response.status) {
expect(response.data).toBeInstanceOf(Array)
}
})
15 changes: 14 additions & 1 deletion lib/miscellaneous/miscellaneous.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ListBanksQuery, ListBanksResponse, ListCountryResponse } from "./types";
import type { ListBanksQuery, ListBanksResponse, ListCountryResponse, ListStatesResponse } from "./types";

export class Miscellaneous {
private secret_key: string;
Expand Down Expand Up @@ -38,6 +38,19 @@ export class Miscellaneous {
return response_data
}


/** Get a list of states for a country for address verification */
async list_states(country: string): Promise<ListStatesResponse> {
const url = new URL("https://api.paystack.co/address_verification/states")
url.searchParams.set("country", country)

const response = await fetch(url, {
headers: this.get_headers(),
method: "GET"
})
const response_data = await response.json() as ListStatesResponse
return response_data
}
private get_headers() {
return {
"Content-Type": "application/json",
Expand Down
16 changes: 12 additions & 4 deletions lib/miscellaneous/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,16 @@ type CountryData = {
relationships: Relationships;
};

export type ListCountryResponse = {
status: boolean;
message: string;
export type ListCountryResponse = { message: string } & ({
status: true;
data: CountryData[];
};
} | PaystackResponseError)

export type ListStatesResponse = { message: string } & ({
status: true;
data: Array<{
name: string;
slug: string;
abbreviation: string;
}>
} | PaystackResponseError)

0 comments on commit 14804ec

Please sign in to comment.