I need help
Oct 20, 2023
3
Level 5
fluutterwave acoount number verification
i have been trying to verify user account name using flutterwave api but i kept getting error
Verification Result:
status: error
message: invalid account
data
code
$banks = Flutterwave::banks()->nigeria();
// Find the bank code based on the provided bank name
$selectedBankName = $this->bank_name;
$selectedBankCode = null;
foreach ($banks['data'] as $bank) {
if ($bank['name'] === $selectedBankName) {
$selectedBankCode = $bank['code'];
break;
}
}
//dd($selectedBankCode);
// Check if the bank code was found
if ($selectedBankCode) {
$secretKey = getenv('FLW_SECRET_KEY');
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . $secretKey,
])->post('https://api.flutterwave.com/v3/accounts/resolve', [
'account_number' => $this->account_number,
'account_bank' => $selectedBankCode, // Use the bank code
]);
//dd($selectedBankCode);
if ($response->successful()) {
$this->accountName = $response->json()['account_name'];
} else {
$this->accountName = $response->json();
}
} else {
// Handle the case where the bank name doesn't match any bank code
$this->accountName = 'Invalid bank name';
}
the curl
curl --request POST 'https://api.flutterwave.com/v3/accounts/resolve' \
--header 'Authorization: Bearer YOUR_SECRET_KEY'\
--header 'Content-Type: application/json'\
--data-raw '{
"account_number": "0690000032",
"account_bank": "044"
}'
link to documentation https://developer.flutterwave.com/docs/verifications/bank-account
Level 122
for starters DON'T use env values directly.
In a config file, eg services.php, add a key like;
'flutterwave' => [
'key' => env('FLW_SECRET_KEY'),
'url' => 'https://api.flutterwave.com/v3/accounts/resolve',
],
and then use it in your code like
$secretKey = config('services.flutterwave.key');
and
->post(config('services.flutterwave.url'), [
You can also dd() the http request to make sure your request has all the required elements
Please or to participate in this conversation.