Skip to content

Commit ce9b9bd

Browse files
committed
chore: client interface, package name ficups, etc.
1 parent a2655b0 commit ce9b9bd

File tree

11 files changed

+94
-42
lines changed

11 files changed

+94
-42
lines changed

.github/workflows/release-pr-maintenance.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
const readmePath = 'README.md';
3636
const original = fs.readFileSync(readmePath, 'utf8');
3737
38-
const kotlinGradlePattern = /(implementation\("com\.sumup:sumup:)([^"]+)("\))/;
38+
const kotlinGradlePattern = /(implementation\("com\.sumup:sumup-sdk:)([^"]+)("\))/;
3939
let kotlinGradleUpdated = false;
4040
const afterKotlinGradle = original.replace(
4141
kotlinGradlePattern,
@@ -49,7 +49,7 @@ jobs:
4949
}
5050
5151
const groovyGradlePattern =
52-
/(implementation\s+['"]com\.sumup:sumup:)([^'"]+)(['"])/;
52+
/(implementation\s+['"]com\.sumup:sumup-sdk:)([^'"]+)(['"])/;
5353
let groovyGradleUpdated = false;
5454
const afterGradle = afterKotlinGradle.replace(
5555
groovyGradlePattern,

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ jobs:
6262
cache: gradle
6363

6464
- name: Publish artifacts
65-
run: ./gradlew :sumup:sonatypeCentralUpload
65+
run: ./gradlew :sumup-sdk:sonatypeCentralUpload

README.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# SumUp Java SDK
44

5-
[![Maven Central Version](https://img.shields.io/maven-central/v/com.sumup/sumup?strategy=releaseProperty)](https://mvnrepository.com/artifact/com.sumup/sumup)
5+
[![Maven Central Version](https://img.shields.io/maven-central/v/com.sumup/sumup-sdk?strategy=releaseProperty)](https://mvnrepository.com/artifact/com.sumup/sumup-sdk)
66
[![Documentation][docs-badge]](https://developer.sumup.com)
77
[![CI Status](https://github.com/sumup/sumup-java/actions/workflows/ci.yaml/badge.svg)](https://github.com/sumup/sumup-java/actions/workflows/ci.yaml)
88
[![License](https://img.shields.io/github/license/sumup/sumup-java)](./LICENSE)
@@ -21,7 +21,7 @@ Add the dependency in your `build.gradle.kts` file:
2121

2222
```kotlin
2323
dependencies {
24-
implementation("com.sumup:sumup:0.0.5")
24+
implementation("com.sumup:sumup-sdk:0.0.5")
2525
}
2626
```
2727

@@ -31,7 +31,7 @@ Add the dependency in your `build.gradle` file:
3131

3232
```groovy
3333
dependencies {
34-
implementation 'com.sumup:sumup:0.0.5'
34+
implementation 'com.sumup:sumup-sdk:0.0.5'
3535
}
3636
```
3737

@@ -42,7 +42,7 @@ Add the dependency in your `pom.xml` file:
4242
```xml
4343
<dependency>
4444
<groupId>com.sumup</groupId>
45-
<artifactId>sumup</artifactId>
45+
<artifactId>sumup-sdk</artifactId>
4646
<version>0.0.5</version>
4747
</dependency>
4848
```
@@ -55,21 +55,25 @@ Authenticate with a personal access token before making calls:
5555
export SUMUP_API_KEY="my-token"
5656
```
5757

58-
Create synchronous and asynchronous clients using the provided builders:
58+
Create clients using the default constructor (reads `SUMUP_API_KEY`):
5959

6060
```java
61-
String apiKey = System.getenv("SUMUP_API_KEY");
61+
SumUpClient client = new SumUpClient();
62+
SumUpAsyncClient asyncClient = new SumUpAsyncClient();
63+
```
64+
65+
Or pass the API key explicitly:
66+
67+
```java
68+
SumUpClient client = new SumUpClient("api-key");
69+
```
70+
71+
If you need more configuration, use the builder:
6272

73+
```java
6374
SumUpClient client =
6475
SumUpClient.builder()
6576
.environment(SumUpEnvironment.PRODUCTION)
66-
.accessToken(apiKey)
67-
.build();
68-
69-
SumUpAsyncClient asyncClient =
70-
SumUpAsyncClient.builder()
71-
.environment(SumUpEnvironment.PRODUCTION)
72-
.accessToken(apiKey)
7377
.build();
7478
```
7579

@@ -86,11 +90,9 @@ import com.sumup.sdk.models.CheckoutCreateRequest;
8690
import com.sumup.sdk.models.Currency;
8791
import java.util.UUID;
8892

89-
String apiKey = System.getenv("SUMUP_API_KEY");
9093
SumUpClient client =
9194
SumUpClient.builder()
9295
.environment(SumUpEnvironment.PRODUCTION)
93-
.accessToken(apiKey)
9496
.build();
9597

9698
String merchantCode = client.merchant().getMerchantProfile().merchantCode();
@@ -121,11 +123,9 @@ import com.sumup.sdk.models.Currency;
121123
import java.util.UUID;
122124
import java.util.concurrent.CompletableFuture;
123125

124-
String apiKey = System.getenv("SUMUP_API_KEY");
125126
SumUpAsyncClient client =
126127
SumUpAsyncClient.builder()
127128
.environment(SumUpEnvironment.PRODUCTION)
128-
.accessToken(apiKey)
129129
.build();
130130

131131
CompletableFuture<Void> checkoutFuture =
@@ -170,13 +170,11 @@ import com.sumup.sdk.models.Money;
170170
import java.util.Optional;
171171
import java.util.UUID;
172172

173-
String apiKey = System.getenv("SUMUP_API_KEY");
174173
String merchantCode = System.getenv("SUMUP_MERCHANT_CODE");
175174

176175
SumUpClient client =
177176
SumUpClient.builder()
178177
.environment(SumUpEnvironment.PRODUCTION)
179-
.accessToken(apiKey)
180178
.build();
181179

182180
String readerId =
@@ -215,13 +213,11 @@ import java.util.Optional;
215213
import java.util.UUID;
216214
import java.util.concurrent.CompletableFuture;
217215

218-
String apiKey = System.getenv("SUMUP_API_KEY");
219216
String merchantCode = System.getenv("SUMUP_MERCHANT_CODE");
220217

221218
SumUpAsyncClient client =
222219
SumUpAsyncClient.builder()
223220
.environment(SumUpEnvironment.PRODUCTION)
224-
.accessToken(apiKey)
225221
.build();
226222

227223
CompletableFuture<String> readerIdFuture =

codegen/internal/generator/templates/sumup_client.tmpl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ public final class {{ .ClassName }} {
1414
private final {{ .ClassName }} {{ .FieldName }};
1515
{{- end }}
1616

17+
/**
18+
* Creates a {{ .ClassName }} using the API key from the SUMUP_API_KEY environment variable.
19+
*/
20+
public {{ .ClassName }}() {
21+
this(readApiKeyFromEnv());
22+
}
23+
24+
/**
25+
* Creates a {{ .ClassName }} using the provided API key.
26+
*
27+
* @param apiKey API key used to authorize requests.
28+
*/
29+
public {{ .ClassName }}(String apiKey) {
30+
this(ApiClient.builder().accessToken(Objects.requireNonNull(apiKey, "apiKey")).build());
31+
}
32+
33+
private static String readApiKeyFromEnv() {
34+
String apiKey = System.getenv("SUMUP_API_KEY");
35+
if (apiKey == null || apiKey.isBlank()) {
36+
throw new IllegalStateException("SUMUP_API_KEY environment variable is not set");
37+
}
38+
return apiKey;
39+
}
40+
1741
/**
1842
* Creates a {{ .ClassName }} using the provided ApiClient.
1943
*

examples/basic/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ application {
88
}
99

1010
dependencies {
11-
implementation project(':sumup')
11+
implementation project(':sumup-sdk')
1212
}

examples/basic/src/main/java/com/sumup/examples/basic/BasicExample.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.sumup.examples.basic;
22

33
import com.sumup.sdk.SumUpClient;
4-
import com.sumup.sdk.SumUpEnvironment;
54
import com.sumup.sdk.core.ApiException;
65
import java.util.List;
76

@@ -16,14 +15,7 @@ public final class BasicExample {
1615
private BasicExample() {}
1716

1817
public static void main(String[] args) {
19-
String apiKey = System.getenv("SUMUP_API_KEY");
20-
if (apiKey == null || apiKey.isBlank()) {
21-
System.err.println("SUMUP_API_KEY environment variable must be set.");
22-
return;
23-
}
24-
25-
SumUpClient client =
26-
SumUpClient.builder().environment(SumUpEnvironment.PRODUCTION).accessToken(apiKey).build();
18+
SumUpClient client = new SumUpClient();
2719

2820
try {
2921
List<com.sumup.sdk.models.CheckoutSuccess> checkouts = client.checkouts().listCheckouts();

examples/card-reader-checkout/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ application {
88
}
99

1010
dependencies {
11-
implementation project(':sumup')
11+
implementation project(':sumup-sdk')
1212
}

examples/card-reader-checkout/src/main/java/com/sumup/examples/cardreader/CardReaderCheckoutExample.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.sumup.examples.cardreader;
22

33
import com.sumup.sdk.SumUpClient;
4-
import com.sumup.sdk.SumUpEnvironment;
54
import com.sumup.sdk.core.ApiException;
65
import com.sumup.sdk.models.CreateReaderCheckoutRequest;
76
import com.sumup.sdk.models.Money;
@@ -14,11 +13,9 @@ public final class CardReaderCheckoutExample {
1413
private CardReaderCheckoutExample() {}
1514

1615
public static void main(String[] args) {
17-
String apiKey = requireEnv("SUMUP_API_KEY");
1816
String merchantCode = requireEnv("SUMUP_MERCHANT_CODE");
1917

20-
SumUpClient client =
21-
SumUpClient.builder().environment(SumUpEnvironment.PRODUCTION).accessToken(apiKey).build();
18+
SumUpClient client = new SumUpClient();
2219

2320
Optional<String> readerId =
2421
client.readers().listReaders(merchantCode).items().stream()

settings.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
rootProject.name = 'sumup-java'
22

3-
include(':sumup')
4-
project(':sumup').projectDir = file('src')
5-
project(':sumup').name = 'sumup-sdk'
3+
include(':sumup-sdk')
4+
project(':sumup-sdk').projectDir = file('src')
65

76
include(':examples:basic')
87
project(':examples:basic').projectDir = file('examples/basic')

src/main/java/com/sumup/sdk/SumUpAsyncClient.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ public final class SumUpAsyncClient {
3737
private final SubaccountsAsyncClient subaccounts;
3838
private final TransactionsAsyncClient transactions;
3939

40+
/** Creates a SumUpAsyncClient using the API key from the SUMUP_API_KEY environment variable. */
41+
public SumUpAsyncClient() {
42+
this(readApiKeyFromEnv());
43+
}
44+
45+
/**
46+
* Creates a SumUpAsyncClient using the provided API key.
47+
*
48+
* @param apiKey API key used to authorize requests.
49+
*/
50+
public SumUpAsyncClient(String apiKey) {
51+
this(ApiClient.builder().accessToken(Objects.requireNonNull(apiKey, "apiKey")).build());
52+
}
53+
54+
private static String readApiKeyFromEnv() {
55+
String apiKey = System.getenv("SUMUP_API_KEY");
56+
if (apiKey == null || apiKey.isBlank()) {
57+
throw new IllegalStateException("SUMUP_API_KEY environment variable is not set");
58+
}
59+
return apiKey;
60+
}
61+
4062
/**
4163
* Creates a SumUpAsyncClient using the provided ApiClient.
4264
*

0 commit comments

Comments
 (0)