
com.lithic.api.services.blocking.AuthStreamEnrollmentServiceImpl.kt Maven / Gradle / Ivy
// File generated from our OpenAPI spec by Stainless.
package com.lithic.api.services.blocking
import com.lithic.api.core.ClientOptions
import com.lithic.api.core.RequestOptions
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.errors.LithicError
import com.lithic.api.models.AuthStreamEnrollment
import com.lithic.api.models.AuthStreamEnrollmentDisenrollParams
import com.lithic.api.models.AuthStreamEnrollmentEnrollParams
import com.lithic.api.models.AuthStreamEnrollmentRetrieveParams
import com.lithic.api.models.AuthStreamEnrollmentRetrieveSecretParams
import com.lithic.api.models.AuthStreamEnrollmentRotateSecretParams
import com.lithic.api.models.AuthStreamSecret
import com.lithic.api.services.emptyHandler
import com.lithic.api.services.errorHandler
import com.lithic.api.services.json
import com.lithic.api.services.jsonHandler
import com.lithic.api.services.withErrorHandler
class AuthStreamEnrollmentServiceImpl
constructor(
private val clientOptions: ClientOptions,
) : AuthStreamEnrollmentService {
private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper)
private val retrieveHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/**
* Check status for whether you have enrolled in Authorization Stream Access (ASA) for your
* program in Sandbox.
*/
override fun retrieve(
params: AuthStreamEnrollmentRetrieveParams,
requestOptions: RequestOptions
): AuthStreamEnrollment {
val request =
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("auth_stream")
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.build()
return clientOptions.httpClient.execute(request, requestOptions).let { response ->
response
.use { retrieveHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val disenrollHandler: Handler = emptyHandler().withErrorHandler(errorHandler)
/** Disenroll Authorization Stream Access (ASA) in Sandbox. */
override fun disenroll(
params: AuthStreamEnrollmentDisenrollParams,
requestOptions: RequestOptions
) {
val request =
HttpRequest.builder()
.method(HttpMethod.DELETE)
.addPathSegments("auth_stream")
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.apply { params.getBody()?.also { body(json(clientOptions.jsonMapper, it)) } }
.build()
clientOptions.httpClient.execute(request, requestOptions).let { response ->
response.use { disenrollHandler.handle(it) }
}
}
private val enrollHandler: Handler = emptyHandler().withErrorHandler(errorHandler)
/**
* Authorization Stream Access (ASA) provides the ability to make custom transaction approval
* decisions through an HTTP interface to the ISO 8583 message stream.
*
* ASA requests are delivered as an HTTP POST during authorization. The ASA request body adheres
* to the Lithic transaction schema, with some additional fields added for use in decisioning. A
* response should be sent with HTTP response code 200 and the approval decision in the response
* body. This response is converted by Lithic back into ISO 8583 format and forwarded to the
* network.
*
* In Sandbox, users can self-enroll and disenroll in ASA. In production, onboarding requires
* manual approval and setup.
*/
override fun enroll(params: AuthStreamEnrollmentEnrollParams, requestOptions: RequestOptions) {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("auth_stream")
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
clientOptions.httpClient.execute(request, requestOptions).let { response ->
response.use { enrollHandler.handle(it) }
}
}
private val retrieveSecretHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/**
* Retrieve the ASA HMAC secret key. If one does not exist for your program yet, calling this
* endpoint will create one for you. The headers (which you can use to verify webhooks) will
* begin appearing shortly after calling this endpoint for the first time. See
* [this page](https://docs.lithic.com/docs/auth-stream-access-asa#asa-webhook-verification) for
* more detail about verifying ASA webhooks.
*/
override fun retrieveSecret(
params: AuthStreamEnrollmentRetrieveSecretParams,
requestOptions: RequestOptions
): AuthStreamSecret {
val request =
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("auth_stream", "secret")
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.build()
return clientOptions.httpClient.execute(request, requestOptions).let { response ->
response
.use { retrieveSecretHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val rotateSecretHandler: Handler = emptyHandler().withErrorHandler(errorHandler)
/**
* Generate a new ASA HMAC secret key. The old ASA HMAC secret key will be deactivated 24 hours
* after a successful request to this endpoint. Make a
* [`GET /auth_stream/secret`](https://docs.lithic.com/reference/getauthstreamsecret) request to
* retrieve the new secret key.
*/
override fun rotateSecret(
params: AuthStreamEnrollmentRotateSecretParams,
requestOptions: RequestOptions
) {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("auth_stream", "secret", "rotate")
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.apply { params.getBody()?.also { body(json(clientOptions.jsonMapper, it)) } }
.build()
clientOptions.httpClient.execute(request, requestOptions).let { response ->
response.use { rotateSecretHandler.handle(it) }
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy