UNPKG

@portone/server-sdk

Version:

PortOne JavaScript SDK for server-side usage

43 lines (42 loc) 1.39 kB
import { AccountError } from "./AccountError.mjs"; import { USER_AGENT } from "../../../client.mjs"; export function AccountClient(init) { const baseUrl = init.baseUrl ?? "https://api.portone.io"; const secret = init.secret; return { getPlatformAccountHolder: async (options) => { const { bank, accountNumber, birthdate, businessRegistrationNumber } = options; const query = [ ["birthdate", birthdate], ["businessRegistrationNumber", businessRegistrationNumber] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/platform/bank-accounts/${encodeURIComponent(bank)}/${encodeURIComponent(accountNumber)}/holder?${query}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new GetPlatformAccountHolderError(await response.json()); } return response.json(); } }; } export class GetPlatformAccountHolderError extends AccountError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPlatformAccountHolderError.prototype); this.name = "GetPlatformAccountHolderError"; } }