Remove reconciliation step

This commit is contained in:
Jon Staab
2026-05-21 17:30:09 -07:00
parent e7c0e6fdbe
commit 97b1bd9a02
2 changed files with 20 additions and 86 deletions
+20 -39
View File
@@ -26,13 +26,22 @@ pub async fn get_invoice(
AuthedPubkey(auth): AuthedPubkey,
Path(id): Path<String>,
) -> ApiResult {
let (invoice, _tenant) = load_authorized_invoice(&api, &auth, &id).await?;
let Some(invoice) = api.stripe.get_invoice(stripe_invoice_id).await.map_err(internal)? else {
return Err(not_found("invoice not found"));
};
let invoice = api
.billing
.reconcile_invoice(&invoice)
let Some(_) = api
.query
.get_tenant_by_stripe_customer_id(&invoice.customer)
.await
.map_err(internal)?;
.map_err(internal)?
else {
return Err(not_found("invoice not found"));
};
api.require_admin_or_tenant(auth, &tenant.pubkey)?;
Ok((invoice, tenant))
ok(invoice)
}
@@ -42,38 +51,6 @@ pub async fn get_lightning_invoice(
AuthedPubkey(auth): AuthedPubkey,
Path(id): Path<String>,
) -> ApiResult {
let (invoice, tenant) = load_authorized_invoice(&api, &auth, &id).await?;
// Settle first: this checks the currently-stored bolt11 against the wallet,
// so a payment that landed before expiry is always caught before we'd
// consider regenerating below.
let invoice = api
.billing
.reconcile_invoice(&invoice)
.await
.map_err(internal)?;
if invoice.status != "open" {
return Err(bad_request("invoice-not-open", "invoice is not open"));
}
let invoice = api
.billing
.ensure_lightning_invoice(&invoice.id, &tenant.pubkey, invoice.amount_due, &invoice.currency)
.await
.map_err(internal)?;
ok(serde_json::json!(invoice))
}
/// Fetch a Stripe invoice and the tenant that owns it, enforcing that the
/// caller is that tenant (or an admin). Returns 404 if the invoice or its
/// tenant can't be found.
async fn load_authorized_invoice(
api: &Api,
auth: &str,
stripe_invoice_id: &str,
) -> Result<(crate::stripe::StripeInvoice, crate::models::Tenant), crate::web::ApiError> {
let Some(invoice) = api.stripe.get_invoice(stripe_invoice_id).await.map_err(internal)? else {
return Err(not_found("invoice not found"));
};
@@ -87,7 +64,11 @@ async fn load_authorized_invoice(
return Err(not_found("invoice not found"));
};
api.require_admin_or_tenant(auth, &tenant.pubkey)?;
let lightning_invoice = api
.billing
.ensure_lightning_invoice(&invoice.id, &tenant.pubkey, invoice.amount_due, &invoice.currency)
.await
.map_err(internal)?;
Ok((invoice, tenant))
ok(serde_json::json!(lightning_invoice))
}