diff --git a/src/client.test.ts b/src/client.test.ts index a10187a..00ac399 100644 --- a/src/client.test.ts +++ b/src/client.test.ts @@ -10,6 +10,7 @@ import { ModelDocument, ModelDocumentFolder, ModelInvoice, + ModelPaymentMethod, ModelUnity, } from "./interfaces.js"; @@ -93,6 +94,13 @@ test("Get unities", async () => { unities.forEach(assertIsUnity); }); +test("Get payment methods", async () => { + const { objects: paymentMethods } = await sevDeskClient.getPaymentMethods(); + + assert.is(paymentMethods.length > 0, true); + paymentMethods.forEach(assertIsPaymentMethod); +}); + const assertIsInvoice = (invoice: ModelInvoice) => { assert.is(invoice.objectName, "Invoice"); }; @@ -117,4 +125,8 @@ const assertIsUnity = (unity: ModelUnity) => { assert.is(unity.objectName, "Unity"); }; +const assertIsPaymentMethod = (paymentMethod: ModelPaymentMethod) => { + assert.is(paymentMethod.objectName, "PaymentMethod"); +}; + test.run(); diff --git a/src/client.ts b/src/client.ts index 78ddb0d..c660415 100644 --- a/src/client.ts +++ b/src/client.ts @@ -7,6 +7,7 @@ import { ModelDocument, ModelDocumentFolder, ModelInvoice, + ModelPaymentMethod, ModelUnity, } from "./interfaces.js"; import { SevDeskUrls } from "./urls.js"; @@ -228,6 +229,23 @@ export class SevDeskClient { }); } + // ------------------------------------------------------- + // PaymentMethod + // ------------------------------------------------------- + + /** + * Get an overview of all payment methods + */ + async getPaymentMethods( + params: UrlParamsFor<"apiGetPaymentMethodsUrl"> = {} + ) { + const url = this.urls.apiGetPaymentMethodsUrl(params); + + return this.request<{ objects: Array> }>(url, { + method: "GET", + }); + } + // // pending invoices from sevdesk includes also outstanding / due invoices // // we remove them with a filter but you could also include the if you only need everything pending // async getPendingInvoices(options = { includeOutstanding: false }) { diff --git a/src/urls.ts b/src/urls.ts index 1b8b5ae..3ccd3df 100644 --- a/src/urls.ts +++ b/src/urls.ts @@ -120,4 +120,15 @@ export class SevDeskUrls { query, }); } + + // ------------------------------------------------------- + // PaymentMethod + // ------------------------------------------------------- + + apiGetPaymentMethodsUrl({ ...query }: DefaultCollectionQuery & Query = {}) { + return this.apiUrl({ + path: `PaymentMethod`, + query, + }); + } }