UNPKG

@portone/server-sdk

Version:

PortOne JavaScript SDK for server-side usage

551 lines (550 loc) 18.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetPlatformDiscountSharePolicyError = exports.GetPlatformDiscountSharePoliciesError = exports.GetPlatformContractsError = exports.GetPlatformContractError = exports.GetPlatformAdditionalFeePolicyError = exports.GetPlatformAdditionalFeePoliciesError = exports.CreatePlatformDiscountSharePolicyError = exports.CreatePlatformContractError = exports.CreatePlatformAdditionalFeePolicyError = exports.ArchivePlatformDiscountSharePolicyError = exports.ArchivePlatformContractError = exports.ArchivePlatformAdditionalFeePolicyError = void 0; exports.PolicyClient = PolicyClient; exports.UpdatePlatformDiscountSharePolicyError = exports.UpdatePlatformContractError = exports.UpdatePlatformAdditionalFeePolicyError = exports.RecoverPlatformDiscountSharePolicyError = exports.RecoverPlatformContractError = exports.RecoverPlatformAdditionalFeePolicyError = void 0; var _PolicyError = require("./PolicyError.cjs"); var _client = require("../../../client.cjs"); function PolicyClient(init) { const baseUrl = init.baseUrl ?? "https://api.portone.io"; const secret = init.secret; return { getPlatformAdditionalFeePolicies: async options => { const page = options?.page; const filter = options?.filter; const requestBody = JSON.stringify({ page, filter }); const query = [["requestBody", requestBody]].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch(new URL(`/platform/additional-fee-policies?${query}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT } }); if (!response.ok) { throw new GetPlatformAdditionalFeePoliciesError(await response.json()); } return response.json(); }, createPlatformAdditionalFeePolicy: async options => { const { id, name, fee, memo, vatPayer } = options; const requestBody = JSON.stringify({ id, name, fee, memo, vatPayer }); const response = await fetch(new URL("/platform/additional-fee-policies", baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT }, body: requestBody }); if (!response.ok) { throw new CreatePlatformAdditionalFeePolicyError(await response.json()); } return response.json(); }, getPlatformAdditionalFeePolicy: async options => { const { id } = options; const response = await fetch(new URL(`/platform/additional-fee-policies/${encodeURIComponent(id)}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT } }); if (!response.ok) { throw new GetPlatformAdditionalFeePolicyError(await response.json()); } return response.json(); }, updatePlatformAdditionalFeePolicy: async options => { const { id, fee, name, memo, vatPayer } = options; const requestBody = JSON.stringify({ fee, name, memo, vatPayer }); const response = await fetch(new URL(`/platform/additional-fee-policies/${encodeURIComponent(id)}`, baseUrl), { method: "PATCH", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT }, body: requestBody }); if (!response.ok) { throw new UpdatePlatformAdditionalFeePolicyError(await response.json()); } return response.json(); }, archivePlatformAdditionalFeePolicy: async options => { const { id } = options; const response = await fetch(new URL(`/platform/additional-fee-policies/${encodeURIComponent(id)}/archive`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT } }); if (!response.ok) { throw new ArchivePlatformAdditionalFeePolicyError(await response.json()); } return response.json(); }, recoverPlatformAdditionalFeePolicy: async options => { const { id } = options; const response = await fetch(new URL(`/platform/additional-fee-policies/${encodeURIComponent(id)}/recover`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT } }); if (!response.ok) { throw new RecoverPlatformAdditionalFeePolicyError(await response.json()); } return response.json(); }, getPlatformContracts: async options => { const page = options?.page; const filter = options?.filter; const requestBody = JSON.stringify({ page, filter }); const query = [["requestBody", requestBody]].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch(new URL(`/platform/contracts?${query}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT } }); if (!response.ok) { throw new GetPlatformContractsError(await response.json()); } return response.json(); }, createPlatformContract: async options => { const { id, name, memo, platformFee, settlementCycle, platformFeeVatPayer, subtractPaymentVatAmount } = options; const requestBody = JSON.stringify({ id, name, memo, platformFee, settlementCycle, platformFeeVatPayer, subtractPaymentVatAmount }); const response = await fetch(new URL("/platform/contracts", baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT }, body: requestBody }); if (!response.ok) { throw new CreatePlatformContractError(await response.json()); } return response.json(); }, getPlatformContract: async options => { const { id } = options; const response = await fetch(new URL(`/platform/contracts/${encodeURIComponent(id)}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT } }); if (!response.ok) { throw new GetPlatformContractError(await response.json()); } return response.json(); }, updatePlatformContract: async options => { const { id, name, memo, platformFee, settlementCycle, platformFeeVatPayer, subtractPaymentVatAmount } = options; const requestBody = JSON.stringify({ name, memo, platformFee, settlementCycle, platformFeeVatPayer, subtractPaymentVatAmount }); const response = await fetch(new URL(`/platform/contracts/${encodeURIComponent(id)}`, baseUrl), { method: "PATCH", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT }, body: requestBody }); if (!response.ok) { throw new UpdatePlatformContractError(await response.json()); } return response.json(); }, archivePlatformContract: async options => { const { id } = options; const response = await fetch(new URL(`/platform/contracts/${encodeURIComponent(id)}/archive`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT } }); if (!response.ok) { throw new ArchivePlatformContractError(await response.json()); } return response.json(); }, recoverPlatformContract: async options => { const { id } = options; const response = await fetch(new URL(`/platform/contracts/${encodeURIComponent(id)}/recover`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT } }); if (!response.ok) { throw new RecoverPlatformContractError(await response.json()); } return response.json(); }, getPlatformDiscountSharePolicies: async options => { const page = options?.page; const filter = options?.filter; const requestBody = JSON.stringify({ page, filter }); const query = [["requestBody", requestBody]].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch(new URL(`/platform/discount-share-policies?${query}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT } }); if (!response.ok) { throw new GetPlatformDiscountSharePoliciesError(await response.json()); } return response.json(); }, createPlatformDiscountSharePolicy: async options => { const { id, name, partnerShareRate, memo } = options; const requestBody = JSON.stringify({ id, name, partnerShareRate, memo }); const response = await fetch(new URL("/platform/discount-share-policies", baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT }, body: requestBody }); if (!response.ok) { throw new CreatePlatformDiscountSharePolicyError(await response.json()); } return response.json(); }, getPlatformDiscountSharePolicy: async options => { const { id } = options; const response = await fetch(new URL(`/platform/discount-share-policies/${encodeURIComponent(id)}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT } }); if (!response.ok) { throw new GetPlatformDiscountSharePolicyError(await response.json()); } return response.json(); }, updatePlatformDiscountSharePolicy: async options => { const { id, name, partnerShareRate, memo } = options; const requestBody = JSON.stringify({ name, partnerShareRate, memo }); const response = await fetch(new URL(`/platform/discount-share-policies/${encodeURIComponent(id)}`, baseUrl), { method: "PATCH", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT }, body: requestBody }); if (!response.ok) { throw new UpdatePlatformDiscountSharePolicyError(await response.json()); } return response.json(); }, archivePlatformDiscountSharePolicy: async options => { const { id } = options; const response = await fetch(new URL(`/platform/discount-share-policies/${encodeURIComponent(id)}/archive`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT } }); if (!response.ok) { throw new ArchivePlatformDiscountSharePolicyError(await response.json()); } return response.json(); }, recoverPlatformDiscountSharePolicy: async options => { const { id } = options; const response = await fetch(new URL(`/platform/discount-share-policies/${encodeURIComponent(id)}/recover`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": _client.USER_AGENT } }); if (!response.ok) { throw new RecoverPlatformDiscountSharePolicyError(await response.json()); } return response.json(); } }; } class GetPlatformAdditionalFeePoliciesError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPlatformAdditionalFeePoliciesError.prototype); this.name = "GetPlatformAdditionalFeePoliciesError"; } } exports.GetPlatformAdditionalFeePoliciesError = GetPlatformAdditionalFeePoliciesError; class CreatePlatformAdditionalFeePolicyError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, CreatePlatformAdditionalFeePolicyError.prototype); this.name = "CreatePlatformAdditionalFeePolicyError"; } } exports.CreatePlatformAdditionalFeePolicyError = CreatePlatformAdditionalFeePolicyError; class GetPlatformAdditionalFeePolicyError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPlatformAdditionalFeePolicyError.prototype); this.name = "GetPlatformAdditionalFeePolicyError"; } } exports.GetPlatformAdditionalFeePolicyError = GetPlatformAdditionalFeePolicyError; class UpdatePlatformAdditionalFeePolicyError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, UpdatePlatformAdditionalFeePolicyError.prototype); this.name = "UpdatePlatformAdditionalFeePolicyError"; } } exports.UpdatePlatformAdditionalFeePolicyError = UpdatePlatformAdditionalFeePolicyError; class ArchivePlatformAdditionalFeePolicyError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, ArchivePlatformAdditionalFeePolicyError.prototype); this.name = "ArchivePlatformAdditionalFeePolicyError"; } } exports.ArchivePlatformAdditionalFeePolicyError = ArchivePlatformAdditionalFeePolicyError; class RecoverPlatformAdditionalFeePolicyError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, RecoverPlatformAdditionalFeePolicyError.prototype); this.name = "RecoverPlatformAdditionalFeePolicyError"; } } exports.RecoverPlatformAdditionalFeePolicyError = RecoverPlatformAdditionalFeePolicyError; class GetPlatformContractsError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPlatformContractsError.prototype); this.name = "GetPlatformContractsError"; } } exports.GetPlatformContractsError = GetPlatformContractsError; class CreatePlatformContractError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, CreatePlatformContractError.prototype); this.name = "CreatePlatformContractError"; } } exports.CreatePlatformContractError = CreatePlatformContractError; class GetPlatformContractError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPlatformContractError.prototype); this.name = "GetPlatformContractError"; } } exports.GetPlatformContractError = GetPlatformContractError; class UpdatePlatformContractError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, UpdatePlatformContractError.prototype); this.name = "UpdatePlatformContractError"; } } exports.UpdatePlatformContractError = UpdatePlatformContractError; class ArchivePlatformContractError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, ArchivePlatformContractError.prototype); this.name = "ArchivePlatformContractError"; } } exports.ArchivePlatformContractError = ArchivePlatformContractError; class RecoverPlatformContractError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, RecoverPlatformContractError.prototype); this.name = "RecoverPlatformContractError"; } } exports.RecoverPlatformContractError = RecoverPlatformContractError; class GetPlatformDiscountSharePoliciesError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPlatformDiscountSharePoliciesError.prototype); this.name = "GetPlatformDiscountSharePoliciesError"; } } exports.GetPlatformDiscountSharePoliciesError = GetPlatformDiscountSharePoliciesError; class CreatePlatformDiscountSharePolicyError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, CreatePlatformDiscountSharePolicyError.prototype); this.name = "CreatePlatformDiscountSharePolicyError"; } } exports.CreatePlatformDiscountSharePolicyError = CreatePlatformDiscountSharePolicyError; class GetPlatformDiscountSharePolicyError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPlatformDiscountSharePolicyError.prototype); this.name = "GetPlatformDiscountSharePolicyError"; } } exports.GetPlatformDiscountSharePolicyError = GetPlatformDiscountSharePolicyError; class UpdatePlatformDiscountSharePolicyError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, UpdatePlatformDiscountSharePolicyError.prototype); this.name = "UpdatePlatformDiscountSharePolicyError"; } } exports.UpdatePlatformDiscountSharePolicyError = UpdatePlatformDiscountSharePolicyError; class ArchivePlatformDiscountSharePolicyError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, ArchivePlatformDiscountSharePolicyError.prototype); this.name = "ArchivePlatformDiscountSharePolicyError"; } } exports.ArchivePlatformDiscountSharePolicyError = ArchivePlatformDiscountSharePolicyError; class RecoverPlatformDiscountSharePolicyError extends _PolicyError.PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, RecoverPlatformDiscountSharePolicyError.prototype); this.name = "RecoverPlatformDiscountSharePolicyError"; } } exports.RecoverPlatformDiscountSharePolicyError = RecoverPlatformDiscountSharePolicyError;