aboutsummaryrefslogtreecommitdiff
path: root/merchant-lib
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-05-16 19:58:31 +0200
committerFlorian Dold <florian@dold.me>2022-05-19 11:05:18 +0200
commit023ea96d26a65d29d408ef78c9405411bb842afd (patch)
tree658717478320443c4dd3cb6c5c906cfa443d2cad /merchant-lib
parent29e19d02b7befa0c8e18b9c73ac912bb256aa7ee (diff)
downloadtaler-android-023ea96d26a65d29d408ef78c9405411bb842afd.tar.gz
taler-android-023ea96d26a65d29d408ef78c9405411bb842afd.tar.bz2
taler-android-023ea96d26a65d29d408ef78c9405411bb842afd.zip
-remove multiplatform dependency, library upgrade WIP
Diffstat (limited to 'merchant-lib')
-rw-r--r--merchant-lib/build.gradle4
-rw-r--r--merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt27
-rw-r--r--merchant-lib/src/main/java/net/taler/merchantlib/OrderHistory.kt4
-rw-r--r--merchant-lib/src/main/java/net/taler/merchantlib/Orders.kt2
-rw-r--r--merchant-lib/src/main/java/net/taler/merchantlib/Refunds.kt3
-rw-r--r--merchant-lib/src/main/java/net/taler/merchantlib/Response.kt10
-rw-r--r--merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt4
-rw-r--r--merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt12
8 files changed, 24 insertions, 42 deletions
diff --git a/merchant-lib/build.gradle b/merchant-lib/build.gradle
index c554b77..c31009d 100644
--- a/merchant-lib/build.gradle
+++ b/merchant-lib/build.gradle
@@ -57,9 +57,11 @@ dependencies {
api "io.ktor:ktor-client:$ktor_version"
api "io.ktor:ktor-client-okhttp:$ktor_version"
api "io.ktor:ktor-client-serialization-jvm:$ktor_version"
+ api "io.ktor:ktor-client-content-negotiation:$ktor_version"
+ implementation "io.ktor:ktor-serialization-kotlinx-json:$ktor_version"
+ implementation "io.ktor:ktor-server-call-logging:$ktor_version"
testImplementation "junit:junit:$junit_version"
testImplementation "io.ktor:ktor-client-mock-jvm:$ktor_version"
- testImplementation "io.ktor:ktor-client-logging-jvm:$ktor_version"
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.1'
}
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 0d22f91..d973813 100644
--- a/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt
+++ b/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt
@@ -17,21 +17,22 @@
package net.taler.merchantlib
import io.ktor.client.HttpClient
+import io.ktor.client.call.body
import io.ktor.client.engine.okhttp.OkHttp
-import io.ktor.client.features.json.JsonFeature
-import io.ktor.client.features.json.serializer.KotlinxSerializer
+import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.request.delete
import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.client.request.post
+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 kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
-import kotlinx.serialization.json.Json
import net.taler.merchantlib.Response.Companion.response
+import io.ktor.serialization.kotlinx.json.*
class MerchantApi(
private val httpClient: HttpClient = getDefaultHttpClient(),
@@ -52,8 +53,8 @@ class MerchantApi(
httpClient.post(merchantConfig.urlFor("private/orders")) {
header(Authorization, "ApiKey ${merchantConfig.apiKey}")
contentType(Json)
- body = orderRequest
- } as PostOrderResponse
+ setBody(orderRequest)
+ }.body()
}
}
@@ -64,7 +65,7 @@ class MerchantApi(
response {
httpClient.get(merchantConfig.urlFor("private/orders/$orderId")) {
header(Authorization, "ApiKey ${merchantConfig.apiKey}")
- } as CheckPaymentResponse
+ }.body()
}
}
@@ -97,7 +98,7 @@ class MerchantApi(
httpClient.post(merchantConfig.urlFor("private/orders/$orderId/refund")) {
header(Authorization, "ApiKey ${merchantConfig.apiKey}")
contentType(Json)
- body = request
+ setBody(request)
} as RefundResponse
}
}
@@ -109,15 +110,7 @@ fun getDefaultHttpClient(): HttpClient = HttpClient(OkHttp) {
retryOnConnectionFailure(true)
}
}
- install(JsonFeature) {
- serializer = getSerializer()
+ install(ContentNegotiation) {
+ json()
}
}
-
-fun getSerializer() = KotlinxSerializer(
- Json {
- encodeDefaults = false
- ignoreUnknownKeys = true
- classDiscriminator = "order_status"
- }
-)
diff --git a/merchant-lib/src/main/java/net/taler/merchantlib/OrderHistory.kt b/merchant-lib/src/main/java/net/taler/merchantlib/OrderHistory.kt
index dfd989b..b1ff5b1 100644
--- a/merchant-lib/src/main/java/net/taler/merchantlib/OrderHistory.kt
+++ b/merchant-lib/src/main/java/net/taler/merchantlib/OrderHistory.kt
@@ -18,8 +18,8 @@ package net.taler.merchantlib
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
-import net.taler.lib.common.Amount
-import net.taler.lib.common.Timestamp
+import net.taler.common.Amount
+import net.taler.common.Timestamp
@Serializable
data class OrderHistory(
diff --git a/merchant-lib/src/main/java/net/taler/merchantlib/Orders.kt b/merchant-lib/src/main/java/net/taler/merchantlib/Orders.kt
index 166ca3c..9572e07 100644
--- a/merchant-lib/src/main/java/net/taler/merchantlib/Orders.kt
+++ b/merchant-lib/src/main/java/net/taler/merchantlib/Orders.kt
@@ -19,8 +19,8 @@ package net.taler.merchantlib
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import net.taler.common.ContractTerms
+import net.taler.common.Duration
import net.taler.lib.android.CustomClassDiscriminator
-import net.taler.lib.common.Duration
@Serializable
data class PostOrderRequest(
diff --git a/merchant-lib/src/main/java/net/taler/merchantlib/Refunds.kt b/merchant-lib/src/main/java/net/taler/merchantlib/Refunds.kt
index b78b571..58073fa 100644
--- a/merchant-lib/src/main/java/net/taler/merchantlib/Refunds.kt
+++ b/merchant-lib/src/main/java/net/taler/merchantlib/Refunds.kt
@@ -18,8 +18,7 @@ package net.taler.merchantlib
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
-import net.taler.lib.common.Amount
-
+import net.taler.common.Amount
@Serializable
data class RefundRequest(
/**
diff --git a/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt b/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt
index 6fd0e37..b7ba1ac 100644
--- a/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt
+++ b/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt
@@ -16,10 +16,10 @@
package net.taler.merchantlib
-import io.ktor.client.call.receive
-import io.ktor.client.features.ClientRequestException
-import io.ktor.client.features.ResponseException
-import io.ktor.client.features.ServerResponseException
+import io.ktor.client.call.body
+import io.ktor.client.plugins.ClientRequestException
+import io.ktor.client.plugins.ResponseException
+import io.ktor.client.plugins.ServerResponseException
import kotlinx.serialization.Serializable
class Response<out T> private constructor(
@@ -72,7 +72,7 @@ class Response<out T> private constructor(
private suspend fun getExceptionString(e: ResponseException): String {
val response = e.response
return try {
- val error: Error = response.receive()
+ val error: Error = response.body()
"Error ${error.code}: ${error.hint}"
} catch (ex: Exception) {
"Status code: ${response.status.value}"
diff --git a/merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt b/merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt
index 6abacfd..8a45c9f 100644
--- a/merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt
+++ b/merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt
@@ -20,10 +20,10 @@ import io.ktor.http.HttpStatusCode.Companion.NotFound
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.TestCoroutineDispatcher
+import net.taler.common.Amount
import net.taler.common.ContractProduct
import net.taler.common.ContractTerms
-import net.taler.lib.common.Amount
-import net.taler.lib.common.Timestamp
+import net.taler.common.Timestamp
import net.taler.merchantlib.MockHttpClient.giveJsonResponse
import net.taler.merchantlib.MockHttpClient.httpClient
import org.junit.Assert.assertEquals
diff --git a/merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt b/merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt
index c8e6f22..880228c 100644
--- a/merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt
+++ b/merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt
@@ -20,11 +20,6 @@ import io.ktor.client.HttpClient
import io.ktor.client.engine.mock.MockEngine
import io.ktor.client.engine.mock.MockEngineConfig
import io.ktor.client.engine.mock.respond
-import io.ktor.client.features.json.JsonFeature
-import io.ktor.client.features.logging.LogLevel
-import io.ktor.client.features.logging.Logger
-import io.ktor.client.features.logging.Logging
-import io.ktor.client.features.logging.SIMPLE
import io.ktor.http.ContentType.Application.Json
import io.ktor.http.HttpStatusCode
import io.ktor.http.Url
@@ -38,13 +33,6 @@ import org.junit.Assert.assertEquals
object MockHttpClient {
val httpClient = HttpClient(MockEngine) {
- install(JsonFeature) {
- serializer = getSerializer()
- }
- install(Logging) {
- logger = Logger.SIMPLE
- level = LogLevel.ALL
- }
engine {
addHandler { error("No response handler set") }
}