Skip to content

Typed response DTOs for LNURL pay-params & invoice #34

Description

@Chemaclass

Context

The two LNURL responses are built as loosely-typed associative arrays, documented only via array-shape docblocks:

  • src/Invoice/Application/CallbackUrl.php — returns the pay-params array.
  • src/Invoice/Application/InvoiceGenerator.phpmapResponseAsArray() returns the invoice array; generateInvoice() also returns the {status, reason} error array.
  • src/Invoice/InvoiceFacade.php — array-shape docblocks on both methods.

Goal

Introduce typed, immutable response value objects (implementing JsonSerializable) for the pay-params and invoice responses, so construction is type-checked and adding protocol fields (comment/successAction/nostr) is safe — while serializing to the exact same JSON.

Scope / Tasks

  • Add readonly DTOs, e.g. PayRequestResponse and InvoiceResponse (+ an error representation), implementing JsonSerializable to emit the current keys/shape byte-for-byte (pr, status, memo, successAction, routes, disposable, error; and callback, maxSendable, minSendable, metadata, tag, commentAllowed).
  • Build responses via the DTOs in CallbackUrl / InvoiceGenerator. JsonResponse in the controller already JSON-encodes; passing a JsonSerializable must produce identical output.
  • Replace the array-shape docblocks on the facade/generator with the DTO return types (or keep facade returning arrays via jsonSerialize() if that's cleaner for consumers — decide and document).
  • Update tests to assert against the serialized shape (unchanged JSON).

Implementation notes

  • The serialized JSON MUST stay identical (this is a wire contract used by wallets) — assert equality against the current expected arrays.
  • Keep DTOs in src/Shared/Transfer/ or an Application/Response/ namespace consistent with the module layout.
  • This is a refactor: no behavior/wire change, purely internal typing + DX.

Acceptance criteria

  • Responses are constructed from typed DTOs; JSON output is byte-identical to today.
  • Facade consumers get precise types (DTO or a typed array shape).
  • composer test-all green.

Out of scope

  • Adding new fields (covered by the LUD/Nostr issues) — this only re-types the existing shape.

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactoringRefactoring or cleaning related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions