import * as gracely from "gracely" import * as isoly from "isoly" import * as authly from "authly" import { Connection } from "@payfunc/model-base" import { Settlement as ModelSettlement } from "../Settlement" export class Settlement { constructor(readonly connection: Connection) {} async list( start?: isoly.Date, end?: isoly.Date, type?: "live" | "test", merchants?: authly.Identifier[] ): Promise { const query = new URLSearchParams({ ...(start ? { start } : {}), ...(end ? { end } : {}), ...(type ? { type } : {}), ...(merchants && merchants.length > 0 ? { merchants: merchants.join(",") } : {}), }).toString() return await this.connection.get("settlement" + (query ? `?${query}` : "")) } async report(settlements: ModelSettlement[], language: "sv" | "en"): Promise { return this.connection.post(`settlement/report?language=${language}`, settlements) } async load(id: authly.Identifier): Promise async load(id: authly.Identifier[]): Promise async load( id: authly.Identifier | authly.Identifier[] ): Promise { return authly.Identifier.is(id) ? await this.connection.get("settlement/" + id) : (await Promise.all(id.map(i => this.connection.get("settlement/" + i)))).filter( ModelSettlement.is ) } static open(url: string, token: string): Settlement static open(url: string | undefined, token: string | undefined): Settlement | undefined static open(url: string | undefined, token: string | undefined): Settlement | undefined { const connection = Connection.open(url, token) return connection && new Settlement(connection) } }