Receive a payment

Future<({String invoice, String hash})> createInvoice(breez.BreezSdk sdk, int sats, String memo) async {
  if (sats < 330) throw ArgumentError('minimum is 330 sats');
  final r = await sdk.receivePayment(
    request: breez.ReceivePaymentRequest(
      paymentMethod: breez.ReceivePaymentMethod.bolt11Invoice(
        description: memo,
        amountSats: BigInt.from(sats),
        expirySecs: 600,
      ),
    ),
  );
  final parsed = await sdk.parse(input: r.paymentRequest);
  if (parsed is! breez.InputType_Bolt11Invoice) throw StateError('not a BOLT11 invoice');
  return (invoice: r.paymentRequest, hash: parsed.field0.paymentHash);   // show `invoice` as text and QR
}

Detect the payment in one of two ways:

Future<breez.Payment?> findPaid(breez.BreezSdk sdk, String hashHex) async {
  for (var offset = 0;; offset += 100) {
    final page = (await sdk.listPayments(
      request: breez.ListPaymentsRequest(
        typeFilter: const [breez.PaymentType.receive], sortAscending: false, offset: offset, limit: 100),
    )).payments;
    for (final p in page) {
      final d = p.details;
      if (d is breez.PaymentDetails_Lightning && d.htlcDetails.paymentHash == hashHex) return p;
    }
    if (page.length < 100) return null;
  }
}
// p.status: completed = credited | pending = in flight | failed = will not complete

Rules that matter for money: