hi @antanasd !
Thank you for your response
I’ve already tried that and couldn’t make it work.
Would you mind taking a look?
I haven’t followed the all items (with repeater instructions) as they are working fine without any coding.
Js:
export function multiply(factor1, factor2) {
return factor1 * factor2;
}
// Execute the sample function above by copying the following into your page code
/*
import {multiply} from ‘backend/events’;
$w.onReady(function () {
multiply(4,5).then(product => {
console.log(product);
// Logs: 20
})
.catch(error => {
console.log(error);
});
});
*/
/*****************************
- Backend code in events.js *
*****************************/
// For inserting data into a collection.
import wixData from ‘wix-data’ ;
// The onPlanPurchased() event is fired when a plan
// is purchased, or a free plan is ordered.
// Get the order information
// from the event’s order object.
export function wixPaidPlans_onPlanPurchased(event) {
// The PlanEvents collection has a title field,
// in which we insert the type of transaction.
// The collection also has a data field,
// where we will insert information about the order
// from the event’s order object (json).
if (event.order.price.amount === 0 ) {
let orderData = {
“title” : “Free plan purchased” ,
“data” : event.order
};
wixData.insert( “Tracking purchases” , orderData);
} else {
let orderData = {
“title” : “Regular plan purchased” ,
“data” : event.order
};
wixData.insert( “Tracking purchases” , orderData);
}
}
On Item page:
#dataset1 - Plans - Planestestimonial
#tracking - Purchases - Tracking Purchases
#comprar -buy btn
Code:
import wixWindow from ‘wix-window’ ;
import wixPay from ‘wix-pay’ ;
import wixPaidPlans from ‘wix-paid-plans’ ;
import wixUsers from ‘wix-users’ ;
$w.onReady( () => {
const currentPlanObject = $w( “#dataset1” ).getCurrentItem();
const planId = currentPlanObject._id;
const planPrice = currentPlanObject.price;
$w( ‘#comprar’ ).onClick((event) => {
let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;
if (!isLoggedIn) {
wixUsers.promptLogin().then(() => {
processPlan(planId, planPrice);
})
} else {
processPlan(planId, planPrice);
}
});
});
function processPlan(myId, myPrice) {
if (myPrice > 0 ) {
wixPaidPlans.orderPlan(myId).then(orderObject => {
wixWindow.openLightbox( “confirm” , orderObject)
.then((goForIt) => {
if (goForIt) {
wixPay.startPayment(orderObject.wixPayOrderId);
}
});
})
} else {
wixPaidPlans.orderPlan(myId).then(orderObject => {
wixWindow.openLightbox( “congrats” , orderObject);
})
}
}
/**
/**