UNPKG

fake-iamport-server

Version:
115 lines (108 loc) 3.59 kB
/** * @packageDocumentation * @module api.functional.internal * @nestia Generated by Nestia - https://github.com/samchon/nestia */ //================================================================ import type { IConnection } from "@nestia/fetcher"; import { PlainFetcher } from "@nestia/fetcher/lib/PlainFetcher"; import type { IIamportPayment } from "../../structures/IIamportPayment"; /** * 웹훅 이벤트 더미 리스너. * * `internal.webhook` 은 실제 아임포트의 서버에는 존재하지 않는 API 로써, * `fake-impoart-server` 의 {@link Configuration.WEBHOOK_URL} 에 아무런 URL 을 설정하지 * 않으면, `fake-iamport-server` 로부터 발생하는 모든 종류의 웹훅 이벤트는 이 곳으로 전달되어 * 무의미하게 사라진다. * * 따라서 `fake-iamport-server` 를 사용하여 아임포트 서버와의 연동을 미리 검증코자 할 때는, * 반드시 {@link Configuration.WEBHOOK_URL} 를 설정하여 웹훅 이벤트가 귀하의 백엔드 서버로 * 제대로 전달되도록 하자. * * @param input 웹훅 이벤트 정보 * @author Samchon * * @controller FakeIamportInternalController.webhook * @path POST /internal/webhook * @nestia Generated by Nestia - https://github.com/samchon/nestia */ export async function webhook( connection: IConnection, input: IIamportPayment.IWebhook, ): Promise<void> { return PlainFetcher.fetch( { ...connection, headers: { ...connection.headers, "Content-Type": "application/json", }, }, { ...webhook.METADATA, template: webhook.METADATA.path, path: webhook.path(), }, input, ); } export namespace webhook { export type Input = IIamportPayment.IWebhook; export const METADATA = { method: "POST", path: "/internal/webhook", request: { type: "application/json", encrypted: false, }, response: { type: "application/json", encrypted: false, }, status: 201, } as const; export const path = () => "/internal/webhook"; } /** * 가상 계좌에 입금하기. * * `internal.deposit` 은 실제 아임포트 결제 서버에는 존재하지 않는 API 로써, 가상 계좌 * 결제를 신청한 고객이, 이후 가상 계좌에 목표 금액을 입금하는 상황을 시뮬레이션 할 수 있는 * 함수이다. * * 즉, `internal.deposit` 는 고객이 스스로에게 가상으로 발급된 계좌에 입금을 하고, 그에 따라 * 아임포트 서버에서 webhook 이벤트가 발생, 이를 귀하의 백엔드 서버로 전송하는 일련의 상황을 * 시뮬레이션하기 위하여 설계된 테스트 함수다. * * @param imp_uid 대상 결제의 {@link IIamportVBankPayment.imp_uid } * @security bearer * @author Samchon * * @controller FakeIamportInternalController.deposit * @path PUT /internal/deposit/:imp_uid * @nestia Generated by Nestia - https://github.com/samchon/nestia */ export async function deposit( connection: IConnection, imp_uid: string, ): Promise<void> { return PlainFetcher.fetch(connection, { ...deposit.METADATA, template: deposit.METADATA.path, path: deposit.path(imp_uid), }); } export namespace deposit { export const METADATA = { method: "PUT", path: "/internal/deposit/:imp_uid", request: null, response: { type: "application/json", encrypted: false, }, status: 200, } as const; export const path = (imp_uid: string) => `/internal/deposit/${encodeURIComponent(imp_uid?.toString() ?? "null")}`; }