findEscrowPayment($orderNumber, (int) Auth::id()); if (! $payment) { abort(404); } $this->apiService->useEscrowCredentials(true); if ($this->isMobile($request)) { return $this->mobileConfirmPage($payment->transaction_id); } return $this->pcConfirmPage($payment->transaction_id); } /** * pcReturn * * @param Request $request * @return Response */ // audit:allow controller-base-request-injection reason: PG(이니시스)가 POST 하는 콜백 표면 — 필드 구성이 PG 소유라 계약을 닫을 수 없다. 값은 문자열 캐스팅 후 tid 대조를 거쳐 payment_meta 에 영속된다(서명 검증 없는 무인증 콜백이라 기록 위조 여지가 있는 사전 상태 — 표시용 메타이며 금액·상태 전이에는 미사용) public function pcReturn(Request $request): Response { $resultCode = (string) $request->input('ResultCode', ''); $tid = (string) $request->input('tid', ''); Log::info('KG Inicis: escrow PC confirm return', [ 'result_code' => $resultCode, 'tid' => $tid, ]); $this->saveConfirmResult($tid, [ 'type' => $resultCode === '00' ? 'confirm' : 'deny', 'result_code' => $resultCode, 'cnf_date' => (string) $request->input('CNF_Date', ''), 'cnf_time' => (string) $request->input('CNF_Time', ''), 'dny_date' => (string) $request->input('DNY_Date', ''), 'dny_time' => (string) $request->input('DNY_Time', ''), 'dny_msg' => (string) $request->input('DNY_DenyMsg', ''), ]); // 팝업 닫기 + 부모 창 새로고침 return $this->htmlResponse( '' ); } /** * close * * @return Response */ public function close(): Response { return $this->htmlResponse(''); } /** * mobileReturn * * @param Request $request * @return RedirectResponse */ // audit:allow controller-base-request-injection reason: PG(이니시스 모바일)가 POST 하는 콜백 표면 — 필드 구성이 PG 소유라 계약을 닫을 수 없다. 값은 문자열 캐스팅 후 tid 대조를 거쳐 payment_meta 에 영속된다(서명 검증 없는 무인증 콜백이라 기록 위조 여지가 있는 사전 상태 — 표시용 메타이며 금액·상태 전이에는 미사용) public function mobileReturn(Request $request): RedirectResponse { $status = (string) $request->input('P_STATUS', ''); $tid = (string) $request->input('P_ESCROW_TID', ''); $clStatus = (string) $request->input('P_CL_STATUS', ''); $rmesg = (string) $request->input('P_RMESG1', ''); Log::info('KG Inicis: escrow mobile confirm return', [ 'status' => $status, 'tid' => $tid, 'cl_status' => $clStatus, ]); $orderNumber = $this->saveConfirmResult($tid, [ 'type' => $status === '00' ? 'confirm' : 'deny', 'result_code' => $status, 'cl_status' => $clStatus, 'result_msg' => $rmesg, ]); return redirect($orderNumber ? '/mypage/orders/'.$orderNumber : '/mypage/orders'); } // ──────────────────────────── Private ──────────────────────────── private function pcConfirmPage(string $tid): Response { $isTest = $this->apiService->isTestMode(); $mid = $this->apiService->getMid(); $mKey = $this->apiService->getEscrowConfirmMKey(); $timestamp = (string) round(microtime(true) * 1000); $jsUrl = $isTest ? self::PC_JS_URL_TEST : self::PC_JS_URL_LIVE; $returnUrl = url('/plugins/sirsoft-pay_kginicis/payment/escrow-confirm/pc/return'); $closeUrl = url('/plugins/sirsoft-pay_kginicis/payment/escrow-confirm/close'); $html = << 에스크로 구매결정

에스크로 구매결정 창을 준비 중입니다...

HTML; return $this->htmlResponse($html); } private function mobileConfirmPage(string $tid): Response { $mid = $this->apiService->getMid(); $nextUrl = url('/plugins/sirsoft-pay_kginicis/payment/escrow-confirm/mobile/return'); $payUrl = self::MOBILE_PAY_URL; $html = << 에스크로 구매결정

에스크로 구매결정 페이지로 이동 중입니다...

HTML; return $this->htmlResponse($html); } private function htmlResponse(string $html): Response { return response($html, 200, ['Content-Type' => 'text/html; charset=UTF-8']); } /** * TID로 payment_meta에 구매결정 결과를 저장하고 주문번호를 반환. */ private function saveConfirmResult(string $tid, array $data): ?string { if ($tid === '') { return null; } // audit:allow controller-direct-data-access reason: PG 플러그인의 결제 레코드 직접 조회/기록 — ecommerce Repository 의존 시 모듈 버전 제약 연쇄(PaymentLimits 선례). Service/Repository 이관은 후속 백로그 $row = DB::table((new OrderPayment)->getTable().' as p') ->join((new Order)->getTable().' as o', 'o.id', '=', 'p.order_id') ->where('p.transaction_id', $tid) ->where('p.pg_provider', 'kginicis') ->where('p.is_escrow', true) ->select('p.id', 'p.payment_meta', 'o.order_number') ->first(); if (! $row) { Log::warning('KG Inicis: escrow confirm — payment not found', ['tid' => $tid]); return null; } $meta = $row->payment_meta ? json_decode($row->payment_meta, true) : []; $meta['escrow_confirm'] = array_merge( ['confirmed_at' => now()->toDateTimeString()], $data, ); // audit:allow controller-direct-data-access reason: PG 플러그인의 결제 레코드 직접 조회/기록 — ecommerce Repository 의존 시 모듈 버전 제약 연쇄(PaymentLimits 선례). Service/Repository 이관은 후속 백로그 DB::table((new OrderPayment)->getTable()) ->where('id', $row->id) ->update([ 'payment_meta' => json_encode($meta, JSON_UNESCAPED_UNICODE), 'updated_at' => now(), ]); Log::info('KG Inicis: escrow confirm saved', [ 'order_number' => $row->order_number, 'tid' => $tid, 'type' => $data['type'] ?? '', ]); return $row->order_number; } private function findEscrowPayment(string $orderNumber, int $userId): ?object { // audit:allow controller-direct-data-access reason: PG 플러그인의 결제 레코드 직접 조회/기록 — ecommerce Repository 의존 시 모듈 버전 제약 연쇄(PaymentLimits 선례). Service/Repository 이관은 후속 백로그 return DB::table((new OrderPayment)->getTable().' as p') ->join((new Order)->getTable().' as o', 'o.id', '=', 'p.order_id') ->where('o.order_number', $orderNumber) ->where('o.user_id', $userId) ->where('p.pg_provider', 'kginicis') ->where('p.is_escrow', true) ->whereNotNull('p.transaction_id') ->select('p.id', 'p.transaction_id') ->first(); } private function isMobile(Request $request): bool { return (bool) preg_match('/(android|iphone|ipad|ipod|mobile|phone)/i', $request->userAgent() ?? ''); } }