Skip to content

Commit 99fc7ce

Browse files
Merge pull request #75 from mathewmeconry/feat/payments_bankaccounts
feat: implement OutgoingPayments and BankAccounts resources
2 parents 613f8aa + ecccfa2 commit 99fc7ce

File tree

11 files changed

+677
-6
lines changed

11 files changed

+677
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ src/test.ts
6868
.vscode/
6969
jest_html_reporters.html
7070
junit.xml
71+
jest-html-reporters-attach/
72+
.yarn/

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import Items from "./resources/Items";
1717
import Invoices from "./resources/Invoices";
1818
import Currencies from "./resources/Currencies";
1919
import BillsV4 from "./resources/BillsV4";
20+
import OutgoingPayments from "./resources/OutgoingPayments";
21+
import BankAccounts from "./resources/BankAccounts";
2022

2123
export * from "./interfaces/BillsStatic";
2224
export * from "./interfaces/BusinessActivitiesStatic";
@@ -41,6 +43,8 @@ export * from "./interfaces/InvoicesStatic";
4143
export * from "./interfaces/PositionStatic";
4244
export * from "./interfaces/CurrenciesStatic";
4345
export * from "./interfaces/BillsV4Static";
46+
export * from "./interfaces/OutgoingPaymentsStatic";
47+
export * from "./interfaces/BankAccountsStatic";
4448

4549
export default class Bexio {
4650
private token: string;
@@ -60,6 +64,7 @@ export default class Bexio {
6064
public orders: Orders;
6165
public expenses: Expenses;
6266
public billsV4: BillsV4;
67+
public outgoingPayments: OutgoingPayments;
6368

6469
/**
6570
* @deprecated Use BillsV4 instead
@@ -86,6 +91,7 @@ export default class Bexio {
8691

8792
// Accounting
8893
public currencies: Currencies;
94+
public bankAccounts: BankAccounts;
8995

9096
constructor(token: string) {
9197
this.token = token;
@@ -103,12 +109,14 @@ export default class Bexio {
103109
this.projectTypes = new ProjectTypes(this.token);
104110
this.expenses = new Expenses(this.token);
105111
this.billsV4 = new BillsV4(this.token);
112+
this.outgoingPayments = new OutgoingPayments(this.token);
106113
this.bills = new Bills(this.token);
107114
this.timetrackings = new Timetrackings(this.token);
108115
this.timetrackingStatuses = new TimetrackingStatuses(this.token);
109116
this.users = new Users(this.token);
110117
this.items = new Items(this.token);
111118
this.invoices = new Invoices(this.token);
112119
this.currencies = new Currencies(this.token);
120+
this.bankAccounts = new BankAccounts(this.token);
113121
}
114122
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export namespace BankAccountsStatic {
2+
export interface BankAccount {
3+
id: number;
4+
name: string;
5+
owner: string;
6+
owner_address: string;
7+
owner_house_number: number | string;
8+
owner_zip: number | string;
9+
owner_city: string;
10+
owner_country_code: string;
11+
bc_nr: number | string;
12+
bank_name: string;
13+
bank_nr: string;
14+
bank_account_nr: string;
15+
iban_nr: string;
16+
currency_id: number;
17+
account_id: number;
18+
remarks: string;
19+
invoice_mode: string;
20+
qr_invoice_iban: string;
21+
type: string;
22+
}
23+
24+
export interface BankAccountFull extends BankAccount {}
25+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
export namespace OutgoingPaymentsStatic {
2+
/**
3+
* Outgoing Payment Status
4+
*/
5+
export enum OutgoingPaymentStatus {
6+
DOWNLOADED = 'DOWNLOADED',
7+
OPEN = 'OPEN',
8+
RECONCILED = 'RECONCILED',
9+
CANCELLED = 'CANCELLED',
10+
UPLOADED = 'UPLOADED',
11+
REJECTED = 'REJECTED',
12+
}
13+
14+
/**
15+
* Outgoing Payment Type
16+
*/
17+
export enum OutgoingPaymentType {
18+
IBAN = 'IBAN',
19+
MANUAL = 'MANUAL',
20+
CASH_DISCOUNT = 'CASH_DISCOUNT',
21+
QR = 'QR',
22+
}
23+
24+
/**
25+
* Fee Type
26+
*/
27+
export enum FeeType {
28+
BY_SENDER = 'BY_SENDER',
29+
BY_RECEIVER = 'BY_RECEIVER',
30+
BREAKDOWN = 'BREAKDOWN',
31+
NO_FEE = 'NO_FEE',
32+
}
33+
34+
/**
35+
* Outgoing Payment
36+
*/
37+
export interface OutgoingPayment {
38+
id: string;
39+
status: OutgoingPaymentStatus | string;
40+
created_at: string;
41+
bill_id: string;
42+
payment_type: OutgoingPaymentType | string;
43+
execution_date: string;
44+
amount: number;
45+
currency_code: string;
46+
exchange_rate: number;
47+
note?: string;
48+
sender_bank_account_id?: number;
49+
sender_iban?: string;
50+
sender_name?: string;
51+
sender_street?: string;
52+
sender_house_no?: string;
53+
sender_city?: string;
54+
sender_postcode?: string;
55+
sender_country_code?: string;
56+
sender_bc_no?: string;
57+
sender_bank_no?: string;
58+
sender_bank_name?: string;
59+
receiver_iban?: string;
60+
receiver_name?: string;
61+
receiver_street?: string;
62+
receiver_house_no?: string;
63+
receiver_city?: string;
64+
receiver_postcode?: string;
65+
receiver_country_code?: string;
66+
receiver_bc_no?: string;
67+
receiver_bank_no?: string;
68+
receiver_bank_name?: string;
69+
fee_type?: FeeType | string;
70+
is_salary_payment: boolean;
71+
reference_no?: string;
72+
message?: string;
73+
booking_text?: string;
74+
banking_payment_id?: string;
75+
banking_payment_entry_id?: string;
76+
transaction_id?: string;
77+
}
78+
79+
/**
80+
* Outgoing Payment Create
81+
*/
82+
export interface OutgoingPaymentCreate {
83+
bill_id: string;
84+
payment_type: OutgoingPaymentType | string;
85+
execution_date: string;
86+
amount: number;
87+
currency_code: string;
88+
exchange_rate: number;
89+
note?: string;
90+
sender_bank_account_id?: number;
91+
sender_iban?: string;
92+
sender_name?: string;
93+
sender_street?: string;
94+
sender_house_no?: string;
95+
sender_city?: string;
96+
sender_postcode?: string;
97+
sender_country_code?: string;
98+
sender_bc_no?: string;
99+
sender_bank_no?: string;
100+
sender_bank_name?: string;
101+
receiver_iban?: string;
102+
receiver_name?: string;
103+
receiver_street?: string;
104+
receiver_house_no?: string;
105+
receiver_city?: string;
106+
receiver_postcode?: string;
107+
receiver_country_code?: string;
108+
receiver_bc_no?: string;
109+
receiver_bank_no?: string;
110+
receiver_bank_name?: string;
111+
fee_type?: FeeType | string;
112+
is_salary_payment: boolean;
113+
reference_no?: string;
114+
message?: string;
115+
booking_text?: string;
116+
}
117+
118+
/**
119+
* Outgoing Payment Update
120+
*/
121+
export interface OutgoingPaymentUpdate {
122+
payment_id: string;
123+
execution_date: string;
124+
amount: number;
125+
fee_type?: FeeType | string;
126+
is_salary_payment: boolean;
127+
reference_no?: string | null;
128+
message?: string | null;
129+
receiver_iban?: string;
130+
receiver_name?: string;
131+
receiver_street?: string;
132+
receiver_house_no?: string;
133+
receiver_city?: string;
134+
receiver_postcode?: string;
135+
receiver_country_code?: string;
136+
}
137+
138+
/**
139+
* List Options
140+
*/
141+
export interface ListOptions {
142+
bill_id: string;
143+
limit?: number;
144+
page?: number;
145+
order?: 'asc' | 'desc';
146+
sort?: string;
147+
}
148+
}

src/resources/BankAccounts.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import BaseCrud from "./BaseCrud";
2+
import { BankAccountsStatic } from "../interfaces/BankAccountsStatic";
3+
import { BaseStatic } from "../interfaces/BaseStatic";
4+
5+
export default class BankAccounts extends BaseCrud<
6+
BankAccountsStatic.BankAccount,
7+
BankAccountsStatic.BankAccountFull,
8+
BankAccountsStatic.BankAccount,
9+
{},
10+
{},
11+
{}
12+
> {
13+
constructor(apiToken: string) {
14+
super(apiToken, "/3.0/banking/accounts");
15+
}
16+
17+
/**
18+
* NOT IMPLEMENTED BY BEXIO YET
19+
*
20+
* @param {Array<BaseStatic.SearchParameter<{}>>} searchOptions
21+
* @param {BaseStatic.BaseOptions} [options]
22+
* @returns {Promise<Array<{}>>}
23+
* @memberof BankAccounts
24+
*/
25+
public async search(
26+
searchOptions: Array<BaseStatic.SearchParameter<{}>>,
27+
options?: BaseStatic.BaseOptions
28+
): Promise<Array<BankAccountsStatic.BankAccount>> {
29+
throw new Error("not implemented by Bexio yet");
30+
}
31+
32+
/**
33+
* NOT IMPLEMENTED BY BEXIO YET
34+
*
35+
* @param {number} id
36+
* @param {{}} ressource
37+
* @returns {Promise<BankAccountsStatic.BankAccountFull>}
38+
* @memberof BankAccounts
39+
*/
40+
public async overwrite(
41+
id: number,
42+
ressource: {}
43+
): Promise<BankAccountsStatic.BankAccountFull> {
44+
throw new Error("not implemented by Bexio yet");
45+
}
46+
47+
/**
48+
* NOT IMPLEMENTED BY BEXIO YET
49+
*
50+
* @param {number} id
51+
* @param {Partial<{}>} ressource
52+
* @returns {Promise<BankAccountsStatic.BankAccountFull>}
53+
* @memberof BankAccounts
54+
*/
55+
public async edit(
56+
id: number,
57+
ressource: Partial<{}>
58+
): Promise<BankAccountsStatic.BankAccountFull> {
59+
throw new Error("not implemented by Bexio yet");
60+
}
61+
62+
/**
63+
* NOT IMPLEMENTED BY BEXIO YET
64+
*
65+
* @param {{}} ressource
66+
* @returns {Promise<BankAccountsStatic.BankAccountFull>}
67+
* @memberof BankAccounts
68+
*/
69+
public async create(
70+
ressource: {}
71+
): Promise<BankAccountsStatic.BankAccountFull> {
72+
throw new Error("not implemented by Bexio yet");
73+
}
74+
75+
/**
76+
* NOT IMPLEMENTED BY BEXIO YET
77+
*
78+
* @param {number} id
79+
* @returns {Promise<boolean>}
80+
* @memberof BankAccounts
81+
*/
82+
public async delete(id: number): Promise<boolean> {
83+
throw new Error("not implemented by Bexio yet");
84+
}
85+
}

src/resources/BaseCrud.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ export default class BaseCrud<
5252
/**
5353
* show a specific ressource
5454
*
55-
* @param {number} id
55+
* @param {string | number} id
5656
* @param {BaseStatic.BaseOptions} [options]
5757
* @returns {Promise<Full>}
5858
* @memberof BaseCrud
5959
*/
6060
public async show(
61-
id: number,
61+
id: string | number,
6262
options?: BaseStatic.BaseOptions
6363
): Promise<Full> {
6464
return this.request<Full>("GET", this.apiEndpoint + "/" + id, options);
@@ -112,11 +112,11 @@ export default class BaseCrud<
112112
/**
113113
* delete an ressource
114114
*
115-
* @param {number} id
115+
* @param {string | number} id
116116
* @returns {Promise<boolean>}
117117
* @memberof BaseCrud
118118
*/
119-
public async delete(id: number): Promise<boolean> {
119+
public async delete(id: string | number): Promise<boolean> {
120120
return (
121121
await this.request<{ success: boolean }>(
122122
"DELETE",
@@ -206,7 +206,14 @@ export default class BaseCrud<
206206

207207
for (let i in options) {
208208
if (options.hasOwnProperty(i)) {
209-
str.push(encodeURIComponent(i) + "=" + encodeURIComponent(options[i]));
209+
const value = options[i];
210+
if (Array.isArray(value)) {
211+
value.forEach((v) => {
212+
str.push(encodeURIComponent(i) + "=" + encodeURIComponent(v));
213+
});
214+
} else {
215+
str.push(encodeURIComponent(i) + "=" + encodeURIComponent(value));
216+
}
210217
}
211218
}
212219

0 commit comments

Comments
 (0)