Inline some invoie route logic

This commit is contained in:
Jon Staab
2026-05-21 15:11:43 -07:00
parent f67ef5bca2
commit bf9a768b88
2 changed files with 33 additions and 44 deletions
+33 -9
View File
@@ -74,15 +74,39 @@ pub async fn get_invoice_bolt11(
return Err(bad_request("invoice-not-open", "invoice is not open"));
}
let bolt11 = api
.billing
.get_or_create_manual_lightning_bolt11(
&id,
&tenant.pubkey,
invoice.amount_due,
&invoice.currency,
)
let bolt11 = if let Some(existing_bolt11) = api
.query
.get_invoice_manual_lightning_bolt11(&id)
.await
.map_err(internal)?;
.map_err(internal)?
{
existing_bolt11
} else {
let bolt11 = api
.billing
.create_bolt11(invoice.amount_due, &invoice.currency)
.await
.map_err(internal)?;
if api
.command
.insert_manual_lightning_invoice_payment(&id, &tenant.pubkey, &bolt11)
.await
.map_err(internal)?
{
bolt11
} else {
api.query
.get_invoice_manual_lightning_bolt11(&id)
.await
.map_err(internal)?
.ok_or_else(|| {
internal(format!(
"manual lightning payment row missing after insert race for invoice {id}"
))
})?
}
};
ok(serde_json::json!({ "bolt11": bolt11 }))
}