File: /var/www/api.vaspayment.com/app/Http/Controllers/Balance/Index.php
<?php
namespace App\Http\Controllers\Balance;
use Illuminate\Http\Request;
use App\Models\HonourworldKey;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Http;
class Index extends Controller
{
private function baseUrl()
{
return config('honourworld.url');
}
private function header()
{
$email = config('app.mail');
// $token = HonourworldKey::first()->live_key;
$token = config('app.honorworld_token');
$headers = [
"Authorization" => "Bearer " . $token,
"Accept" => "application/json",
"Content-Type" => "application/json",
];
return $headers;
}
private function station()
{
$token = config('app.station');
$headers = [
'Authorization' => 'Token ' . $token,
'Content-Type' => 'application/json',
];
return $headers;
}
public function index()
{
try {
$data_station = $this->getDataFromDatastation();
$honourworld = $this->getWalletDataFromHonourworld();
// $ringo = $this->getWalletDataFromRingo();
return response()->json([
"status" => "success",
"station" => $data_station ?? [],
"honourworld" => $honourworld ?? [],
"ringo" => $ringo ?? [],
"message" => "Balance from Bills fetched successfully"
], 200);
} catch (\Throwable $th) {
return response()->json([
"status" => "error",
"message" => $th->getMessage()
], 402);
}
}
protected function getDataFromDatastation()
{
try {
$getUrl = 'https://datastation.com.ng/api/user/';
$response = Http::withHeaders($this->station())->get($getUrl);
if ($response->successful()) {
return [
'stationAccount' => $response->json()['user']['Account_Balance'],
'stationBalance' => $response->json()['user']['wallet_balance'],
'stationBonus' => $response->json()['user']['bonus_balance'],
];
}
return null;
} catch (\Throwable $th) {
// Log the error or handle it accordingly
return null;
}
}
protected function getWalletDataFromHonourworld()
{
try {
$agentWalletUrl = $this->baseUrl() . '/api/v2/wallet/manage-wallet-balance';
$response = Http::withHeaders($this->header())->get($agentWalletUrl);
info($response);
if ($response->successful()) {
return $response->json()['data'];
}
return null;
} catch (\Throwable $th) {
Log::info($th->getMessage());
return null;
}
}
protected function getWalletDataFromRingo()
{
try {
$response = Http::withHeaders([
'Content-Type' => 'application/json',
'email' => config('app.ringo_email'),
'password' => config('app.ringo_password'),
])->post(config('app.ringo_airtime'), [
'serviceCode' => 'INFO',
]);
if ($response->successful()) {
return [
'balance' => $response->json()['wallet']['wallet']['balance'],
'commission' => $response->json()['wallet']['wallet']['commission_balance'],
];
}
return null;
} catch (\Throwable $th) {
return null;
}
}
}