Skip to content

Commit

Permalink
chore(docs): add back custom readme code
Browse files Browse the repository at this point in the history
This reverts commit bb93822.
  • Loading branch information
meorphis committed Mar 13, 2024
1 parent bb93822 commit 0ff33b5
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,43 @@ See [Pagination](#pagination) below for more information on transparently workin

---

## Enums

The Lithic SDK generates wrapper classes for all enum properties in the API. You can read and write these
values directly using the static instances of the class:

```kotlin
// Read an enum property
if (card.state == Card.State.CLOSED) {
// ...
}

// Write an enum property
card.builder().state(Card.State.CLOSED).build()
```

Over time, the Lithic API may add new values to the property that are not yet represented by the enum type in
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:

```kotlin
when (card.state.value()) {
Card.State.Value.CLOSED -> {
// ... handle recognized enum value
}
...
case Card.State.Value._UNKNOWN -> {
String cardState = card.state.asString()
// ... handle unrecognized enum value as string
}
}
```

To write an unrecognized enum value, pass a string to the wrapper class's `of` constructor method:

```kotlin
Card.builder().state(State.of("NEW_STATE")).build()
```

## Requests

### Parameters and bodies
Expand Down Expand Up @@ -131,6 +168,15 @@ When receiving a response, the Lithic Kotlin SDK will deserialize it into instan
val card = client.cards().create().validate()
```

### Nullable Properties

Model properties that are optional or allow a null value are represented as `Optional`. The empty case can represent either that the field was provided as null, or that it was simply not present.

```kotlin
// Card.cvv returns String?
card.cvv != null // false
```

### Response properties as JSON

In rare cases, you may want to access the underlying JSON value for a response property rather than using the typed version provided by
Expand Down Expand Up @@ -211,6 +257,20 @@ while (page != null) {

---

---

## Webhook Verification

We provide helper methods for verifying that a webhook request came from Lithic, and not a malicious third party.

You can use `lithic.webhooks().verifySignature(body, headers, secret?)` or `lithic.webhooks().unwrap(body, headers, secret?)`,
both of which will raise an error if the signature is invalid.

Note that the "body" parameter must be the raw JSON string sent from the server (do not parse it first).
The `.unwrap()` method can parse this JSON for you.

---

## Error handling

This library throws exceptions in a single hierarchy for easy handling:
Expand Down

0 comments on commit 0ff33b5

Please sign in to comment.