You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27-77Lines changed: 27 additions & 77 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Lithic Java API Library
2
2
3
-
The Lithic Java SDK provides convenient access to the Lithic REST API from applications written in Java or Kotlin. It includes helper classes with helpful types and documentation for every request and response property.
3
+
The Lithic Java SDK provides convenient access to the Lithic REST API from applications written in Java. It includes helper classes with helpful types and documentation for every request and response property.
4
4
5
5
## Documentation
6
6
@@ -12,12 +12,6 @@ The API documentation can be found [here](https://docs.lithic.com).
12
12
13
13
### Install dependencies
14
14
15
-
During private beta, this package is not published to a public repository. To make it available as a dependency, you can either publish it to your private repository or make it available in local maven with:
16
-
17
-
```sh
18
-
./gradlew publishToMavenLocal
19
-
```
20
-
21
15
#### Gradle
22
16
23
17
```kotlin
@@ -52,9 +46,7 @@ Alternately, set the environment variable `LITHIC_API_KEY` and use `LithicClient
52
46
LithicClient client =LithicClient.fromEnv();
53
47
```
54
48
55
-
A `LithicInvalidDataException` will be thrown if a required client property is not provided.
56
-
57
-
Read the documentation for more configuration options. See [Dependency injection](#dependency-injection) below for advice on injecting Lithic services into your application classes.
49
+
Read the documentation for more configuration options.
Over time, the Lithic API may add new values to the property that are not yet represented by the enum type in
113
-
this SDK. If an unrecognized value is found, the enum is set to a special sentinel value `_UNKNOWN` and you can use `value` to read the string that was received:
105
+
this SDK. If an unrecognized value is found, the enum is set to a special sentinel value `_UNKNOWN` and you can use `asString` to read the string that was received:
For building entities from Kotlin, you can use the following shorthand syntax:
159
-
160
-
```kotlin
161
-
val params =CardCreateParams {
162
-
type =CardCreateParams.Type.VIRTUAL
163
-
}
164
-
```
165
-
166
-
The shorthand syntax is also supported directly when passing parameters to the API methods:
167
-
168
-
```kotlin
169
-
// No need to create an explicit CardCreateParams instance!
170
-
val page = client.cards().create {
171
-
type =Type.VIRTUAL
172
-
};
173
-
```
174
-
175
148
## Responses
176
149
177
150
### Response validation
178
151
179
-
When receiving a response, the Lithic Java SDK tries to deserialize it into instances of the well-typed model classes. If the API returns a response property that doesn't match the expected type, the deserialization will still succeed and model instances will be created. However, if the client code tries to access a property that had an invalid type, a `LithicInvalidDataException` will be thrown.
180
-
181
-
If you would like to immediately raise an exception if a response contains at least one unexpected type, you can call `.validate()` on the returned model.
152
+
When receiving a response, the Lithic Java SDK will deserialize it into instances of the typed model classes. In rare cases, the API may return a response property that doesn't match the expected Java type. If you directly access the mistaken property, the SDK will throw an unchecked `LithicInvalidDataException` at runtime. If you would prefer to check in advance that that response is completely well-typed, call `.validate()` on the returned model.
182
153
183
154
```java
184
155
Card card = client.cards().create().validate();
@@ -193,12 +164,30 @@ Model properties that are optional or allow a null value are represented as `Opt
193
164
card.cvv().isPresent(); // false
194
165
```
195
166
167
+
### Response properties as JSON
168
+
169
+
In rare cases, you may want to access the underlying JSON value for a response property rather than using the typed version provided by
170
+
this SDK. Each model property has a corresponding JSON version, with an underscore before the method name, which returns a `JsonField` value.
171
+
172
+
```java
173
+
JsonField state() = card._state();
174
+
175
+
if (state().isMissing()) {
176
+
// Value was not specified in the JSON response
177
+
} elseif (state().isNull()) {
178
+
// Value was provided as a literall null
179
+
} else {
180
+
// See if value was provided as a string
181
+
Optional<String> jsonString = state().asString();
182
+
}
183
+
```
184
+
196
185
### Additional model properties
197
186
198
-
Sometimes, the server response may include additional properties that are not yet available in this library's types. You can access them using the model's `additionalProperties` map:
187
+
Sometimes, the server response may include additional properties that are not yet available in this library's types. You can access them using the model's `_additionalProperties` method:
If you're using a dependency injection framework and are providing a `LithicClient`
308
-
instance to it, then you can also directly inject a `CardService` instead of calling `client.create()`.
309
-
310
-
### Details and example
311
-
312
-
For your convenience, the client library is designed to work with all modern dependency injection frameworks that support `javax.inject` annotations, which includes Spring, Dagger and Guice. You can simply inject the services in your code as you do with all other dependencies. Here's an example with constructor injection:
313
-
314
-
```java
315
-
publicclassYourClass {
316
-
privatefinalCardService cardsService;
317
-
318
-
@javax.inject.Inject
319
-
YourClass(CardServicecardsService) {
320
-
this.cardsService = cardsService;
321
-
}
322
-
323
-
voidyourMethod() {
324
-
Card card = cardsService.create();
325
-
}
326
-
}
327
-
```
328
-
329
-
For this to work, you need to provide a `LithicClient` instance to your dependency injection framework. Here's an example for Dagger:
330
-
331
-
```java
332
-
@Module
333
-
classYourDaggerModule {
334
-
@Provides
335
-
@Singleton
336
-
staticLithicClientLithicClient() {
337
-
returnLithicClient.create("<your private API key">);
0 commit comments