Shop Review A M6: Stripe-Status auf 4000 Zeichen begrenzen (30 Eintraege zu 100 Zeichen, notfalls weiter kuerzen)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d4b9e6a5b9
commit
21805c9a93
2 files changed
+33
-5
No files matched your search
@@ -80,18 +80,34 @@ export async function onboardingLink(accountId, { returnUrl, refreshUrl }) {
|
||||
return link.url
|
||||
}
|
||||
|
||||
/** Bereitschaftsstatus aus einem Konto-Objekt (auch fuer den Webhook account.updated). Rein bis auf die Zeit. */
|
||||
const MAX_EINTRAEGE = 30
|
||||
const MAX_EINTRAG_ZEICHEN = 100
|
||||
/** Die Spalte stripeStatus fasst 4000 Zeichen; darunter bleibt Platz fuer den Hinweis zu Klarna/SEPA (merkeHinweis). */
|
||||
const MAX_STATUS_JSON = 3500
|
||||
const kapp = (liste) =>
|
||||
(Array.isArray(liste) ? liste : []).filter((e) => typeof e === 'string').slice(0, MAX_EINTRAEGE).map((e) => e.slice(0, MAX_EINTRAG_ZEICHEN))
|
||||
|
||||
/**
|
||||
* Bereitschaftsstatus aus einem Konto-Objekt (auch fuer den Webhook account.updated). Rein bis auf die Zeit. Die Listen werden
|
||||
* auf 30 Eintraege zu je 100 Zeichen gekappt und notfalls weiter gekuerzt, damit das JSON in die Spalte stripeStatus (4000 Zeichen) passt.
|
||||
*/
|
||||
export function statusAusKonto(account, now = new Date()) {
|
||||
const req = account?.requirements || {}
|
||||
return {
|
||||
const status = {
|
||||
charges_enabled: account?.charges_enabled === true,
|
||||
payouts_enabled: account?.payouts_enabled === true,
|
||||
details_submitted: account?.details_submitted === true,
|
||||
currently_due: Array.isArray(req.currently_due) ? [...req.currently_due] : [],
|
||||
past_due: Array.isArray(req.past_due) ? [...req.past_due] : [],
|
||||
disabled_reason: req.disabled_reason ?? null,
|
||||
currently_due: kapp(req.currently_due),
|
||||
past_due: kapp(req.past_due),
|
||||
disabled_reason: typeof req.disabled_reason === 'string' ? req.disabled_reason.slice(0, MAX_EINTRAG_ZEICHEN) : (req.disabled_reason ?? null),
|
||||
geprueftAt: new Date(now).toISOString(),
|
||||
}
|
||||
while (JSON.stringify(status).length > MAX_STATUS_JSON) {
|
||||
const laenger = status.currently_due.length >= status.past_due.length ? status.currently_due : status.past_due
|
||||
if (laenger.length === 0) break
|
||||
laenger.pop()
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
export async function kontoStatus(accountId) {
|
||||
|
||||
Reference in new issue
Block a user