diff options
author | Torsten Grote <t@grobox.de> | 2023-01-17 14:56:08 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2023-01-17 14:56:08 -0300 |
commit | de209564ed4dd6494774f9b4a26982f89637facb (patch) | |
tree | 828955058a7c9f1b5f581cf05b986c327bd589f3 /merchant-lib/src/main/java/net | |
parent | 3383aa3e7cb39a53203a8d0ad372097060e91d69 (diff) | |
download | taler-android-de209564ed4dd6494774f9b4a26982f89637facb.tar.gz taler-android-de209564ed4dd6494774f9b4a26982f89637facb.tar.bz2 taler-android-de209564ed4dd6494774f9b4a26982f89637facb.zip |
[pos] Change ApiKey Authorization to Bearer
Diffstat (limited to 'merchant-lib/src/main/java/net')
-rw-r--r-- | merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt b/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt index c02907b..950cea6 100644 --- a/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt +++ b/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt @@ -20,6 +20,7 @@ import io.ktor.client.HttpClient import io.ktor.client.call.body import io.ktor.client.engine.okhttp.OkHttp import io.ktor.client.plugins.contentnegotiation.ContentNegotiation +import io.ktor.client.request.HttpRequestBuilder import io.ktor.client.request.delete import io.ktor.client.request.get import io.ktor.client.request.header @@ -28,13 +29,12 @@ import io.ktor.client.request.setBody import io.ktor.http.ContentType.Application.Json import io.ktor.http.HttpHeaders.Authorization import io.ktor.http.contentType +import io.ktor.serialization.kotlinx.json.json import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import net.taler.merchantlib.Response.Companion.response -import io.ktor.serialization.kotlinx.json.* -import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json +import net.taler.merchantlib.Response.Companion.response class MerchantApi( private val httpClient: HttpClient = getDefaultHttpClient(), @@ -53,7 +53,7 @@ class MerchantApi( ): Response<PostOrderResponse> = withContext(ioDispatcher) { response { httpClient.post(merchantConfig.urlFor("private/orders")) { - header(Authorization, "ApiKey ${merchantConfig.apiKey}") + auth(merchantConfig) contentType(Json) setBody(orderRequest) }.body() @@ -66,7 +66,7 @@ class MerchantApi( ): Response<CheckPaymentResponse> = withContext(ioDispatcher) { response { httpClient.get(merchantConfig.urlFor("private/orders/$orderId")) { - header(Authorization, "ApiKey ${merchantConfig.apiKey}") + auth(merchantConfig) }.body() } } @@ -77,7 +77,7 @@ class MerchantApi( ): Response<Unit> = withContext(ioDispatcher) { response { httpClient.delete(merchantConfig.urlFor("private/orders/$orderId")) { - header(Authorization, "ApiKey ${merchantConfig.apiKey}") + auth(merchantConfig) }.body() } } @@ -86,7 +86,7 @@ class MerchantApi( withContext(ioDispatcher) { response { httpClient.get(merchantConfig.urlFor("private/orders")) { - header(Authorization, "ApiKey ${merchantConfig.apiKey}") + auth(merchantConfig) }.body() } } @@ -98,12 +98,16 @@ class MerchantApi( ): Response<RefundResponse> = withContext(ioDispatcher) { response { httpClient.post(merchantConfig.urlFor("private/orders/$orderId/refund")) { - header(Authorization, "ApiKey ${merchantConfig.apiKey}") + auth(merchantConfig) contentType(Json) setBody(request) }.body() } } + + private fun HttpRequestBuilder.auth(merchantConfig: MerchantConfig) { + header(Authorization, "Bearer ${merchantConfig.apiKey}") + } } fun getDefaultHttpClient(): HttpClient = HttpClient(OkHttp) { |