import { gracely } from "gracely" import { isoly } from "isoly" import { http } from "cloudly-http" import { Card } from "../Card" import { Settlement } from "../Settlement" export class Settlements { constructor(private readonly client: http.Client) {} async create(configuration: string): Promise { return this.client.post(`/settlement`, { configuration: configuration }) } async fetch(id: string): Promise { return this.client.get(`/settlement/${id}`) } async list(options?: { limit?: number cursor?: string date?: isoly.Date }): Promise<(Settlement[] & { cursor?: string }) | gracely.Error> { return this.client.get( `/settlement${options?.cursor && !options.date ? `?cursor=${options.cursor}` : ""}${ options?.date ? `?date=${options.date}` : "" }`, options?.limit ? { limit: options?.limit.toString() } : {} ) } async remove(settlement: string): Promise { return this.client.delete(`/settlement/${settlement}`) } async update(settlement: string): Promise { return this.client.patch(`/settlement/${settlement}`, {}) } async listEntries(settlement: string): Promise { return this.client.get(`/settlement/${settlement}/entry`) } async listFailedEntries(settlement: string): Promise { return this.client.get(`/settlement/${settlement}/entry/failed`) } async addPayoutTransactions(settlement: string, transactions: string[]): Promise { return this.client.patch(`/settlement/${settlement}/settled`, transactions) } async downloadFile(stack: Card.Stack, reference: string): Promise { return this.client.get(`/processor/${stack}/file/${reference}`) } }