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
+2
View File
@@ -28,6 +28,8 @@ A sorok a fiók törlése után is megmaradnak (`user_id` → NULL), mert a szá
Fizetéskor a backend egy `invoices` sort is létrehoz a számla minden adatával: a vevő (név, e-mail, ország, irányítószám, város, cím, Billingo-adótípus: `HAS_TAX_NUMBER` / `NO_TAX_NUMBER` / `FOREIGN`, adószám) és a tétel (név, végösszeg, nettó, áfa, áfakód). Az áfakód az `INVOICE_VAT` (a backend `.env`-je): alapból `AAM` (alanyi adómentes: nettó = végösszeg, áfa 0, a számla megjegyzésében „Alanyi adómentes.”), vagy egy kulcs, pl. `27%`. Cégnél a `business_name` és a magyar adószám (`hu_tin`, ennek híján `eu_vat`) kerül a számlára.
**Teszt módú fizetéshez (`sk_test_…`) nem készül számla**, mert a Billingo számlái valódiak (a NAV-hoz is bekerülnek); a csomagot ilyenkor is megkapja az admin.
A worker `invoices` feladata (`WORKER_TASKS`, prodon a `worker` konténerben) a Billingo API v3-mal:
1. létrehozza a partnert (`POST /partners`),
+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)
+26 -5
View File
@@ -2475,14 +2475,35 @@ async fn stripe_checkout_grants_the_paid_package_once(pool: PgPool) {
.unwrap();
assert_eq!((name.as_str(), tax_type.as_str()), ("Anna Teszt", "NO_TAX_NUMBER"));
// A test payment grants the package but gets no invoice (Billingo's are real).
sqlx::query(
"INSERT INTO stripe_checkouts (id, user_id, package, price_huf, live) \
SELECT 'cs_test_1', id, 'single', 2000, false FROM users WHERE email = 'anna@example.com'",
)
.execute(&app.pool)
.await
.unwrap();
let test = json!({"type": "checkout.session.completed",
"data": {"object": {"id": "cs_test_1", "payment_status": "paid", "amount_total": 200000, "currency": "huf"}}});
let sig = crate::stripe::sign("whsec_fake", test.to_string().as_bytes(), now);
let r = app.call_with("POST", "/v1/payments/stripe/webhook", None, Some(test), &[("stripe-signature", &sig)]).await;
assert_eq!(r.status, StatusCode::OK);
assert_eq!(stripe_orders(&app.pool, "anna@example.com").await.len(), 3);
let (invoices,): (i64,) = sqlx::query_as("SELECT count(*) FROM invoices WHERE checkout_id = 'cs_test_1'")
.fetch_one(&app.pool)
.await
.unwrap();
assert_eq!(invoices, 0);
// Deleting the account keeps the payments (accounting law).
let r = app.call("DELETE", "/v1/me", Some(&anna), Some(json!({"confirm": "DELETE"}))).await;
assert!(r.status.is_success(), "{}", r.body);
let (kept,): (i64,) =
sqlx::query_as("SELECT count(*) FROM stripe_checkouts WHERE user_id IS NULL AND completed_at IS NOT NULL")
.fetch_one(&app.pool)
.await
.unwrap();
let (kept,): (i64,) = sqlx::query_as(
"SELECT count(*) FROM stripe_checkouts WHERE user_id IS NULL AND completed_at IS NOT NULL AND live",
)
.fetch_one(&app.pool)
.await
.unwrap();
assert_eq!(kept, 2);
let (kept,): (i64,) =
sqlx::query_as("SELECT count(*) FROM invoices WHERE user_id IS NULL").fetch_one(&app.pool).await.unwrap();