# wixPricingPlans\_onPlanPurchased(event) not firing after purchase

**URL:** <https://forum.wixstudio.com/t/wixpricingplans-onplanpurchased-event-not-firing-after-purchase/61712>\
**Category:** Ask the community\
**Tags:** wix-pricing-plans-backend, api, question, code\
**Created:** [August 7, 2024, 4:14pm UTC](https://forum.wixstudio.com/t/wixpricingplans-onplanpurchased-event-not-firing-after-purchase/61712 "2024-08-07T16:14:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SimonP](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/simonp/32/80542_2.png) [@SimonP](https://forum.wixstudio.com/u/SimonP)\
**Post date:** [August 7, 2024, 4:14pm UTC](https://forum.wixstudio.com/t/wixpricingplans-onplanpurchased-event-not-firing-after-purchase/61712/1 "2024-08-07T16:14:08Z")

</div>

There’s an error in the Velo API that needs to be fixed…no idea where else to post this but the reason I found it just now was that others on this forum have found it before. Wix should have a place to submit documentation errors more easily.

_ **PLEASE CAN SOMEONE CORRECT THE API…IT’S COST ME HOURS OF TIME TODAY TRYING TO FIGURE OUT AND I AM CLEARLY NOT THE FIRST PERSON TO DO SO.** _

The API calls out **wixPricingPlans** \_onPlanPurchased(event) as the event that can be run in events.js after a plan is purchased. The correct event name is actually **wixPaidPlans** \_onPlanPurchased, though…which is not detailed anywhere in the documentation but the event variable structure is EXACTLY the same as below.

Here’s the sample code from the API:

```javascript
import wixData from "wix-data";

export function wixPricingPlans_onPlanPurchased(event) {
  // Insert a title reflecting the type of transaction, and
  // the event's order object (json) into
  // the collection's data field.
  if (event.order.price.amount === 0) {
    let orderData = {
      title: "Free plan purchased",
      data: event.order,
    };
    wixData.insert("planEvents", orderData);
  } else {
    let orderData = {
      title: "Regular plan purchased",
      data: event.order,
    };
    wixData.insert("planEvents", orderData);
  }
}

/* Event object for a free, one-month purchase, ordered using Thailand baht currency:
 *
 * When the purchase is free, the `wixPayOrderId` is blank,
 * the `price.amount` is 0, and the paymentStatus is marked `PAID`.
 *
 * {
 * "order":{
 * "paymentStatus":"PAID",
 * "validUntil":"2019-09-12T05:43:53.246Z",
 * "price":{
 * "currency":"THB",
 * "amount":0
 * },
 * "validFrom":"2019-08-12T05:43:53.246Z",
 * "planName":"valid 1 week",
 * "wixPayOrderId":"",
 * "recurring":false,
 * "id":"b8401bab-8e5d-4bf6-944b-b2d56698d4c9",
 * "dateCreated":"2019-08-12T05:43:53.246Z",
 * "status":"ACTIVE",
 * "roleId":"",
 * "planDescription":"Platinum Plan",
 * "memberId":"42d90dcb-b9ad-47be-9a36-488be3dec679",
 * "orderType":"ONLINE",
 * "planId":"a52f41cc-8129-4812-9e1c-fafa2807a25d",
 * "validFor":{
 * "forever":false,
 * "period":{
 * "amount":1,
 * "unit":"MONTH"
 * }
 * }
 * }
 * }
 *
 *
 * Event object for a purchase that is valid until the user cancels:
 *
 * When the purchase is valid until the user cancels, `validFor.forever` is true, and
 * `validFor.forever.period.amount` is 0.
 *
 * {
 * "order":{
 * "paymentStatus":"PAID",
 * "validUntil":"2019-09-12T05:43:53.246Z",
 * "price":{
 * "currency":"USD",
 * "amount":0
 * },
 * "cancellationReason":"CANCELLATION_REASON_UNDEFINED",
 * "validFrom":"2019-08-12T05:43:53.246Z",
 * "planName":"valid 1 week",
 * "wixPayOrderId":"a52f41cc-8129-4812-9e1c-fafa2807a25d",
 * "recurring":false,
 * "id":"b8401bab-8e5d-4bf6-944b-b2d56698d4c9",
 * "dateCreated":"2019-08-12T05:43:53.246Z",
 * "status":"ACTIVE",
 * "roleId":"",
 * "planDescription":"Gold Plan",
 * "memberId":"42d90dcb-b9ad-47be-9a36-488be3dec679",
 * "orderType":"ONLINE",
 * "planId":"a52f41cc-8129-4812-9e1c-fafa2807a25d",
 * "validFor":{
 * "forever":true,
 * "period":{
 * "amount":0,
 * "unit":"MONTH"
 * }
 * }
 * }
 * }
 *
 */

```

---

<div class="post-metadata">

**Author:** ![noahlovell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/noahlovell/32/118920_2.png) [@noahlovell](https://forum.wixstudio.com/u/noahlovell)\
**Post date:** [August 7, 2024, 4:26pm UTC](https://forum.wixstudio.com/t/wixpricingplans-onplanpurchased-event-not-firing-after-purchase/61712/2 "2024-08-07T16:26:36Z")

</div>

If **wixPricingPlans** isn’t working for you, I think this might be an issue with that specific event, since **wixPaidPlans** was put into End of Life March last year. So, I’d likely not rely on it.

 ![Screenshot 2024-08-07 at 17.23.52](https://us1.discourse-cdn.com/wix/original/3X/4/5/456881149a565a022d5fe26009f7ab7722714259.png)

I’ll ask the team, in the meantime, does **onOrderPurchased** have all the data you need, or run at the right time in the flow as an alterative?

---

<div class="post-metadata">

**Author:** ![SimonP](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/simonp/32/80542_2.png) [@SimonP](https://forum.wixstudio.com/u/SimonP)\
**Post date:** [August 7, 2024, 4:55pm UTC](https://forum.wixstudio.com/t/wixpricingplans-onplanpurchased-event-not-firing-after-purchase/61712/3 "2024-08-07T16:55:38Z")

</div>

Hi Noah,

Really appreciate your swift response here. You’re not just a source of weekly emails about fascinating new features - you’re responsive here too!..which I did not know. I won’t be in production for a little while so have some time for this to get figured out.

I don’t need much from the event variable, so yes it is working fine. I only have one paid plan so when it runs, I am just grabbing the email of the purchaser so I can write some data to a different collection.

**wixPricingPlans** \_onPlanPurchased(event) simply never runs. I proved this by writing simple, identical code into to two different events for Pricing Plans in events.js.

Code was as follows, triggering on order creation and plan purchased:

The first always writes data to the BackEndOps collection and the second never ever does.

```javascript
import wixData from "wix-data";

export async function wixPricingPlans_onOrderCreated(event) {

    let now = new Date
    let opDate = now.toLocaleString()

    let toInsert = {
    dateOfOp: opDate,
    collectionWritten: "MembershipData",
    operation: "Testing the wixPricingPlans_onOrderCreated",
    objectWritten: event
    };

    wixData
    .insert("BackEndOps", toInsert)
    .then((item) => {
        console.log(item); //see item below
    })
    .catch((err) => {
        console.log(err);
    });
}

export async function wixPricingPlans_onPlanPurchased(event) {
    console.log("wixPaidPlans_onPlanPurchased is running", event)

    let now = new Date
    let opDate = now.toLocaleString()

    let toInsert = {
    dateOfOp: opDate,
    collectionWritten: "MembershipData",
    operation: "Testing the wixPricingPlans_onPlanPurchased",
    objectWritten: event
    };

    wixData
    .insert("BackEndOps", toInsert)
    .then((item) => {
        console.log(item); //see item below
    })
    .catch((err) => {
        console.log(err);
    });
}

```

---

<div class="post-metadata">

**Author:** ![Baksheesh](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@Baksheesh](https://forum.wixstudio.com/u/Baksheesh)\
**Post date:** [August 10, 2024, 8:56am UTC](https://forum.wixstudio.com/t/wixpricingplans-onplanpurchased-event-not-firing-after-purchase/61712/4 "2024-08-10T08:56:18Z")

</div>

I ran into the same issue with wixPricingPlans \_onPlanPurchased().

Tried using a different event trigger when a user purchases a pricing plan like onOrderCreated() or onOrderPurchased() but they still wouldn’t fire. Only when I changed the events.js to the deprecated API wixPaidPlans\_onPlanPurchased() did it finally trigger.

---

<div class="post-metadata">

**Author:** ![SimonP](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/simonp/32/80542_2.png) [@SimonP](https://forum.wixstudio.com/u/SimonP)\
**Post date:** [August 26, 2024, 8:47am UTC](https://forum.wixstudio.com/t/wixpricingplans-onplanpurchased-event-not-firing-after-purchase/61712/5 "2024-08-26T08:47:12Z")

</div>

Hi again Noah,

I never heard anything back from anyone at Wix. I’m reluctant to use the deprecated API but, if it is the only thing that works, it seems like my best option for now.

Did you learn anything new on this?

Simon.
