Abo: Testkonten zahlen per Rabatt nur 0,50 EUR (ABO_TEST_EMAILS)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-09-25 17:09:52 +00:00
1 parent 7237ec729d
commit 90e85f5989
4 files changed
+27

No files matched your search

+19
View File
@@ -265,6 +265,22 @@ async function getOrCreateStripeCustomer(customer) {
return created.id
}
/** Rabatt fuer Testkonten: 49,50 € auf jede Abrechnung -> es werden nur 0,50 € abgebucht. */
async function ensureTestCoupon() {
const stripe = getStripe()
const existing = await stripe.coupons.retrieve(config.abo.testCouponId).catch(() => null)
if (existing) return existing.id
const created = await stripe.coupons.create({
id: config.abo.testCouponId,
name: 'Testzugang WEBklar (0,50 €)',
amount_off: config.stripe.priceAmountCents - 50,
currency: 'eur',
duration: 'forever',
metadata: { webklar: 'wartungs-abo-test' },
})
return created.id
}
/**
* Stripe Checkout fuer das Abo. Der Kunde hat seine Bestellung vorher im Portal
* abgegeben ("Zahlungspflichtig bestellen"); hier hinterlegt er die Zahlungsart.
@@ -284,6 +300,8 @@ export async function createAboCheckout(customer, consent) {
getOrCreateStripeCustomer(customer),
])
const lateStart = consent.startChoice === 'nach_frist'
const isTestAccount = config.abo.testEmails.includes(String(customer.email || '').toLowerCase())
const testCoupon = isTestAccount ? await ensureTestCoupon() : null
// Stripe-Metadaten: max. 500 Zeichen je Wert
const meta = {
webklarCustomerId: customer.$id,
@@ -311,6 +329,7 @@ export async function createAboCheckout(customer, consent) {
...(lateStart ? { trial_period_days: config.abo.lateStartTrialDays } : {}),
},
metadata: meta,
...(testCoupon ? { discounts: [{ coupon: testCoupon }] } : {}),
custom_text: {
submit: {
message: lateStart