Dynamically Handle User Subscription Success/Failure in React Next.js and Lemonsqueezy

29 Views Asked by At

I have a React Next.js component that contains a function triggering a subscription purchase when a button is clicked. Here's the code snippet:

export default function Home() {
  
  function buyingNow(){
    LemonSqueezy.Url.Open(process.env.NEXT_PUBLIC_LEMONSQUEEZY_SUBSCRIPTION_URL);
  }

  return (
    <div className="">
      <button onClick={buyingNow}>Subscribe Now</button>
    </div>
  )
}

Now, I want to dynamically handle the user's subscription status. Specifically, I aim to be notified via console.log if the user's payment is successful or if it fails. This notification will help me proceed with further SaaS logic accordingly.

How can I implement a mechanism to track subscription success or failure after the buyingNow function is triggered? I'm using an external library (let's call it LemonSqueezy) to open the subscription URL. Any suggestions on how to approach this would be greatly appreciated! it would also help if I could also know if the payment was recurring since I have already set it in lemonsqueezy as a subscription in test mode.

0

There are 0 best solutions below