79464888

Date: 2025-02-24 22:02:53
Score: 0.5
Natty:
Report link

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 || "",
  };
};
Reasons:
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: tiimgreen