Browse Source

Charges the first hour worth of credits upon creating a server.

AVMG20 3 years ago
parent
commit
f4237b2e88

+ 6 - 0
app/Http/Controllers/ServerController.php

@@ -74,6 +74,12 @@ class ServerController extends Controller
             'identifier' => $response->json()['attributes']['identifier']
         ]);
 
+        if (Configuration::getValueByKey('SERVER_CREATE_CHARGE_FIRST_HOUR' , 'true') == 'true'){
+            if (Auth::user()->credits >= $server->product->getHourlyPrice()){
+                Auth::user()->decrement('credits', $server->product->getHourlyPrice());
+            }
+        }
+
         return redirect()->route('servers.index')->with('success', 'server created');
     }
 

+ 8 - 0
database/seeders/Seeds/ConfigurationSeeder.php

@@ -128,6 +128,14 @@ class ConfigurationSeeder extends Seeder
             'description' => 'Set the display name of your currency :)'
         ]);
 
+        //credits display name
+        Configuration::firstOrCreate([
+            'key' => 'SERVER_CREATE_CHARGE_FIRST_HOUR',
+        ], [
+            'value'       => 'true',
+            'type'        => 'boolean',
+            'description' => 'Charges the first hour worth of credits upon creating a server.'
+        ]);
 
     }
 }