Files
Gnuboard7/plugins/_bundled/sirsoft-pay_nicepayments/resources/js/index.ts
T
HeuJung 8b9bfd0c91 refactor(ecommerce,pay): 간편결제 브랜드 마크 카탈로그 편입 + 애플페이 iOS 게이팅 이관
3사 PG 플러그인의 체크아웃 DOM 인젝터가 렌더 후 브랜드 마크를 주입하고
injector끼리 같은 버튼을 두고 경합하던 구조를 제거한다. 시각정보(색 배지/
SVG 로고)를 결제수단 카탈로그(_cached_brand_mark)로 편입해 코어 체크아웃
레이아웃의 신규 BrandMark 컴포넌트가 데이터 기반으로 직접 렌더한다.
reconcileKginicisPatchedDuplicates(중복 방어)도 함께 제거했다.

애플페이 iOS 게이팅도 injector 밖으로 이관: 이커머스 모듈 DetectDevice
미들웨어가 UA로 기기를 판정해 코어 core.frontend.filter_app_config 훅으로
appConfig.isIos를 주입하고(1차), 템플릿 부트스트랩이 iPadOS 데스크탑 UA를
클라 신호로 보정한다(2차). 코어는 훅만 제공하고 감지 로직은 모듈이 소유한다.

미들웨어는 Router::pushMiddlewareToGroup 이 아닌 HTTP Kernel::appendMiddlewareToGroup
으로 web 그룹에 등록한다(전자는 Router 레지스트리만 갱신해 SSR 셸 요청 파이프라인에
미반영 → isIos 항상 false). sirsoft-gdpr 선례와 동일.

코어 최소 요구 버전 7.0.5 상향(appConfig 필터 훅 도입).
2026-07-15 17:50:39 +09:00

100 lines
3.1 KiB
TypeScript

import { handlerMap } from './handlers';
import { initEasyPayWatcher } from './handlers/setPaymentMethod';
import { installOrderResponseInterceptor } from './orderResponseInterceptor';
import { installOrderCompleteReceiptInjector } from './orderCompleteReceiptInjector';
import { installMypageOrderShowInjector } from './mypageOrderShowInjector';
import { installAdminPaymentMethodBrandInjector } from './adminPaymentMethodBrandInjector';
import { installAdminOrderPaymentDisplayInjector } from './adminOrderPaymentDisplayInjector';
const PLUGIN_IDENTIFIER = 'sirsoft-pay_nicepayments';
const logger = {
info: (...args: unknown[]) => console.info(`[${PLUGIN_IDENTIFIER}]`, ...args),
warn: (...args: unknown[]) => console.warn(`[${PLUGIN_IDENTIFIER}]`, ...args),
error: (...args: unknown[]) => console.error(`[${PLUGIN_IDENTIFIER}]`, ...args),
};
function registerHandlers(): number {
const g7Core = (window as Record<string, unknown>).G7Core as Record<string, unknown> | undefined;
if (!g7Core) {
return 0;
}
const getDispatcher = g7Core.getActionDispatcher as (() => Record<string, unknown>) | undefined;
if (typeof getDispatcher !== 'function') {
return 0;
}
const dispatcher = getDispatcher() as Record<string, unknown> | undefined;
if (!dispatcher || typeof dispatcher.registerHandler !== 'function') {
return 0;
}
let count = 0;
for (const [name, handler] of Object.entries(handlerMap)) {
const fullName = `${PLUGIN_IDENTIFIER}.${name}`;
dispatcher.registerHandler(fullName, handler, {
category: 'plugin',
source: PLUGIN_IDENTIFIER,
});
count++;
}
return count;
}
function initPlugin(): void {
// fetch 인터셉터는 G7Core 초기화와 무관하게 즉시 설치
installOrderResponseInterceptor();
installOrderCompleteReceiptInjector();
installMypageOrderShowInjector();
installAdminPaymentMethodBrandInjector();
installAdminOrderPaymentDisplayInjector();
const doInit = () => {
const count = registerHandlers();
if (count > 0) {
logger.info(`${count} handler(s) registered`);
initEasyPayWatcher();
return;
}
let retries = 0;
const maxRetries = 50;
const interval = setInterval(() => {
retries++;
const result = registerHandlers();
if (result > 0) {
clearInterval(interval);
logger.info(`${result} handler(s) registered (after ${retries} retries)`);
initEasyPayWatcher();
return;
}
if (retries >= maxRetries) {
clearInterval(interval);
logger.warn('ActionDispatcher not available after timeout');
}
}, 100);
};
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', doInit);
} else {
doInit();
}
}
initPlugin();
(window as Record<string, unknown>).__SirsoftNicepayments = {
identifier: PLUGIN_IDENTIFIER,
handlers: Object.keys(handlerMap),
initPlugin,
};