Invoice every payment again, test payments included
CI / test (push) Successful in 1m27s
CI / build (push) Successful in 4m36s
CI / deploy (push) Skipped

The Billingo account is a test one for now, and the whole flow is being
tested; skipping test payments was not asked for. Stripe and Billingo
go live together at the opening.

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 10:00:48 +00:00
co-authored by Claude Opus 5.5
parent e4905ec5f1
commit e741f9b491
3 changed files with 13 additions and 39 deletions
+7 -12
View File
@@ -170,14 +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?;
type Checkout = (Option<Uuid>, String, i32, bool, Option<OffsetDateTime>);
type Checkout = (Option<Uuid>, String, i32, 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",
"SELECT user_id, package, price_huf, 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, live, completed_at)) = row else { return Ok(false) };
let Some((user_id, package_id, price_huf, completed_at)) = row else { return Ok(false) };
if completed_at.is_some() {
return Ok(true);
}
@@ -206,15 +206,10 @@ async fn complete(state: &AppState, session: &stripe::Session) -> Result<bool, A
.bind(&session.customer_details)
.execute(&mut *tx)
.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, comment) = package.invoice_item();
let gross = amount_huf.unwrap_or(i64::from(price_huf));
invoices::queue(&mut tx, &session.id, user_id, &buyer, (&item, &comment), gross, state.config.invoice_vat)
.await?;
}
let buyer = invoices::Buyer::from_stripe(session.customer_details.as_ref().unwrap_or(&Value::Null), None);
let (item, comment) = package.invoice_item();
let gross = amount_huf.unwrap_or(i64::from(price_huf));
invoices::queue(&mut tx, &session.id, user_id, &buyer, (&item, &comment), gross, state.config.invoice_vat).await?;
tx.commit().await?;
tracing::info!(user = ?user_id, package = %package_id, session = %session.id, "package paid");
Ok(true)