Copying the code I used on one of my sites. You need to add the event handler to the backend as well. Naturally youâll need to change the planIDs and page urls plus the image (#group4) that shows during the plan purchase confirmation.
This works but the same code does not work on another site. Maybe @yisrael-wix might give us some insight.
// API Reference: Introduction - Velo API Reference - Wix.com
// âHello, World!â Example: Velo Learning Center
import wixLocation from âwix-locationâ ;
import wixData from âwix-dataâ ;
import wixUsers from âwix-usersâ ;
function getUTCTime ( ) {
var utcTime = new Date ()
utcTime . setMinutes ( utcTime . getMinutes () + utcTime . getTimezoneOffset ())
console . log ( utcTime )
return utcTime
}
$w . onReady ( async function () {
let date = new Date ()
console . log ( date )
let newDate = date . setMinutes ( date . getMinutes () - 1 );
console . log ( date )
wixLocation . onChange ( async ( location ) => {
let newPath = location . path ;
if ( newPath . includes ( âstatusâ )) {
// wixLocation.to(â/paid-plan-purchaseâ);
$w ( '#group4' ). show ()
$w ( '#membershipPlanPickerTpa1' ). hide ()
let user = wixUsers . currentUser ;
let userId = user . id ;
**await** wait ( 4000 );
let date = **await** getUTCTime ()
console . log ( date )
let newDate = date . setMinutes ( date . getMinutes () - 1 );
console . log ( date )
wixData . query ( "PaidPlanPurchases" )
. eq ( "paymentStatus" , "PAID" )
. eq ( "memberId" , userId )
//.ge("_createdDate", newDate)
. find ()
. then (( results ) => {
if ( results . items . length > 0 ) {
console . log ( "Found" )
let firstItem = results . items [ 0 ];
console . log ( firstItem )
let plan = firstItem . planID
if ( plan === "41e4fcbc-9ef9-4a21-adf9-46c5913638a9" ) {
wixLocation . to ( "https://www.mattsoule.com/account/free-membership" );
} **else if** ( plan === "bfea41d3-a4bf-4f19-aec6-95346d3830fb" ) {
wixLocation . to ( "https://www.mattsoule.com/account/master-stress-membership" );
}
} **else** {
console . log ( "NotFound" )
$w ( '#group4' ). hide ()
$w ( '#membershipPlanPickerTpa1' ). show ()
// $w('#text108').show()
// $w('#button1').show()
}
})
. catch (( err ) => {
let errorMsg = err ;
});
}
});
});
function wait ( ms = 500 ) {
return new Promise (( res ) => {
setTimeout (() => { res ( âdoneâ ) }, ms );
});
}
===Backend js.===
import wixData from âwix-dataâ ;
export function wixPaidPlans_onPlanPurchased ( event ) {
console . log ( âTriggeredâ )
console . log ( event )
let plan = event . order . planId
let toInsert = {
âplanIDâ : event . order . planId ,
âmemberIdâ : event . order . memberId ,
âpaymentStatusâ : event . order . paymentStatus ,
};
wixData . insert ( "PaidPlanPurchases" , toInsert )
. then (( results ) => {
let item = results ;
console . log ( item )
console . log ( "Inserted to Database" )
})
. catch (( err ) => {
let errorMsg = err ;
console . log ( "Error Inserted to Database" )
console . log ( errorMsg )
});
}
export function test ( ) {
var utcTime = new Date ()
utcTime . setMinutes ( utcTime . getMinutes () + utcTime . getTimezoneOffset ())
console . log ( utcTime )
return utcTime
}