import type { PaymentReadiness } from '../../../services/OrganizationService.tsx'; import { environment } from '../../../environments/environment'; export type ReadinessView = PaymentReadiness | { state: 'checking' }; export interface ReadinessCopy { label: string; tone: 'success' | 'error' | 'neutral'; detail?: string; canRecheck: boolean; } // Stored keys alone never read as Connected: only the provider's own answer does. export function describeReadiness(view: ReadinessView, production: boolean = environment.production): ReadinessCopy { switch (view.state) { case 'not-configured': return { label: 'Not connected', tone: 'neutral', canRecheck: false }; case 'checking': return { label: 'Checking with Stripe\u2026', tone: 'neutral', canRecheck: false }; case 'ready': return { label: 'Connected', tone: 'success', canRecheck: false }; case 'unable': if (view.reason === 'wrong-mode') { const mode = production ? 'live' : 'test'; return { label: 'Wrong kind of key', tone: 'error', detail: `This site requires a Stripe ${mode}-mode secret key. The saved key is for a different mode. Enter the correct key and save.`, canRecheck: false, }; } return view.reason === 'credentials-rejected' ? { label: 'Keys not accepted', tone: 'error', detail: 'Stripe did not accept this secret key. Enter a current key and save.', canRecheck: false, } : { label: 'Cannot take payments yet', tone: 'error', detail: 'Stripe says this account cannot take card payments yet. Finish the account setup in your Stripe dashboard, then check again.', canRecheck: true, }; default: return { label: 'Not checked', tone: 'neutral', detail: 'We could not reach Stripe to check whether online payments are available. Try again in a moment.', canRecheck: true, }; } }