This should give you the answers you need: https://shopify.dev/docs/apps/launch/billing/redirect-plan-selection-page
Code snippet taken from that doc:
// app/routes/app.jsx
export const loader = async ({ request }) => {
// Replace with the "app_handle" from your shopify.app.toml file
const appHandle = "YOUR_APP_HANDLE";
// Authenticate with Shopify credentials to handle server-side queries
const { authenticate } = await import("../shopify.server");
// Initiate billing and redirect utilities
const { billing, redirect } = await authenticate.admin(request);
// Check whether the store has an active subscription
const { hasActivePayment } = await billing.check();
// If there's no active subscription, redirect to the plan selection page...
if (!hasActivePayment) {
return redirect(`shopify://admin/charges/${appHandle}/pricing_plans`, {
target: "_top", // required since the URL is outside the embedded app scope
});
}
// ...Otherwise, continue loading the app as normal
return {
apiKey: process.env.SHOPIFY_API_KEY || "",
};
};