
com.lithic.api.services.blocking.AccountServiceImpl.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.Account
import com.lithic.api.models.AccountListPage
import com.lithic.api.models.AccountListParams
import com.lithic.api.models.AccountRetrieveParams
import com.lithic.api.models.AccountUpdateParams
import com.lithic.api.services.blocking.accounts.CreditConfigurationService
import com.lithic.api.services.blocking.accounts.CreditConfigurationServiceImpl
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 AccountServiceImpl
constructor(
private val clientOptions: ClientOptions,
) : AccountService {
private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper)
private val creditConfigurations: CreditConfigurationService by lazy {
CreditConfigurationServiceImpl(clientOptions)
}
override fun creditConfigurations(): CreditConfigurationService = creditConfigurations
private val retrieveHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Get account configuration such as spend limits. */
override fun retrieve(params: AccountRetrieveParams, requestOptions: RequestOptions): Account {
val request =
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("accounts", params.getPathParam(0))
.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 updateHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/**
* Update account configuration such as spend limits and verification address. Can only be run
* on accounts that are part of the program managed by this API key.
*
* Accounts that are in the `PAUSED` state will not be able to transact or create new cards.
*/
override fun update(params: AccountUpdateParams, requestOptions: RequestOptions): Account {
val request =
HttpRequest.builder()
.method(HttpMethod.PATCH)
.addPathSegments("accounts", params.getPathParam(0))
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.execute(request, requestOptions).let { response ->
response
.use { updateHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val listHandler: Handler =
jsonHandler(clientOptions.jsonMapper)
.withErrorHandler(errorHandler)
/** List account configurations. */
override fun list(params: AccountListParams, requestOptions: RequestOptions): AccountListPage {
val request =
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("accounts")
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.build()
return clientOptions.httpClient.execute(request, requestOptions).let { response ->
response
.use { listHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
.let { AccountListPage.of(this, params, it) }
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy