Compare commits

...
Author SHA1 Message Date
sagifer bbfa5b28c3 Merge pull request 'Invoice every payment again, test payments included' (#29) from main into prod
CI / test (push) Successful in 1m29s
CI / build (push) Successful in 1m50s
CI / deploy (push) Successful in 55s
Reviewed-on: #29
2026-11-20 11:09:30 +01:00
fecoandClaude Opus 5.5 e741f9b491 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
2026-11-20 10:00:48 +00:00
3 changed files with 13 additions and 39 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ 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%`. A tétel a törvény szerint azonosítja a szolgáltatást (Áfa tv. 169. § e): megnevezése pl. „Online tartalomszolgáltatás – Páros csomag”, egysége `csomag`, megjegyzése a tartalom („Hozzáférés a sorsfonalak.hu szoftveresen előállított, személyre szabott szöveges tartalmaihoz: 2 képletelemzés, … Digitális tartalom.”; `Package::invoice_item`). Szándékosan nem „asztrológiai”: a szolgáltatás egy weboldal programmal előállított tartalma, nem személyes szakmai tanácsadás. 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.
Minden igazolt fizetéshez készül számla, a teszt módúakhoz (`sk_test_…`) is: így a teljes folyamat próbálható egy teszt Billingo-fiókkal. Éles Billingo-fiók mellett ezért prodon már ne legyen teszt Stripe-kulcs (a kettőt megnyitáskor együtt kell élesre cserélni).
A worker `invoices` feladata (`WORKER_TASKS`, prodon a `worker` konténerben) a Billingo API v3-mal:
+4 -9
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?;
}
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)
+2 -23
View File
@@ -2475,32 +2475,11 @@ 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 AND live",
)
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();