11import { PaymentMethod, PaymentProvider } from '@prisma/client';
22import { AppError } from '../../errors/AppError';
33
4- // 1. 결제 수단 매핑
4+ // 결제 수단 매핑
55export function normalizePaymentMethod(input: string): PaymentMethod {
66 const code = input.toUpperCase().replace(/\s+/g, '');
77
8- if (code === 'CARD' || code.includes('카드') ) return 'CARD';
9- if (code === 'VIRTUAL_ACCOUNT' || code.includes('가상계좌') ) return 'VIRTUAL_ACCOUNT';
10- if (code === 'TRANSFER' || code.includes('계좌이체') ) return 'TRANSFER';
11- if (code === 'MOBILE' || code.includes('MOBILE_PHONE') || code.includes('휴대폰') ) return 'MOBILE';
12- if (code === 'EASY_PAY' || code.includes('간편결제') ) return 'EASY_PAY';
8+ if (code === 'PaymentMethodCard' ) return 'CARD';
9+ if (code === 'PaymentMethodVirtualAccount' ) return 'VIRTUAL_ACCOUNT';
10+ if (code === 'PaymentMethodEasyPay' ) return 'TRANSFER';
11+ if (code === 'PaymentMethodTransfer' ) return 'MOBILE';
12+ if (code === 'PaymentMethodMobile' ) return 'EASY_PAY';
1313
1414 throw new AppError(`지원하지 않는 결제 수단입니다: ${input}`, 400, 'UnsupportedPaymentMethod');
15- }
16-
17- // 2. 제공자 (Provider) 매핑
18- export function normalizePaymentProvider(input: string, method: PaymentMethod): PaymentProvider {
19- const code = (input || '').toUpperCase().replace(/\s+/g, '');
20-
21- if (code.includes('KAKAO') || code.includes('카카오')) {
22- return 'KAKAOPAY';
23- }
24- if (code.includes('TOSSPAY') || code.includes('토스')) {
25- return 'TOSSPAY';
26- }
27- if (
28- code.includes('NAVER') || code.includes('네이버') ||
29- code.includes('SAMSUNG') || code.includes('삼성') ||
30- code.includes('APPLE') || code.includes('애플') ||
31- code.includes('PAYCO') || code.includes('페이코') ||
32- code.includes('LPAY') || code.includes('엘페이') ||
33- code.includes('SSG') || code.includes('에스에스지') ||
34- code.includes('PINPAY') || code.includes('핀페이')
35- ) {
36- throw new AppError(`현재 지원하지 않는 간편결제사입니다: ${input}`, 400, 'ProviderNotSupported');
37- }
38- if (method !== 'EASY_PAY') {
39- return 'TOSSPAYMENTS';
40- }
41- throw new AppError(`식별할 수 없는 결제 제공자입니다: ${input}`, 400, 'UnknownPaymentProvider');
4215}
0 commit comments