Advertisement
ikamal7

lifetime-plan.tsx

Jan 4th, 2025
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import type { LoaderFunctionArgs } from "@remix-run/node";
  2. import { redirect } from "@remix-run/node";
  3. import { authenticate, LIFETIME_BASIC_PLAN } from "app/shopify.server";
  4. // import { Updatepreloader } from "~/utils/preload.server";
  5.  
  6. export const loader = async ({ request }: LoaderFunctionArgs) => {
  7.   const { billing, session } = await authenticate.admin(request);
  8.   let { shop } = session;
  9.   let myShop: string = shop.replace(".myshopify.com", "");
  10.  
  11.   const billingCheck = await billing.require({
  12.     plans: [LIFETIME_BASIC_PLAN],
  13.     onFailure: async () =>
  14.       billing.request({
  15.         plan: LIFETIME_BASIC_PLAN,
  16.         isTest: true,
  17.         returnUrl: `https://admin.shopify.com/store/${myShop}/apps/${process.env.APP_NAME}/app/plan`,
  18.       }),
  19.   });
  20.  
  21.   const subscription = billingCheck.appSubscriptions[0];
  22.  
  23.   if (!subscription) {
  24.     return redirect("/app/lifetime-basic");
  25.   }
  26.   // Add the following line to redirect to the annual plan page
  27.   return redirect("/app/plan");
  28. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement