@portone/server-sdk
Version:
PortOne JavaScript SDK for server-side usage
43 lines (42 loc) • 1.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AdditionalFeatureClient = AdditionalFeatureClient;
exports.GetPgCardPromotionsError = void 0;
var _AdditionalFeatureError = require("./AdditionalFeatureError.cjs");
var _client = require("../../../client.cjs");
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": _client.USER_AGENT
}
});
if (!response.ok) {
throw new GetPgCardPromotionsError(await response.json());
}
return response.json();
}
};
}
class GetPgCardPromotionsError extends _AdditionalFeatureError.AdditionalFeatureError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetPgCardPromotionsError.prototype);
this.name = "GetPgCardPromotionsError";
}
}
exports.GetPgCardPromotionsError = GetPgCardPromotionsError;