7.0.7 페이로드 전수 검증에서 발견된 error 4건·warn 14건을 릴리즈 전에 처리했다. 미출시 분량의 자체 결함(회원 통합검색 500, 관리자 스코프 403 의 500 위장 등)이므로 페이로드에 합류시키고, 출시 대상 26개 CHANGELOG 의 버전 섹션 날짜를 2026-08-18 로 정렬했다. - 통합검색 import 복원 + 이커머스 관리자 typed 403 catch 대칭(테스트 동반) - admin 판정 스니핑 사설 사본 전수 수렴(BoardResource) + 조건 스캔 테스트 - 스케줄 인터프리터 변형 표기(확장자·버전 접미사) 정규화 차단 - ckeditor5 참조 판정 배치화·fail-safe, 결제 플러그인 진단 페이로드 대칭 - 템플릿 다크 대비·상태 Select value-제어 + --production 재빌드 - Upgrade_7_0_7 잔존 중복 색인 정리 스텝, API 문서·i18n(ko/en/ja) 동기
291 lines
12 KiB
PHP
291 lines
12 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Plugins\Sirsoft\PayKginicis\Controllers;
|
|
|
|
// audit:allow api-doc-coverage 요청 파라미터·응답 구조 무변경 — 테이블명 리터럴을 모델 파생으로 정리한 내부 리팩토링 (#571)
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Modules\Sirsoft\Ecommerce\Models\Order;
|
|
use Modules\Sirsoft\Ecommerce\Models\OrderPayment;
|
|
use Plugins\Sirsoft\PayKginicis\Services\KgInicisApiService;
|
|
|
|
/**
|
|
* KG 이니시스 에스크로 구매결정 컨트롤러 (사용자용)
|
|
*
|
|
* PC: INIStdPay_escrow_conf.js 팝업 → POST returnUrl
|
|
* 모바일: mobile.inicis.com/smart/payment/ 자동 submit → POST P_NEXT_URL
|
|
*/
|
|
class UserEscrowConfirmController extends Controller
|
|
{
|
|
private const PC_JS_URL_TEST = 'https://stgstdpay.inicis.com/stdjs/INIStdPay_escrow_conf.js';
|
|
|
|
private const PC_JS_URL_LIVE = 'https://stdpay.inicis.com/stdjs/INIStdPay_escrow_conf.js';
|
|
|
|
private const MOBILE_PAY_URL = 'https://mobile.inicis.com/smart/payment/';
|
|
|
|
public function __construct(
|
|
private readonly KgInicisApiService $apiService,
|
|
) {}
|
|
|
|
/**
|
|
* show
|
|
*
|
|
* @param Request $request
|
|
* @param string $orderNumber
|
|
* @return Response
|
|
*/
|
|
// audit:allow controller-base-request-injection reason: 본문 입력을 읽지 않음 — 에스크로 확인 HTML 화면 렌더 (검증 대상 필드 없음)
|
|
public function show(Request $request, string $orderNumber): Response
|
|
{
|
|
$payment = $this->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(
|
|
'<script>try{window.opener&&window.opener.location.reload();}catch(e){}window.close();</script>'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* close
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function close(): Response
|
|
{
|
|
return $this->htmlResponse('<script>window.close();</script>');
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
<!DOCTYPE html>
|
|
<html lang="ko">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
<title>에스크로 구매결정</title>
|
|
<script src="{$jsUrl}" charset="UTF-8"></script>
|
|
<script>window.onload = function() { INIStdPay.pay('escrow_confirm_form'); };</script>
|
|
<style>
|
|
body { font-family: sans-serif; display: flex; align-items: center;
|
|
justify-content: center; height: 100vh; margin: 0; background: #f5f5f5; }
|
|
p { color: #666; font-size: 14px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<p>에스크로 구매결정 창을 준비 중입니다...</p>
|
|
<form id="escrow_confirm_form" method="post">
|
|
<input type="hidden" name="version" value="1.0">
|
|
<input type="hidden" name="mid" value="{$mid}">
|
|
<input type="hidden" name="tid" value="{$tid}">
|
|
<input type="hidden" name="timestamp" value="{$timestamp}">
|
|
<input type="hidden" name="mKey" value="{$mKey}">
|
|
<input type="hidden" name="currency" value="WON">
|
|
<input type="hidden" name="returnUrl" value="{$returnUrl}">
|
|
<input type="hidden" name="closeUrl" value="{$closeUrl}">
|
|
<input type="hidden" name="acceptmethod" value="">
|
|
</form>
|
|
</body>
|
|
</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
|
|
<!DOCTYPE html>
|
|
<html lang="ko">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
<title>에스크로 구매결정</title>
|
|
<style>
|
|
body { font-family: sans-serif; display: flex; align-items: center;
|
|
justify-content: center; height: 100vh; margin: 0; background: #f5f5f5; }
|
|
p { color: #666; font-size: 14px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<p>에스크로 구매결정 페이지로 이동 중입니다...</p>
|
|
<form id="mobile_confirm_form" name="mobileweb" method="post"
|
|
action="{$payUrl}" accept-charset="euc-kr">
|
|
<input type="hidden" name="P_INI_PAYMENT" value="ESCROWCONFIRM">
|
|
<input type="hidden" name="P_MID" value="{$mid}">
|
|
<input type="hidden" name="P_ESCROW_TID" value="{$tid}">
|
|
<input type="hidden" name="P_NEXT_URL" value="{$nextUrl}">
|
|
<input type="hidden" name="P_RESERVED" value="">
|
|
</form>
|
|
<script>document.getElementById('mobile_confirm_form').submit();</script>
|
|
</body>
|
|
</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() ?? '');
|
|
}
|
|
}
|