@portone/server-sdk
Version:
PortOne JavaScript SDK for server-side usage
41 lines (40 loc) • 1.22 kB
JavaScript
import { PgSpecificError } from "./PgSpecificError.mjs";
import { USER_AGENT } from "../../client.mjs";
export function PgSpecificClient(init) {
const baseUrl = init.baseUrl ?? "https://api.portone.io";
const secret = init.secret;
return {
getKakaopayPaymentOrder: async (options) => {
const {
pgTxId,
channelKey
} = options;
const query = [
["pgTxId", pgTxId],
["channelKey", channelKey]
].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&");
const response = await fetch(
new URL(`/kakaopay/payment/order?${query}`, baseUrl),
{
method: "GET",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new GetKakaopayPaymentOrderError(await response.json());
}
return response.json();
}
};
}
export class GetKakaopayPaymentOrderError extends PgSpecificError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetKakaopayPaymentOrderError.prototype);
this.name = "GetKakaopayPaymentOrderError";
}
}