Browse Source

payment settings in database

1Day 3 years ago
parent
commit
e959cc79cb

+ 0 - 16
.env.example

@@ -29,22 +29,6 @@ DB_USERNAME=dashboarduser
 DB_PASSWORD=
 ### --- DB Settings End --- ###
 
-### --- Payment Options (required for payments) --- ###
-# Paypal API Credentials - https://developer.paypal.com/docs/integration/direct/rest/ - Sandbox credentials are being used when APP_ENV is set to local
-PAYPAL_SANDBOX_SECRET=
-PAYPAL_SANDBOX_CLIENT_ID=
-PAYPAL_SECRET=
-PAYPAL_CLIENT_ID=
-
-# Stripe API Credentials - https://dashboard.stripe.com/account/apikeys - Test credentials are being used when APP_ENV is set to local
-STRIPE_TEST_SECRET=
-STRIPE_SECRET=
-#https://dashboard.stripe.com/webhooks -> webhook route: <your.controlpanel.gg>/payment/StripeWebhooks
-STRIPE_ENDPOINT_TEST_SECRET=
-STRIPE_ENDPOINT_SECRET=
-# Stripe payment methods - comma seperated list of payment methods that are enabled https://stripe.com/docs/payments/payment-methods/integration-options
-STRIPE_METHODS=
-### --- Payment Options End --- ###
 
 ### --- Discord Settings (optional) --- ###
 # Discord API Credentials - https://discordapp.com/developers/applications/

+ 53 - 0
app/Classes/Settings/Payments.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace App\Classes\Settings;
+
+use App\Models\Settings;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Session;
+
+class Payments
+{
+    public $tabTitle = 'Payment Settings';
+    public $paymentSettings;
+
+    public function __construct()
+    {
+        return;
+    }
+
+
+    public function updatePaymentSettings(Request $request)
+    {
+
+        $values = [
+            //SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form)
+            "SETTINGS::PAYMENTS:PAYPAL:SECRET" => "paypal-client-secret",
+            "SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID" => "paypal-client-id",
+            "SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET" => "paypal-sandbox-secret",
+            "SETTINGS::PAYMENTS:PAYPAL:SANDBOX_CLIENT_ID" => "paypal-sandbox-id",
+            "SETTINGS::PAYMENTS:STRIPE:SECRET" => "stripe-secret",
+            "SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET" => "stripe-endpoint-secret",
+            "SETTINGS::PAYMENTS:STRIPE:TEST_SECRET" => "stripe-test-secret",
+            "SETTINGS::PAYMENTS:STRIPE:ENDPOINT_TEST_SECRET" => "stripe-endpoint-test-secret",
+            "SETTINGS::PAYMENTS:STRIPE:METHODS" => "stripe-methods",
+            "SETTINGS::PAYMENTS:SALES_TAX" => "salex_tax"
+        ];
+
+
+        foreach ($values as $key => $value) {
+            $param = $request->get($value);
+            if (!$param) {
+                $param = "";
+            }
+            Settings::where('key', $key)->update(['value' => $param]);
+            Cache::forget("setting" . ':' . $key);
+            Session::remove("locale");
+        }
+
+
+        return redirect()->route('admin.settings.index')->with('success', 'Payment settings updated!');
+    }
+
+}

+ 3 - 2
app/Http/Controllers/Admin/CreditProductController.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers\Admin;
 
 use App\Models\CreditProduct;
+use App\Models\Settings;
 use Illuminate\Contracts\Foundation\Application;
 use Illuminate\Contracts\View\Factory;
 use Illuminate\Contracts\View\View;
@@ -25,8 +26,8 @@ class CreditProductController extends Controller
 
         if (
             env('APP_ENV') == 'local' ||
-            env('PAYPAL_SECRET') && env('PAYPAL_CLIENT_ID') ||
-            env('STRIPE_SECRET') && env('STRIPE_ENDPOINT_SECRET') && env('STRIPE_METHODS')
+            Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:SECRET") && Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID") ||
+            Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:SECRET") && Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET") && Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:METHODS")
         ) $isPaymentSetup = true;
 
         return view('admin.store.index', [

+ 7 - 7
app/Http/Controllers/Admin/PaymentController.php

@@ -134,7 +134,7 @@ class PaymentController extends Controller
      */
     protected function getPaypalClientId()
     {
-        return env('APP_ENV') == 'local' ? env('PAYPAL_SANDBOX_CLIENT_ID') : env('PAYPAL_CLIENT_ID');
+        return env('APP_ENV') == 'local' ?  Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:SANDBOX_CLIENT_ID") : Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID");
     }
 
     /**
@@ -142,7 +142,7 @@ class PaymentController extends Controller
      */
     protected function getPaypalClientSecret()
     {
-        return env('APP_ENV') == 'local' ? env('PAYPAL_SANDBOX_SECRET') : env('PAYPAL_SECRET');
+        return env('APP_ENV') == 'local' ? Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET") : Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:SECRET");
     }
 
     /**
@@ -266,7 +266,7 @@ class PaymentController extends Controller
             ],
 
             'mode' => 'payment',
-            "payment_method_types" => str_getcsv(env('STRIPE_METHODS')),
+            "payment_method_types" => str_getcsv(Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:METHODS")),
             'success_url' => route('payment.StripeSuccess',  ['product' => $creditProduct->id]) . '&session_id={CHECKOUT_SESSION_ID}',
             'cancel_url' => route('payment.Cancel'),
         ]);
@@ -474,8 +474,8 @@ class PaymentController extends Controller
     protected function getStripeSecret()
     {
         return env('APP_ENV') == 'local'
-            ?  env('STRIPE_TEST_SECRET')
-            :  env('STRIPE_SECRET');
+            ?  Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:TEST_SECRET")
+            :  Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:SECRET");
     }
 
     /**
@@ -484,8 +484,8 @@ class PaymentController extends Controller
     protected function getStripeEndpointSecret()
     {
         return env('APP_ENV') == 'local'
-            ?  env('STRIPE_ENDPOINT_TEST_SECRET')
-            :  env('STRIPE_ENDPOINT_SECRET');
+            ?  Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:ENDPOINT_TEST_SECRET")
+            :  Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET");
     }
 
 

+ 2 - 2
app/Http/Controllers/StoreController.php

@@ -15,8 +15,8 @@ class StoreController extends Controller
 
         if (
             env('APP_ENV') == 'local' ||
-            env('PAYPAL_SECRET') && env('PAYPAL_CLIENT_ID') ||
-            env('STRIPE_SECRET') && env('STRIPE_ENDPOINT_SECRET') && env('STRIPE_METHODS')
+            Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:SECRET") && Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID") ||
+            Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:SECRET") && Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET") && Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:METHODS")
         ) $isPaymentSetup = true;
 
         //Required Verification for creating an server

+ 132 - 0
database/seeders/Seeds/SettingsSeeder.php

@@ -246,5 +246,137 @@ class SettingsSeeder extends Seeder
             'type'  => 'string',
             'description'  => 'The Language of the Datatables. Grab the Language-Codes from here https://datatables.net/plug-ins/i18n/'
         ]);
+
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::PAYMENTS:PAYPAL:SECRET',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Your PayPal Secret-Key ( https://developer.paypal.com/docs/integration/direct/rest/)'
+        ]);
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Your PayPal Client_ID'
+        ]);
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Your PayPal SANDBOX Secret-Key used for testing '
+        ]);
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::PAYMENTS:PAYPAL:SANDBOX_CLIENT_ID',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Your PayPal SANDBOX Client-ID used for testing '
+        ]);
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::PAYMENTS:STRIPE:SECRET',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Your Stripe  Secret-Key  ( https://dashboard.stripe.com/account/apikeys )'
+        ]);
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Your Stripe endpoint secret-key'
+        ]);
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::PAYMENTS:STRIPE:TEST_SECRET',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Your Stripe test secret-key'
+        ]);
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::PAYMENTS:STRIPE:ENDPOINT_TEST_SECRET',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Your Stripe endpoint test secret-key'
+        ]);
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::PAYMENTS:STRIPE:METHODS',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Comma seperated list of payment methods that are enabled (https://stripe.com/docs/payments/payment-methods/integration-options)'
+        ]);
+
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::DISCORD:CLIENT_ID',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Discord API Credentials - https://discordapp.com/developers/applications/'
+        ]);
+
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::DISCORD:CLIENT_SECRET',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Discord API Credentials - https://discordapp.com/developers/applications/'
+        ]);
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::DISCORD:BOT_TOKEN',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Discord API Credentials - https://discordapp.com/developers/applications/'
+        ]);
+
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::DISCORD:GUILD_ID',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Discord API Credentials - https://discordapp.com/developers/applications/'
+        ]);
+
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::DISCORD:ROLE_ID',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Discord role that will be assigned to users when they register'
+        ]);
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::DISCORD:INVITE_URL',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'The invite URL to your Discord Server'
+        ]);
+
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::SYSTEM:PTERODACTYL:TOKEN',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'Admin API Token from Pterodactyl Panel - necessary for the Panel to work. The Key needs all read&write permissions!'
+        ]);
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::SYSTEM:PTERODACTYL:URL',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'The URL to your Pterodactyl Panel. Must not end with a / '
+        ]);
+        Settings::firstOrCreate([
+            'key'   => 'SETTINGS::MISC:PHPMYADMIN:URL',
+        ], [
+            'value' => '',
+            'type'  => 'string',
+            'description'  => 'The URL to your PHPMYADMIN Panel. Must not end with a /, remove to remove database button'
+        ]);
     }
 }

+ 0 - 7
resources/views/admin/settings/tabs/language.blade.php

@@ -77,13 +77,6 @@
         </div>
         <button class="btn btn-primary">{{ __('Save') }}</button>
     </form>
-</div>
-
-</div>
-
-
-
-
 </div>
 
 <script>

+ 129 - 0
resources/views/admin/settings/tabs/payments.blade.php

@@ -0,0 +1,129 @@
+<div class="tab-pane mt-3" id="payments">
+    <form method="POST" enctype="multipart/form-data" class="mb-3"
+        action="{{ route('admin.settings.update.paymentsettings') }}">
+        @csrf
+        @method('PATCH')
+
+        <div class="row">
+            <div class="col-md-6">
+                <img class="mb-3" height="50"
+                     src="{{ url('/images/paypal_logo.png') }}">
+                <!-- PAYPAL -->
+                <div class="form-group">
+                    <div class="custom-control mb-3">
+                        <label for="paypal-client-id">{{ __('Enter your PayPal Client_ID') }}</label>
+                        <input x-model="paypal-client-id" id="paypal-client-id" name="paypal-client-id" type="text"
+                            value="{{ App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID") }}"
+                            class="form-control @error('paypal-client-id') is-invalid @enderror">
+                    </div>
+                </div>
+
+                <!-- PAYPAL -->
+                <div class="form-group">
+                    <div class="custom-control mb-3">
+                        <label for="paypal-client-secret">{{ __('Your PayPal Secret-Key')}} ( https://developer.paypal.com/docs/integration/direct/rest/ ) </label>
+                        <input x-model="paypal-client-secret" id="paypal-client-secret" name="paypal-client-secret" type="text"
+                               value="{{ App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:SECRET") }}"
+                               class="form-control @error('paypal-client-secret') is-invalid @enderror">
+                    </div>
+                </div>
+
+                <!-- PAYPAL -->
+                <div class="form-group">
+                    <div class="custom-control mb-3">
+                        <label for="paypal-sandbox-id">{{ __('Your PayPal SANDBOX Client-ID used for testing') }}</label>
+                        <input x-model="paypal-sandbox-id" id="paypal-sandbox-id" name="paypal-sandbox-id" type="text"
+                               value="{{ App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:SANDBOX_CLIENT_ID") }}"
+                               class="form-control @error('paypal-sandbox-id') is-invalid @enderror">
+                    </div>
+                </div>
+
+                <!-- PAYPAL -->
+                <div class="form-group">
+                    <div class="custom-control mb-3">
+                        <label for="paypal-sandbox-secret">{{ __('Your PayPal SANDBOX Secret-Key used for testing ') }}</label>
+                        <input x-model="paypal-sandbox-secret" id="paypal-sandbox-secret" name="paypal-sandbox-secret" type="text"
+                               value="{{ App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET") }}"
+                               class="form-control @error('paypal-sandbox-secret') is-invalid @enderror">
+                    </div>
+                </div>
+            </div>
+            <div class="col-md-6">
+
+                <img class="mb-3" height="50"
+                     src="{{ url('/images/stripe_logo.png') }}">
+                <!-- STRIPE -->
+                <div class="form-group">
+                    <div class="custom-control mb-3">
+                        <label for="stripe-secret">{{ __('Your Stripe  Secret-Key')}}  ( https://dashboard.stripe.com/account/apikeys )</label>
+                        <input x-model="stripe-secret" id="stripe-secret" name="stripe-secret" type="text"
+                               value="{{ App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:SECRET") }}"
+                               class="form-control @error('stripe-secret') is-invalid @enderror">
+                    </div>
+                </div>
+                <!-- STRIPE -->
+                <div class="form-group">
+                    <div class="custom-control mb-3">
+                        <label for="stripe-endpoint-secret">{{ __('Enter your Stripe endpoint-secret-key') }}</label>
+                        <input x-model="stripe-endpoint-secret" id="stripe-endpoint-secret" name="stripe-endpoint-secret" type="text"
+                               value="{{ App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET") }}"
+                               class="form-control @error('stripe-endpoint-secret') is-invalid @enderror">
+                    </div>
+                </div>
+
+                <!-- STRIPE -->
+                <div class="form-group">
+                    <div class="custom-control mb-3">
+                        <label for="stripe-test-secret">{{ __('Enter your Stripe test-secret-key') }}</label>
+                        <input x-model="stripe-test-secret" id="stripe-test-secret" name="stripe-test-secret" type="text"
+                               value="{{ App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:TEST_SECRET") }}"
+                               class="form-control @error('stripe-test-secret') is-invalid @enderror">
+                    </div>
+                </div>
+
+                <!-- STRIPE -->
+                <div class="form-group">
+                    <div class="custom-control mb-3">
+                        <label for="stripe-endpoint-test-secret">{{ __('Enter your Stripe endpoint-test-secret-key') }}</label>
+                        <input x-model="stripe-endpoint-test-secret" id="stripe-endpoint-test-secret" name="stripe-endpoint-test-secret" type="text"
+                               value="{{ App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:ENDPOINT_TEST_SECRET") }}"
+                               class="form-control @error('stripe-endpoint-test-secret') is-invalid @enderror">
+                    </div>
+                </div>
+
+                <!-- STRIPE -->
+                <div class="form-group">
+                    <div class="custom-control mb-3">
+                        <label for="stripe-methods">{{ __('Comma seperated list of payment methods that are enabled')}} (https://stripe.com/docs/payments/payment-methods/integration-options)</label>
+                        <input x-model="stripe-methods" id="stripe-methods" name="stripe-methods" type="text"
+                               value="{{ App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:METHODS") }}"
+                               class="form-control @error('stripe-methods') is-invalid @enderror">
+                    </div>
+                </div>
+            </div>
+
+
+
+            <!-- Sorry IceToast, aber kein plan wie man das hier schön gestalten soll.... -->
+        <div class="row">
+            <div class="col-md-6">
+
+                <!-- Tax -->
+                <div class="form-group">
+                    <div class="custom-control mb-3">
+                        <label for="salex_tax">{{ __('The %-value of tax that will be added to the product price on checkout')}}</label>
+                        <input x-model="salex_tax" id="salex_tax" name="salex_tax" type="number"
+                               value="{{ App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:SALES_TAX") }}"
+                               class="form-control @error('salex_tax') is-invalid @enderror">
+                    </div>
+                </div>
+            </div>
+        </div>
+        </div>
+        <button class="btn btn-primary">{{ __('Submit') }}</button>
+
+        <!-- end -->
+
+    </form>
+</div>
+

+ 1 - 1
resources/views/layouts/main.blade.php

@@ -211,7 +211,7 @@
                             </a>
                         </li>
 
-                        @if ((env('PAYPAL_SECRET') && env('PAYPAL_CLIENT_ID')) || env('APP_ENV', 'local') == 'local')
+                        @if ((\App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:SECRET") && \App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID")) || env('APP_ENV', 'local') == 'local')
                             <li class="nav-item">
                                 <a href="{{ route('store.index') }}" class="nav-link @if (Request::routeIs('store.*') || Request::routeIs('checkout')) active @endif">
                                     <i class="nav-icon fa fa-coins"></i>

+ 2 - 2
resources/views/store/checkout.blade.php

@@ -78,7 +78,7 @@
                                 <p class="lead">{{ __('Payment Methods') }}:</p>
 
                                 <div>
-                                    @if (env('PAYPAL_SANDBOX_SECRET') || env('PAYPAL_SECRET'))
+                                    @if (\App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:SECRET")|| \App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET"))
                                         <label class="text-center " for="paypal">
                                             <img class="mb-3" height="50"
                                                 src="{{ url('/images/paypal_logo.png') }}"></br>
@@ -88,7 +88,7 @@
                                             </input>
                                         </label>
                                     @endif
-                                    @if (env('STRIPE_TEST_SECRET') || env('STRIPE_SECRET'))
+                                    @if (\App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:TEST_SECRET") || \App\Models\Settings::getValueByKey("SETTINGS::PAYMENTS:STRIPE:SECRET"))
                                         <label class="ml-5 text-center " for="stripe">
                                             <img class="mb-3" height="50"
                                                 src="{{ url('/images/stripe_logo.png') }}" /></br>

+ 2 - 0
routes/web.php

@@ -1,5 +1,6 @@
 <?php
 
+use App\Classes\Settings\Payments;
 use App\Http\Controllers\Admin\ActivityLogController;
 use App\Http\Controllers\Admin\ApplicationApiController;
 use App\Http\Controllers\Admin\InvoiceController;
@@ -135,6 +136,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
         Route::patch('settings/update/icons', [SettingsController::class, 'updateIcons'])->name('settings.update.icons');
         Route::patch('settings/update/invoice-settings', [Invoices::class, 'updateInvoiceSettings'])->name('settings.update.invoicesettings');
         Route::patch('settings/update/language', [Language::class, 'updateLanguageSettings'])->name('settings.update.languagesettings');
+        Route::patch('settings/update/payment', [Payments::class, 'updatePaymentSettings'])->name('settings.update.paymentsettings');
         Route::resource('settings', SettingsController::class)->only('index');
 
         #invoices