taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

force-delete-blames-a-wallet.md (5910B)


      1 <!--
      2   This file is part of GNU Taler
      3   (C) 2026 Taler Systems S.A.
      4 
      5   GNU Taler is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13   You should have received a copy of the GNU General Public License along with
     14   GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 -->
     16 
     17 # Every failed delete says a wallet claimed the order
     18 
     19 Cancel an order, have the DELETE fail for any reason at all, and the terminal
     20 tells the cashier this:
     21 
     22 ![The force-delete dialog](images/force-delete-blames-a-wallet.png)
     23 
     24 ```
     25 Force delete order?
     26 This order has been claimed by a wallet. Force deleting it will release any
     27 inventory locks and prevent the wallet from completing the payment.
     28 [Cancel payment] [Force delete]
     29 ```
     30 
     31 No wallet had claimed it. The episode records the dialog and the backend's own
     32 view of the same order, seconds apart:
     33 
     34 ```
     35 order on screen: 2026.313-ZHY9Z0163KAHM
     36 backend on 2026.313-ZHY9Z0163KAHM: order_status='unpaid'
     37 after cancelling: Force delete order? | This order has been claimed by a wallet. ...
     38 ```
     39 
     40 The order was never claimed and was still there afterwards: "Cancel order"
     41 left a live order behind while telling the cashier a wallet had taken it.
     42 
     43 ## Why it happens
     44 
     45 `payment/PaymentManager.kt`, `tryDeleteOrder()`:
     46 
     47 ```kotlin
     48 val result = api.deleteOrder(merchantConfig, orderId)
     49 result.handle(
     50     onFailure = { errorStr ->
     51         Log.w(TAG, "Delete order $orderId failed: $errorStr")
     52         mDeleteNeedsForce.postValue(true)        // <- every failure
     53     },
     54 ```
     55 
     56 The reason is logged and thrown away. `ProcessPaymentFragment` turns the flag
     57 straight into the dialog, whose message is `force_delete_dialog_message`. So a
     58 network error, a 5xx, an expired token and a 404 are all reported as a claim.
     59 
     60 `history/HistoryManager.kt`, `deleteOrder()`, has the same shape and does not
     61 even bind the error:
     62 
     63 ```kotlin
     64 api.deleteOrder(merchantConfig, orderId).handle(
     65     { _ ->
     66         assertUiThread()
     67         mIsLoading.value = false
     68         mForceDeleteOrderId.value = orderId      // <- every failure
     69     }
     70 ```
     71 
     72 The backend distinguishes these: 404 for an unknown order, 409 for
     73 already-paid, awaiting-payment (the claim) and externally-paid. Only a 409 is
     74 a refusal `force` can override.
     75 
     76 **The correct pattern is twenty lines above the second one.**
     77 `HistoryManager.deleteConfirmedOrder()` asks first and derives `force` from
     78 the answer:
     79 
     80 ```kotlin
     81 api.checkOrder(config, item.orderId).handle({ error = it }) { current = it }
     82 …
     83 val force =
     84     checked is CheckPaymentResponse.Claimed ||
     85         (checked.paymentDetails?.amountExternal?.isNotEmpty() ?: item.hasExternalPayments)
     86 ```
     87 
     88 ## Severity
     89 
     90 Medium to high, and it is wrong information rather than a cosmetic slip. A
     91 till on shop Wi-Fi loses its backend routinely; an expired token and a 502 are
     92 ordinary. In every one of those cases a cashier standing in front of a
     93 customer is told a wallet may be paying, so cancelling might strand a payment
     94 — and the one fact the decision rests on is untrue.
     95 
     96 It does not end there. Pressing **Force delete** sends the same request over
     97 the same broken transport, reports failure only to `Log.w`, and navigates back
     98 regardless: no error, and the order survives. Pressing **Cancel payment**
     99 returns to the payment screen with no message at all.
    100 
    101 ## How it was found
    102 
    103 `fault_insecure_pay_uri_cancel` takes the "Cancel order" branch of the
    104 insecure-pay-URI dialog. The delete fails there for an incidental reason —
    105 see the harness note below — but the defect is independent of it: the terminal
    106 never looks at *why*.
    107 
    108 Three consecutive reproductions, same screen each time. The scenario now
    109 records the order id and asks the backend about it, so the contradiction is in
    110 the artifact rather than in somebody's memory.
    111 
    112 ## Suggested fix
    113 
    114 `force-delete-blames-a-wallet.diff`, verified on the emulator. `Response`
    115 gains the status code it already holds but does not expose, and the force
    116 prompt is raised only on 409:
    117 
    118 ```kotlin
    119 val statusCode: Int?
    120     get() = ((value as? Failure)?.exception as? ResponseException)
    121         ?.response?.status?.value
    122 …
    123 val needsForce = result.statusCode == 409
    124 ```
    125 
    126 with the other branch surfacing the real error — through `mPayment.error` on
    127 the payment screen, through the existing `error_delete_order` string in the
    128 history list.
    129 
    130 After the patch the same sequence says:
    131 
    132 ```
    133 Error: No payment received | Network error: check your internet connection
    134 and merchant URL. | OK
    135 ```
    136 
    137 and the backend still reports that order `unpaid`, which is the truth.
    138 `:merchant-terminal:testSimUnitTest` and `:merchant-lib:test` pass.
    139 
    140 Left out of the patch because they want a decision rather than a fix:
    141 409/2521 (`ALREADY_PAID`) and 409/2537 (`EXTERNALLY_PAID`) also reach the
    142 "claimed by a wallet" wording, so the message could be split by error code;
    143 and `forceDeleteOrder` should report its own failure instead of navigating
    144 back on hope.
    145 
    146 Filed as [11977](https://bugs.gnunet.org/view?id=11977).
    147 
    148 ## A harness note that matters for every `fault_*` scenario
    149 
    150 **`taler-twister` cannot proxy DELETE.** `taler-twister-service.c` handles
    151 PUT, POST and GET and answers anything else with
    152 
    153 ```
    154 WARNING Unsupported HTTP method `DELETE'
    155 ```
    156 
    157 closing the connection without a reply. So a DELETE through twister always
    158 fails, armed or not — which is what made this path fail, and which means
    159 `fault_insecure_pay_uri_cancel` can never observe a *successful* cancel. Any
    160 fault scenario that needs a delete to reach the backend is in the same
    161 position.