The KYC Information section of the AP Investment Platform API documentation provides detailed information on managing user KYC information within the platform. This section is divided into the following key areas:
Once the page is accessed, data is fetched from the /api:fH8MNGPq:v1/kyc/load_data endpoint to display the user's KYC information. The endpoint runs the App\Http\Controllers\KYCController@loadData method to retrieve user KYC data.
{
"id": 01,
"profile": {
"link": "",
"status": ""
},
"phone": {
"phone": "0712345678",
"status": "verified"
},
"kra": {
"link": "https://africaspocket.ongea.studio/api/files/documents/PinSample.pdf",
"status": "pending",
"kra_pin": "",
"reason": ""
},
"bank_statement": {
"link": "https://africaspocket.ongea.studio/api/files/documents/BankSample.pdf",
"status": "pending",
"bank_name": "",
"account_number": 0,
"reason": ""
},
"address": {
"link": "https://africaspocket.ongea.studio/api/files/documents/CopySample.pdf",
"status": "pending",
"postal_code": "",
"building_name": "",
"road": "",
"area": "",
"town": "",
"reason": ""
},
"next_of_kin": {
"firstname": "Jane",
"lastname": "Doe",
"phone": "0123456789",
"relationship": "Mother",
"dob": null
},
"ID_passport": {
"link": "",
"status": "",
"reason": "",
"id_passport": "",
"id_passport_confirm": ""
},
"photo": {
"link": "",
"status": "",
"reason": ""
},
"status": "pending",
"users_id": 0123,
"created_at": "2022-12-22T09:10:59.000000Z",
"updated_at": null,
"uploaded_by": null,
"is_manual_upload": false
}
The Phone Number section allows users to update their phone number. This section provides endpoints to retrieve user phone number and update phone number details. Updating the phone number triggers an SMS verification process to confirm the new phone number. The endpoint /api:Ql0QXoET/send_otp is used to send an OTP to the new phone number for verification. It runs the App\Http\Controllers\OTPController@sendOTP method to send the OTP.
public function sendOTP(Request $request)
{
$validator = Validator::make($request->all(), [
'phone' => 'required|numeric',
]);
if ($validator->fails()) {
return RespondWithError::make()->handle(
RespondWithError::$ERROR_CODE_BAD_REQUEST,
message: $validator->errors()->first(),
payload: $validator->errors()->all(),
status: 422
);
}
$data = $validator->validated();
$message = 'Your verification code is ';
$otp = CreateOTP::make()->handle(Auth::id());
$verificationCode = $otp->code;
$message .= $verificationCode;
$phone_number = $data['phone'];
try {
SendSMS::dispatch($phone_number, $message);
return RespondWithSuccess::make()->handle(['message' => 'OK']);
} catch (Throwable $exception) {
return RespondWithError::make()->handle(message: $exception->getMessage());
}
}
The code snippet above shows the sendOTP method in the OTPController class. This method uses the App\Actions\Auth\CreateOTP action to generate a verification code and the App\Actions\AfricasTalking\SendSMS job to send the verification code to the user's phone number.
The user can then enter the verification code received via SMS to confirm the new phone number. The endpoint /api:Ql0QXoET/verify_otp is used to verify the OTP entered by the user. It runs the App\Http\Controllers\OTPController@verifyOTP method to verify the OTP.
public function verifyOTP(Request $request)
{
$validator = Validator::make($request->all(), [
'phone' => 'required|numeric',
'code' => 'required|numeric|integer',
]);
if ($validator->fails()) {
return RespondWithError::make()->handle(code: RespondWithError::$ERROR_CODE_BAD_REQUEST, payload: $validator->errors()->all(), status: 422);
}
$data = $validator->validated();
$code = $data['code'];
$phone_number = $data['phone'];
$userId = Auth::id();
$isValidOTP = ValidateOTP::make()->handle($userId, $code);
if (!$isValidOTP) {
return RespondWithError::make()->handle(message: 'Invalid or Expired OTP');
}
AddUserPhoneNumber::make()->handle($userId, $phone_number);
$kyc = KYC::where('users_id', Auth::id())->get();
return RespondWithSuccess::make()->handle($kyc);
}
The code snippet above shows the verifyOTP method in the OTPController class. This method uses the App\Actions\Auth\ValidateOTP action to validate the OTP entered by the user and the App\Actions\AddUserPhoneNumber action to update the user's phone number in the KYC information.
The KRA PIN section allows users to submit their KRA PIN for verification. Users can upload a PDF or JPG document containing their KRA PIN details. The endpoint /api:fH8MNGPq:v1/kyc/kra is used to upload the KRA PIN document. It runs the App\Http\Controllers\KYCController@store method to handle the file upload.
public function store(Request $request, $type)
{
$validator = Validator::make($request->all(), [
'link' => 'required|url',
]);
if ($validator->fails()) {
return RespondWithError::make()->handle(
message: $validator->errors()->first(),
payload: $validator->errors()->all(),
status: 422
);
}
$data = $validator->validated();
$column = $this->getColumnFromType($type);
KYC::query()->updateOrCreate([
'users_id' => Auth::id(),
],
[
$column => [
'link' => $data['link'],
'status' => 'pending',
],
'status' => 'pending'
]);
return RespondWithSuccess::make()->handle(['message' => 'Link stored successfully']);
}
The code snippet above ahows the store method in the KYCController class, which handles the file upload for the KRA PIN document. The method uses the getColumnFromType() function to determine the column in the database based on the type of document being uploaded.
private function getColumnFromType(string $type): ?string
{
$map = [
'kra' => 'kra',
'bank' => 'bank_statement',
'address' => 'address',
'next_of_kin' => 'next_of_kin',
'ID_Passport' => 'ID_passport',
'Photo' => 'photo',
];
return $map[$type] ?? null;
}
All the user needs to do is upload the document, and the system will update the KYC information with the new KRA PIN document link.
The Bank Statement section allows users to upload their bank statement for verification. Users can upload a PDF or JPG document containing their bank statement details. The endpoint /api:fH8MNGPq:v1/kyc/bank is used to upload the bank statement document. It runs the App\Http\Controllers\KYCController@store method to handle the file upload. The process is similar to the KRA PIN upload process.
The ID/Passport Copy section allows users to upload a copy of their ID or passport for verification. Users can upload a PDF or JPG document containing their ID or passport details. The endpoint /api:fH8MNGPq:v1/kyc/ID_Passport is used to upload the ID or passport document. It runs the App\Http\Controllers\KYCController@store method to handle the file upload. The process is similar to the KRA PIN upload process.
The Passport Photo section allows users to upload a passport photo for verification. Users can upload a JPG document containing their passport photo. The endpoint /api:fH8MNGPq:v1/kyc/photo is used to upload the passport photo document. It runs the App\Http\Controllers\KYCController@store method to handle the file upload. The process is similar to the KRA PIN upload process.
The Next of Kin section allows users to add their next of kin details. Users can provide the first name, last name, phone number, and relationship of their next of kin. The endpoint /api:fH8MNGPq:v1/kyc/next_of_kin is used to add the next of kin details. It runs the App\Http\Controllers\KYCController@nextOfKin method to store the next of kin information.
public function nextOfKin(Request $request)
{
$validator = Validator::make($request->all(), [
'firstname' => ['required', 'string', 'max:15'],
'lastname' => ['required', 'string', 'max:15'],
'relationship' => ['required', 'string', 'max:15'],
'phone' => ['required', 'string', 'max:15'],
]);
if ($validator->fails()) {
return RespondWithError::make()->handle(
message: $validator->errors()->first(),
payload: $validator->errors()->all(),
status: 422
);
}
KYC::query()->updateOrCreate([
'users_id' => Auth::id(),
],
[
'next_of_kin' => [
'firstname' => $request->input('firstname'),
'lastname' => $request->input('lastname'),
'phone' => $request->input('phone'),
'relationship' => $request->input('relationship'),
],
'status' => 'pending'
]);
return RespondWithSuccess::make()->handle();
}
The code snippet above shows the nextOfKin method in the KYCController class, which handles the addition of next of kin details. The method updates the KYC information with the new next of kin details provided by the user.