There are two scenarios where I am trying to use a backend function but no matter how many different combinations of code or forum responses I read I am losing. The ActivityLog is a database I have set up.
(1) After someone purchases a plan, I want to record the purchase. In the front end I have the following (which works fine as the automated confirmation email is triggered)
import wixPaidPlans from'wix-paid-plans';
import wixData from'wix-data';
import wixPay from 'wix-paid-plans';
export function ConfirmationButton_click(event) {
wixPaidPlans.purchasePlan(selectedPlan._id) // selectedPlan specified earlier
.catch((err) => {
console.log(err);
});
}
This successfully purchases the plan but never triggers the ‘onPlanPurchased’ function in the events.js file in the backend where I have:
import wixPaidPlans from 'wix-paid-plans';
import wixData from 'wix-data';
export function wixPaidPlans_onPlanPurchased(event) {
let purchaseData = event.order;
wixData.insert("ActivityLog", purchaseData);
}
(2) I would like to use scheduled jobs for a variety of things, but can even get a test function to work. I have set up the job in the jobs.config file in two separate ways, unsure if the .jsw or .js file type was causing the issue:
{
"jobs": [ // Define up to 20 different jobs
// Choose one of the options below to define the job execution interval:
{
"functionLocation": "/TimedJobs.jsw", // Relatively to Backend folder, started by slash
"functionName": "testFunction",
"description": "Test",
"executionConfig": {
"time": "20:04",
}
},
{
"functionLocation": "/events.js", // Relatively to Backend folder, started by slash
"functionName": "testFunction",
"description": "Test",
"executionConfig": {
"time": "20:04",
}
}
]
}
I then have the same testFunction code in a TimedJobs.jsw file and an events.js file both in the backend section which read as follows:
import wixData from 'wix-data';
export function testFunction() {
let activityDetails = { "title": "test" }
wixData.insert("ActivityLog", activityDetails)
}
Hope that is clear. Any help on either of these issues would be greatly appreciated. Thanks in advance