Skip to content

Commit e79889d

Browse files
committed
feat: Add customer validation feature
1 parent b8a6975 commit e79889d

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

lib/customer.test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,24 @@ test("update customer", async () => {
5454
expect(response.data.first_name).toBe("updated")
5555
}
5656
}
57+
})
58+
59+
// {
60+
// "country": "NG",
61+
// "type": "bank_account",
62+
// "account_number": "0123456789",
63+
// "bvn": "20012345677",
64+
// "bank_code": "007",
65+
// "first_name": "Asta",
66+
// "last_name": "Lavista"
67+
// }
68+
69+
test("validate customer", async () => {
70+
let cust = (await customer())
71+
expect(cust.status).toBe(true)
72+
if (cust.status) {
73+
let response = await paystack().customer.validate(cust.data.customer_code, { country: "NG", type: "bank_account", account_number: "0123456789", bvn: "20012345677", bank_code: "007", first_name: "Asta", last_name: "Lavista" })
74+
expect(response.status).toBe(true)
75+
76+
}
5777
})

lib/customer.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CreateCustomerData, CreateCustomerResponse, FetchCustomerResponse, ListCustomerData, ListCustomerResponse, UpdateCustomerData, UpdateCustomerResponse } from "./types";
1+
import type { CreateCustomerData, CreateCustomerResponse, FetchCustomerResponse, ListCustomerData, ListCustomerResponse, UpdateCustomerData, UpdateCustomerResponse, ValidateCustomerData, ValidateCustomerResponse } from "./types";
22

33
export class Customer {
44
private secret_key: string;
@@ -92,4 +92,18 @@ export class Customer {
9292
return response_data;
9393
}
9494

95+
/** Validate a customer's identity */
96+
async validate(code: string, data: ValidateCustomerData): Promise<ValidateCustomerResponse> {
97+
const headers = this.get_headers();
98+
const response = await fetch(`${this.endpoint}/${code}/identification`, {
99+
headers: headers,
100+
method: "POST",
101+
body: JSON.stringify(data)
102+
})
103+
104+
const response_data = await response.json() as ValidateCustomerResponse;
105+
106+
return response_data;
107+
}
108+
95109
}

lib/types.ts

+45-1
Original file line numberDiff line numberDiff line change
@@ -669,4 +669,48 @@ export type UpdateCustomerResponse = { message: string } & ({
669669
createdAt: string;
670670
updatedAt: string;
671671
}
672-
} | PaymentRequestError)
672+
} | PaymentRequestError)
673+
674+
export type ValidateCustomerData = {
675+
676+
/** Customer's first name */
677+
first_name: string;
678+
679+
/** Customer's last name */
680+
last_name: string;
681+
682+
/**
683+
* Predefined types of identification.
684+
* Only bank_account is supported at the moment
685+
* */
686+
type: string;
687+
688+
/** Customer's identification number */
689+
value?: string
690+
691+
/** 2 letter country code of identification issuer */
692+
country: string;
693+
694+
/** Customer's Bank Verification Number */
695+
bvn: string;
696+
697+
/**
698+
* You can get the list of Bank Codes by calling the List Banks endpoint.
699+
* (required if type is bank_account)
700+
* */
701+
bank_code: string;
702+
703+
/**
704+
* Customer's bank account number.
705+
* (required if type is bank_account)
706+
* */
707+
account_number: string;
708+
709+
/** customer's middle name */
710+
middle_name?: string;
711+
}
712+
713+
export type ValidateCustomerResponse = {
714+
status: boolean;
715+
message: string;
716+
}

0 commit comments

Comments
 (0)