Class: Portage::Ucp::Confirmer::Terminal
- Inherits:
-
Object
- Object
- Portage::Ucp::Confirmer::Terminal
- Defined in:
- lib/portage/ucp/confirmer.rb
Overview
Blocks the CLI process on stdin: "Approve? [y/N]". Fail-closed — no
answer within timeout_seconds denies, same as an explicit "n",
never leaves a payment pending on an agent that's still waiting.
Checkout staleness while the operator was thinking isn't handled
here: the confirmed amount is re-validated by nothing in this class,
but the adapter call call_adapter makes right after this passes
hits the real backend, which is the thing that'd reject a checkout
that expired mid-wait — no separate re-check needed.
Constant Summary collapse
- DEFAULT_TIMEOUT_SECONDS =
120
Instance Method Summary collapse
-
#confirm!(amount:, currency:, merchant:, idempotency_key:) ⇒ Hash
{approved: true}on "y". -
#initialize(timeout_seconds: DEFAULT_TIMEOUT_SECONDS, input: $stdin, output: $stdout) ⇒ Terminal
constructor
A new instance of Terminal.
Constructor Details
#initialize(timeout_seconds: DEFAULT_TIMEOUT_SECONDS, input: $stdin, output: $stdout) ⇒ Terminal
Returns a new instance of Terminal.
27 28 29 30 31 |
# File 'lib/portage/ucp/confirmer.rb', line 27 def initialize(timeout_seconds: DEFAULT_TIMEOUT_SECONDS, input: $stdin, output: $stdout) @timeout_seconds = timeout_seconds @input = input @output = output end |
Instance Method Details
#confirm!(amount:, currency:, merchant:, idempotency_key:) ⇒ Hash
Returns {approved: true} on "y".
37 38 39 40 41 42 43 44 45 |
# File 'lib/portage/ucp/confirmer.rb', line 37 def confirm!(amount:, currency:, merchant:, idempotency_key:) @output.print("Approve payment of #{amount} #{currency} to #{merchant.inspect}? [y/N] ") @output.flush answer = read_with_timeout return { approved: true } if answer&.strip&.downcase == "y" deny!(answer.nil? ? :timeout : :denied, idempotency_key) end |