When should the onPlanPurchased() method be invoked, either manually after placement in events.js or automatically triggered?

My plan involves creating a wallet collection in the database manually using Wix Velo code. Once a pricing plan is purchased by the user, I need to determine where to call the onPlanPurchased() method to add the amount to the wallet

import wixData from 'wix-data';

export function wixPaidPlans_onPlanPurchased(event) {
  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); 
  }
}

Answer №1

When you insert event handlers into the events.js file on the backend in Wix, they are automatically triggered by the platform. For example, when a user purchases a plan, the function wixPaidPlans_onPlanPurchased() will be executed and will receive details about the purchased plan through the event parameter passed to it.

On a side note, it seems like the event you're currently using is becoming outdated, and it's recommended to switch to the one provided by wix-pricing-plans instead.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Could someone break down for me the behavior exhibited within this method?

Hello there, I'm a beginner so please forgive me for any lack of knowledge. const example = { myFunction(){ console.log(this); }, myFunction2(){ function myFunction3(){ console.log(this) } return ...

Using JavaScript to convert date and time into ISO format

Similar Question: How do I output an ISO-8601 formatted string in Javascript? I've been attempting to change a date and time input into an ISO format but keep encountering the error .toISOString is undefined. It seems like I must be overlooking s ...

Tips for importing a json response into PHP

After successfully bringing all the results from fetch.php to my bootstrap modal HTML screen using JSON, I encountered a problem. I want to run a MYSQL query with a value from the same JSON used for the modal, but I'm unable to assign this value to a ...

Challenges with implementing asynchronous functions in NestJS controllers

Currently, I am in the process of developing a finance tracker application that involves importing data from a CSV file. The import functionality checks if an entry already exists in the database, adds a specific category to it if not found, and then saves ...

Updating an array of numbers in Mongoose: A guide

I am having trouble updating an array within a MongoDB document using Mongoose. Below is my stock model definition: const ticker = new mongoose.Schema({ ticker: String, Price: Number, Amount: Number, PastPrices: [Number] }); export const stock ...

Tips for incorporating flow and TypeScript typings into an NPM module

Are there any resources available for adding both flow and typescript typings to an NPM module at the same time? I've been struggling to find a comprehensive guide on this topic, and it seems to be a common issue faced by open source library maintain ...

The function $.fn.dataTable.render.moment does not exist in npm package

I have encountered an issue with my application that I am struggling to solve: I want to format dates in my data table using Moment.js like I have done in the following script: $().ready(function() { const FROM_PATTERN = 'YYYY-MM-DD HH:mm:ss.SSS&a ...

Is there a way to modify the spacing between labels and text in the TextBox MUI component while using custom label sizes?

https://i.sstatic.net/OvAN9.png I've customized a material ui TextField component by increasing the font size of the label. However, I'm facing an issue where the gap in the border for the label remains unchanged despite the larger text size. I ...

Tips for sending a JavaScript parameter to PHP

I am implementing a pop-up modal window that retrieves data from the myForm and saves the email field value to a JavaScript variable in index.php. How can I pass this JavaScript value to PHP and display it using echo, without refreshing the index.php windo ...

Utilize Sequelize to enclose a column with double quotation marks in a where clause

I am working with a JSONB column in my database. My goal is to make a query to the database where I can check if a specific value in this JSON is true or false: SELECT * FROM table WHERE ("json_column"->'data'->>'data2')::boo ...

Integrate data from Firebase into a React-Table component

I am currently working on a table component that fetches data from Firebase to populate three fields: Name Date Comment For each entry, I want to add a new row. The pivot has been successfully added. However, when trying to populate the table, I am encou ...

jQuery animation for expanding accordion headers

I want to create a cool animation for my accordion headers that mimics a ribbon being dragged onto the wrapper when hovered over, and then dragged out when the hover ends. Everything was working fine in this initial jsFiddle, but as soon as I tried to ani ...

Developing a ReactJS counter component that dynamically increments by a custom value specified in props and saved in the component's state

Here is an example code snippet that demonstrates functionality. It works in Firefox but had issues in Chrome. By clicking buttons, the number next to the word "Count" increases based on the value of the button clicked (1, 5, or 10). Code for Desired Out ...

Sharing images on Facebook via a page

My website features an image slider with a Facebook share button for each image. I want the specific image to be posted along with the current URL when the share button is clicked. The script I am using is as follows: <script type="text/javascript"> ...

Encountering a display issue within a port using Express

Recently, I enrolled in an advanced ExpressJS course. While exploring the course website, I stumbled upon the "hello world" section. Intrigued, I decided to copy and paste the code provided below: const express = require('express') const app = ex ...

I require fixed headers that no longer stick once reaching a specific point

I have a setup where the names and occupations of participants are displayed next to their artworks, and I've made it sticky so that as we scroll through the images, the names stay on the left. Now, I want the names to scroll out once the images for e ...

Bot activities involve keeping information updated

I implemented a feature in the status to display the number of online members out of the total, but it doesn't update in real-time unless the bot is restarted. Is there a way to have this information automatically update with new data when the activit ...

Having difficulty controlling the movement of my object with an onscreen joystick (nipplejs) using three js and ammo js

Currently, I am working on an open-world project using three.js along with the ammo.js physics engine. After completing all the necessary setup and ensuring that collisions are functioning correctly, I encountered a particular issue. Despite my efforts, ...

Verify the accuracy of quiz responses with PHP and AJAX

I am working on a picture quiz that has one input field for each image. I am looking for a solution to verify if the value entered into the input field matches the correct answer. If it does match, I need to perform certain operations like adding or removi ...

Using app.js in a blade file can cause jQuery functions and libraries to malfunction

In my Laravel application, I am facing an issue with my vue.js component of Pusher notification system and the installation of tinymce for blog posts. Adding js/app.js in my main layout blade file causes my tinymce and other jQuery functions to stop workin ...