Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
73 lines
2.4 KiB
TypeScript
73 lines
2.4 KiB
TypeScript
/**
|
|
* Pure, dependency-free helpers for presenting payment providers in the
|
|
* checkout UI. The set of providers actually offered to a buyer comes from
|
|
* GET /billing/providers (only rails whose secrets are configured server-side);
|
|
* these helpers just turn a provider id into display copy and pick a sensible
|
|
* default. No secrets and no network here.
|
|
*/
|
|
|
|
import { PAYMENT_PROVIDERS, type PaymentProvider } from "@/lib/types";
|
|
|
|
/** Human-readable label for a provider id (widened `string` tolerated). */
|
|
export function providerLabel(provider: PaymentProvider | string): string {
|
|
switch (provider) {
|
|
case "stripe":
|
|
return "Stripe";
|
|
case "iyzico":
|
|
return "iyzico";
|
|
case "creem":
|
|
return "Creem";
|
|
case "polar":
|
|
return "Polar";
|
|
default:
|
|
return provider
|
|
? provider.charAt(0).toUpperCase() + provider.slice(1)
|
|
: "Card";
|
|
}
|
|
}
|
|
|
|
/** Short one-line hint about a provider (for a subtitle under a chip row). */
|
|
export function providerHint(provider: PaymentProvider | string): string {
|
|
switch (provider) {
|
|
case "stripe":
|
|
return "Card checkout via Stripe.";
|
|
case "iyzico":
|
|
return "Local card checkout for Turkey.";
|
|
case "creem":
|
|
return "Merchant-of-record checkout via Creem.";
|
|
case "polar":
|
|
return "Merchant-of-record checkout via Polar.";
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Order the enabled providers for display, keeping the canonical
|
|
* {@link PAYMENT_PROVIDERS} order and appending any unknown (forward-compat)
|
|
* providers the backend may return after them. Pure — never mutates `enabled`.
|
|
*/
|
|
export function orderProviders(
|
|
enabled: readonly (PaymentProvider | string)[],
|
|
): (PaymentProvider | string)[] {
|
|
const set = new Set(enabled);
|
|
const known = PAYMENT_PROVIDERS.filter((p) => set.has(p));
|
|
const extras = enabled.filter(
|
|
(p) => !(PAYMENT_PROVIDERS as readonly string[]).includes(p),
|
|
);
|
|
return [...known, ...extras];
|
|
}
|
|
|
|
/**
|
|
* Pick the default provider to pre-select from the enabled set: prefer Stripe
|
|
* when available, otherwise the first enabled provider (in display order).
|
|
* Returns `null` when nothing is enabled.
|
|
*/
|
|
export function defaultProvider(
|
|
enabled: readonly (PaymentProvider | string)[],
|
|
): PaymentProvider | string | null {
|
|
const ordered = orderProviders(enabled);
|
|
if (ordered.length === 0) return null;
|
|
return ordered.includes("stripe") ? "stripe" : ordered[0];
|
|
}
|