If you want to be using Wix Paid Plans events, then it needs to be all in a events.js in your backend as stated in the Wix Paid Plans Backend API Reference.
https://www.wix.com/corvid/reference/wix-paid-plans-backend.Events.html
To add a paid plan event handler, add an events.js file to the Backend section of your site if one does not already exist. All event handler functions for your site are defined in this file.
Note that backend events don’t work when previewing your site.
https://www.wix.com/corvid/reference/wix-paid-plans-backend.Events.html#onPlanPurchased
Examples
An event when a paid plan is purchased
This example adds purchased plan event data to a manually-created planEvents database. The database has a data field.
When a plan is purchased and the onPlanPurchased event is triggered, the JSON format of the object is inserted into the data field.
// Place this code in the events.js file
// of your site's Backend section.
// For inserting data about a plan transaction:
import wixData from 'wix-data';
export function wixPaidPlans_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
* },
* "cancellationReason":"CANCELLATION_REASON_UNDEFINED",
* "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"
* }
* }
* }
* }
*
*/