summaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-08-12 13:23:31 -0300
committerTorsten Grote <t@grobox.de>2020-08-12 13:23:31 -0300
commit038673c5ddb97c4b02fe0064758f6301ffcc2a6f (patch)
tree07367c29c8426533e880fb092ab72fe1b434a427 /wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
parent2d23935587d0efe8f1ebc13985988b3ea369e4dd (diff)
downloadtaler-android-038673c5ddb97c4b02fe0064758f6301ffcc2a6f.tar.gz
taler-android-038673c5ddb97c4b02fe0064758f6301ffcc2a6f.tar.bz2
taler-android-038673c5ddb97c4b02fe0064758f6301ffcc2a6f.zip
[wallet] adapt to new Refund API
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt')
-rw-r--r--wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt35
1 files changed, 25 insertions, 10 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt b/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
index 5593486..fdacb0d 100644
--- a/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
@@ -19,28 +19,43 @@ package net.taler.wallet.refund
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.launch
+import kotlinx.serialization.Serializable
+import net.taler.common.Amount
import net.taler.wallet.TAG
import net.taler.wallet.backend.WalletBackendApi
-import org.json.JSONObject
sealed class RefundStatus {
object Error : RefundStatus()
- object Success : RefundStatus()
+ data class Success(val response: RefundResponse) : RefundStatus()
}
-class RefundManager(private val walletBackendApi: WalletBackendApi) {
+@Serializable
+data class RefundResponse(
+ val amountEffectivePaid: Amount,
+ val amountRefundGranted: Amount,
+ val amountRefundGone: Amount,
+ val pendingAtExchange: Boolean
+)
+
+class RefundManager(
+ private val api: WalletBackendApi,
+ private val scope: CoroutineScope
+) {
fun refund(refundUri: String): LiveData<RefundStatus> {
val liveData = MutableLiveData<RefundStatus>()
- val args = JSONObject().also { it.put("talerRefundUri", refundUri) }
- walletBackendApi.sendRequest("applyRefund", args) { isError, result ->
- if (isError) {
- Log.e(TAG, "Refund Error: $result")
+ scope.launch {
+ api.request("applyRefund", RefundResponse.serializer()) {
+ put("talerRefundUri", refundUri)
+ }.onError {
+ Log.e(TAG, "Refund Error: $it")
// TODO show error string
liveData.postValue(RefundStatus.Error)
- } else {
- Log.e(TAG, "Refund Success: $result")
- liveData.postValue(RefundStatus.Success)
+ }.onSuccess {
+ Log.e(TAG, "Refund Success: $it")
+ liveData.postValue(RefundStatus.Success(it))
}
}
return liveData