driver api setting 1
This commit is contained in:
@@ -39,8 +39,25 @@ class WalletController extends Controller
|
||||
public function balance(Request $request): JsonResponse
|
||||
{
|
||||
$id = $request->attributes->get('_jwt_user_id');
|
||||
$bal = DB::connection('primary')->table('passengerWallet')
|
||||
->where('passenger_id', $id)->value('balance') ?? '0.00';
|
||||
$userType = $request->attributes->get('_jwt_user_type');
|
||||
|
||||
if ($userType === 'driver') {
|
||||
$bal = DB::connection('primary')->table('captain_wallet')
|
||||
->where('captain_id', $id)->value('balance') ?? '0.00';
|
||||
} else {
|
||||
$bal = DB::connection('primary')->table('passengerWallet')
|
||||
->where('passenger_id', $id)->value('balance') ?? '0.00';
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'success', 'data' => ['balance' => $bal]]);
|
||||
}
|
||||
|
||||
/** GET /v2/wallet/driver/balance (Explicit) */
|
||||
public function driverBalance(Request $request): JsonResponse
|
||||
{
|
||||
$id = $request->attributes->get('_jwt_user_id');
|
||||
$bal = DB::connection('primary')->table('captain_wallet')
|
||||
->where('captain_id', $id)->value('balance') ?? '0.00';
|
||||
|
||||
return response()->json(['status' => 'success', 'data' => ['balance' => $bal]]);
|
||||
}
|
||||
@@ -54,6 +71,11 @@ class WalletController extends Controller
|
||||
]);
|
||||
|
||||
$id = $request->attributes->get('_jwt_user_id');
|
||||
$userType = $request->attributes->get('_jwt_user_type');
|
||||
|
||||
if ($userType !== 'passenger') {
|
||||
return response()->json(['status' => 'failure', 'message' => 'Only passengers can add funds manually'], 403);
|
||||
}
|
||||
|
||||
DB::connection('primary')->beginTransaction();
|
||||
try {
|
||||
@@ -106,33 +128,46 @@ class WalletController extends Controller
|
||||
|
||||
$request->validate([
|
||||
'balance' => 'required|numeric|min:0',
|
||||
'passenger_id' => 'required|string',
|
||||
'user_id' => 'required|string',
|
||||
'type' => 'required|in:passenger,driver',
|
||||
]);
|
||||
|
||||
DB::connection('primary')->table('passengerWallet')
|
||||
->where('passenger_id', $request->input('passenger_id'))
|
||||
$table = $request->input('type') === 'driver' ? 'captain_wallet' : 'passengerWallet';
|
||||
$key = $request->input('type') === 'driver' ? 'captain_id' : 'passenger_id';
|
||||
|
||||
DB::connection('primary')->table($table)
|
||||
->where($key, $request->input('user_id'))
|
||||
->update(['balance' => $request->input('balance')]);
|
||||
|
||||
return response()->json(['status' => 'success']);
|
||||
}
|
||||
|
||||
|
||||
/** GET /v2/wallet/passenger/transactions */
|
||||
/** GET /v2/wallet/transactions */
|
||||
public function transactions(Request $request): JsonResponse
|
||||
{
|
||||
$id = $request->attributes->get('_jwt_user_id');
|
||||
$userType = $request->attributes->get('_jwt_user_type');
|
||||
$page = (int) $request->input('page', 1);
|
||||
$limit = min((int) $request->input('limit', 20), 50);
|
||||
|
||||
// Get from payments table (completed rides)
|
||||
$payments = DB::connection('primary')->table('payments')
|
||||
->where('passengerID', $id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->skip(($page - 1) * $limit)
|
||||
->take($limit)
|
||||
->get();
|
||||
if ($userType === 'driver') {
|
||||
$transactions = DB::connection('primary')->table('payments')
|
||||
->where('driverID', $id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->skip(($page - 1) * $limit)
|
||||
->take($limit)
|
||||
->get();
|
||||
} else {
|
||||
$transactions = DB::connection('primary')->table('payments')
|
||||
->where('passengerID', $id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->skip(($page - 1) * $limit)
|
||||
->take($limit)
|
||||
->get();
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'success', 'data' => $payments]);
|
||||
return response()->json(['status' => 'success', 'data' => $transactions]);
|
||||
}
|
||||
|
||||
/** POST /v2/wallet/passenger/token */
|
||||
|
||||
Reference in New Issue
Block a user