[DEADLINE HELP] Insert some data when a paid plan is purchased

Hello,
Im trying to make a code that will insert user email and a number in a database when a user purchase a paid plan.
I tried to follow whats here but i cant make work : https://www.wix.com/velo/reference/wix-paid-plans-backend/events/onplanpurchased.

This my code (in backend) :


import wixData from 'wix-data';
import wixUsers from 'wix-users';

export function wixPaidPlans_onPlanPurchased(event) {
  if (event.order.price.amount === 4.99) {
     
let user = wixUsers.currentUser;
let userEmail; 

user.getEmail()
  .then( (email) => {
      userEmail = email;

let orderData = {
       "email": userEmail,
       "amount": "+10"
     };

wixData.insert("Transactions", orderData);
      }); 
  } 

//

if (event.order.price.amount === 9.99) {
     
let user = wixUsers.currentUser;
let userEmail; 

user.getEmail()
  .then( (email) => {
      userEmail = email;

let orderData = {
       "email": userEmail,
       "amount": "+20"
     };

wixData.insert("Transactions", orderData);

      }); 
  } 
//

if (event.order.price.amount === 19.99) {

let user = wixUsers.currentUser;
let userEmail; 

user.getEmail()
  .then( (email) => {
      userEmail = email;

let orderData = {
       "email": userEmail,
       "amount": "+100"
     };

wixData.insert("Transactions", orderData);

      }); 

  } 

//

} else {

     };

}
}

Thank you so much.

@yisrael-wix please can i get some help with this :pray: