공개 (답변 중복 등록)/(문의 삭제 시 답변 잔존) 수정과 동형 결함 전수 해소.
- 문의 답변 단일성: 1차(피벗 is_answered) + 2차(게시판 리스너 duplicate 마커) 이중 방어,
경합 경로에서도 사유(reply_already_exists 422)가 보존되도록 훅 반환 계약 확장
- 질문·답변·피벗 생명주기 대칭: 삭제/복원/영구삭제 훅 연동 + 고아 데이터 백필 업그레이드 스텝
- 게시판별 답글 삭제 정책(cascade/block) 신설, 정렬 화이트리스트·per_page 게이트
(전량 조회 소비처 200/999 를 수용하는 상한 999 — 조였다가 관리자 화면 2곳 422 회귀 즉시 정정)
- 결제/본인인증 플러그인 검증 계약: FormRequest 15종 승격 + 컨트롤러 catch 정합.
거래 조회 tid 상한은 저장 컬럼(varchar 100) 기준 — 해외 CBT TID(40자) 수용
- onError 토스트 고정 문구 전수 해소(67건/50파일/15확장) — 서버 실패 사유를 그대로 표면화,
change-password 오변수(response→error) 교정
- 코어 플러그인 설정 검증 안내의 항목 표시명이 스키마 라벨(ko/en) 폴백에 덮여 요청 로케일
(ja) 라벨을 잃던 회귀 정정 — 번역 등록이 있으면 그것을 우선 (7.0.7 미출시 기능 자체 결함)
- 사전 결함 정리(Icon 등가표 27·darkmode 2·validated 통일), API 문서·CHANGELOG·ja 팩 동기
- develop(60652fdc0) 리베이스: getTable 정비와 병합 — 양측 의도 보존 (충돌 18파일)
141 lines
4.7 KiB
PHP
141 lines
4.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Plugins\Sirsoft\PayKginicis\Controllers;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\RateLimiter;
|
|
use Modules\Sirsoft\Ecommerce\Services\OrderProcessingService;
|
|
use Plugins\Sirsoft\PayKginicis\Concerns\ValidatesCbtOrderContext;
|
|
use Plugins\Sirsoft\PayKginicis\Concerns\ValidatesTimestampFreshness;
|
|
use Plugins\Sirsoft\PayKginicis\Http\Requests\CbtHashDataRequest;
|
|
use Plugins\Sirsoft\PayKginicis\Services\CbtCheckoutTokenService;
|
|
use Plugins\Sirsoft\PayKginicis\Services\KgInicisApiService;
|
|
|
|
class CbtHashDataController
|
|
{
|
|
use ValidatesCbtOrderContext;
|
|
use ValidatesTimestampFreshness;
|
|
|
|
public function __construct(
|
|
private readonly KgInicisApiService $apiService,
|
|
private readonly OrderProcessingService $orderService,
|
|
private readonly CbtCheckoutTokenService $checkoutTokenService,
|
|
) {}
|
|
|
|
/**
|
|
* generate
|
|
*
|
|
* 형식·길이 검증은 CbtHashDataRequest 가 담당한다 (국내 SignatureRequest 와 동일 강도).
|
|
* 계약 변경: 빈 checkout_token 은 종전 403(토큰 검증 실패) → 422(필수 검증).
|
|
*
|
|
* @param CbtHashDataRequest $request oid/price/timestamp/checkout_token/buyer 정보
|
|
* @return JsonResponse hash_data 또는 403/404/422
|
|
*/
|
|
public function generate(CbtHashDataRequest $request): JsonResponse
|
|
{
|
|
$oid = (string) $request->validated('oid');
|
|
$price = (int) $request->validated('price');
|
|
$timestamp = (string) $request->validated('timestamp');
|
|
$checkoutToken = (string) $request->validated('checkout_token');
|
|
|
|
$rateLimitKey = $this->rateLimitKey($request, $oid);
|
|
if (RateLimiter::tooManyAttempts($rateLimitKey, 10)) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Too many CBT hash requests. Please try again later.',
|
|
], 429);
|
|
}
|
|
RateLimiter::hit($rateLimitKey, 60);
|
|
|
|
if (! $this->isTimestampFresh($timestamp)) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Timestamp is stale or invalid (signature replay protection).',
|
|
], 422);
|
|
}
|
|
|
|
if (! $this->apiService->isJapanEnabled()) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Japan CBT payment is disabled.',
|
|
], 422);
|
|
}
|
|
|
|
if (! $this->apiService->isJapanConfigured()) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Japan CBT payment is not configured.',
|
|
], 422);
|
|
}
|
|
|
|
$order = $this->orderService->findByOrderNumber($oid);
|
|
if (! $order) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Order not found.',
|
|
], 404);
|
|
}
|
|
|
|
if (! $order->order_status->isBeforePayment()) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Order is not payable.',
|
|
], 422);
|
|
}
|
|
|
|
if ((string) $order->currency !== 'JPY') {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'CBT payment is only available for JPY orders.',
|
|
], 422);
|
|
}
|
|
|
|
if (! $this->cbtRequestMatchesOrderBuyer($request, $order)) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Order buyer verification failed.',
|
|
], 403);
|
|
}
|
|
|
|
$expectedPrice = $this->cbtExpectedPrice($order);
|
|
if ($price !== $expectedPrice) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Payment amount does not match the order amount.',
|
|
], 422);
|
|
}
|
|
|
|
if (! $this->checkoutTokenService->verify(
|
|
$checkoutToken,
|
|
$oid,
|
|
$price,
|
|
(string) $request->input('buyer_email', ''),
|
|
(string) $request->input('buyer_phone', ''),
|
|
$request,
|
|
)) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'CBT checkout token verification failed.',
|
|
], 403);
|
|
}
|
|
|
|
$mid = $this->apiService->getJapanMid();
|
|
$hashData = $this->apiService->generateCbtHashData($mid, $timestamp, $price, $oid);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => [
|
|
'hash_data' => $hashData,
|
|
],
|
|
]);
|
|
}
|
|
|
|
private function rateLimitKey(Request $request, string $oid): string
|
|
{
|
|
return 'sirsoft-pay_kginicis:cbt-hash:'.sha1($request->ip().'|'.$oid);
|
|
}
|
|
}
|