Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*~
*.key
*.pem
.idea
.local
2 changes: 2 additions & 0 deletions kotlin_example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
.gradle
74 changes: 74 additions & 0 deletions kotlin_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Enable Banking API — Kotlin Example

This implementation uses [Spring Boot 4](https://spring.io/projects/spring-boot) with
[Spring's RestClient](https://docs.spring.io/spring-framework/reference/integration/rest-clients.html)
for HTTP calls and [Auth0 java-jwt](https://github.com/auth0/java-jwt) for JWT signing.

## Prerequisites

- **JDK 25** — download from [adoptium.net](https://adoptium.net/) or [sdkman.io](https://sdkman.io/)
- No separate Gradle install needed — the included `./gradlew` wrapper downloads Gradle 9 automatically

## Configuration

Edit `src/main/resources/application.yml` with your application credentials:

```yaml
enablebanking:
key-path: "../<your-app-id>.pem" # path to your PEM private key, relative to this directory
application-id: "<your-app-id>"
redirect-url: "http://localhost:8080/auth_redirect"
```

The `key-path` and `application-id` values come from your application registered at
[enablebanking.com/cp/applications](https://enablebanking.com/cp/applications).

## Running

### Account information (AIS)

```bash
./gradlew bootRun --args="--spring.profiles.active=ais"
```

### Payment initiation (PIS)

```bash
./gradlew bootRun --args="--spring.profiles.active=pis"
```

## Authorization flow (AIS)

The account information example includes an interactive consent step:

1. The app prints a bank authorization URL — **open it in your browser**
2. Log in with your bank credentials and approve the consent
- Sandbox credentials: **customera / 12345678**
3. The bank redirects your browser to the `redirect-url` from `application.yml`
(e.g. `http://localhost:8080/auth_redirect?code=...`) — the page may show an error, that is expected
4. **Copy the full URL** from the browser address bar and paste it into the terminal when prompted
5. The app extracts the `code` parameter automatically and continues to fetch balances and transactions

## Integrating into an existing Spring Boot 4 service

`EnableBankingService` is a standard `@Service` bean — inject it anywhere:

```kotlin
@Service
class YourService(private val enableBanking: EnableBankingService) {

fun fetchBalances(accountId: String) = enableBanking.getBalances(accountId)
}
```

Add the following to your `application.yml`:

```yaml
enablebanking:
key-path: "/path/to/your-key.pem"
application-id: "your-application-id"
redirect-url: "https://your-redirect-url"
```

Copy across: `Config.kt`, `Models.kt`, `JwtUtils.kt`, `EnableBankingService.kt`, and add
`com.auth0:java-jwt:4.4.0` to your dependencies.
42 changes: 42 additions & 0 deletions kotlin_example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
plugins {
kotlin("jvm") version "2.1.21"
kotlin("plugin.spring") version "2.1.21"
id("org.springframework.boot") version "4.1.0"
id("io.spring.dependency-management") version "1.1.7"
}

group = "com.enablebanking"
version = "1.0.0"

java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
}

// Kotlin 2.1.x does not yet support JVM target 25; align both compilers to 23
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_23
}
}

tasks.withType<JavaCompile> {
sourceCompatibility = "23"
targetCompatibility = "23"
}

repositories {
mavenCentral()
}

tasks.named<org.springframework.boot.gradle.tasks.run.BootRun>("bootRun") {
standardInput = System.`in`
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("com.auth0:java-jwt:4.4.0")
}
Binary file added kotlin_example/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions kotlin_example/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
187 changes: 187 additions & 0 deletions kotlin_example/gradlew

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

1 change: 1 addition & 0 deletions kotlin_example/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "enablebanking-kotlin-example"
Loading