com.lithic.api.services.async.ExternalPaymentServiceAsyncImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lithic-java-core Show documentation
Show all versions of lithic-java-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.
// 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.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.ExternalPayment
import com.lithic.api.models.ExternalPaymentCancelParams
import com.lithic.api.models.ExternalPaymentCreateParams
import com.lithic.api.models.ExternalPaymentListPageAsync
import com.lithic.api.models.ExternalPaymentListParams
import com.lithic.api.models.ExternalPaymentReleaseParams
import com.lithic.api.models.ExternalPaymentRetrieveParams
import com.lithic.api.models.ExternalPaymentReverseParams
import com.lithic.api.models.ExternalPaymentSettleParams
import com.lithic.api.services.errorHandler
import com.lithic.api.services.json
import com.lithic.api.services.jsonHandler
import com.lithic.api.services.withErrorHandler
import java.util.concurrent.CompletableFuture
class ExternalPaymentServiceAsyncImpl
constructor(
private val clientOptions: ClientOptions,
) : ExternalPaymentServiceAsync {
private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper)
private val createHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Create external payment */
override fun create(
params: ExternalPaymentCreateParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("v1", "external_payments")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { createHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val retrieveHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Get external payment */
override fun retrieve(
params: ExternalPaymentRetrieveParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("v1", "external_payments", params.getPathParam(0))
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { retrieveHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val listHandler: Handler =
jsonHandler(clientOptions.jsonMapper)
.withErrorHandler(errorHandler)
/** List external payments */
override fun list(
params: ExternalPaymentListParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("v1", "external_payments")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { listHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
.let { ExternalPaymentListPageAsync.of(this, params, it) }
}
}
private val cancelHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Cancel external payment */
override fun cancel(
params: ExternalPaymentCancelParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("v1", "external_payments", params.getPathParam(0), "cancel")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { cancelHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val releaseHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Release external payment */
override fun release(
params: ExternalPaymentReleaseParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("v1", "external_payments", params.getPathParam(0), "release")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { releaseHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val reverseHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Reverse external payment */
override fun reverse(
params: ExternalPaymentReverseParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("v1", "external_payments", params.getPathParam(0), "reverse")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { reverseHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val settleHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Settle external payment */
override fun settle(
params: ExternalPaymentSettleParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("v1", "external_payments", params.getPathParam(0), "settle")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { settleHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy