From 7cf93f3d457029ad28fa3247cb87e22a042c9560 Mon Sep 17 00:00:00 2001 From: Mirko Pira Date: Fri, 4 Aug 2023 18:38:59 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20chore(api.ts):=20add=20DocumentP?= =?UTF-8?q?aymentAPI=20class=20to=20handle=20document=20payment=20related?= =?UTF-8?q?=20requests=20=F0=9F=93=A6=20chore(index.ts):=20import=20and=20?= =?UTF-8?q?initialize=20DocumentPaymentAPI=20in=20EasybillClient=20class?= =?UTF-8?q?=20=F0=9F=93=A6=20chore(documentPayment.ts):=20define=20types?= =?UTF-8?q?=20for=20DocumentPayment,=20GetDocumentPaymentsParams,=20and=20?= =?UTF-8?q?CreateDocumentPaymentParams=20The=20changes=20add=20support=20f?= =?UTF-8?q?or=20document=20payment=20related=20functionality=20to=20the=20?= =?UTF-8?q?EasybillClient=20library.=20The=20new=20`DocumentPaymentAPI`=20?= =?UTF-8?q?class=20is=20added=20to=20handle=20requests=20related=20to=20do?= =?UTF-8?q?cument=20payments.=20The=20`DocumentPaymentAPI`=20class=20inclu?= =?UTF-8?q?des=20methods=20for=20getting=20document=20payments,=20getting?= =?UTF-8?q?=20a=20specific=20document=20payment,=20creating=20a=20document?= =?UTF-8?q?=20payment,=20and=20deleting=20a=20document=20payment.=20The=20?= =?UTF-8?q?necessary=20types=20for=20document=20payments=20are=20also=20de?= =?UTF-8?q?fined=20in=20the=20`documentPayment.ts`=20file.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/documentPayment/api.ts | 37 ++++++++++++++++++++++++++++++++++++ src/index.ts | 4 ++++ src/types/documentPayment.ts | 5 +++++ src/types/index.ts | 1 + 4 files changed, 47 insertions(+) create mode 100644 src/documentPayment/api.ts create mode 100644 src/types/documentPayment.ts 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';