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
-35
View File
@@ -231,41 +231,6 @@ impl Billing {
// --- Public API helpers ---
pub async fn get_or_create_manual_lightning_bolt11(
&self,
invoice_id: &str,
tenant_pubkey: &str,
amount_due_minor: i64,
currency: &str,
) -> Result<String> {
if let Some(existing_bolt11) = self
.query
.get_invoice_manual_lightning_bolt11(invoice_id)
.await?
{
return Ok(existing_bolt11);
}
let bolt11 = self.create_bolt11(amount_due_minor, currency).await?;
if self
.command
.insert_manual_lightning_invoice_payment(invoice_id, tenant_pubkey, &bolt11)
.await?
{
return Ok(bolt11);
}
self.query
.get_invoice_manual_lightning_bolt11(invoice_id)
.await?
.ok_or_else(|| {
anyhow!(
"manual lightning payment row missing after insert race for invoice {invoice_id}"
)
})
}
pub async fn create_bolt11(&self, amount_due_minor: i64, currency: &str) -> Result<String> {
let amount_msats = bitcoin::fiat_to_msats(amount_due_minor, currency).await?;
self.wallet
+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 }))
}