commit ae87119aee1cfd663af2e2eec3a22730ff407cc3 parent edfc59fbff80f4c8de276263a77e37e41ca1b01a Author: Iván Ávalos <avalos@disroot.org> Date: Tue, 24 Nov 2026 13:22:21 +0100 [wallet] render "order not found" and "order already claimed" states (fixes #12078) Diffstat:
12 files changed, 73 insertions(+), 24 deletions(-)
diff --git a/wallet/src/main/java/net/taler/wallet/deposit/TransactionDepositComposable.kt b/wallet/src/main/java/net/taler/wallet/deposit/TransactionDepositComposable.kt @@ -105,7 +105,7 @@ fun TransactionDepositComposable( Spacer(Modifier.height(16.dp)) } - TransactionStateComposable(state = t.txState) + TransactionStateComposable(state = t.txState, tx = t) Text( modifier = Modifier.padding(16.dp), diff --git a/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt b/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt @@ -431,14 +431,11 @@ class PaymentManager( } /** - * Called on transaction-state-transition notifications. If the currently - * active payment is deleted by wallet-core with cause "claim-failed" - * (e.g. the merchant rejected or deleted the order), the UI is taken - * out of its loading state and shown the error instead. + * Called on transaction-state-transition notifications. */ @Synchronized fun onTransactionStateTransition(payload: NotificationPayload.TransactionStateTransition) { - if (!payload.isClaimFailureDeletion()) return + if (!payload.isClaimFailureTransition()) return val transactionId = checkNotNull(payload.transactionId) if (transactionId != currentTransactionId) return currentTransactionId = null @@ -446,7 +443,7 @@ class PaymentManager( message = "The order could not be found. Maybe the merchant deleted it.", code = TalerErrorCode.WALLET_MERCHANT_ORDER_NOT_FOUND, ) - Log.e(TAG, "prepared transaction $transactionId deleted by wallet-core: $errorInfo") + Log.e(TAG, "payment $transactionId failed to claim the order: $errorInfo") mPayStatus.postValue(PayStatus.Error(error = errorInfo, transactionId = transactionId)) } @@ -489,14 +486,16 @@ class PaymentManager( } /** - * Matches the deletion notification emitted by wallet-core when a payment - * claim failed, e.g. because the merchant rejected or deleted the order. - * Only this specific state transition is of interest to in-progress - * payments; other deletions must not surface as payment errors. + * Matches the notification emitted by wallet-core when a payment claim + * failed, e.g. because the merchant rejected or deleted the order. */ -internal fun NotificationPayload.TransactionStateTransition.isClaimFailureDeletion(): Boolean = +internal fun NotificationPayload.TransactionStateTransition.isClaimFailureTransition(): Boolean = transactionId != null && causeHint == "claim-failed" && oldTxState?.major == TransactionMajorState.Pending && oldTxState.minor == TransactionMinorState.ClaimProposal && - newTxState?.major == TransactionMajorState.Deleted + newTxState?.let { + it.major == TransactionMajorState.Deleted || + (it.major == TransactionMajorState.Failed && + it.minor == TransactionMinorState.ClaimProposal) + } == true diff --git a/wallet/src/main/java/net/taler/wallet/payment/TransactionPaymentComposable.kt b/wallet/src/main/java/net/taler/wallet/payment/TransactionPaymentComposable.kt @@ -69,6 +69,7 @@ import net.taler.wallet.transactions.TransactionPayment import net.taler.wallet.transactions.TransactionState import net.taler.wallet.transactions.TransactionStateComposable import net.taler.wallet.transactions.TransitionsComposable +import net.taler.wallet.transactions.failureReason @Composable fun TransactionPaymentComposable( @@ -110,7 +111,7 @@ fun TransactionPaymentComposable( .verticalScroll(scrollState), horizontalAlignment = CenterHorizontally, ) { - TransactionStateComposable(state = t.txState) + TransactionStateComposable(state = t.txState, tx = t) Text( modifier = Modifier.padding(16.dp), @@ -156,7 +157,7 @@ fun TransactionPaymentComposable( onFulfill(t.info.fulfillmentUrl ?: "") } - if (t.error != null) { + if (t.failureReason != null) { ErrorTransactionButton(onShowError = onShowError) } TransitionsComposable(t, devMode, onTransition) diff --git a/wallet/src/main/java/net/taler/wallet/refund/TransactionRefundComposable.kt b/wallet/src/main/java/net/taler/wallet/refund/TransactionRefundComposable.kt @@ -69,7 +69,7 @@ fun TransactionRefundComposable( .verticalScroll(scrollState), horizontalAlignment = CenterHorizontally, ) { - TransactionStateComposable(state = t.txState) + TransactionStateComposable(state = t.txState, tx = t) Text( modifier = Modifier.padding(16.dp), diff --git a/wallet/src/main/java/net/taler/wallet/transactions/LegacyTransactionsComposable.kt b/wallet/src/main/java/net/taler/wallet/transactions/LegacyTransactionsComposable.kt @@ -430,7 +430,13 @@ fun LegacyTransactionExtraInfo(tx: Transaction) { ) tx.txState.major == Failed -> Text( - stringResource(R.string.payment_failed), + stringResource( + when (tx.failureReason?.code) { + TalerErrorCode.WALLET_ORDER_ALREADY_CLAIMED -> R.string.payment_order_already_claimed + TalerErrorCode.WALLET_MERCHANT_ORDER_NOT_FOUND -> R.string.payment_order_not_found + else -> R.string.payment_failed + } + ), color = MaterialTheme.colorScheme.error, ) diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionDetailScreen.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionDetailScreen.kt @@ -18,7 +18,6 @@ package net.taler.wallet.transactions import android.content.Context import android.util.Log -import androidx.collection.intSetOf import androidx.compose.foundation.basicMarquee import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -232,7 +231,7 @@ fun TransactionDetailScreen( model.paymentManager.checkDonauForChoice(choice) }, onShowError = { - tx.error?.let { onShowError(it) } + tx.failureReason?.let { onShowError(it) } }, ) } @@ -412,7 +411,7 @@ fun TransactionRefreshComposable( .verticalScroll(scrollState), horizontalAlignment = Alignment.CenterHorizontally, ) { - TransactionStateComposable(state = t.txState) + TransactionStateComposable(state = t.txState, tx = t) Text( modifier = Modifier.padding(16.dp), @@ -452,7 +451,7 @@ fun TransactionPeerComposable( .verticalScroll(scrollState), horizontalAlignment = Alignment.CenterHorizontally, ) { - TransactionStateComposable(state = t.txState) + TransactionStateComposable(state = t.txState, tx = t) Text( modifier = Modifier.padding(16.dp), @@ -493,7 +492,7 @@ fun TransitionLossComposable( .verticalScroll(scrollState), horizontalAlignment = Alignment.CenterHorizontally, ) { - TransactionStateComposable(state = t.txState) + TransactionStateComposable(state = t.txState, tx = t) Text( modifier = Modifier.padding(16.dp), diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionStateComposable.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionStateComposable.kt @@ -34,6 +34,8 @@ import net.taler.common.RelativeTime import net.taler.common.Timestamp import net.taler.lib.android.toAbsoluteTime import net.taler.wallet.R +import net.taler.wallet.backend.TalerErrorCode +import net.taler.wallet.backend.TalerErrorInfo import net.taler.wallet.balances.ScopeInfo import net.taler.wallet.compose.Banner import net.taler.wallet.compose.TalerSurface @@ -54,6 +56,7 @@ import net.taler.wallet.transactions.TransactionMinorState.KycRequired import net.taler.wallet.transactions.TransactionMinorState.Repurchase import net.taler.wallet.transactions.WithdrawalDetails.ManualTransfer import net.taler.wallet.ui.theme.TalerTheme +import kotlin.concurrent.timer @Composable fun TransactionStateComposable( @@ -79,7 +82,11 @@ fun TransactionStateComposable( TransactionState(Aborting) -> stringResource(R.string.transaction_state_aborting) TransactionState(Suspended) -> stringResource(R.string.transaction_state_suspended) TransactionState(Failed, Repurchase) -> stringResource(R.string.payment_already_paid) - TransactionState(Failed) -> stringResource(R.string.transaction_state_failed) + TransactionState(Failed) -> when (tx?.failureReason?.code) { + TalerErrorCode.WALLET_ORDER_ALREADY_CLAIMED -> stringResource(R.string.payment_order_already_claimed) + TalerErrorCode.WALLET_MERCHANT_ORDER_NOT_FOUND -> stringResource(R.string.payment_order_not_found) + else -> stringResource(R.string.transaction_state_failed) + } TransactionState(Finalizing) -> stringResource(R.string.transaction_state_finalizing) TransactionState(Expired) -> stringResource(R.string.transaction_state_expired) else -> return @@ -142,6 +149,14 @@ fun TransactionStateComposablePreview() { TransactionStateComposable(modifier, state = TransactionState(Suspended)) TransactionStateComposable(modifier, state = TransactionState(Failed, Repurchase)) TransactionStateComposable(modifier, state = TransactionState(Failed)) + TransactionStateComposable(modifier, state = TransactionState(Failed), DummyTransaction( + transactionId = "txn:123", + timestamp = Timestamp.now(), + error = TalerErrorInfo(code = TalerErrorCode.WALLET_ORDER_ALREADY_CLAIMED))) + TransactionStateComposable(modifier, state = TransactionState(Failed), DummyTransaction( + transactionId = "txn:123", + timestamp = Timestamp.now(), + error = TalerErrorInfo(code = TalerErrorCode.WALLET_MERCHANT_ORDER_NOT_FOUND))) TransactionStateComposable(modifier, state = TransactionState(Finalizing)) TransactionStateComposable(modifier, state = TransactionState(Expired)) TransactionStateComposable(modifier, state = TransactionState(Done)) diff --git a/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt b/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt @@ -132,6 +132,17 @@ sealed class Transaction { abstract val generalTitleRes: Int } +/** + * The error to present for this transaction. wallet-core reports terminal + * failures in [TransactionPayment.failReason] and keeps [Transaction.error] + * for the last retryable error, so prefer the former when both are present. + */ +val Transaction.failureReason: TalerErrorInfo? + get() = when (this) { + is TransactionPayment -> failReason ?: error + else -> error + } + @Serializable enum class TransactionAction { // Common States @@ -448,6 +459,12 @@ data class TransactionPayment( override val txActions: List<TransactionAction>, val info: TransactionInfo? = null, override val error: TalerErrorInfo? = null, + /** + * Terminal failure reason reported by wallet-core. Unlike [error], which + * only holds the last retryable error, this is set when wallet-core gives + * up on the transaction (e.g. "order already claimed"). + */ + val failReason: TalerErrorInfo? = null, override val amountRaw: Amount, override val amountEffective: Amount, override val scopes: List<ScopeInfo>, diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsComposable.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsComposable.kt @@ -419,7 +419,13 @@ fun TransactionExtraInfo(tx: Transaction) { ) tx.txState.major == Failed -> Text( - stringResource(R.string.payment_failed), + stringResource( + when (tx.failureReason?.code) { + TalerErrorCode.WALLET_ORDER_ALREADY_CLAIMED -> R.string.payment_order_already_claimed + TalerErrorCode.WALLET_MERCHANT_ORDER_NOT_FOUND -> R.string.payment_order_not_found + else -> R.string.payment_failed + } + ), color = MaterialTheme.colorScheme.error, ) diff --git a/wallet/src/main/res/values-de/strings.xml b/wallet/src/main/res/values-de/strings.xml @@ -123,6 +123,7 @@ <string name="transactions_delete_dialog_title">Transaktion löschen</string> <string name="receive_peer_payment_intro">Möchten Sie diese Zahlung erhalten?</string> <string name="transactions_abort">Abbruch ausführen</string> + <string name="payment_order_not_found">Diese Bestellung existiert nicht mehr oder ist abgelaufen</string> <string name="payment_pay_template_title">Passen Sie Ihre Bestellung an</string> <string name="send_deposit_title">Einzahlung an Bankkonto</string> <string name="withdraw_manual_ready_account">Konto</string> @@ -456,4 +457,5 @@ <string name="token_valid_from">Gültig ab %1$s</string> <string name="tokens_filter_available">Gültig</string> <string name="tokens_filter_expired">Abgelaufen</string> + <string name="payment_order_already_claimed">Diese Bestellung wurde bereits von einer anderen Wallet beansprucht</string> </resources> diff --git a/wallet/src/main/res/values-fr/strings.xml b/wallet/src/main/res/values-fr/strings.xml @@ -180,6 +180,7 @@ <string name="amount_received">Montant reçu</string> <string name="amount_sent">Montant envoyé</string> <string name="transactions_retry">Réessayez</string> + <string name="payment_order_not_found">Cette commande n\'existe plus ou a expiré</string> <string name="payment_pay_template_title">Personnalisez votre commande</string> <string name="send_peer_expiration_30d">30 jours</string> <string name="transaction_dummy_title">Transaction inconnue</string> @@ -411,4 +412,5 @@ <string name="token_valid_from">Valable dès le %1$s</string> <string name="tokens_filter_available">Valide</string> <string name="tokens_filter_expired">Expiré</string> + <string name="payment_order_already_claimed">Cette commande a déjà été réclamée par un autre portefeuille</string> </resources> diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml @@ -305,6 +305,8 @@ GNU Taler is immune to many types of fraud such as credit card data theft, phish <string name="payment_failed">Failed</string> <string name="payment_fee">+%s payment fee</string> <string name="payment_label_order_summary">Purchase</string> + <string name="payment_order_already_claimed">This order was already claimed by another wallet</string> + <string name="payment_order_not_found">This order no longer exists or has expired</string> <string name="payment_pay_template_title">Customize your order</string> <!-- <quantity> × <price> --> <string name="payment_product_price_quantity">%1$s × %2$s</string>