Payments.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Classes\Settings;
  3. use App\Models\Settings;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\Cache;
  6. use Illuminate\Support\Facades\Validator;
  7. class Payments
  8. {
  9. public function __construct()
  10. {
  11. }
  12. public function updateSettings(Request $request)
  13. {
  14. $validator = Validator::make($request->all(), [
  15. 'paypal-client_id' => 'nullable|string',
  16. 'paypal-client-secret' => 'nullable|string',
  17. 'paypal-sandbox-secret' => 'nullable|string',
  18. 'stripe-secret-key' => 'nullable|string',
  19. 'stripe-endpoint-secret' => 'nullable|string',
  20. 'stripe-test-secret-key' => 'nullable|string',
  21. 'stripe-test-endpoint-secret' => 'nullable|string',
  22. 'stripe-methods' => 'nullable|string',
  23. 'sales-tax' => 'nullable|numeric',
  24. ]);
  25. if ($validator->fails()) {
  26. return redirect(route('admin.settings.index').'#payment')->with('error', __('Payment settings have not been updated!'))->withErrors($validator)
  27. ->withInput();
  28. }
  29. $values = [
  30. //SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form)
  31. 'SETTINGS::PAYMENTS:PAYPAL:SECRET' => 'paypal-client-secret',
  32. 'SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID' => 'paypal-client-id',
  33. 'SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET' => 'paypal-sandbox-secret',
  34. 'SETTINGS::PAYMENTS:PAYPAL:SANDBOX_CLIENT_ID' => 'paypal-sandbox-id',
  35. 'SETTINGS::PAYMENTS:STRIPE:SECRET' => 'stripe-secret',
  36. 'SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET' => 'stripe-endpoint-secret',
  37. 'SETTINGS::PAYMENTS:STRIPE:TEST_SECRET' => 'stripe-test-secret',
  38. 'SETTINGS::PAYMENTS:STRIPE:ENDPOINT_TEST_SECRET' => 'stripe-endpoint-test-secret',
  39. 'SETTINGS::PAYMENTS:STRIPE:METHODS' => 'stripe-methods',
  40. 'SETTINGS::PAYMENTS:SALES_TAX' => 'sales-tax',
  41. ];
  42. foreach ($values as $key => $value) {
  43. $param = $request->get($value);
  44. Settings::where('key', $key)->updateOrCreate(['key' => $key], ['value' => $param]);
  45. Cache::forget('setting'.':'.$key);
  46. }
  47. return redirect(route('admin.settings.index').'#payment')->with('success', __('Payment settings updated!'));
  48. }
  49. }