|
1 | 1 | import * as PortOne from "@portone/browser-sdk/v2";
|
2 |
| -import { match } from "ts-pattern"; |
| 2 | +import { match, NonExhaustiveError } from "ts-pattern"; |
3 | 3 |
|
4 | 4 | import type { Params } from "./type";
|
5 | 5 |
|
@@ -324,141 +324,151 @@ function templatedPayment(
|
324 | 324 | } satisfies PortOne.PaymentRequest;
|
325 | 325 | }
|
326 | 326 |
|
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 | + } |
464 | 474 | }
|
0 commit comments