Backend event.js OnPlanPurchased function not firing when plan is purchased

I have created a default plan for my site, and I have created an event.js file in the backend section of my site. I am using the OnPlanPurchased code to access a third party API and am using ‘wix-fetch’. Whenever I purchase a free plan on my site, the event does not fire and I know this because I have it log to the console. Am I missing something? Does the default plan format not call onPlanPurchased?

The file should be " events.js " not " event.js " - Notice the " s " at the end of " events "

Hi,

I am having the same issue as above.

I have my onPlanPurchased set up in the “events.js” in the backend but it’s not firing.

I know it’s not firing because I have tested the code inside the event and it works.

Am I missing something?

I figured what it was: the event is actually called wixPaidPlans_onPlanPurchased() not wixPricingPlans_onPlanPurchased as stated in the documentation. Come on guys, people are going crazy with this, what’s the point of the docs if they are misleading?!

The method below has worked for me. I am using a default Wix Pricing Plan app in the frontend (without any custom code).

  1. Initially, I added the events.js by adding New .js File, the Site Events was not logging any info returned from wixPricingPlans_onPlanPurchased(event).

  2. I then deleted the file and added it by Handle Backend Events to create the events.js file. – I suspect this was the key reason.

  3. In the events.js file, I tested a few events function:
    wixPricingPlans_onPlanPurchased(event)
    wixPricingPlans_onOrderPurchased(event)
    wixPricingPlans_onOrderMarkedAsPaid(event)
    wixPricingPlans_onOrderStarted(event)
    wixPricingPlans_onOrderEnded(event)

  4. At the end, wixPricingPlans_onOrderPurchased(event) return the event after clicking “Get Plan” button of the Wix Pricing Plan app.
    – JSON returned starts with “data”:{“order”:{“planId”:"f5e69f…
    – I find it strange that onOrderPurchased() fired up instead of on PlanPurchased().

This video at 21:04 has a demo of how to add the events.js properly.