feat: ✨ Added Server Cancelation route method and charging
This commit is contained in:
parent
32384044ea
commit
78a6787607
6 changed files with 43 additions and 8 deletions
|
@ -81,14 +81,14 @@ class ChargeServers extends Command
|
|||
continue;
|
||||
}
|
||||
|
||||
// check if user has enough credits to charge the server
|
||||
if ($user->credits < $product->price) {
|
||||
// check if the server is canceled or if user has enough credits to charge the server or
|
||||
if ( $server->cancelled || $user->credits < $product->price) {
|
||||
try {
|
||||
#suspend server
|
||||
// suspend server
|
||||
$this->line("<fg=yellow>{$server->name}</> from user: <fg=blue>{$user->name}</> has been <fg=red>suspended!</>");
|
||||
$server->suspend();
|
||||
|
||||
#add user to notify list
|
||||
// add user to notify list
|
||||
if (!in_array($user, $this->usersToNotify)) {
|
||||
array_push($this->usersToNotify, $user);
|
||||
}
|
||||
|
|
|
@ -108,6 +108,24 @@ class ServerController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the Server billing cycle.
|
||||
*
|
||||
* @param Server $server
|
||||
* @return RedirectResponse|Response
|
||||
*/
|
||||
public function cancel (Server $server)
|
||||
{
|
||||
try {
|
||||
error_log($server->update([
|
||||
'cancelled' => now(),
|
||||
]));
|
||||
return redirect()->route('servers.index')->with('success', __('Server cancelled'));
|
||||
} catch (Exception $e) {
|
||||
return redirect()->route('servers.index')->with('error', __('An exception has occurred while trying to cancel the server"') . $e->getMessage() . '"');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Server $server
|
||||
* @return RedirectResponse
|
||||
|
|
|
@ -210,7 +210,21 @@ class ServerController extends Controller
|
|||
$server->delete();
|
||||
return redirect()->route('servers.index')->with('success', __('Server removed'));
|
||||
} catch (Exception $e) {
|
||||
return redirect()->route('servers.index')->with('error', __('An exception has occurred while trying to remove a resource "') . $e->getMessage() . '"');
|
||||
return redirect()->route('servers.index')->with('error', __('An exception has occurred while trying to delete the server"') . $e->getMessage() . '"');
|
||||
}
|
||||
}
|
||||
|
||||
/** Cancel Server */
|
||||
public function cancel (Server $server)
|
||||
{
|
||||
try {
|
||||
error_log($server->update([
|
||||
'cancelled' => now(),
|
||||
]));
|
||||
|
||||
return redirect()->route('servers.index')->with('success', __('Server cancelled'));
|
||||
} catch (Exception $e) {
|
||||
return redirect()->route('servers.index')->with('error', __('An exception has occurred while trying to cancel the server"') . $e->getMessage() . '"');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,8 @@ class Server extends Model
|
|||
"identifier",
|
||||
"product_id",
|
||||
"pterodactyl_id",
|
||||
"last_billed"
|
||||
"last_billed",
|
||||
"cancelled"
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -219,8 +219,8 @@
|
|||
}).then((result) => {
|
||||
if (result.value) {
|
||||
// Delete server
|
||||
fetch("{{ route('servers.destroy', '') }}" + '/' + serverId, {
|
||||
method: 'DELETE',
|
||||
fetch("{{ route('servers.cancel', '') }}" + '/' + serverId, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
|
|||
#normal routes
|
||||
Route::get('notifications/readAll',[NotificationController::class,'readAll'])->name('notifications.readAll');
|
||||
Route::resource('notifications', NotificationController::class);
|
||||
Route::patch('/servers/cancel/{server}', [ServerController::class, 'cancel'])->name('servers.cancel');
|
||||
Route::resource('servers', ServerController::class);
|
||||
Route::resource('profile', ProfileController::class);
|
||||
Route::resource('store', StoreController::class);
|
||||
|
@ -112,6 +113,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
|
|||
#servers
|
||||
Route::get('servers/datatable', [AdminServerController::class, 'datatable'])->name('servers.datatable');
|
||||
Route::post('servers/togglesuspend/{server}', [AdminServerController::class, 'toggleSuspended'])->name('servers.togglesuspend');
|
||||
Route::patch('/servers/cancel/{server}', [AdminServerController::class, 'cancel'])->name('servers.cancel');
|
||||
Route::resource('servers', AdminServerController::class);
|
||||
|
||||
#products
|
||||
|
|
Loading…
Reference in a new issue