UNPKG

@portone/server-sdk

Version:

PortOne JavaScript SDK for server-side usage

46 lines (45 loc) • 1.36 kB
import { PayoutError } from "./PayoutError.mjs"; import { USER_AGENT } from "../../../client.mjs"; export function PayoutClient(init) { const baseUrl = init.baseUrl ?? "https://api.portone.io"; const secret = init.secret; return { getPlatformPayouts: async (options) => { const test = options?.test; const isForTest = options?.isForTest; const page = options?.page; const filter = options?.filter; const requestBody = JSON.stringify({ isForTest, page, filter }); const query = [ ["test", test], ["requestBody", requestBody] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/platform/payouts?${query}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new GetPlatformPayoutsError(await response.json()); } return response.json(); } }; } export class GetPlatformPayoutsError extends PayoutError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPlatformPayoutsError.prototype); this.name = "GetPlatformPayoutsError"; } }