wixPricingPlans_onPlanPurchased(event) not firing after purchase

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:

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"
 *         }
 *      }
 *   }
 * }
 *
 */
1 Like

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.

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?

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.

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);
    });
}

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.

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.