Abo-Spiegel: Produkt und tatsächlicher Preis aus den Stripe-Positionen

Neues Appwrite-Feld subscriptions.productKey (Setup-Skript). Ohne bekannten
Abo-Preis gilt ein Abo weiter als Wartungs-Abo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-09-27 15:31:56 +00:00
1 parent 54defb75c4
commit d097704d49
4 files changed
+88 -2

No files matched your search

+10 -2
View File
@@ -8,6 +8,7 @@ import {
updateDocument,
} from './appwriteAdmin.js'
import { lateStartAt } from './deadlines.js'
import { describeItems } from './products.js'
/**
* Wartungs-Abo ueber Stripe Billing.
@@ -160,14 +161,21 @@ export async function syncSubscription(subscriptionId) {
return null
}
const customer = typeof sub.customer === 'string' ? null : sub.customer
// Abo-Posten (Hosting/Wartung) unabhängig von der Reihenfolge; ohne bekannten Preis gilt das Abo
// als Wartungs-Abo (Altbestand bzw. von Hand angelegt)
const items = describeItems(sub.items?.data)
if (!items.productKey) {
console.warn(`[stripe] Abo ${sub.id}: kein bekannter Abo-Preis – als Wartungs-Abo gespiegelt`)
}
const doc = await upsertSubscriptionDoc(sub.id, {
customerId,
email: meta.email || customer?.email || '',
stripeCustomerId: typeof sub.customer === 'string' ? sub.customer : sub.customer?.id,
stripeSubscriptionId: sub.id,
status: sub.status,
planKey: config.stripe.priceLookupKey,
priceAmount: sub.items?.data?.[0]?.price?.unit_amount ?? config.stripe.priceAmountCents,
productKey: items.productKey || 'wartung',
planKey: items.lookupKey || config.products.wartung.lookupKey,
priceAmount: items.priceAmount ?? sub.items?.data?.[0]?.price?.unit_amount ?? config.products.wartung.amountCents,
startedAt: toIso(sub.start_date),
currentPeriodEnd: toIso(periodEndOf(sub)),
cancelAtPeriodEnd: Boolean(sub.cancel_at_period_end || sub.cancel_at),