Skip to content

feat: add "custom" internally settled fiat method - #245

Open
cashowdev wants to merge 1 commit into
lnbits:mainfrom
cashowdev:feat/custom-fiat-method
Open

feat: add "custom" internally settled fiat method#245
cashowdev wants to merge 1 commit into
lnbits:mainfrom
cashowdev:feat/custom-fiat-method

Conversation

@cashowdev

Copy link
Copy Markdown

HUMAN WARNING: This PR is entirely AI generated

Remain cautious before merging current PR ...

What

Adds a second internally settled fiat method, custom, alongside the existing
cash settlement.

It follows exactly the same flow: an internal invoice is created and a cashier
confirms it manually. The only difference is that it records
fiat_method: "custom" instead of "cash", so the two can be told apart in
payment history, on receipts and in the Orders extension.

Why

Merchants regularly take a payment through a channel LNbits does not integrate
with: a bank transfer, a voucher, a staff tab, a partner app. Today the only way
to get that into the till total is to book it as cash, which then makes the cash
figure wrong at the end of the day. A second, neutrally named method keeps the
books straight without pretending to be a payment integration.

How

Rather than duplicating every cash branch, the literal "cash" checks are
replaced by a shared tuple in helpers.py:

INTERNAL_FIAT_METHODS = ("cash", "custom")

Adding a third administrative method later is then a one line change plus a
button, not another pass through the codebase.

Backend:

  • helpers.py: INTERNAL_FIAT_METHODS and a label colour per method
  • views_payments.py: invoice creation, _payment_method_from_payment and
    _serialize_tpos_invoice_response work on the tuple
  • views_payments.py: validation extracted into
    _validate_internal_fiat_invoice. The existing POST .../cash/validate
    route is unchanged; POST .../custom/validate sits next to it
  • tasks.py: _payment_method reports custom. _tabs_settlement_method
    falls through to other, which is the right bucket for this method
  • checking_id becomes internal_custom_<hash> instead of
    internal_cash_<hash>

Frontend:

  • payment-method-selector.js: Custom button, same visibility rule as cash.
    Currency symbol plus the more_horiz icon, since qr_code, toll and
    credit_card are already taken
  • tpos.js: an internalFiatMethod computed drives both the confirmation
    dialog title and which validation route is called
  • dialogs.html: the confirmation dialog shows CUSTOM <currency> or
    CASH <currency>

Tests

test_custom_validate_invoice_endpoint in tests/test_api.py, mirroring the
existing cash test. It also asserts that /cash/validate rejects a custom
invoice with a 400, so the two routes cannot be used interchangeably.

Backwards compatibility

Nothing existing changes behaviour. /cash/validate keeps its path and its
semantics, fiat_method: "cash" payments are unaffected, and no migration is
needed.

Important note

custom currently reuses the allow_cash_settlement toggle and the same
super user requirement, so it needs no schema change.

Adds a second administrative payment method alongside the existing cash
settlement. It follows exactly the same flow, an internal invoice that a
cashier confirms manually, but records fiat_method "custom" instead of
"cash", so operators can tell the two apart in payment history, receipts
and the Orders extension.

The use case is a payment received through a channel LNbits does not
integrate with, for example a bank transfer, a voucher or a staff tab,
that still has to end up in the till total.

Rather than duplicating the cash branches, the literal "cash" checks are
replaced by a shared INTERNAL_FIAT_METHODS tuple in helpers.py, so adding
another method later is a one line change.

- helpers.py: INTERNAL_FIAT_METHODS and a label colour per method
- views_payments.py: invoice creation, _payment_method_from_payment and
  _serialize_tpos_invoice_response now work on that tuple
- views_payments.py: validation logic extracted into
  _validate_internal_fiat_invoice, with the existing /cash/validate route
  unchanged and a new /custom/validate route next to it
- tasks.py: _payment_method reports "custom"; _tabs_settlement_method
  falls through to "other", which is correct for this method
- checking_id becomes internal_custom_<hash> instead of internal_cash_<hash>
- payment-method-selector.js: Custom button, same visibility rule as cash
- tpos.js: internalFiatMethod computed drives both the dialog title and
  the validation route
- dialogs.html: the confirmation dialog shows CUSTOM or CASH
- tests: test_custom_validate_invoice_endpoint, mirroring the cash test,
  and asserting that /cash/validate rejects a custom invoice

Custom reuses the allow_cash_settlement toggle and the same super user
requirement. A separate per TPoS toggle would need a migration; happy to
add one if you prefer that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant