Custom controller for period of payment

Can you help with logic in custom controller. I have a subscription for users that are different, for 1 month, for 3 months and for a year. After the payment is made, an order is created that has an endDate field that autofills depending on how much is paid. It contains the date when the subscription ends. After a successful payment, also in the user model, I also have an isPaid field that changes from false to true . Thus, the user has access to the application. I need some help because I’m still new with strapi. How do I write the controller when endDate occurs, the isPaid field changes to false . Here is my order controller. `“use strict”;
const stripe = require(“stripe”)(
“sk_test_51MAx7LHHWofrktpqON8S03o96SERWwgOQyOXgndXmT95mms6wWrKJVTg6YOu4BLZeAbNdsUgNKQZBB0LqfE461pB00M8YtzY9f”
);

function calcDiscountPrice(price) {
const result = price

return result.toFixed(2);
}

/**

  • order controller
    */

const { createCoreController } = require(“@strapi/strapi”).factories;

module.exports = createCoreController(“api::order.order”, ({ strapi }) => ({
async paymentOrder(ctx) {
const { token, products, userId, } = ctx.request.body;

let totalPayment = 0;
products.forEach((product) => {
  const priceTemp = calcDiscountPrice(product.price);
  totalPayment += Number(priceTemp) * product.quantity;
});

  // Calculate endDate based on totalPayment

let endDate;
if (totalPayment === 10) {
endDate = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000); // Add 30 days
} else if (totalPayment === 20) {
endDate = new Date(Date.now() + 90 * 24 * 60 * 60 * 1000); // Add 90 days
} else if (totalPayment === 50) {
endDate = new Date(Date.now() + 365 * 24 * 60 * 60 * 1000); // Add 365 days
} else {
throw new Error(‘Invalid totalPayment value’);
}

const charge = await stripe.charges.create({
  amount: Math.round(totalPayment * 100),
  currency: "eur",
  source: token,
  description: `User ID: ${userId}`,
});


const data = {
  products,
  user: userId,
  totalPayment,
  idPayment: charge.id,
  endDate,
   };

const model = strapi.contentTypes["api::order.order"];
const validData = await strapi.entityValidator.validateEntityCreation(
  model,
  data
);

const entry = await strapi.db
  .query("api::order.order")
  .create({ data: validData });

return entry;

},
}));
`