diff --git a/src/documentPayment/api.ts b/src/documentPayment/api.ts new file mode 100644 index 0000000..2fba0d9 --- /dev/null +++ b/src/documentPayment/api.ts @@ -0,0 +1,37 @@ +import { Requestable } from '../base/Requestable'; +import { ResultList } from '../base/ResultList'; +import { CreateDocumentPaymentParams, DocumentPayment, GetDocumentPaymentsParams } from '../types'; + +export class DocumentPaymentAPI extends Requestable { + getDocumentPayments( + params: GetDocumentPaymentsParams = { limit: 100, page: 1 }, + ): Promise> { + return this.request>({ + method: 'GET', + url: '/document-payments', + params, + }); + } + + getDocumentPayment(documentPaymentId: number): Promise { + return this.request({ + method: 'GET', + url: `/document-payments/${documentPaymentId}`, + }); + } + + createDocumentPayment(data: CreateDocumentPaymentParams): Promise { + return this.request({ + method: 'POST', + url: '/document-payments', + data, + }); + } + + deleteDocumentPayment(documentPaymentId: number): Promise { + return this.request({ + method: 'DELETE', + url: `/document-payments/${documentPaymentId}`, + }); + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index f14eb28..d290d53 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import { CustomerAPI } from './customer/api'; import { CustomerGroupAPI } from './customerGroup/api'; import { DocumentAPI } from './document/api'; +import { DocumentPaymentAPI } from './documentPayment/api'; export class EasybillClient { private static instanceMap: Map = new Map(); @@ -13,6 +14,8 @@ export class EasybillClient { public readonly documentAPI: DocumentAPI; + public readonly documentPaymentAPI: DocumentPaymentAPI; + private constructor(apiKey: string) { const baseURL = 'https://api.easybill.de/rest/v1'; @@ -20,6 +23,7 @@ export class EasybillClient { this.customerAPI = new CustomerAPI(baseURL, apiKey); this.customerGroupAPI = new CustomerGroupAPI(baseURL, apiKey); this.documentAPI = new DocumentAPI(baseURL, apiKey); + this.documentPaymentAPI = new DocumentPaymentAPI(baseURL, apiKey); } public static getInstance(apiKey: string): EasybillClient { diff --git a/src/types/documentPayment.ts b/src/types/documentPayment.ts new file mode 100644 index 0000000..35dd986 --- /dev/null +++ b/src/types/documentPayment.ts @@ -0,0 +1,5 @@ +import { definitions, paths } from '../generated/types'; + +export type DocumentPayment = definitions['DocumentPayments']; +export type GetDocumentPaymentsParams = paths['/document-payments']['get']['parameters']['query']; +export type CreateDocumentPaymentParams = paths['/document-payments']['post']['parameters']['body']['body']; \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index dcd3988..f9ca48b 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,3 +1,4 @@ export * from './customer'; export * from './customerGroup'; export * from './document'; +export * from './documentPayment';