UNPKG

@portone/server-sdk

Version:

PortOne JavaScript SDK for server-side usage

586 lines (585 loc) 17 kB
import { PolicyError } from "./PolicyError.mjs"; import { USER_AGENT } from "../../../client.mjs"; export 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": 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": 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": 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": 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": 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": 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": 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": 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": 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": 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": 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": 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": 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": 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": 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": 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": 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": USER_AGENT } } ); if (!response.ok) { throw new RecoverPlatformDiscountSharePolicyError(await response.json()); } return response.json(); } }; } export class GetPlatformAdditionalFeePoliciesError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPlatformAdditionalFeePoliciesError.prototype); this.name = "GetPlatformAdditionalFeePoliciesError"; } } export class CreatePlatformAdditionalFeePolicyError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, CreatePlatformAdditionalFeePolicyError.prototype); this.name = "CreatePlatformAdditionalFeePolicyError"; } } export class GetPlatformAdditionalFeePolicyError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPlatformAdditionalFeePolicyError.prototype); this.name = "GetPlatformAdditionalFeePolicyError"; } } export class UpdatePlatformAdditionalFeePolicyError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, UpdatePlatformAdditionalFeePolicyError.prototype); this.name = "UpdatePlatformAdditionalFeePolicyError"; } } export class ArchivePlatformAdditionalFeePolicyError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, ArchivePlatformAdditionalFeePolicyError.prototype); this.name = "ArchivePlatformAdditionalFeePolicyError"; } } export class RecoverPlatformAdditionalFeePolicyError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, RecoverPlatformAdditionalFeePolicyError.prototype); this.name = "RecoverPlatformAdditionalFeePolicyError"; } } export class GetPlatformContractsError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPlatformContractsError.prototype); this.name = "GetPlatformContractsError"; } } export class CreatePlatformContractError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, CreatePlatformContractError.prototype); this.name = "CreatePlatformContractError"; } } export class GetPlatformContractError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPlatformContractError.prototype); this.name = "GetPlatformContractError"; } } export class UpdatePlatformContractError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, UpdatePlatformContractError.prototype); this.name = "UpdatePlatformContractError"; } } export class ArchivePlatformContractError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, ArchivePlatformContractError.prototype); this.name = "ArchivePlatformContractError"; } } export class RecoverPlatformContractError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, RecoverPlatformContractError.prototype); this.name = "RecoverPlatformContractError"; } } export class GetPlatformDiscountSharePoliciesError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPlatformDiscountSharePoliciesError.prototype); this.name = "GetPlatformDiscountSharePoliciesError"; } } export class CreatePlatformDiscountSharePolicyError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, CreatePlatformDiscountSharePolicyError.prototype); this.name = "CreatePlatformDiscountSharePolicyError"; } } export class GetPlatformDiscountSharePolicyError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetPlatformDiscountSharePolicyError.prototype); this.name = "GetPlatformDiscountSharePolicyError"; } } export class UpdatePlatformDiscountSharePolicyError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, UpdatePlatformDiscountSharePolicyError.prototype); this.name = "UpdatePlatformDiscountSharePolicyError"; } } export class ArchivePlatformDiscountSharePolicyError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, ArchivePlatformDiscountSharePolicyError.prototype); this.name = "ArchivePlatformDiscountSharePolicyError"; } } export class RecoverPlatformDiscountSharePolicyError extends PolicyError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, RecoverPlatformDiscountSharePolicyError.prototype); this.name = "RecoverPlatformDiscountSharePolicyError"; } }