com.lithic.api.services.async.TokenizationServiceAsyncImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lithic-kotlin-core Show documentation
Show all versions of lithic-kotlin-core Show documentation
The Lithic Developer API is designed to provide a predictable programmatic
interface for accessing your Lithic account through an API and transaction
webhooks. Note that your API key is a secret and should be treated as such.
Don't share it with anyone, including us. We will never ask you for it.
The newest version!
// File generated from our OpenAPI spec by Stainless.
package com.lithic.api.services.async
import com.lithic.api.core.ClientOptions
import com.lithic.api.core.RequestOptions
import com.lithic.api.core.handlers.emptyHandler
import com.lithic.api.core.handlers.errorHandler
import com.lithic.api.core.handlers.jsonHandler
import com.lithic.api.core.handlers.withErrorHandler
import com.lithic.api.core.http.HttpMethod
import com.lithic.api.core.http.HttpRequest
import com.lithic.api.core.http.HttpResponse.Handler
import com.lithic.api.core.json
import com.lithic.api.errors.LithicError
import com.lithic.api.models.TokenizationActivateParams
import com.lithic.api.models.TokenizationDeactivateParams
import com.lithic.api.models.TokenizationListPageAsync
import com.lithic.api.models.TokenizationListParams
import com.lithic.api.models.TokenizationPauseParams
import com.lithic.api.models.TokenizationResendActivationCodeParams
import com.lithic.api.models.TokenizationRetrieveParams
import com.lithic.api.models.TokenizationRetrieveResponse
import com.lithic.api.models.TokenizationSimulateParams
import com.lithic.api.models.TokenizationSimulateResponse
import com.lithic.api.models.TokenizationUnpauseParams
import com.lithic.api.models.TokenizationUpdateDigitalCardArtParams
import com.lithic.api.models.TokenizationUpdateDigitalCardArtResponse
class TokenizationServiceAsyncImpl
constructor(
private val clientOptions: ClientOptions,
) : TokenizationServiceAsync {
private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper)
private val retrieveHandler: Handler =
jsonHandler(clientOptions.jsonMapper)
.withErrorHandler(errorHandler)
/** Get tokenization */
override suspend fun retrieve(
params: TokenizationRetrieveParams,
requestOptions: RequestOptions
): TokenizationRetrieveResponse {
val request =
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("v1", "tokenizations", params.getPathParam(0))
.putAllQueryParams(clientOptions.queryParams)
.replaceAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.replaceAllHeaders(params.getHeaders())
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).let { response ->
response
.use { retrieveHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val listHandler: Handler =
jsonHandler(clientOptions.jsonMapper)
.withErrorHandler(errorHandler)
/** List card tokenizations */
override suspend fun list(
params: TokenizationListParams,
requestOptions: RequestOptions
): TokenizationListPageAsync {
val request =
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("v1", "tokenizations")
.putAllQueryParams(clientOptions.queryParams)
.replaceAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.replaceAllHeaders(params.getHeaders())
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).let { response ->
response
.use { listHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
.let { TokenizationListPageAsync.of(this, params, it) }
}
}
private val activateHandler: Handler = emptyHandler().withErrorHandler(errorHandler)
/**
* This endpoint is used to ask the card network to activate a tokenization. A successful
* response indicates that the request was successfully delivered to the card network. When the
* card network activates the tokenization, the state will be updated and a tokenization.updated
* event will be sent. The endpoint may only be used on digital wallet tokenizations with status
* `INACTIVE`, `PENDING_ACTIVATION`, or `PENDING_2FA`. This will put the tokenization in an
* active state, and transactions will be allowed. Reach out at
* [lithic.com/contact](https://lithic.com/contact) for more information.
*/
override suspend fun activate(
params: TokenizationActivateParams,
requestOptions: RequestOptions
) {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("v1", "tokenizations", params.getPathParam(0), "activate")
.putAllQueryParams(clientOptions.queryParams)
.replaceAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.replaceAllHeaders(params.getHeaders())
.apply { params.getBody()?.also { body(json(clientOptions.jsonMapper, it)) } }
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).let { response ->
response.use { activateHandler.handle(it) }
}
}
private val deactivateHandler: Handler = emptyHandler().withErrorHandler(errorHandler)
/**
* This endpoint is used to ask the card network to deactivate a tokenization. A successful
* response indicates that the request was successfully delivered to the card network. When the
* card network deactivates the tokenization, the state will be updated and a
* tokenization.updated event will be sent. Authorizations attempted with a deactivated
* tokenization will be blocked and will not be forwarded to Lithic from the network.
* Deactivating the token is a permanent operation. If the target is a digital wallet
* tokenization, it will be removed from its device. Reach out at
* [lithic.com/contact](https://lithic.com/contact) for more information.
*/
override suspend fun deactivate(
params: TokenizationDeactivateParams,
requestOptions: RequestOptions
) {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("v1", "tokenizations", params.getPathParam(0), "deactivate")
.putAllQueryParams(clientOptions.queryParams)
.replaceAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.replaceAllHeaders(params.getHeaders())
.apply { params.getBody()?.also { body(json(clientOptions.jsonMapper, it)) } }
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).let { response ->
response.use { deactivateHandler.handle(it) }
}
}
private val pauseHandler: Handler = emptyHandler().withErrorHandler(errorHandler)
/**
* This endpoint is used to ask the card network to pause a tokenization. A successful response
* indicates that the request was successfully delivered to the card network. When the card
* network pauses the tokenization, the state will be updated and a tokenization.updated event
* will be sent. The endpoint may only be used on tokenizations with status `ACTIVE`. A paused
* token will prevent merchants from sending authorizations, and is a temporary status that can
* be changed. Reach out at [lithic.com/contact](https://lithic.com/contact) for more
* information.
*/
override suspend fun pause(params: TokenizationPauseParams, requestOptions: RequestOptions) {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("v1", "tokenizations", params.getPathParam(0), "pause")
.putAllQueryParams(clientOptions.queryParams)
.replaceAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.replaceAllHeaders(params.getHeaders())
.apply { params.getBody()?.also { body(json(clientOptions.jsonMapper, it)) } }
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).let { response ->
response.use { pauseHandler.handle(it) }
}
}
private val resendActivationCodeHandler: Handler =
emptyHandler().withErrorHandler(errorHandler)
/**
* This endpoint is used to ask the card network to send another activation code to a cardholder
* that has already tried tokenizing a card. A successful response indicates that the request
* was successfully delivered to the card network. The endpoint may only be used on Mastercard
* digital wallet tokenizations with status `INACTIVE`, `PENDING_ACTIVATION`, or `PENDING_2FA`.
* The network will send a new activation code to the one of the contact methods provided in the
* initial tokenization flow. If a user fails to enter the code correctly 3 times, the contact
* method will not be eligible for resending the activation code, and the cardholder must
* restart the provision process. Reach out at [lithic.com/contact](https://lithic.com/contact)
* for more information.
*/
override suspend fun resendActivationCode(
params: TokenizationResendActivationCodeParams,
requestOptions: RequestOptions
) {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments(
"v1",
"tokenizations",
params.getPathParam(0),
"resend_activation_code"
)
.putAllQueryParams(clientOptions.queryParams)
.replaceAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.replaceAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).let { response ->
response.use { resendActivationCodeHandler.handle(it) }
}
}
private val simulateHandler: Handler =
jsonHandler(clientOptions.jsonMapper)
.withErrorHandler(errorHandler)
/**
* This endpoint is used to simulate a card's tokenization in the Digital Wallet and merchant
* tokenization ecosystem.
*/
override suspend fun simulate(
params: TokenizationSimulateParams,
requestOptions: RequestOptions
): TokenizationSimulateResponse {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("v1", "simulate", "tokenizations")
.putAllQueryParams(clientOptions.queryParams)
.replaceAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.replaceAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).let { response ->
response
.use { simulateHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val unpauseHandler: Handler = emptyHandler().withErrorHandler(errorHandler)
/**
* This endpoint is used to ask the card network to unpause a tokenization. A successful
* response indicates that the request was successfully delivered to the card network. When the
* card network unpauses the tokenization, the state will be updated and a tokenization.updated
* event will be sent. The endpoint may only be used on tokenizations with status `PAUSED`. This
* will put the tokenization in an active state, and transactions may resume. Reach out at
* [lithic.com/contact](https://lithic.com/contact) for more information.
*/
override suspend fun unpause(
params: TokenizationUnpauseParams,
requestOptions: RequestOptions
) {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("v1", "tokenizations", params.getPathParam(0), "unpause")
.putAllQueryParams(clientOptions.queryParams)
.replaceAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.replaceAllHeaders(params.getHeaders())
.apply { params.getBody()?.also { body(json(clientOptions.jsonMapper, it)) } }
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).let { response ->
response.use { unpauseHandler.handle(it) }
}
}
private val updateDigitalCardArtHandler: Handler =
jsonHandler(clientOptions.jsonMapper)
.withErrorHandler(errorHandler)
/**
* This endpoint is used update the digital card art for a digital wallet tokenization. A
* successful response indicates that the card network has updated the tokenization's art, and
* the tokenization's `digital_cart_art_token` field was updated. The endpoint may not be used
* on tokenizations with status `DEACTIVATED`. Note that this updates the art for one specific
* tokenization, not all tokenizations for a card. New tokenizations for a card will be created
* with the art referenced in the card object's `digital_card_art_token` field. Reach out at
* [lithic.com/contact](https://lithic.com/contact) for more information.
*/
override suspend fun updateDigitalCardArt(
params: TokenizationUpdateDigitalCardArtParams,
requestOptions: RequestOptions
): TokenizationUpdateDigitalCardArtResponse {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments(
"v1",
"tokenizations",
params.getPathParam(0),
"update_digital_card_art"
)
.putAllQueryParams(clientOptions.queryParams)
.replaceAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.replaceAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).let { response ->
response
.use { updateDigitalCardArtHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy