Skip to content

Commit

Permalink
feat: Adds getPaymentMethods
Browse files Browse the repository at this point in the history
  • Loading branch information
jondewoo committed Dec 11, 2024
1 parent 6eb7d9b commit 5a981d5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ModelDocument,
ModelDocumentFolder,
ModelInvoice,
ModelPaymentMethod,
ModelUnity,
} from "./interfaces.js";

Expand Down Expand Up @@ -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");
};
Expand All @@ -117,4 +125,8 @@ const assertIsUnity = (unity: ModelUnity) => {
assert.is(unity.objectName, "Unity");
};

const assertIsPaymentMethod = (paymentMethod: ModelPaymentMethod) => {
assert.is(paymentMethod.objectName, "PaymentMethod");
};

test.run();
18 changes: 18 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ModelDocument,
ModelDocumentFolder,
ModelInvoice,
ModelPaymentMethod,
ModelUnity,
} from "./interfaces.js";
import { SevDeskUrls } from "./urls.js";
Expand Down Expand Up @@ -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<Required<ModelPaymentMethod>> }>(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 }) {
Expand Down
11 changes: 11 additions & 0 deletions src/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,15 @@ export class SevDeskUrls {
query,
});
}

// -------------------------------------------------------
// PaymentMethod
// -------------------------------------------------------

apiGetPaymentMethodsUrl({ ...query }: DefaultCollectionQuery & Query = {}) {
return this.apiUrl({
path: `PaymentMethod`,
query,
});
}
}

0 comments on commit 5a981d5

Please sign in to comment.