aboutsummaryrefslogtreecommitdiff
path: root/merchant-lib
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-08-24 14:28:34 -0300
committerTorsten Grote <t@grobox.de>2020-08-24 14:28:34 -0300
commit35bc91761ad1f8336f331c6b04cff8bf4d9ae064 (patch)
tree330c195f60d909de5de4d156357a1f74847da70e /merchant-lib
parentd3955c2d8ae552c22547a186ab196274e32919e7 (diff)
downloadtaler-android-35bc91761ad1f8336f331c6b04cff8bf4d9ae064.tar.gz
taler-android-35bc91761ad1f8336f331c6b04cff8bf4d9ae064.tar.bz2
taler-android-35bc91761ad1f8336f331c6b04cff8bf4d9ae064.zip
Upgrade to Kotlin 1.4
Diffstat (limited to 'merchant-lib')
-rw-r--r--merchant-lib/build.gradle2
-rw-r--r--merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt11
-rw-r--r--merchant-lib/src/main/java/net/taler/merchantlib/Orders.kt23
-rw-r--r--merchant-lib/src/main/java/net/taler/merchantlib/Response.kt5
-rw-r--r--merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt5
5 files changed, 23 insertions, 23 deletions
diff --git a/merchant-lib/build.gradle b/merchant-lib/build.gradle
index 5082253..9b349ea 100644
--- a/merchant-lib/build.gradle
+++ b/merchant-lib/build.gradle
@@ -47,8 +47,6 @@ android {
dependencies {
api project(":taler-kotlin-android")
- implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
-
api "io.ktor:ktor-client:$ktor_version"
api "io.ktor:ktor-client-okhttp:$ktor_version"
api "io.ktor:ktor-client-serialization-jvm:$ktor_version"
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 a4ca397..ea5b996 100644
--- a/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt
+++ b/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt
@@ -31,7 +31,6 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.serialization.json.Json
-import kotlinx.serialization.json.JsonConfiguration
import net.taler.merchantlib.Response.Companion.response
class MerchantApi(
@@ -116,10 +115,8 @@ fun getDefaultHttpClient(): HttpClient = HttpClient(OkHttp) {
}
fun getSerializer() = KotlinxSerializer(
- Json(
- JsonConfiguration(
- encodeDefaults = false,
- ignoreUnknownKeys = true
- )
- )
+ Json {
+ encodeDefaults = false
+ ignoreUnknownKeys = true
+ }
)
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 0a405ad..9c23ef1 100644
--- a/merchant-lib/src/main/java/net/taler/merchantlib/Orders.kt
+++ b/merchant-lib/src/main/java/net/taler/merchantlib/Orders.kt
@@ -16,14 +16,16 @@
package net.taler.merchantlib
-import kotlinx.serialization.Decoder
-import kotlinx.serialization.Encoder
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Serializer
-import kotlinx.serialization.json.JsonInput
+import kotlinx.serialization.encoding.Decoder
+import kotlinx.serialization.encoding.Encoder
+import kotlinx.serialization.json.JsonDecoder
import kotlinx.serialization.json.JsonObject
+import kotlinx.serialization.json.boolean
+import kotlinx.serialization.json.jsonPrimitive
import net.taler.common.ContractTerms
import net.taler.lib.common.Duration
@@ -45,19 +47,20 @@ data class PostOrderResponse(
sealed class CheckPaymentResponse {
abstract val paid: Boolean
+ @Suppress("EXPERIMENTAL_API_USAGE")
@Serializer(forClass = CheckPaymentResponse::class)
companion object : KSerializer<CheckPaymentResponse> {
override fun deserialize(decoder: Decoder): CheckPaymentResponse {
- val input = decoder as JsonInput
- val tree = input.decodeJson() as JsonObject
- val orderStatus = tree.getPrimitive("order_status").content
-// return if (orderStatus == "paid") decoder.json.fromJson(Paid.serializer(), tree)
-// else decoder.json.fromJson(Unpaid.serializer(), tree)
+ val input = decoder as JsonDecoder
+ val tree = input.decodeJsonElement() as JsonObject
+ val orderStatus = tree.getValue("order_status").jsonPrimitive.content
+// return if (orderStatus == "paid") decoder.json.decodeFromJsonElement(Paid.serializer(), tree)
+// else decoder.json.decodeFromJsonElement(Unpaid.serializer(), tree)
// manual parsing due to https://github.com/Kotlin/kotlinx.serialization/issues/576
return if (orderStatus == "paid") Paid(
- refunded = tree.getPrimitive("refunded").boolean
+ refunded = tree.getValue("refunded").jsonPrimitive.boolean
) else Unpaid(
- talerPayUri = tree.getPrimitive("taler_pay_uri").content
+ talerPayUri = tree.getValue("taler_pay_uri").jsonPrimitive.content
)
}
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 fb48b46..1b63900 100644
--- a/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt
+++ b/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt
@@ -70,11 +70,12 @@ class Response<out T> private constructor(
}
private suspend fun getExceptionString(e: ResponseException): String {
+ val response = e.response ?: return e.toString()
return try {
- val error: Error = e.response.receive()
+ val error: Error = response.receive()
"Error ${error.code}: ${error.hint}"
} catch (ex: Exception) {
- "Status code: ${e.response.status.value}"
+ "Status code: ${response.status.value}"
}
}
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 993be15..c8e6f22 100644
--- a/merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt
+++ b/merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt
@@ -32,6 +32,7 @@ import io.ktor.http.content.TextContent
import io.ktor.http.fullPath
import io.ktor.http.headersOf
import io.ktor.http.hostWithPort
+import kotlinx.serialization.json.Json.Default.parseToJsonElement
import org.junit.Assert.assertEquals
object MockHttpClient {
@@ -75,8 +76,8 @@ object MockHttpClient {
private val Url.fullUrl: String get() = "${protocol.name}://$hostWithPortIfRequired$fullPath"
private fun assertJsonEquals(json1: String, json2: String) {
- val parsed1 = kotlinx.serialization.json.Json.parseJson(json1)
- val parsed2 = kotlinx.serialization.json.Json.parseJson(json2)
+ val parsed1 = parseToJsonElement(json1)
+ val parsed2 = parseToJsonElement(json2)
assertEquals(parsed1, parsed2)
}