Simplify Memberstack Payment Flows With Redirect Script For Unpaid Accounts

When users sign up in Webflow using Memberstack but don't complete the payment, their account is created without a subscription plan. This simple script from Sarkis Buniatyan can handle this by checking if the logged-in user has a plan; if not, they are redirected to an activation page.

Summary:

When integrating Memberstack with Webflow for handling paid accounts, there is a potential issue where users who sign up but don't finalize the payment still have accounts created, albeit without an active subscription plan. This can lead to users inadvertently accessing content or features meant only for paying customers.


This script runs every time a user logs in, checking if their account has an active subscription. If it detects that the account lacks a plan, the script automatically redirects the user to a specific activation page, ensuring that only paying members proceed to access the intended features.


Key Takeaways:


  • The script checks if an account has a subscription plan on login.
  • If no plan is detected, the user is redirected to an activation page.
  • This approach simplifies handling unpaid accounts and ensures only paying users have access to content.


<script>
(function() {
  const ACTIVATE_PAGE = '/account/activate';

  function checkUserPlan(member) {
    const currentPath = window.location.pathname;
    if (currentPath === ACTIVATE_PAGE) {
      return;
    }

    const hasActivePlan = member.planConnections && member.planConnections.length > 0;
    if (!hasActivePlan) {
      window.location.href = ACTIVATE_PAGE;
    }
  }

  function getCurrentMember() {
    if (window.$memberstackDom && window.$memberstackDom.getCurrentMember) {
      window.$memberstackDom.getCurrentMember()
        .then(({ data: member }) => {
          if (member) {
            checkUserPlan(member);
          }
        })
        .catch(() => {});
    }
  }

  function setup() {
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
      getCurrentMember();
    } else {
      window.addEventListener('load', getCurrentMember);
    }
  }

  setup();
})();
</script>
Simplify Memberstack Payment Flows With Redirect Script For Unpaid Accounts

Subscribe for updates

Load more