TossController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Http\Controllers\Admin\Config\Register;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\Config;
  6. class TossController extends Controller
  7. {
  8. private Config $configModel;
  9. public function __construct(Config $config)
  10. {
  11. $this->configModel = $config;
  12. }
  13. /**
  14. * 토스 인증
  15. * @method GET
  16. * @see /admin/config/register/toss
  17. */
  18. public function index()
  19. {
  20. return view('admin.config.register.toss', [
  21. 'config' => $this->configModel->getAllMeta()
  22. ]);
  23. }
  24. /**
  25. * 토스 인증 저장
  26. * @method POST
  27. * @see /admin/config/register/toss
  28. */
  29. public function store(Request $request)
  30. {
  31. $rules = [
  32. 'toss_cert_is_test' => 'numeric|nullable|in:0,1',
  33. 'live_toss_cert_client_id' => 'required_if:toss_cert_is_test,0|string|max:255',
  34. 'live_toss_cert_client_secret' => 'required_if:toss_cert_is_test,0|string|max:255',
  35. 'test_toss_cert_client_id' => 'required_if:toss_cert_is_test,1|string|max:255',
  36. 'test_toss_cert_client_secret' => 'required_if:toss_cert_is_test,1|string|max:255',
  37. ];
  38. $attributes = [
  39. 'toss_cert_is_test' => '실 토스 인증 여부',
  40. 'live_toss_cert_client_id' => 'Live Client Key',
  41. 'live_toss_cert_client_secret' => 'Live client Secret',
  42. 'test_toss_cert_client_id' => 'Test Client Key',
  43. 'test_toss_cert_client_secret' => 'Test Client Secret'
  44. ];
  45. $posts = $this->validate($request, $rules, [], $attributes);
  46. $this->configModel->save($posts, $attributes);
  47. $message = '토스 인증서가 저장되었습니다.';
  48. return redirect()->route('admin.config.register.toss.index')->with('message', $message);
  49. }
  50. }