-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAbacatePay.java
More file actions
72 lines (59 loc) · 2.1 KB
/
Copy pathAbacatePay.java
File metadata and controls
72 lines (59 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.abacatepay;
import com.abacatepay.clients.factories.AbacatePayClientFactory;
import com.abacatepay.model.AbacatePayBilling;
import com.abacatepay.model.IAbacatePay;
import com.abacatepay.model.IAbacatePayBilling;
import feign.RequestInterceptor;
public class AbacatePay implements IAbacatePay {
private static final String API_BASE_URL = "https://api.abacatepay.com/v1";
private static final String SDK_NAME = "abacatepay-java-sdk";
private static final String SDK_VERSION = resolveVersion();
private final String apiKey;
private final String userAgent;
private final IAbacatePayBilling billing;
public AbacatePay(String apiKey) {
if (apiKey == null || apiKey.isBlank()) {
throw new IllegalArgumentException("API key not provided");
}
this.apiKey = apiKey;
this.userAgent = buildUserAgent();
this.billing = new AbacatePayBilling(
AbacatePayClientFactory.create(
API_BASE_URL,
requestInterceptor()
)
);
}
private RequestInterceptor requestInterceptor() {
return template -> {
template.header("Authorization", "Bearer " + apiKey);
template.header("Content-Type", "application/json");
template.header("User-Agent", userAgent);
};
}
@Override
public IAbacatePayBilling billing() {
return billing;
}
private static String resolveVersion() {
Package pkg = AbacatePay.class.getPackage();
String version = null;
if (pkg != null) {
version = pkg.getImplementationVersion();
}
if (version == null || version.isBlank()) {
version = "dev";
}
return version;
}
private static String buildUserAgent() {
return String.format(
"%s/%s Java/%s (%s %s)",
SDK_NAME,
SDK_VERSION,
System.getProperty("java.version"),
System.getProperty("os.name"),
System.getProperty("os.version")
);
}
}