No invoice for test payments
CI / test (push) Successful in 1m28s
CI / build (push) Successful in 6m16s
CI / deploy (push) Skipped

Billingo's invoices are real (reported to the tax authority), so a
payment made with a Stripe test key grants the package but queues no
invoice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-20 08:30:54 +00:00
co-authored by Claude Opus 5.5
parent 184f19e1f2
commit 76bc965537
3 changed files with 40 additions and 12 deletions
+12 -7
View File
@@ -170,13 +170,14 @@ pub async fn checkout(
/// grants its package and queues the invoice, once. `false`: not our session.
async fn complete(state: &AppState, session: &stripe::Session) -> Result<bool, ApiError> {
let mut tx = state.db.begin().await?;
let row: Option<(Option<Uuid>, String, i32, Option<OffsetDateTime>)> = sqlx::query_as(
"SELECT user_id, package, price_huf, completed_at FROM stripe_checkouts WHERE id = $1 FOR UPDATE",
type Checkout = (Option<Uuid>, String, i32, bool, Option<OffsetDateTime>);
let row: Option<Checkout> = sqlx::query_as(
"SELECT user_id, package, price_huf, live, completed_at FROM stripe_checkouts WHERE id = $1 FOR UPDATE",
)
.bind(&session.id)
.fetch_optional(&mut *tx)
.await?;
let Some((user_id, package_id, price_huf, completed_at)) = row else { return Ok(false) };
let Some((user_id, package_id, price_huf, live, completed_at)) = row else { return Ok(false) };
if completed_at.is_some() {
return Ok(true);
}
@@ -205,10 +206,14 @@ async fn complete(state: &AppState, session: &stripe::Session) -> Result<bool, A
.bind(&session.customer_details)
.execute(&mut *tx)
.await?;
let buyer = invoices::Buyer::from_stripe(session.customer_details.as_ref().unwrap_or(&Value::Null), None);
let item = format!("Sorsfonalak – {}", package.name);
let gross = amount_huf.unwrap_or(i64::from(price_huf));
invoices::queue(&mut tx, &session.id, user_id, &buyer, &item, gross, state.config.invoice_vat).await?;
// A test payment gets no invoice: Billingo's invoices are real (reported
// to the tax authority).
if live {
let buyer = invoices::Buyer::from_stripe(session.customer_details.as_ref().unwrap_or(&Value::Null), None);
let item = format!("Sorsfonalak – {}", package.name);
let gross = amount_huf.unwrap_or(i64::from(price_huf));
invoices::queue(&mut tx, &session.id, user_id, &buyer, &item, gross, state.config.invoice_vat).await?;
}
tx.commit().await?;
tracing::info!(user = ?user_id, package = %package_id, session = %session.id, "package paid");
Ok(true)