Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
#21 Stabilize code of Accounts services: finish implementation and wr…
Browse files Browse the repository at this point in the history
…ite tests
  • Loading branch information
proshin-roman committed Oct 28, 2018
1 parent 9e3d687 commit a33c96b
Show file tree
Hide file tree
Showing 32 changed files with 891 additions and 149 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[*]
charset=utf-8
end_of_line=lf
insert_final_newline=true
indent_style=space
indent_size=4
Expand Down
12 changes: 0 additions & 12 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ This library is in early alpha version and not all API methods are implemented y
- [x] Get an account
- [ ] ~~Get multiple accounts~~ (won't be implemented as deprecated)
- [x] Get and search all accounts
- [ ] Get daily balances
- [x] Get daily balances
- [x] Edit an account
- [ ] Request SEPA Money Transfer
- [ ] Execute SEPA Money Transfer
- [ ] Request SEPA Direct Debit
- [ ] Execute SEPA Direct Debit
- [x] Request SEPA Money Transfer
- [x] Execute SEPA Money Transfer
- [x] Request SEPA Direct Debit
- [x] Execute SEPA Direct Debit
- [x] Delete an account
- [x] Delete all accounts
- Transactions
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/proshin/finapi/account/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.proshin.finapi.account.in.FpEditParameters;
import org.proshin.finapi.account.out.ClearingAccount;
import org.proshin.finapi.account.out.Holder;
import org.proshin.finapi.account.out.Order;
import org.proshin.finapi.account.out.Status;
import org.proshin.finapi.bankconnection.BankConnection;

public interface Account {
Expand Down Expand Up @@ -65,9 +67,5 @@ public interface Account {

void edit(FpEditParameters parameters);

MoneyTransfer moneyTransfer();

DirectDebit directDebit();

void delete(Long id);
}
8 changes: 7 additions & 1 deletion src/main/java/org/proshin/finapi/account/Accounts.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@
package org.proshin.finapi.account;

import org.proshin.finapi.account.in.DailyBalancesCriteria;
import org.proshin.finapi.account.in.FpQueryCriteria;
import org.proshin.finapi.account.out.DailyBalances;
import org.proshin.finapi.account.out.DirectDebit;

public interface Accounts {

Account one(Long id);

Iterable<Account> query(QueryCriteria criteria);
Iterable<Account> query(FpQueryCriteria criteria);

DailyBalances dailyBalances(DailyBalancesCriteria criteria);

MoneyTransfer moneyTransfer();

DirectDebit directDebit();

void deleteAll();
}
28 changes: 8 additions & 20 deletions src/main/java/org/proshin/finapi/account/FpAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.proshin.finapi.account.out.FpClearingAccount;
import org.proshin.finapi.account.out.FpHolder;
import org.proshin.finapi.account.out.Holder;
import org.proshin.finapi.account.out.Order;
import org.proshin.finapi.account.out.Status;
import org.proshin.finapi.bankconnection.BankConnection;
import org.proshin.finapi.bankconnection.FpBankConnections;
import org.proshin.finapi.endpoint.Endpoint;
Expand All @@ -41,11 +43,13 @@ public final class FpAccount implements Account {
private final Endpoint endpoint;
private final AccessToken token;
private final JSONObject origin;
private final String url;

public FpAccount(final Endpoint endpoint, final AccessToken token, final JSONObject origin) {
public FpAccount(final Endpoint endpoint, final AccessToken token, final JSONObject origin, final String url) {
this.endpoint = endpoint;
this.token = token;
this.origin = origin;
this.url = url;
}

@Override
Expand All @@ -56,7 +60,7 @@ public Long id() {
@Override
public BankConnection bankConnection() {
return new FpBankConnections(this.endpoint, this.token)
.one(this.origin.getLong("bankConnectionId"));
.one(this.origin.getLong("bankConnectionId"));
}

@Override
Expand Down Expand Up @@ -152,29 +156,13 @@ public Iterable<ClearingAccount> clearingAccounts() {

@Override
public void edit(final FpEditParameters parameters) {
this.endpoint.patch(String.format("/api/v1/accounts/%d", this.id()), this.token, parameters, 200);
}

/**
* @todo #21 Implement money transfer
*/
@Override
public MoneyTransfer moneyTransfer() {
throw new UnsupportedOperationException("This method is not implemented yet");
}

/**
* @todo #21 Implement direct debit
*/
@Override
public DirectDebit directDebit() {
throw new UnsupportedOperationException("This method is not implemented yet");
this.endpoint.patch(this.url + this.id(), this.token, parameters, 200);
}

@Override
public void delete(final Long id) {
this.endpoint.delete(
String.format("/api/v1/accounts/%d", this.id()),
this.url + this.id(),
this.token
);
}
Expand Down
43 changes: 33 additions & 10 deletions src/main/java/org/proshin/finapi/account/FpAccounts.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
import org.json.JSONObject;
import org.proshin.finapi.accesstoken.AccessToken;
import org.proshin.finapi.account.in.DailyBalancesCriteria;
import org.proshin.finapi.account.in.FpQueryCriteria;
import org.proshin.finapi.account.out.DailyBalances;
import org.proshin.finapi.account.out.DirectDebit;
import org.proshin.finapi.account.out.FpDailyBalances;
import org.proshin.finapi.account.out.FpDirectDebit;
import org.proshin.finapi.endpoint.Endpoint;
import org.proshin.finapi.primitives.IterableJsonArray;

Expand All @@ -29,10 +33,16 @@ public final class FpAccounts implements Accounts {

private final Endpoint endpoint;
private final AccessToken token;
private final String url;

public FpAccounts(final Endpoint endpoint, final AccessToken token) {
this(endpoint, token, "/api/v1/accounts/");
}

public FpAccounts(final Endpoint endpoint, final AccessToken token, final String url) {
this.endpoint = endpoint;
this.token = token;
this.url = url;
}

@Override
Expand All @@ -41,39 +51,52 @@ public Account one(final Long id) {
this.endpoint,
this.token,
new JSONObject(
this.endpoint.get(String.format("/api/v1/accounts/%d", id), this.token)
)
this.endpoint.get(this.url + id, this.token)
),
this.url
);
}

@Override
public Iterable<Account> query(final QueryCriteria criteria) {
public Iterable<Account> query(final FpQueryCriteria criteria) {
return new IterableJsonArray<>(
new JSONObject(
this.endpoint.get(
"/api/v1/accounts",
this.url,
this.token,
criteria
)
).getJSONArray("accounts"),
(array, index) -> new FpAccount(
this.endpoint,
this.token,
array.getJSONObject(index)
array.getJSONObject(index),
this.url
)
);
}

/**
* @todo #21 Implement daily balances for accounts endpoint
*/
@Override
public DailyBalances dailyBalances(final DailyBalancesCriteria criteria) {
throw new UnsupportedOperationException("This method is not implemented yet");
return new FpDailyBalances(
new JSONObject(
this.endpoint.get(this.url + "dailyBalances", this.token, criteria)
)
);
}

@Override
public MoneyTransfer moneyTransfer() {
return new FpMoneyTransfer(this.endpoint, this.token, this.url);
}

@Override
public DirectDebit directDebit() {
return new FpDirectDebit(this.endpoint, this.token, this.url);
}

@Override
public void deleteAll() {
this.endpoint.delete("/api/v1/accounts", this.token);
this.endpoint.delete(this.url, this.token);
}
}
67 changes: 67 additions & 0 deletions src/main/java/org/proshin/finapi/account/FpMoneyTransfer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2018 Roman Proshin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.proshin.finapi.account;

import org.json.JSONObject;
import org.proshin.finapi.accesstoken.AccessToken;
import org.proshin.finapi.account.in.MoneyTransferParameters;
import org.proshin.finapi.account.out.FpSepaExecutingResponse;
import org.proshin.finapi.account.out.FpSepaRequestingResponse;
import org.proshin.finapi.account.out.SepaExecutingResponse;
import org.proshin.finapi.account.out.SepaRequestingResponse;
import org.proshin.finapi.endpoint.Endpoint;

public final class FpMoneyTransfer implements MoneyTransfer {

private final Endpoint endpoint;
private final AccessToken token;
private final String url;

public FpMoneyTransfer(final Endpoint endpoint, final AccessToken token, final String url) {
this.endpoint = endpoint;
this.token = token;
this.url = url;
}

@Override
public SepaRequestingResponse request(final MoneyTransferParameters parameters) {
return new FpSepaRequestingResponse(
new JSONObject(
this.endpoint.post(
this.url + "requestSepaMoneyTransfer",
this.token,
parameters
)
)
);
}

@Override
public SepaExecutingResponse execute(final Long account, final String bankingTan) {
return new FpSepaExecutingResponse(
new JSONObject(
this.endpoint.post(
this.url + "executeSepaMoneyTransfer",
this.token,
() -> new JSONObject()
.put("accountId", account)
.put("bankingTan", bankingTan)
.toString()
)
)
);
}
}
8 changes: 8 additions & 0 deletions src/main/java/org/proshin/finapi/account/MoneyTransfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@
*/
package org.proshin.finapi.account;

import org.proshin.finapi.account.in.MoneyTransferParameters;
import org.proshin.finapi.account.out.SepaExecutingResponse;
import org.proshin.finapi.account.out.SepaRequestingResponse;

public interface MoneyTransfer {

SepaRequestingResponse request(final MoneyTransferParameters parameters);

SepaExecutingResponse execute(Long account, String bankingTan);
}
39 changes: 0 additions & 39 deletions src/main/java/org/proshin/finapi/account/QueryCriteria.java

This file was deleted.

Loading

0 comments on commit a33c96b

Please sign in to comment.