taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

commit de209564ed4dd6494774f9b4a26982f89637facb
parent 3383aa3e7cb39a53203a8d0ad372097060e91d69
Author: Torsten Grote <t@grobox.de>
Date:   Tue, 17 Jan 2023 14:56:08 -0300

[pos] Change ApiKey Authorization to Bearer

Diffstat:
Mmerchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt | 20++++++++++++--------
1 file 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 @@ -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) {