caelum0x d56639a594
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
Menivor — open source release (MIT), free to use and fork
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.
2026-12-04 02:10:26 +03:00

50 lines
1.9 KiB
TypeScript

/**
* Opens a hosted-checkout URL from the billing surfaces, preferring the in-app
* browser (expo-web-browser) and falling back to the system browser
* (expo-linking). Shared by the team-credits purchase panel and the ENTERPRISE
* Plan & Usage upgrade CTA so both open checkout identically.
*
* MONEY-CORRECTNESS: this only *navigates* the buyer to the provider's page.
* No credits or entitlements are granted client-side — the backend fulfils the
* purchase idempotently on the provider webhook. No secrets are handled here.
*/
import { Platform } from "react-native";
import * as Linking from "expo-linking";
import * as WebBrowser from "expo-web-browser";
/**
* STORE POLICY: App Store Guideline 3.1.1 and Google Play's payments policy
* require digital goods (generation credits, plan upgrades) bought inside a
* store-distributed app to use the store's in-app purchase system. The mobile
* app therefore sells only Menivor Pro (RevenueCat / store IAP) and never opens
* a hosted web checkout on iOS or Android. Web builds, and internal/enterprise
* builds that set EXPO_PUBLIC_EXTERNAL_CHECKOUT=1, keep the hosted checkout.
*/
export function externalCheckoutAvailable(): boolean {
if (Platform.OS === "web") return true;
return process.env.EXPO_PUBLIC_EXTERNAL_CHECKOUT?.trim() === "1";
}
/**
* Open `url` in the in-app browser, falling back to the system browser. Throws
* with a user-facing message when neither can open it (e.g. a malformed URL).
*/
export async function openCheckoutUrl(url: string): Promise<void> {
if (!externalCheckoutAvailable()) {
throw new Error("Purchases in this app are made through Menivor Pro.");
}
try {
await WebBrowser.openBrowserAsync(url);
return;
} catch {
// Fall through to the system browser.
}
const canOpen = await Linking.canOpenURL(url).catch(() => false);
if (!canOpen) {
throw new Error("Couldn't open the checkout page on this device.");
}
await Linking.openURL(url);
}