Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

108 lines
3.0KB

  1. <?php
  2. namespace App\Http\Controllers\Web\RobotPayment\CreditCard;
  3. use App\Http\Controllers\Web\WebController;
  4. use App\Kintone\Models\CreditcardAutoPaymentInfo;
  5. use App\Kintone\Models\CreditcardAutoPaymentResult;
  6. use App\Kintone\Models\Customer;
  7. use App\Util\DateUtil;
  8. use Exception;
  9. use Illuminate\Database\Eloquent\ModelNotFoundException;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Http\Response;
  12. use Illuminate\Support\Facades\Log;
  13. use LogicException;
  14. class PaymentInfoController extends WebController
  15. {
  16. public function name(): string
  17. {
  18. return "クレジットカード 自動課金情報登録";
  19. }
  20. public function description(): string
  21. {
  22. return "クレジットカード 自動課金情報登録";
  23. }
  24. public function __construct(protected PaymentInfoParam $param)
  25. {
  26. parent::__construct();
  27. }
  28. protected function run(Request $request): Response
  29. {
  30. $param = $this->param;
  31. logger("リクエスト受信 creditcard", ["param" => $request->all()]);
  32. // 認証チェック
  33. // 初回の決済結果はトークン付で送信されるのでチェックする
  34. if ($param->token !== config('custom.creditcard.token')) {
  35. abort(403);
  36. }
  37. $customer = Customer::findByCustomerCode($param->customerCode);
  38. $customer->paymentMethod = "クレジットカード";
  39. $model = new CreditcardAutoPaymentInfo();
  40. $model->customerCode = $param->customerCode;
  41. $model->autoPaymentNo = $param->acid;
  42. $model->shopOrderNo = $param->cod;
  43. $model->paymentInterval = $this->getPaymentInterval();
  44. $model->paymentAmount = $this->getPaymentAmount();
  45. // 機密な情報をリクエストデータから除外して登録する
  46. $requestArr = request()->toArray();
  47. unset($requestArr["token"]);
  48. unset($requestArr["id"]);
  49. unset($requestArr["pa"]);
  50. $model->dataResult = json_encode(
  51. $requestArr,
  52. JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
  53. );
  54. $model->save();
  55. $customer->save();
  56. return response()->view('robot-payment.creditcard.ok');
  57. }
  58. private function getPaymentAmount(): int
  59. {
  60. $param = $this->param;
  61. return intval($param->acam) + intval($param->actx) + intval($param->acsf);
  62. }
  63. private function getPaymentInterval(): string
  64. {
  65. $code = $this->param->actp;
  66. if ($code === "2") {
  67. return "毎週課金";
  68. }
  69. if ($code === "3") {
  70. return "隔週課金";
  71. }
  72. if ($code === "4") {
  73. return "毎月課金";
  74. }
  75. if ($code === "5") {
  76. return "隔月課金";
  77. }
  78. if ($code === "6") {
  79. return "3ヶ月課金";
  80. }
  81. if ($code === "7") {
  82. return "6ヶ月課金";
  83. }
  84. if ($code === "8") {
  85. return "1年課金";
  86. }
  87. return "";
  88. }
  89. }