From 21c79819fa6aad2bf9c68bd03faa273ff450ca56 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Fri, 5 Feb 2021 13:49:51 -0300 Subject: [pos] Remove QR code once order has been claimed --- .../java/net/taler/merchantpos/payment/Payment.kt | 1 + .../net/taler/merchantpos/payment/PaymentManager.kt | 19 ++++++++++++------- .../merchantpos/payment/ProcessPaymentFragment.kt | 20 ++++++++++++-------- merchant-terminal/src/main/res/values/strings.xml | 1 + 4 files changed, 26 insertions(+), 15 deletions(-) (limited to 'merchant-terminal') diff --git a/merchant-terminal/src/main/java/net/taler/merchantpos/payment/Payment.kt b/merchant-terminal/src/main/java/net/taler/merchantpos/payment/Payment.kt index 9200ced..b3ff14b 100644 --- a/merchant-terminal/src/main/java/net/taler/merchantpos/payment/Payment.kt +++ b/merchant-terminal/src/main/java/net/taler/merchantpos/payment/Payment.kt @@ -24,6 +24,7 @@ data class Payment( val currency: String, val orderId: String? = null, val talerPayUri: String? = null, + val claimed: Boolean = false, val paid: Boolean = false, val error: String? = null ) 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 b017726..98161db 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 @@ -46,7 +46,7 @@ class PaymentManager( private val context: Context, private val configManager: ConfigManager, private val scope: CoroutineScope, - private val api: MerchantApi + private val api: MerchantApi, ) { private val mPayment = MutableLiveData() @@ -89,12 +89,17 @@ class PaymentManager( assertUiThread() if (!isActive) return@handle // don't continue if job was cancelled val currentValue = requireNotNull(mPayment.value) - if (response.paid) { - mPayment.value = currentValue.copy(paid = true) - checkTimer.cancel() - } else if (currentValue.talerPayUri == null) { - response as CheckPaymentResponse.Unpaid - mPayment.value = currentValue.copy(talerPayUri = response.talerPayUri) + when (response) { + is CheckPaymentResponse.Unpaid -> { + mPayment.value = currentValue.copy(talerPayUri = response.talerPayUri) + } + is CheckPaymentResponse.Claimed -> { + mPayment.value = currentValue.copy(claimed = true) + } + is CheckPaymentResponse.Paid -> { + mPayment.value = currentValue.copy(paid = true) + checkTimer.cancel() + } } } } diff --git a/merchant-terminal/src/main/java/net/taler/merchantpos/payment/ProcessPaymentFragment.kt b/merchant-terminal/src/main/java/net/taler/merchantpos/payment/ProcessPaymentFragment.kt index dc5d554..201c9cf 100644 --- a/merchant-terminal/src/main/java/net/taler/merchantpos/payment/ProcessPaymentFragment.kt +++ b/merchant-terminal/src/main/java/net/taler/merchantpos/payment/ProcessPaymentFragment.kt @@ -45,8 +45,8 @@ class ProcessPaymentFragment : Fragment() { override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { + savedInstanceState: Bundle?, + ): View { ui = FragmentProcessPaymentBinding.inflate(inflater, container, false) return ui.root } @@ -79,18 +79,22 @@ class ProcessPaymentFragment : Fragment() { navigate(actionProcessPaymentToPaymentSuccess()) return } + if (payment.claimed) { + ui.qrcodeView.fadeOut() + ui.payIntroView.setText(R.string.payment_claimed) + } else { + payment.talerPayUri?.let { + ui.qrcodeView.setImageBitmap(makeQrCode(it)) + ui.qrcodeView.fadeIn() + ui.progressBar.fadeOut() + } + } ui.payIntroView.fadeIn() ui.amountView.text = payment.order.total.toString() payment.orderId?.let { ui.orderRefView.text = getString(R.string.payment_order_id, it) ui.orderRefView.fadeIn() } - payment.talerPayUri?.let { - val qrcodeBitmap = makeQrCode(it) - ui.qrcodeView.setImageBitmap(qrcodeBitmap) - ui.qrcodeView.fadeIn() - ui.progressBar.fadeOut() - } } private fun onPaymentCancel() { diff --git a/merchant-terminal/src/main/res/values/strings.xml b/merchant-terminal/src/main/res/values/strings.xml index bee3cd4..f06866d 100644 --- a/merchant-terminal/src/main/res/values/strings.xml +++ b/merchant-terminal/src/main/res/values/strings.xml @@ -38,6 +38,7 @@ Please let customer scan QR Code or use NFC to pay. Please let customer scan QR Code to pay. + Waiting for customer to confirm payment… Cancel payment Payment received Continue -- cgit v1.2.3