Funktionen: Buchung per Stripe, Webhook, Mails und Freischalt-Job
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
770cbe32b7
commit
0cc35bf1a5
12 files changed
+642
-8
No files matched your search
@@ -591,6 +591,48 @@ export async function createAboCheckout(customer, consent, productKey, offer = n
|
||||
return session.url
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkout fuer die einmalige Einrichtung einer Funktion (News-Pinnwand, 30 € brutto, kein Abo). Die Sitzung
|
||||
* verfaellt nach 24 Stunden (Stripe-Hoechstwert; fuenf Minuten Luft fuer die Laufzeit des Aufrufs), die
|
||||
* Rechnung erzeugt Stripe selbst. Nur die Zuordnung steht in den Metadaten, der Zustimmungswortlaut nicht.
|
||||
* @returns {Promise<{ id: string, url: string }>}
|
||||
*/
|
||||
export async function createFeatureCheckout(customer, { projectId, key = 'news', consentAt }) {
|
||||
const stripe = getStripe()
|
||||
const [priceId, stripeCustomerId] = await Promise.all([ensurePrice('newsSetup'), getOrCreateStripeCustomer(customer)])
|
||||
const params = {
|
||||
mode: 'payment',
|
||||
customer: stripeCustomerId,
|
||||
client_reference_id: customer.$id,
|
||||
line_items: [{ price: priceId, quantity: 1 }],
|
||||
payment_method_types: ['card', 'sepa_debit'],
|
||||
locale: 'de',
|
||||
billing_address_collection: 'required',
|
||||
customer_update: { address: 'auto', name: 'auto' },
|
||||
invoice_creation: {
|
||||
enabled: true,
|
||||
invoice_data: { description: config.newsSetup.name, footer: config.stripe.invoiceFooter },
|
||||
},
|
||||
metadata: { customerId: customer.$id, projectId, featureKey: key, ...(consentAt ? { consentAt } : {}) },
|
||||
expires_at: Math.floor(Date.now() / 1000) + 24 * 60 * 60 - 5 * 60,
|
||||
success_url: `${config.publicBaseUrl}/dashboard.html#news?bestellt=1`,
|
||||
cancel_url: `${config.publicBaseUrl}/dashboard.html#news`,
|
||||
}
|
||||
let session
|
||||
try {
|
||||
session = await stripe.checkout.sessions.create(params)
|
||||
} catch (err) {
|
||||
// SEPA-Lastschrift noch nicht im Stripe-Konto aktiviert -> nur Karte anbieten (wie beim Abo-Checkout)
|
||||
if (/sepa_debit|payment_method_types/i.test(err.message || '')) {
|
||||
console.warn('[stripe] SEPA-Lastschrift nicht verfuegbar, Checkout nur mit Karte:', err.message)
|
||||
session = await stripe.checkout.sessions.create({ ...params, payment_method_types: ['card'] })
|
||||
} else {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
return { id: session.id, url: session.url }
|
||||
}
|
||||
|
||||
export async function createBillingPortalUrl(customerId) {
|
||||
const sub = await getCurrentSubscription(customerId)
|
||||
if (!sub?.stripeCustomerId) {
|
||||
|
||||
Reference in new issue
Block a user