force-delete-blames-a-wallet.diff (4157B)
1 diff --git a/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt b/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt 2 index b91e0723..c49eb345 100644 3 --- a/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt 4 +++ b/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt 5 @@ -56,6 +56,15 @@ class Response<out T> private constructor( 6 7 val isFailure: Boolean get() = value is Failure 8 9 + /** 10 + * The HTTP status the backend answered with, or null when the request never 11 + * got an answer at all (a network error) or succeeded. Callers that have to 12 + * tell one kind of failure from another need this: the message cannot. 13 + */ 14 + val statusCode: Int? 15 + get() = ((value as? Failure)?.exception as? ResponseException) 16 + ?.response?.status?.value 17 + 18 suspend fun handle(onFailure: ((String) -> Unit)? = null, onSuccess: ((T) -> Unit)? = null) { 19 if (value is Failure) onFailure?.let { it(getFailureString(value)) } 20 else onSuccess?.let { 21 diff --git a/merchant-terminal/src/main/java/net/taler/merchantpos/history/HistoryManager.kt b/merchant-terminal/src/main/java/net/taler/merchantpos/history/HistoryManager.kt 22 index 1b8e27a2..41ac8c44 100644 23 --- a/merchant-terminal/src/main/java/net/taler/merchantpos/history/HistoryManager.kt 24 +++ b/merchant-terminal/src/main/java/net/taler/merchantpos/history/HistoryManager.kt 25 @@ -233,11 +233,22 @@ class HistoryManager( 26 mIsLoading.value = true 27 mIsLoadingMore.value = false 28 val merchantConfig = configManager.merchantConfig!! 29 - api.deleteOrder(merchantConfig, orderId).handle( 30 - { _ -> 31 + val result = api.deleteOrder(merchantConfig, orderId) 32 + // Same as on the payment screen: only a 409 is a claim that force can 33 + // override, so only a 409 may raise the force-delete prompt. 34 + val needsForce = result.statusCode == 409 35 + result.handle( 36 + { errorMsg -> 37 assertUiThread() 38 mIsLoading.value = false 39 - mForceDeleteOrderId.value = orderId 40 + if (needsForce) 41 + { 42 + mForceDeleteOrderId.value = orderId 43 + } 44 + else 45 + { 46 + onError(R.string.error_delete_order, errorMsg) 47 + } 48 } 49 ) { 50 assertUiThread() 51 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 52 index 91672e4f..9934d9c5 100644 53 --- a/merchant-terminal/src/main/java/net/taler/merchantpos/payment/PaymentManager.kt 54 +++ b/merchant-terminal/src/main/java/net/taler/merchantpos/payment/PaymentManager.kt 55 @@ -402,10 +402,23 @@ class PaymentManager( 56 val orderId = mPayment.value?.orderId ?: return 57 scope.launch { 58 val result = api.deleteOrder(merchantConfig, orderId) 59 + // Only a 409 is the backend refusing because the order is claimed or 60 + // already paid. Every other failure -- no network, a 5xx, an expired 61 + // token -- is a failure of the request itself, which force cannot fix 62 + // and which must not be reported to the cashier as a wallet's claim. 63 + val needsForce = result.statusCode == 409 64 result.handle( 65 onFailure = { errorStr -> 66 Log.w(TAG, "Delete order $orderId failed: $errorStr") 67 - mDeleteNeedsForce.postValue(true) 68 + if (needsForce) 69 + { 70 + mDeleteNeedsForce.postValue(true) 71 + } 72 + else 73 + { 74 + mPayment.postValue(mPayment.value?.copy(error = errorStr)) 75 + mDeleteNeedsForce.postValue(null) 76 + } 77 }, 78 onSuccess = { 79 Log.d(TAG, "Delete order $orderId succeeded")