How to get subscription plan handle for managed app pricing

I use managed app pricing.

I am getting the active plan like this

export async function getActivePlan(admin) {
  const result = await admin.graphql(
  query { currentAppInstallation { activeSubscriptions { name status } } }
  );

  const qJson = await result.json();

  const inst = qJson.data.currentAppInstallation;
  const activeSub = inst.activeSubscriptions?.find(
    (s) => s.status === "ACTIVE"
  );
  const activePlan = activeSub ? activeSub.name : "Free";

  return activePlan;
} 

But the problem is that the plan name can be localized so I am getting Standaard instead of Standard and Avancé instead of Advanced. Is there a way to get the plan handle? I can get plan name from the plan price, but that could cause problems if later I decide to change the price and forget to update the plan check method.

1 Like

So one sulution could be to match the localized plan name with a list of all possible translations for that name

export async function getActivePlan(admin) {
  const result = await admin.graphql(`
    query {
      currentAppInstallation {
        activeSubscriptions {
          name
          status
        }
      }
    }
  `);

  const qJson = await result.json();
  const inst = qJson.data.currentAppInstallation;

  const activeSub = inst.activeSubscriptions?.find(
    (s) => s.status === "ACTIVE"
  );

  if (!activeSub) return "Free";

  const name = activeSub.name.toLowerCase();

  // --- STANDARD translations ---
  const standardKeywords = [
    "standard",
    "standaard",          // Dutch
    "estándar",           // Spanish
    "estandar",           // Spanish (alt)
    "standardowy",        // Polish
    "standardna",         // Croatian/Bosnian/Serbian (f)
    "standardno",         // Croatian/Bosnian/Serbian (n)
    "standardni",         // Croatian/Bosnian/Serbian (m)
    "standardní",         // Czech
    "standardne",         // Slovak/Slovenian variant
    "standardinis",       // Lithuanian
    "standardowy",        // Polish
    "standardowy plan",   // Polish (common)
    "стандарт",           // Russian / Bulgarian
    "стандартный",        // Russian
    "стандартен",         // Bulgarian
    "standardna nabídka", // Czech variant
    "standardas",         // Lithuanian
    "standardnoe",        // Russian variant
    "standarda",          // Esperanto-ish variant
    "standart",           // Turkish
    "standarta",          // Latvian
    "standardpaket",      // Germanic variants
    "piano standard",     // Italian
    "plan standard",      // French/Spanish general
    "tarif standard",     // French
    "tarifa estándar",    // Spanish
    "stándard",           // Spanish alt
    "スタンダード",         // Japanese (Standard)
    "표준",                // Korean (Standard)
    "มาตรฐาน",             // Thai (Standard)
    "标准",                // Simplified Chinese
    "標準",                // Traditional Chinese
    "standardplan",
    "standard plan",
  ];

  // --- ADVANCED translations ---
  const advancedKeywords = [
    "advanced",
    "avanzado",           // Spanish
    "avanzada",           // Spanish (f)
    "avancé",             // French
    "avancée",            // French (f)
    "gevorderd",          // Dutch
    "avançado",           // Portuguese
    "avançada",           // Portuguese (f)
    "avanzata",           // Italian (f)
    "avanzato",           // Italian (m)
    "pokročilý",          // Czech (m)
    "pokročilá",          // Czech (f)
    "pokročilé",          // Czech (n)
    "napredni",           // Slovenian/Yugoslav
    "napredno",           // Croatian/Serbian
    "napredna",           // Croatian/Serbian
    "zaawansowany",       // Polish (m)
    "zaawansowana",       // Polish (f)
    "zaawansowane",       // Polish (n)
    "усиленный",          // Russian (“enhanced”)
    "продвинутый",        // Russian (actual “advanced”)
    "avansat",            // Romanian
    "avansată",           // Romanian (f)
    "avansert",           // Norwegian
    "avanceret",          // Danish
    "avancerad",          // Swedish
    "avansert plan",      // Nordic variant
    "progresif",          // Turkish / Indonesian context
    "advanse",            // Haitian Creole (common Shopify locale)
    "avansată",           // Romanian
    "高级",                // Chinese (advanced)
    "進階",                // Traditional Chinese
    "上級",                // Japanese
    "고급",                // Korean
    "ขั้นสูง",             // Thai
    "advancedplan",
    "advanced plan",
  ];

  // Detect Standard
  if (standardKeywords.some((k) => name.includes(k))) {
    return "Standard";
  }

  // Detect Advanced
  if (advancedKeywords.some((k) => name.includes(k))) {
    return "Advanced";
  }

  // Default fallback
  return "Free";
}

Is there a better way?

Actually planHandle is available in pricing details

query {
        currentAppInstallation {
            activeSubscriptions {
                status
                lineItems {
                    plan {
                        pricingDetails {
                            __typename
                            ... on AppRecurringPricing {
                                planHandle
                            }
                        }
                    }
                }
            }
        }
      }

But I was on older Api version so it was not working.

I also needed to update the Api version to ApiVersion.July25.