Skip to content

Latest commit

 

History

History
139 lines (106 loc) · 4.69 KB

File metadata and controls

139 lines (106 loc) · 4.69 KB

moneta-api-spring-boot-starter

Spring Boot auto-configuration for the client: add the dependency, set moneta.*, inject MonetaClient. Works on Spring Boot 3.5 and 4; testing/spring-boot checks each.

Install

// build.gradle.kts
dependencies {
    implementation("cz.insuit:moneta-api-spring-boot-starter:0.2.0")
}
Maven
<!-- in <dependencies> -->
<dependency>
    <groupId>cz.insuit</groupId>
    <artifactId>moneta-api-spring-boot-starter</artifactId>
    <version>0.2.0</version>
</dependency>

GitHub Packages asks for a token even for a public package: the repository block and the token are in Installing.

With a coding assistant

Paste this into it:

Add the MONETA API client to this Spring Boot project.

1. Read https://github.com/landsman/moneta-api-java/blob/main/llms.txt and https://github.com/landsman/moneta-api-java/blob/main/modules/moneta-api-spring-boot-starter/README.md first. Do not guess the API.
2. Dependency: cz.insuit:moneta-api-spring-boot-starter:0.2.0 from GitHub Packages, with Gradle or Maven, as
   https://github.com/landsman/moneta-api-java/blob/main/.docs/install.md shows. Never write a token into the project.
3. Configuration: moneta.token: ${MONETA_TOKEN} in application.yml.
4. Code: inject MonetaClient and AccessToken. Bind the token with moneta.with(token), read with
   transactions().between(from, to), narrowed by incoming(), outgoing(), transfers(),
   cards(), booked() or pending(), then list().
5. Act on booked movements only, unless I ask for pending ones.

Configure

moneta:
  token: ${MONETA_TOKEN}

That is the whole setup for an application reading one account: inject MonetaClient and AccessToken. One serving many account holders leaves moneta.token unset and passes each one's token with the call. Keep the token in the environment, never in a committed file.

import cz.insuit.moneta.AccessToken;
import cz.insuit.moneta.AccountHolder;
import cz.insuit.moneta.MonetaClient;
import cz.insuit.moneta.Transaction;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.List;
import org.springframework.stereotype.Service;

@Service
public class Payments {
    private final AccountHolder me;

    public Payments(MonetaClient moneta, AccessToken token) {
        this.me = moneta.with(token);
    }

    /** Money received over the last week, booked. */
    public List<Transaction> receivedThisWeek() {
        var today = LocalDate.now(ZoneId.of("Europe/Prague"));
        return me.transactions().between(today.minusDays(7), today).incoming().booked().list();
    }
}
Kotlin
import cz.insuit.moneta.AccessToken
import cz.insuit.moneta.MonetaClient
import cz.insuit.moneta.Transaction
import java.time.LocalDate
import java.time.ZoneId
import org.springframework.stereotype.Service

@Service
class Payments(moneta: MonetaClient, token: AccessToken) {
    private val me = moneta.with(token)

    /** Money received over the last week, booked. */
    fun receivedThisWeek(): List<Transaction> {
        val today = LocalDate.now(ZoneId.of("Europe/Prague"))
        return me.transactions().between(today.minusDays(7), today).incoming().booked().list()
    }
}

It reads the only account the token opens and throws IllegalStateException when there are more; then, or with one token per account holder, see More than one account. Without moneta.token there is no AccessToken bean to inject.

A MonetaClient bean of the application's own replaces the auto-configured one. A token the client would refuse stops the application at startup, not at the first call. IntelliJ completes the properties from the metadata the starter ships.

Logging

One DEBUG line per HTTP request, with MONETA's X-Request-Id and never the token (what it holds). Spring Boot routes it into Logback; switch it on as any logger:

logging.level.cz.insuit.moneta=DEBUG

Optional properties

None is needed against production.

Property Default
moneta.base-uri production, MonetaClient.PRODUCTION a test server; the sandbox is the same host, chosen by its token
moneta.request-timeout the client's, 30 s one call to MONETA
moneta.partner.identification-number, .business-name, .application-name none the registered application's headers, all three or none, ASCII only

MONETA does not ask for the partner headers: its specification marks them optional, and every live call went through without (how it behaves).