aboutsummaryrefslogtreecommitdiff
path: root/merchant-lib
diff options
context:
space:
mode:
Diffstat (limited to 'merchant-lib')
-rw-r--r--merchant-lib/build.gradle9
-rw-r--r--merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt10
-rw-r--r--merchant-lib/src/main/java/net/taler/merchantlib/Response.kt2
-rw-r--r--merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt14
4 files changed, 20 insertions, 15 deletions
diff --git a/merchant-lib/build.gradle b/merchant-lib/build.gradle
index a173cce..f53baa2 100644
--- a/merchant-lib/build.gradle
+++ b/merchant-lib/build.gradle
@@ -45,6 +45,11 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
+
+ compileOptions {
+ sourceCompatibility = 1.8
+ targetCompatibility = 1.8
+ }
}
dependencies {
@@ -54,8 +59,8 @@ dependencies {
api "io.ktor:ktor-client-okhttp:$ktor_version"
api "io.ktor:ktor-client-serialization-jvm:$ktor_version"
- testImplementation 'junit:junit:4.13.1'
+ 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.3.9'
+ testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.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 a467c41..0d22f91 100644
--- a/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt
+++ b/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt
@@ -35,7 +35,7 @@ import net.taler.merchantlib.Response.Companion.response
class MerchantApi(
private val httpClient: HttpClient = getDefaultHttpClient(),
- private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
+ private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO,
) {
suspend fun getConfig(baseUrl: String): Response<ConfigResponse> = withContext(ioDispatcher) {
@@ -46,7 +46,7 @@ class MerchantApi(
suspend fun postOrder(
merchantConfig: MerchantConfig,
- orderRequest: PostOrderRequest
+ orderRequest: PostOrderRequest,
): Response<PostOrderResponse> = withContext(ioDispatcher) {
response {
httpClient.post(merchantConfig.urlFor("private/orders")) {
@@ -59,7 +59,7 @@ class MerchantApi(
suspend fun checkOrder(
merchantConfig: MerchantConfig,
- orderId: String
+ orderId: String,
): Response<CheckPaymentResponse> = withContext(ioDispatcher) {
response {
httpClient.get(merchantConfig.urlFor("private/orders/$orderId")) {
@@ -70,7 +70,7 @@ class MerchantApi(
suspend fun deleteOrder(
merchantConfig: MerchantConfig,
- orderId: String
+ orderId: String,
): Response<Unit> = withContext(ioDispatcher) {
response {
httpClient.delete(merchantConfig.urlFor("private/orders/$orderId")) {
@@ -91,7 +91,7 @@ class MerchantApi(
suspend fun giveRefund(
merchantConfig: MerchantConfig,
orderId: String,
- request: RefundRequest
+ request: RefundRequest,
): Response<RefundResponse> = withContext(ioDispatcher) {
response {
httpClient.post(merchantConfig.urlFor("private/orders/$orderId/refund")) {
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 1b63900..6fd0e37 100644
--- a/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt
+++ b/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt
@@ -70,7 +70,7 @@ class Response<out T> private constructor(
}
private suspend fun getExceptionString(e: ResponseException): String {
- val response = e.response ?: return e.toString()
+ val response = e.response
return try {
val error: Error = response.receive()
"Error ${error.code}: ${error.hint}"
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 63188f9..6abacfd 100644
--- a/merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt
+++ b/merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt
@@ -18,8 +18,8 @@ package net.taler.merchantlib
import io.ktor.http.HttpStatusCode.Companion.NotFound
import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.TestCoroutineDispatcher
-import kotlinx.coroutines.test.runBlockingTest
import net.taler.common.ContractProduct
import net.taler.common.ContractTerms
import net.taler.lib.common.Amount
@@ -41,7 +41,7 @@ class MerchantApiTest {
private val orderId = "orderIdFoo"
@Test
- fun testGetConfig() = runBlockingTest {
+ fun testGetConfig() = runBlocking {
httpClient.giveJsonResponse("https://backend.int.taler.net/config") {
"""
{
@@ -56,7 +56,7 @@ class MerchantApiTest {
}
@Test
- fun testPostOrder() = runBlockingTest {
+ fun testPostOrder() = runBlocking {
val product = ContractProduct(
productId = "foo",
description = "bar",
@@ -113,7 +113,7 @@ class MerchantApiTest {
}
@Test
- fun testCheckOrder() = runBlockingTest {
+ fun testCheckOrder() = runBlocking {
val unpaidResponse = CheckPaymentResponse.Unpaid(false, "http://taler.net/foo")
httpClient.giveJsonResponse("http://example.net/instances/testInstance/private/orders/$orderId") {
"""{
@@ -142,7 +142,7 @@ class MerchantApiTest {
}
@Test
- fun testDeleteOrder() = runBlockingTest {
+ fun testDeleteOrder() = runBlocking {
httpClient.giveJsonResponse("http://example.net/instances/testInstance/private/orders/$orderId") {
"{}"
}
@@ -165,7 +165,7 @@ class MerchantApiTest {
}
@Test
- fun testGetOrderHistory() = runBlockingTest {
+ fun testGetOrderHistory() = runBlocking {
httpClient.giveJsonResponse("http://example.net/instances/testInstance/private/orders") {
"""{ "orders": [
{
@@ -215,7 +215,7 @@ class MerchantApiTest {
}
@Test
- fun testGiveRefund() = runBlockingTest {
+ fun testGiveRefund() = runBlocking {
httpClient.giveJsonResponse("http://example.net/instances/testInstance/private/orders/$orderId/refund") {
"""{
"taler_refund_uri": "taler://refund/foo/bar"