Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📦 chore: add DocumentPaymentAPI to handle document payments related requests #203

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/documentPayment/api.ts
Original file line number Diff line number Diff line change
@@ -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<ResultList<DocumentPayment>> {
return this.request<ResultList<DocumentPayment>>({
method: 'GET',
url: '/document-payments',
params,
});
}

getDocumentPayment(documentPaymentId: number): Promise<DocumentPayment> {
return this.request<DocumentPayment>({
method: 'GET',
url: `/document-payments/${documentPaymentId}`,
});
}

createDocumentPayment(data: CreateDocumentPaymentParams): Promise<DocumentPayment> {
return this.request<DocumentPayment>({
method: 'POST',
url: '/document-payments',
data,
});
}

deleteDocumentPayment(documentPaymentId: number): Promise<void> {
return this.request<void>({
method: 'DELETE',
url: `/document-payments/${documentPaymentId}`,
});
}
}
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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<string, EasybillClient> = new Map();
Expand All @@ -13,13 +14,16 @@ export class EasybillClient {

public readonly documentAPI: DocumentAPI;

public readonly documentPaymentAPI: DocumentPaymentAPI;

private constructor(apiKey: string) {
const baseURL = 'https://api.easybill.de/rest/v1';

this.apiKey = apiKey;
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 {
Expand Down
5 changes: 5 additions & 0 deletions src/types/documentPayment.ts
Original file line number Diff line number Diff line change
@@ -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'];
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './customer';
export * from './customerGroup';
export * from './document';
export * from './documentPayment';