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?!

2 Likes

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.

Thank you, this solved it for me. Wix docs really proves to be a tough time.

OK; This is the contents of my events.js file, and the only event firing
is wixPricingPlans_onOrderCanceled

export function wixPricingPlans_onOrderPurchased(event) {
    console.log("wixPricingPlans_onOrderPurchased", event)
}
export function wixPricingPlans_onOrderMarkedAsPaid(event) {
    console.log("wixPricingPlans_onOrderMarkedAsPaid", event)
}

export function wixPricingPlans_onOrderStarted(event) {
    console.log("wixPricingPlans_onOrderStarted", event)
}
export function wixPricingPlans_onOrderEnded(event) {
    console.log("wixPricingPlans_onOrderEnded", event)
}

export function wixPaidPlans_onPlanPurchased(event) {
    console.log("wixPaidPlans_onPlanPurchased", event)
}

export function wixPricingPlans_onPlanPurchased(event) {
    console.log("wixPricingPlans_onPlanPurchased", event)
}

export function wixPricingPlans_onOrderCanceled(event) {
    console.log("wixPricingPlans_onOrderCanceled", event)
}

The cancel looks like this:

wixPricingPlans_onOrderCanceled {"metadata":{"id":"f570193d-507c-4d80-97ce-d102996e9060","entityId":"1ddedc00-8c51-4c0d-ace4-1dda20b7e6cc","eventTime":"2025-02-25T10:35:59.435221961Z","triggeredByAnonymizeRequest":false},"data":{"order":{"planId":"ca7da152-9f89-4d6c-a41c-3b5692b4eb42","subscriptionId":"fba924cc-7ead-4b10-866d-34393ee596bb","buyer":{"memberId":"993a2ef5-992d-4096-a8af-4f7b7877ade7","contactId":"993a2ef5-992d-4096-a8af-4f7b7877ade7"},"priceDetails":{"subtotal":"0.00","discount":"0","total":"0","planPrice":"0","currency":"USD","singlePaymentUnlimited":true},"pricing":{"singlePaymentUnlimited":true,"prices":[{"duration":{"cycleFrom":1,"numberOfCycles":1},"price":{"subtotal":"0.00","discount":"0","total":"0","currency":"USD","fees":[],"proration":"0"}}]},"type":"ONLINE","orderMethod":"UNKNOWN","status":"CANCELED","cancellation":{"cause":"MEMBER_ACTION","effectiveAt":"IMMEDIATELY"},"lastPaymentStatus":"NOT_APPLICABLE","startDate":"2025-02-25T10:33:02.329Z","endDate":"2025-02-25T10:35:59.126Z","pausePeriods":[],"cycles":[{"index":1,"startedDate":"2025-02-25T10:33:02.329Z","endedDate":"2025-02-25T10:35:59.126Z"}],"planName":"Family Social & Group Raquet","planDescription":"Family Membership & Group Racquet Membership","planPrice":"0","formData":{"formId":"883df132-d4c0-4916-84ab-fae5c3ff77d5","submissionId":"b080753d-4f48-4130-ab2d-a5caef02d641","submissionData":{}},"statusNew":"CANCELED","_id":"1ddedc00-8c51-4c0d-ace4-1dda20b7e6cc","_createdDate":"2025-02-25T10:33:02.329Z","_updatedDate":"2025-02-25T10:35:59.378Z"}}}

why is the onOrderPurchased not being called?