diff options
author | Torsten Grote <t@grobox.de> | 2020-07-23 11:54:34 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2020-07-23 11:54:34 -0300 |
commit | 08b10a2408f958cae96ae0c674ee450a35109e8a (patch) | |
tree | d4bee31f1b007ca94f2dfe90b4e47b866481fe46 /merchant-terminal | |
parent | a8c811f6cdf4bf1b787ebaaa9fd220588fd1ffcf (diff) | |
download | taler-android-08b10a2408f958cae96ae0c674ee450a35109e8a.tar.gz taler-android-08b10a2408f958cae96ae0c674ee450a35109e8a.tar.bz2 taler-android-08b10a2408f958cae96ae0c674ee450a35109e8a.zip |
[pos] delete unpaid/unclaimed orders when user cancels or timeout happens
This is still not working due to a bug in the merchant API
Diffstat (limited to 'merchant-terminal')
-rw-r--r-- | merchant-terminal/src/main/java/net/taler/merchantpos/payment/PaymentManager.kt | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/merchant-terminal/src/main/java/net/taler/merchantpos/payment/PaymentManager.kt b/merchant-terminal/src/main/java/net/taler/merchantpos/payment/PaymentManager.kt index e238284..ea16cb4 100644 --- a/merchant-terminal/src/main/java/net/taler/merchantpos/payment/PaymentManager.kt +++ b/merchant-terminal/src/main/java/net/taler/merchantpos/payment/PaymentManager.kt @@ -18,6 +18,7 @@ package net.taler.merchantpos.payment import android.content.Context import android.os.CountDownTimer +import android.util.Log import androidx.annotation.UiThread import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData @@ -27,6 +28,7 @@ import kotlinx.coroutines.launch import net.taler.merchantlib.CheckPaymentResponse import net.taler.merchantlib.MerchantApi import net.taler.merchantlib.PostOrderResponse +import net.taler.merchantpos.MainActivity.Companion.TAG import net.taler.merchantpos.R import net.taler.merchantpos.config.ConfigManager import net.taler.merchantpos.order.Order @@ -54,8 +56,7 @@ class PaymentManager( } override fun onFinish() { - val str = context.getString(R.string.error_timeout) - payment.value?.copy(error = str)?.let { mPayment.value = it } + cancelPayment(context.getString(R.string.error_timeout)) } } @@ -97,7 +98,19 @@ class PaymentManager( cancelPayment(error) } + @UiThread fun cancelPayment(error: String) { + // delete unpaid order + val merchantConfig = configManager.merchantConfig!! + mPayment.value?.let { payment -> + if (!payment.paid) payment.orderId?.let { orderId -> + Log.e(TAG, "Deleting cancelled and unpaid order $orderId") + scope.launch(Dispatchers.IO) { + api.deleteOrder(merchantConfig.convert(), orderId) + } + } + } + mPayment.value = mPayment.value!!.copy(error = error) checkTimer.cancel() } |