UNPKG

@portone/server-sdk

Version:

PortOne JavaScript SDK for server-side usage

43 lines (42 loc) • 1.3 kB
import { AdditionalFeatureError } from "./AdditionalFeatureError.mjs"; import { USER_AGENT } from "../../../client.mjs"; export function AdditionalFeatureClient(init) { const baseUrl = init.baseUrl ?? "https://api.portone.io"; const secret = init.secret; return { getPgCardPromotions: async (options) => { const { channelKey, amount, cardCompany } = options; const query = [ ["channelKey", channelKey], ["amount", amount], ["cardCompany", cardCompany] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/payment-gateways/card-promotion?${query}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new GetPgCardPromotionsError(await response.json()); } return response.json(); } }; } export class GetPgCardPromotionsError extends AdditionalFeatureError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPgCardPromotionsError.prototype); this.name = "GetPgCardPromotionsError"; } }