Files
Gnuboard7/plugins/_bundled/sirsoft-pay_nicepayments/resources/js/handlers/setPaymentMethod.ts
T
HeuJung e896a47d4f feat(ecommerce,pay): 확장 결제수단(간편결제) 1급화
PG 플러그인이 등록하는 간편결제(네이버페이 등)를 코어가 정식 결제수단으로
인식하도록 결제수단 카탈로그를 SSoT 로 전환했다. 확장 결제수단이
pg_provider=null 로 등록돼 서버가 "PG 결제가 아닌 주문"으로 오인, 결제 실패
주문에 관리자 신규주문 알림이 발송되고 TempOrder 가 즉시 삭제돼 재결제가
막히던 두 결함을 하나의 원인(능력 해석을 enum 이 답하지 못함)으로 근본 해결.

- PaymentMethodResolver 신규: 능력(PG 필요/라벨/환불수단/PG 고정) 해석을
 카탈로그 SSoT 로 통일, enum case 없는 확장 ID 도 동일 판정
- 프론트 결제수단 위장(card) 제거, provider-agnostic 결제 진입(pg_payment_handler)
- 관리자 주문설정 결제수단 목록 PG 고정 3분기 UI (pg_locked/needs_pg)
- 저장된 pg_provider=null 자가치유(read-time merge) + 백필 업그레이드 스텝
- 사용자 주문완료 화면 즉시 결제완료 헤더를 입금대기 여집합으로 판정(basic 1.0.3)
- 전 계층 회귀 테스트: 훅 발화 스파이(관리자 알림 미발화/PG 환불 훅 진입),
 주문 응답 계약(requires_pg_payment/pg_payment_handler)+TempOrder 보존,
 관리자 3분기 렌더, 확장 E2E 인프라
2026-07-15 11:23:51 +09:00

84 lines
3.1 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
const METHOD_TO_TEXT: Record<string, string> = {
nicepay_naverpay: '네이버페이',
nicepay_kakaopay: '카카오페이',
nicepay_samsungpay: '삼성페이',
nicepay_applepay: '애플페이',
nicepay_payco: 'PAYCO',
nicepay_skpay: '11pay',
nicepay_ssgpay: 'SSG페이',
nicepay_lpay: 'L.pay',
};
// 흰색 내부 ring + 어두운 외부 ring으로 어떤 버튼 배경색에도 선택 상태가 확실히 보임
const SELECTED_SHADOW = '0 0 0 2px #ffffff, 0 0 0 5px rgba(0,0,0,0.55)';
function getEasyPayButtonContainer(): Element | null {
const section = document.getElementById('nicepay_checkout_payment_section');
if (!section) return null;
const paras = section.querySelectorAll('p');
for (const p of paras) {
if (p.textContent?.includes('간편결제')) {
return p.nextElementSibling;
}
}
return null;
}
function clearEasyPayButtonStyles(): void {
const container = getEasyPayButtonContainer();
if (!container) return;
container.querySelectorAll<HTMLButtonElement>('button').forEach(btn => {
btn.style.boxShadow = '';
btn.style.outline = '';
});
}
function updateEasyPayButtonStyles(selectedMethod: string): void {
const container = getEasyPayButtonContainer();
if (!container) return;
const selectedText = METHOD_TO_TEXT[selectedMethod];
container.querySelectorAll<HTMLButtonElement>('button').forEach(btn => {
if (btn.textContent?.trim() === selectedText) {
btn.style.boxShadow = SELECTED_SHADOW;
btn.style.outline = 'none';
} else {
btn.style.boxShadow = '';
btn.style.outline = '';
}
});
}
export function setPaymentMethodHandler(action: any): void {
const paymentMethod = action.params?.paymentMethod;
if (!paymentMethod) return;
// 확장 결제수단은 1급 시민 — 선택한 수단 ID 를 그대로 서버에 보낸다.
// (과거에는 서버 검증이 확장 ID 를 422 로 막아 'card' 로 정규화한 serverPaymentMethod 를
// 함께 저장했으나, 소비처가 없는 죽은 코드였고 위장 자체가 결함의 원인이었다 — #475)
const isEasyPay = typeof paymentMethod === 'string' && paymentMethod.indexOf('nicepay_') === 0;
(window as any).G7Core?.state?.setLocal?.({ paymentMethod });
if (isEasyPay) {
updateEasyPayButtonStyles(paymentMethod);
} else {
clearEasyPayButtonStyles();
}
}
// 코어 결제 버튼(신용카드 등) 클릭 시에도 간편결제 선택 표시 해제
export function initEasyPayWatcher(): void {
const templateApp = (window as any).__templateApp;
if (typeof templateApp?.onGlobalStateChange !== 'function') return;
templateApp.onGlobalStateChange((state: any) => {
const paymentMethod = state?._local?.paymentMethod;
if (typeof paymentMethod !== 'string') return;
if (!paymentMethod.startsWith('nicepay_')) {
clearEasyPayButtonStyles();
}
});
}