After members save 60 item on the database, I need monthly plan or subscription automatically canceled even if the month aren't ending

Hi there, I have a site with a monthly payment but i need a code that member only can use what I offer 60 times then automatically plans subscription cancel, or automatically expiry, even if the month are not ending. what i offer is something that person click a button and copy to the clipboard so if you copy and click the button 60 times, plan is over, even if the month is not ending, so member needs to pay again. Thank you, is my first time on the forum. I need some help

This is what you need to do.

When a member clicks on the button, add something to the database. You can do this with the wixData.save() api.

Then in the then after the save write this -

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

let toSave = {
  "title":        "Mr.",
  "first_name":   "John",
  "last_name":    "Doe"
};

wixData.save("myCollection", toSave)
	.then( (results) => {
		let items = results.items; //see item below
		let count = items.length
		if (count >= 60) {
		
		}
	} )

Then inside that .then((results)) you need to get the users plans and cancel the first plan they have. https://www.wix.com/velo/reference/wix-paid-plans/cancelorder

thank you sir let me try it, will let you know

Hi sir, I do not understand this part below, how I can do that Thank you:
Then inside that .then((results)) you need to get the users plans and cancel the first plan they have.

Hi sir, That is what i did, is that the right code ?

Thank you

import wixData from ‘wix-data’ ;
import wixUsers from ‘wix-users’
// …
let toSave = {
“title” : “Mr.” ,
“first_name” : “John” ,
“last_name” : “Doe”
};

wixData . save ( “myCollection” , toSave )
. then ( ( results ) => {
let items = results . items ; //see item below
let count = items . length
if ( count >= 60 ) {
wixPaidPlans . cancelOrder (1)
}
} )

Its almost the same code, is that right ? thank you
import wixData from ‘wix-data’ ;
import wixPaidPlans from ‘wix-paid-plans’ ;
import wixUsers from ‘wix-users’ ;
let user = wixUsers . currentUser ;

let toSave = {
“title” : “Mr.” ,
“first_name” : “John” ,
“last_name” : “Doe”
};

wixData . save ( “myCollection” , toSave )
. then ( ( results ) => {
let items = results . items ; //see item below
let count = items . length
if ( count >= 60 ) {
wixPaidPlans . cancelOrder ( 1 )
}
} )