Skip to content

Commit ea7c454

Browse files
committed
퀵가이드 상태 수정
1 parent b6ce534 commit ea7c454

File tree

5 files changed

+168
-144
lines changed

5 files changed

+168
-144
lines changed

src/routes/(root)/opi/ko/quick-guide/payment/_preview/Preview.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ export function Preview() {
3939
// 파라미터가 변경될 때마다 초기화
4040
createEffect(on(() => trackStore(params), reload));
4141

42-
const isChannelUnavailable = () =>
43-
!("channelKey" in createPaymentRequest(params, ""));
42+
const isChannelUnavailable = () => {
43+
const paymentRequest = createPaymentRequest(params, "");
44+
return match(paymentRequest)
45+
.with(P.nullish, () => true)
46+
.with({ channelKey: P.string }, () => false)
47+
.otherwise(() => true);
48+
};
4449

4550
const requestPayment = async () => {
4651
if (paymentStatus().status === "PENDING") return undefined;
@@ -53,6 +58,7 @@ export function Preview() {
5358
untrack(() => params),
5459
paymentId,
5560
);
61+
if (request === null) return;
5662

5763
setPaymentStatus({ status: "PENDING" });
5864
setPayment(await PortOne.requestPayment(request));

src/routes/(root)/opi/ko/quick-guide/payment/_preview/frontend/html/index.html.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ export default code<{
116116
${({ section }) => section("client:request-payment")`
117117
const paymentId = randomId()
118118
const payment = await PortOne.requestPayment(${({ params }) => {
119+
const paymentRequest = createPaymentRequest(params, "");
120+
if (paymentRequest === null) {
121+
return code`null`;
122+
}
119123
const {
120124
storeId,
121125
channelKey,
@@ -129,7 +133,7 @@ export default code<{
129133
giftCertificate,
130134
bypass,
131135
productType,
132-
} = createPaymentRequest(params, "");
136+
} = paymentRequest;
133137
return code`{
134138
storeId: "${storeId}",
135139
channelKey: "${channelKey}",

src/routes/(root)/opi/ko/quick-guide/payment/_preview/frontend/react/app.jsx.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export function App() {
4949
${({ section }) => section("client:request-payment")`
5050
const paymentId = randomId()
5151
const payment = await PortOne.requestPayment(${({ params }) => {
52+
const paymentRequest = createPaymentRequest(params, "");
53+
if (paymentRequest === null) {
54+
return code`{`;
55+
}
5256
const {
5357
storeId,
5458
channelKey,
@@ -62,7 +66,7 @@ export function App() {
6266
giftCertificate,
6367
bypass,
6468
productType,
65-
} = createPaymentRequest(params, "");
69+
} = paymentRequest;
6670
return code`{
6771
storeId: "${storeId}",
6872
channelKey: "${channelKey}",

src/routes/(root)/opi/ko/quick-guide/payment/_preview/request.ts

+148-138
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as PortOne from "@portone/browser-sdk/v2";
2-
import { match } from "ts-pattern";
2+
import { match, NonExhaustiveError } from "ts-pattern";
33

44
import type { Params } from "./type";
55

@@ -324,141 +324,151 @@ function templatedPayment(
324324
} satisfies PortOne.PaymentRequest;
325325
}
326326

327-
export function createPaymentRequest(params: Params, paymentId: string) {
328-
return match(params)
329-
.with({ pg: { name: "toss", payMethods: "card" } }, () =>
330-
templatedPayment(paymentId, overrides.toss.card),
331-
)
332-
.with({ pg: { name: "toss", payMethods: "virtualAccount" } }, () =>
333-
templatedPayment(paymentId, overrides.toss.virtualAccount),
334-
)
335-
.with({ pg: { name: "toss", payMethods: "easyPay" } }, () =>
336-
templatedPayment(paymentId, overrides.toss.easyPay),
337-
)
338-
.with({ pg: { name: "toss", payMethods: "transfer" } }, () =>
339-
templatedPayment(paymentId, overrides.toss.transfer),
340-
)
341-
.with({ pg: { name: "toss", payMethods: "mobile" } }, () =>
342-
templatedPayment(paymentId, overrides.toss.mobile),
343-
)
344-
.with({ pg: { name: "toss", payMethods: "giftCertificate" } }, () =>
345-
templatedPayment(paymentId, overrides.toss.giftCertificate),
346-
)
347-
.with({ pg: { name: "nice", payMethods: "card" } }, () =>
348-
templatedPayment(paymentId, overrides.nice.card),
349-
)
350-
.with({ pg: { name: "nice", payMethods: "virtualAccount" } }, () =>
351-
templatedPayment(paymentId, overrides.nice.virtualAccount),
352-
)
353-
.with({ pg: { name: "nice", payMethods: "easyPay" } }, () =>
354-
templatedPayment(paymentId, overrides.nice.easyPay),
355-
)
356-
.with({ pg: { name: "nice", payMethods: "transfer" } }, () =>
357-
templatedPayment(paymentId, overrides.nice.transfer),
358-
)
359-
.with({ pg: { name: "nice", payMethods: "mobile" } }, () =>
360-
templatedPayment(paymentId, overrides.nice.mobile),
361-
)
362-
.with({ pg: { name: "nice", payMethods: "giftCertificate" } }, () =>
363-
templatedPayment(paymentId, overrides.nice.giftCertificate),
364-
)
365-
.with({ pg: { name: "smartro", payMethods: "card" } }, () =>
366-
templatedPayment(paymentId, overrides.smartro.card),
367-
)
368-
.with({ pg: { name: "smartro", payMethods: "virtualAccount" } }, () =>
369-
templatedPayment(paymentId, overrides.smartro.virtualAccount),
370-
)
371-
.with({ pg: { name: "smartro", payMethods: "easyPay" } }, () =>
372-
templatedPayment(paymentId, overrides.smartro.easyPay),
373-
)
374-
.with({ pg: { name: "smartro", payMethods: "transfer" } }, () =>
375-
templatedPayment(paymentId, overrides.smartro.transfer),
376-
)
377-
.with({ pg: { name: "smartro", payMethods: "mobile" } }, () =>
378-
templatedPayment(paymentId, overrides.smartro.mobile),
379-
)
380-
.with({ pg: { name: "inicis", payMethods: "card" } }, () =>
381-
templatedPayment(paymentId, overrides.inicis.card),
382-
)
383-
.with({ pg: { name: "inicis", payMethods: "virtualAccount" } }, () =>
384-
templatedPayment(paymentId, overrides.inicis.virtualAccount),
385-
)
386-
.with({ pg: { name: "inicis", payMethods: "easyPay" } }, () =>
387-
templatedPayment(paymentId, overrides.inicis.easyPay),
388-
)
389-
.with({ pg: { name: "inicis", payMethods: "transfer" } }, () =>
390-
templatedPayment(paymentId, overrides.inicis.transfer),
391-
)
392-
.with({ pg: { name: "inicis", payMethods: "mobile" } }, () =>
393-
templatedPayment(paymentId, overrides.inicis.mobile),
394-
)
395-
.with({ pg: { name: "inicis", payMethods: "giftCertificate" } }, () =>
396-
templatedPayment(paymentId, overrides.inicis.giftCertificate),
397-
)
398-
.with({ pg: { name: "kcp", payMethods: "card" } }, () =>
399-
templatedPayment(paymentId, overrides.kcp.card),
400-
)
401-
.with({ pg: { name: "kcp", payMethods: "virtualAccount" } }, () =>
402-
templatedPayment(paymentId, overrides.kcp.virtualAccount),
403-
)
404-
.with({ pg: { name: "kcp", payMethods: "easyPay" } }, () =>
405-
templatedPayment(paymentId, overrides.kcp.easyPay),
406-
)
407-
.with({ pg: { name: "kcp", payMethods: "transfer" } }, () =>
408-
templatedPayment(paymentId, overrides.kcp.transfer),
409-
)
410-
.with({ pg: { name: "kcp", payMethods: "mobile" } }, () =>
411-
templatedPayment(paymentId, overrides.kcp.mobile),
412-
)
413-
.with({ pg: { name: "kcp", payMethods: "giftCertificate" } }, () =>
414-
templatedPayment(paymentId, overrides.kcp.giftCertificate),
415-
)
416-
.with({ pg: { name: "kpn", payMethods: "card" } }, () =>
417-
templatedPayment(paymentId, overrides.kpn.card),
418-
)
419-
.with({ pg: { name: "kpn", payMethods: "virtualAccount" } }, () =>
420-
templatedPayment(paymentId, overrides.kpn.virtualAccount),
421-
)
422-
.with({ pg: { name: "kpn", payMethods: "easyPay" } }, () =>
423-
templatedPayment(paymentId, overrides.kpn.easyPay),
424-
)
425-
.with({ pg: { name: "kpn", payMethods: "transfer" } }, () =>
426-
templatedPayment(paymentId, overrides.kpn.transfer),
427-
)
428-
.with({ pg: { name: "kpn", payMethods: "mobile" } }, () =>
429-
templatedPayment(paymentId, overrides.kpn.mobile),
430-
)
431-
.with({ pg: { name: "ksnet", payMethods: "card" } }, () =>
432-
templatedPayment(paymentId, overrides.ksnet.card),
433-
)
434-
.with({ pg: { name: "ksnet", payMethods: "virtualAccount" } }, () =>
435-
templatedPayment(paymentId, overrides.ksnet.virtualAccount),
436-
)
437-
.with({ pg: { name: "ksnet", payMethods: "easyPay" } }, () =>
438-
// easyPayBypass 파라미터 누락
439-
// @ts-expect-error(2345)
440-
templatedPayment(paymentId, overrides.ksnet.easyPay),
441-
)
442-
.with({ pg: { name: "ksnet", payMethods: "transfer" } }, () =>
443-
templatedPayment(paymentId, overrides.ksnet.transfer),
444-
)
445-
.with({ pg: { name: "ksnet", payMethods: "mobile" } }, () =>
446-
templatedPayment(paymentId, overrides.ksnet.mobile),
447-
)
448-
.with({ pg: { name: "kakao", payMethods: "easyPay" } }, () =>
449-
templatedPayment(paymentId, overrides.kakao.easyPay),
450-
)
451-
.with({ pg: { name: "naver", payMethods: "easyPay" } }, () =>
452-
templatedPayment(paymentId, overrides.naver.easyPay),
453-
)
454-
.with({ pg: { name: "tosspay", payMethods: "easyPay" } }, () =>
455-
templatedPayment(paymentId, overrides.tosspay.easyPay),
456-
)
457-
.with({ pg: { name: "hyphen", payMethods: "easyPay" } }, () =>
458-
templatedPayment(paymentId, overrides.hyphen.easyPay),
459-
)
460-
.with({ pg: { name: "eximbay", payMethods: "card" } }, () =>
461-
templatedPayment(paymentId, overrides.eximbay.card),
462-
)
463-
.exhaustive();
327+
export function createPaymentRequest(
328+
params: Params,
329+
paymentId: string,
330+
): PortOne.PaymentRequest | null {
331+
try {
332+
return match(params)
333+
.with({ pg: { name: "toss", payMethods: "card" } }, () =>
334+
templatedPayment(paymentId, overrides.toss.card),
335+
)
336+
.with({ pg: { name: "toss", payMethods: "virtualAccount" } }, () =>
337+
templatedPayment(paymentId, overrides.toss.virtualAccount),
338+
)
339+
.with({ pg: { name: "toss", payMethods: "easyPay" } }, () =>
340+
templatedPayment(paymentId, overrides.toss.easyPay),
341+
)
342+
.with({ pg: { name: "toss", payMethods: "transfer" } }, () =>
343+
templatedPayment(paymentId, overrides.toss.transfer),
344+
)
345+
.with({ pg: { name: "toss", payMethods: "mobile" } }, () =>
346+
templatedPayment(paymentId, overrides.toss.mobile),
347+
)
348+
.with({ pg: { name: "toss", payMethods: "giftCertificate" } }, () =>
349+
templatedPayment(paymentId, overrides.toss.giftCertificate),
350+
)
351+
.with({ pg: { name: "nice", payMethods: "card" } }, () =>
352+
templatedPayment(paymentId, overrides.nice.card),
353+
)
354+
.with({ pg: { name: "nice", payMethods: "virtualAccount" } }, () =>
355+
templatedPayment(paymentId, overrides.nice.virtualAccount),
356+
)
357+
.with({ pg: { name: "nice", payMethods: "easyPay" } }, () =>
358+
templatedPayment(paymentId, overrides.nice.easyPay),
359+
)
360+
.with({ pg: { name: "nice", payMethods: "transfer" } }, () =>
361+
templatedPayment(paymentId, overrides.nice.transfer),
362+
)
363+
.with({ pg: { name: "nice", payMethods: "mobile" } }, () =>
364+
templatedPayment(paymentId, overrides.nice.mobile),
365+
)
366+
.with({ pg: { name: "nice", payMethods: "giftCertificate" } }, () =>
367+
templatedPayment(paymentId, overrides.nice.giftCertificate),
368+
)
369+
.with({ pg: { name: "smartro", payMethods: "card" } }, () =>
370+
templatedPayment(paymentId, overrides.smartro.card),
371+
)
372+
.with({ pg: { name: "smartro", payMethods: "virtualAccount" } }, () =>
373+
templatedPayment(paymentId, overrides.smartro.virtualAccount),
374+
)
375+
.with({ pg: { name: "smartro", payMethods: "easyPay" } }, () =>
376+
templatedPayment(paymentId, overrides.smartro.easyPay),
377+
)
378+
.with({ pg: { name: "smartro", payMethods: "transfer" } }, () =>
379+
templatedPayment(paymentId, overrides.smartro.transfer),
380+
)
381+
.with({ pg: { name: "smartro", payMethods: "mobile" } }, () =>
382+
templatedPayment(paymentId, overrides.smartro.mobile),
383+
)
384+
.with({ pg: { name: "inicis", payMethods: "card" } }, () =>
385+
templatedPayment(paymentId, overrides.inicis.card),
386+
)
387+
.with({ pg: { name: "inicis", payMethods: "virtualAccount" } }, () =>
388+
templatedPayment(paymentId, overrides.inicis.virtualAccount),
389+
)
390+
.with({ pg: { name: "inicis", payMethods: "easyPay" } }, () =>
391+
templatedPayment(paymentId, overrides.inicis.easyPay),
392+
)
393+
.with({ pg: { name: "inicis", payMethods: "transfer" } }, () =>
394+
templatedPayment(paymentId, overrides.inicis.transfer),
395+
)
396+
.with({ pg: { name: "inicis", payMethods: "mobile" } }, () =>
397+
templatedPayment(paymentId, overrides.inicis.mobile),
398+
)
399+
.with({ pg: { name: "inicis", payMethods: "giftCertificate" } }, () =>
400+
templatedPayment(paymentId, overrides.inicis.giftCertificate),
401+
)
402+
.with({ pg: { name: "kcp", payMethods: "card" } }, () =>
403+
templatedPayment(paymentId, overrides.kcp.card),
404+
)
405+
.with({ pg: { name: "kcp", payMethods: "virtualAccount" } }, () =>
406+
templatedPayment(paymentId, overrides.kcp.virtualAccount),
407+
)
408+
.with({ pg: { name: "kcp", payMethods: "easyPay" } }, () =>
409+
templatedPayment(paymentId, overrides.kcp.easyPay),
410+
)
411+
.with({ pg: { name: "kcp", payMethods: "transfer" } }, () =>
412+
templatedPayment(paymentId, overrides.kcp.transfer),
413+
)
414+
.with({ pg: { name: "kcp", payMethods: "mobile" } }, () =>
415+
templatedPayment(paymentId, overrides.kcp.mobile),
416+
)
417+
.with({ pg: { name: "kcp", payMethods: "giftCertificate" } }, () =>
418+
templatedPayment(paymentId, overrides.kcp.giftCertificate),
419+
)
420+
.with({ pg: { name: "kpn", payMethods: "card" } }, () =>
421+
templatedPayment(paymentId, overrides.kpn.card),
422+
)
423+
.with({ pg: { name: "kpn", payMethods: "virtualAccount" } }, () =>
424+
templatedPayment(paymentId, overrides.kpn.virtualAccount),
425+
)
426+
.with({ pg: { name: "kpn", payMethods: "easyPay" } }, () =>
427+
templatedPayment(paymentId, overrides.kpn.easyPay),
428+
)
429+
.with({ pg: { name: "kpn", payMethods: "transfer" } }, () =>
430+
templatedPayment(paymentId, overrides.kpn.transfer),
431+
)
432+
.with({ pg: { name: "kpn", payMethods: "mobile" } }, () =>
433+
templatedPayment(paymentId, overrides.kpn.mobile),
434+
)
435+
.with({ pg: { name: "ksnet", payMethods: "card" } }, () =>
436+
templatedPayment(paymentId, overrides.ksnet.card),
437+
)
438+
.with({ pg: { name: "ksnet", payMethods: "virtualAccount" } }, () =>
439+
templatedPayment(paymentId, overrides.ksnet.virtualAccount),
440+
)
441+
.with({ pg: { name: "ksnet", payMethods: "easyPay" } }, () =>
442+
// easyPayBypass 파라미터 누락
443+
// @ts-expect-error(2345)
444+
templatedPayment(paymentId, overrides.ksnet.easyPay),
445+
)
446+
.with({ pg: { name: "ksnet", payMethods: "transfer" } }, () =>
447+
templatedPayment(paymentId, overrides.ksnet.transfer),
448+
)
449+
.with({ pg: { name: "ksnet", payMethods: "mobile" } }, () =>
450+
templatedPayment(paymentId, overrides.ksnet.mobile),
451+
)
452+
.with({ pg: { name: "kakao", payMethods: "easyPay" } }, () =>
453+
templatedPayment(paymentId, overrides.kakao.easyPay),
454+
)
455+
.with({ pg: { name: "naver", payMethods: "easyPay" } }, () =>
456+
templatedPayment(paymentId, overrides.naver.easyPay),
457+
)
458+
.with({ pg: { name: "tosspay", payMethods: "easyPay" } }, () =>
459+
templatedPayment(paymentId, overrides.tosspay.easyPay),
460+
)
461+
.with({ pg: { name: "hyphen", payMethods: "easyPay" } }, () =>
462+
templatedPayment(paymentId, overrides.hyphen.easyPay),
463+
)
464+
.with({ pg: { name: "eximbay", payMethods: "card" } }, () =>
465+
templatedPayment(paymentId, overrides.eximbay.card),
466+
)
467+
.exhaustive();
468+
} catch (error) {
469+
if (error instanceof NonExhaustiveError) {
470+
console.error(error);
471+
}
472+
return null;
473+
}
464474
}

src/state/interactive-docs/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const [InteractiveDocsProvider, useInteractiveDocs] = createContextProvider(
103103
(props: { initial?: InteractiveDocsInit }) => {
104104
const defaultInitial: InteractiveDocsInit = {
105105
pgOptions: {
106-
hyphen: { payMethods: ["card"] },
106+
toss: { payMethods: ["card"] },
107107
},
108108
languages: {
109109
frontend: ["react"],
@@ -112,7 +112,7 @@ const [InteractiveDocsProvider, useInteractiveDocs] = createContextProvider(
112112
},
113113
params: {
114114
pg: {
115-
name: "hyphen",
115+
name: "toss",
116116
payMethods: "card",
117117
},
118118
},

0 commit comments

Comments
 (0)