diff options
Diffstat (limited to 'merchant-lib/src/main/java/net/taler')
-rw-r--r-- | merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt | 16 | ||||
-rw-r--r-- | merchant-lib/src/main/java/net/taler/merchantlib/Orders.kt | 8 |
2 files changed, 16 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 d973813..c02907b 100644 --- a/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt +++ b/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt @@ -33,6 +33,8 @@ 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 class MerchantApi( private val httpClient: HttpClient = getDefaultHttpClient(), @@ -41,7 +43,7 @@ class MerchantApi( suspend fun getConfig(baseUrl: String): Response<ConfigResponse> = withContext(ioDispatcher) { response { - httpClient.get("$baseUrl/config") as ConfigResponse + httpClient.get("$baseUrl/config").body() } } @@ -76,7 +78,7 @@ class MerchantApi( response { httpClient.delete(merchantConfig.urlFor("private/orders/$orderId")) { header(Authorization, "ApiKey ${merchantConfig.apiKey}") - } as Unit + }.body() } } @@ -85,7 +87,7 @@ class MerchantApi( response { httpClient.get(merchantConfig.urlFor("private/orders")) { header(Authorization, "ApiKey ${merchantConfig.apiKey}") - } as OrderHistory + }.body() } } @@ -99,18 +101,22 @@ class MerchantApi( header(Authorization, "ApiKey ${merchantConfig.apiKey}") contentType(Json) setBody(request) - } as RefundResponse + }.body() } } } fun getDefaultHttpClient(): HttpClient = HttpClient(OkHttp) { + expectSuccess = true engine { config { retryOnConnectionFailure(true) } } install(ContentNegotiation) { - json() + json(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 9572e07..391abf5 100644 --- a/merchant-lib/src/main/java/net/taler/merchantlib/Orders.kt +++ b/merchant-lib/src/main/java/net/taler/merchantlib/Orders.kt @@ -16,11 +16,12 @@ package net.taler.merchantlib +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonClassDiscriminator import net.taler.common.ContractTerms import net.taler.common.Duration -import net.taler.lib.android.CustomClassDiscriminator @Serializable data class PostOrderRequest( @@ -36,9 +37,10 @@ data class PostOrderResponse( val orderId: String ) +@OptIn(ExperimentalSerializationApi::class) @Serializable -sealed class CheckPaymentResponse: CustomClassDiscriminator { - override val discriminator: String = "order_status" +@JsonClassDiscriminator("order_status") +sealed class CheckPaymentResponse { abstract val paid: Boolean @Serializable |