All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.carpentum.sdk.payment.internal.generated.api.AuthApi.kt Maven / Gradle / Ivy

The newest version!
/**
 *
 * Please note:
 * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * Do not edit this file manually.
 *
 */

@file:Suppress(
    "ArrayInDataClass",
    "EnumEntryName",
    "RemoveRedundantQualifierName",
    "UnusedImport"
)

package tech.carpentum.sdk.payment.internal.generated.api

import java.io.IOException
import okhttp3.OkHttpClient
import okhttp3.HttpUrl

import tech.carpentum.sdk.payment.model.AuthTokenByActionRequest
import tech.carpentum.sdk.payment.model.AuthTokenRequest
import tech.carpentum.sdk.payment.model.AuthTokenResponse
import tech.carpentum.sdk.payment.model.BasicError
import tech.carpentum.sdk.payment.model.PostAuthTokensError

import com.squareup.moshi.Json

import tech.carpentum.sdk.payment.internal.generated.infrastructure.ApiClient
import tech.carpentum.sdk.payment.internal.generated.infrastructure.ApiResponse
import tech.carpentum.sdk.payment.internal.generated.infrastructure.ClientException
import tech.carpentum.sdk.payment.internal.generated.infrastructure.ClientError
import tech.carpentum.sdk.payment.internal.generated.infrastructure.ServerException
import tech.carpentum.sdk.payment.internal.generated.infrastructure.ServerError
import tech.carpentum.sdk.payment.internal.generated.infrastructure.MultiValueMap
import tech.carpentum.sdk.payment.internal.generated.infrastructure.PartConfig
import tech.carpentum.sdk.payment.internal.generated.infrastructure.RequestConfig
import tech.carpentum.sdk.payment.internal.generated.infrastructure.RequestMethod
import tech.carpentum.sdk.payment.internal.generated.infrastructure.ResponseType
import tech.carpentum.sdk.payment.internal.generated.infrastructure.Success
import tech.carpentum.sdk.payment.internal.generated.infrastructure.toMultiValue

internal open class AuthApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient = ApiClient.defaultClient) : ApiClient(basePath, client) {
    companion object {
        @JvmStatic
        val defaultBasePath: String by lazy {
            System.getProperties().getProperty(ApiClient.baseUrlKey, "https://api.sandbox.carpentum.tech")
        }
    }

    /**
     * Authorization token.
     *  Issues JSON Web Token (JWT) that can be used to call authorized payment API.  Validates the secret and responds with a JWT allowing the given merchant access to the given endpoints.  For more info about security concepts see the [Security](general.html#security) section.  For more info about payment web app integration security see the [Payment Web App - Auth Token](payin-webapp.html#get-a-authorization-token) section.  For more info about direct integration security see the [Direct integration - Authentication and Authorization](payin-common.html) section. 
     * @param xAPIVersion Required API version. See [Versioning](general.html#versioning)
     * @param authTokenRequest 
     * @return AuthTokenResponse
     * @throws IllegalStateException If the request is not correctly configured
     * @throws IOException Rethrows the OkHttp execute method exception
     * @throws UnsupportedOperationException If the API returns an informational or redirection response
     * @throws ClientException If the API returns a client error response
     * @throws ServerException If the API returns a server error response
     */
    @Suppress("UNCHECKED_CAST")
    @Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class)
    fun createAuthToken(xAPIVersion: kotlin.Int, authTokenRequest: AuthTokenRequest) : AuthTokenResponse {
        val localVarResponse = createAuthTokenWithHttpInfo(xAPIVersion = xAPIVersion, authTokenRequest = authTokenRequest)

        return when (localVarResponse.responseType) {
            ResponseType.Success -> (localVarResponse as Success<*>).data as AuthTokenResponse
            ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
            ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
            ResponseType.ClientError -> {
                val localVarError = localVarResponse as ClientError<*>
                throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
            }
            ResponseType.ServerError -> {
                val localVarError = localVarResponse as ServerError<*>
                throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()} ${localVarError.body}", localVarError.statusCode, localVarResponse)
            }
        }
    }

    /**
     * Authorization token.
     *  Issues JSON Web Token (JWT) that can be used to call authorized payment API.  Validates the secret and responds with a JWT allowing the given merchant access to the given endpoints.  For more info about security concepts see the [Security](general.html#security) section.  For more info about payment web app integration security see the [Payment Web App - Auth Token](payin-webapp.html#get-a-authorization-token) section.  For more info about direct integration security see the [Direct integration - Authentication and Authorization](payin-common.html) section. 
     * @param xAPIVersion Required API version. See [Versioning](general.html#versioning)
     * @param authTokenRequest 
     * @return ApiResponse
     * @throws IllegalStateException If the request is not correctly configured
     * @throws IOException Rethrows the OkHttp execute method exception
     */
    @Suppress("UNCHECKED_CAST")
    @Throws(IllegalStateException::class, IOException::class)
    fun createAuthTokenWithHttpInfo(xAPIVersion: kotlin.Int, authTokenRequest: AuthTokenRequest) : ApiResponse {
        val localVariableConfig = createAuthTokenRequestConfig(xAPIVersion = xAPIVersion, authTokenRequest = authTokenRequest)

        return request(
            localVariableConfig
        )
    }

    /**
     * To obtain the request config of the operation createAuthToken
     *
     * @param xAPIVersion Required API version. See [Versioning](general.html#versioning)
     * @param authTokenRequest 
     * @return RequestConfig
     */
    fun createAuthTokenRequestConfig(xAPIVersion: kotlin.Int, authTokenRequest: AuthTokenRequest) : RequestConfig {
        val localVariableBody = authTokenRequest
        val localVariableQuery: MultiValueMap = mutableMapOf()
        val localVariableHeaders: MutableMap = mutableMapOf()
        xAPIVersion.apply { localVariableHeaders["X-API-Version"] = this.toString() }
        localVariableHeaders["Content-Type"] = "application/json"
        localVariableHeaders["Accept"] = "application/json"

        return RequestConfig(
            method = RequestMethod.POST,
            path = "/auth-tokens",
            query = localVariableQuery,
            headers = localVariableHeaders,
            requiresAuthentication = false,
            body = localVariableBody
        )
    }

    /**
     * Authorization token via action specification.
     *  Issues JSON Web Token (JWT) that can be used to call authorized payment API.  Expects action and idPayment on input. If fine-grained control is needed, use [`POST /auth-tokens`](#operations-authTokens) API.  Validates the secret and responds with a JWT allowing the given merchant access to the given endpoints.  For more info about security concepts see the [Security](general.html#security) section.  For more info about payment web app integration security see the [Payment Web App - Auth Token](payin-webapp.html#get-a-authorization-token) section.  For more info about direct integration security see the [Direct integration - Authentication and Authorization](payin-common.html) section. 
     * @param xAPIVersion Required API version. See [Versioning](general.html#versioning)
     * @param authTokenByActionRequest 
     * @return AuthTokenResponse
     * @throws IllegalStateException If the request is not correctly configured
     * @throws IOException Rethrows the OkHttp execute method exception
     * @throws UnsupportedOperationException If the API returns an informational or redirection response
     * @throws ClientException If the API returns a client error response
     * @throws ServerException If the API returns a server error response
     */
    @Suppress("UNCHECKED_CAST")
    @Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class)
    fun createAuthTokenByAction(xAPIVersion: kotlin.Int, authTokenByActionRequest: AuthTokenByActionRequest) : AuthTokenResponse {
        val localVarResponse = createAuthTokenByActionWithHttpInfo(xAPIVersion = xAPIVersion, authTokenByActionRequest = authTokenByActionRequest)

        return when (localVarResponse.responseType) {
            ResponseType.Success -> (localVarResponse as Success<*>).data as AuthTokenResponse
            ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
            ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
            ResponseType.ClientError -> {
                val localVarError = localVarResponse as ClientError<*>
                throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
            }
            ResponseType.ServerError -> {
                val localVarError = localVarResponse as ServerError<*>
                throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()} ${localVarError.body}", localVarError.statusCode, localVarResponse)
            }
        }
    }

    /**
     * Authorization token via action specification.
     *  Issues JSON Web Token (JWT) that can be used to call authorized payment API.  Expects action and idPayment on input. If fine-grained control is needed, use [`POST /auth-tokens`](#operations-authTokens) API.  Validates the secret and responds with a JWT allowing the given merchant access to the given endpoints.  For more info about security concepts see the [Security](general.html#security) section.  For more info about payment web app integration security see the [Payment Web App - Auth Token](payin-webapp.html#get-a-authorization-token) section.  For more info about direct integration security see the [Direct integration - Authentication and Authorization](payin-common.html) section. 
     * @param xAPIVersion Required API version. See [Versioning](general.html#versioning)
     * @param authTokenByActionRequest 
     * @return ApiResponse
     * @throws IllegalStateException If the request is not correctly configured
     * @throws IOException Rethrows the OkHttp execute method exception
     */
    @Suppress("UNCHECKED_CAST")
    @Throws(IllegalStateException::class, IOException::class)
    fun createAuthTokenByActionWithHttpInfo(xAPIVersion: kotlin.Int, authTokenByActionRequest: AuthTokenByActionRequest) : ApiResponse {
        val localVariableConfig = createAuthTokenByActionRequestConfig(xAPIVersion = xAPIVersion, authTokenByActionRequest = authTokenByActionRequest)

        return request(
            localVariableConfig
        )
    }

    /**
     * To obtain the request config of the operation createAuthTokenByAction
     *
     * @param xAPIVersion Required API version. See [Versioning](general.html#versioning)
     * @param authTokenByActionRequest 
     * @return RequestConfig
     */
    fun createAuthTokenByActionRequestConfig(xAPIVersion: kotlin.Int, authTokenByActionRequest: AuthTokenByActionRequest) : RequestConfig {
        val localVariableBody = authTokenByActionRequest
        val localVariableQuery: MultiValueMap = mutableMapOf()
        val localVariableHeaders: MutableMap = mutableMapOf()
        xAPIVersion.apply { localVariableHeaders["X-API-Version"] = this.toString() }
        localVariableHeaders["Content-Type"] = "application/json"
        localVariableHeaders["Accept"] = "application/json"

        return RequestConfig(
            method = RequestMethod.POST,
            path = "/auth-tokens-by-action",
            query = localVariableQuery,
            headers = localVariableHeaders,
            requiresAuthentication = false,
            body = localVariableBody
        )
    }


    private fun encodeURIComponent(uriComponent: kotlin.String): kotlin.String =
        HttpUrl.Builder().scheme("http").host("localhost").addPathSegment(uriComponent).build().encodedPathSegments[0]
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy