2022-01-07 08:54:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Classes\Settings;
|
|
|
|
|
|
|
|
use App\Models\Settings;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
2022-01-15 00:25:27 +00:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
2022-01-07 08:54:01 +00:00
|
|
|
class Payments
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
|
2023-01-05 17:01:42 +00:00
|
|
|
}
|
2022-01-07 08:54:01 +00:00
|
|
|
|
2022-01-14 17:06:24 +00:00
|
|
|
public function updateSettings(Request $request)
|
2022-01-07 08:54:01 +00:00
|
|
|
{
|
2022-01-15 00:25:27 +00:00
|
|
|
$validator = Validator::make($request->all(), [
|
2023-01-05 17:01:42 +00:00
|
|
|
'paypal-client_id' => 'nullable|string',
|
|
|
|
'paypal-client-secret' => 'nullable|string',
|
|
|
|
'paypal-sandbox-secret' => 'nullable|string',
|
|
|
|
'stripe-secret-key' => 'nullable|string',
|
|
|
|
'stripe-endpoint-secret' => 'nullable|string',
|
|
|
|
'stripe-test-secret-key' => 'nullable|string',
|
|
|
|
'stripe-test-endpoint-secret' => 'nullable|string',
|
|
|
|
'stripe-methods' => 'nullable|string',
|
|
|
|
'sales-tax' => 'nullable|numeric',
|
2022-01-15 00:25:27 +00:00
|
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
2023-01-05 17:01:42 +00:00
|
|
|
return redirect(route('admin.settings.index').'#payment')->with('error', __('Payment settings have not been updated!'))->withErrors($validator)
|
2022-01-15 00:25:27 +00:00
|
|
|
->withInput();
|
|
|
|
}
|
2022-01-07 08:54:01 +00:00
|
|
|
|
|
|
|
$values = [
|
|
|
|
//SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form)
|
2023-01-05 17:01:42 +00:00
|
|
|
'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' => 'sales-tax',
|
2022-01-07 08:54:01 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($values as $key => $value) {
|
|
|
|
$param = $request->get($value);
|
2022-01-14 23:49:33 +00:00
|
|
|
|
2022-01-14 09:19:41 +00:00
|
|
|
Settings::where('key', $key)->updateOrCreate(['key' => $key], ['value' => $param]);
|
2023-01-05 17:01:42 +00:00
|
|
|
Cache::forget('setting'.':'.$key);
|
2022-01-07 08:54:01 +00:00
|
|
|
}
|
|
|
|
|
2023-01-05 17:01:42 +00:00
|
|
|
return redirect(route('admin.settings.index').'#payment')->with('success', __('Payment settings updated!'));
|
2022-01-07 08:54:01 +00:00
|
|
|
}
|
|
|
|
}
|