Shopify App to Add product variants in the product details page

I am trying to pull the product options in the product details page for my private shopify app, the product options are pulled from my different server and are display in the details page, the problem is when I select the product options the price of those options doesn’t get added to the cart when I click on add to cart. The options are added but not the price, here is my code.

   const productPrice = $('[data-price]').data('price');

    $('#product_form_' + productId).on('submit', function(e) {
      e.preventDefault();
      const formData = new FormData($(this)[0]);

      // Get the product price from the HTML
      const priceEl = $('.product__price [data-regular-price], .product__price [data-sale-price]');
      const price = 0; //parseFloat(priceEl.attr('data-sale-price') || priceEl.attr('data-regular-price'));
        alert(price);
      // Calculate the total price of the selected options
      let totalPrice = 0; // Initialize totalPrice to 0
      options.forEach(option => {
        option.values.forEach(value => {
            const inputName = `properties[option-${option.VirtualOptionID}][${value.OptionValue}]`;
            const quantity_name = `properties[option-${option.VirtualOptionID}][${value.OptionValue}-quantity]`;
            const input = formData.get(inputName);
           
            // alert(input);
                if (input) {
                    const optionPrice = parseFloat(option.values.find(value => value.OptionValue === input).Price);
                    alert(optionPrice);
                    const quantity = 1; //parseInt(formData.get(quantity_name));
                totalPrice += optionPrice * quantity;
                alert('totalprice:'+totalPrice);
                // Add the custom option price to the form data
                formData.set(`items[0][properties][_Ymq${option.VirtualOptionID}]`, optionPrice.toFixed(2));
                }                 
            });
        });
  
        totalPrice += price; // Add the product price to the total price
        alert('final:'+totalPrice);
        // Set the total additional price as a property in the form data
        formData.set('items[0][id]', formData.get('id'));
        formData.set('items[0][properties][_additionalItemPrice]', totalPrice.toFixed(2));
  
        $.ajax({
          url: '/cart/add.js',
          dataType: 'json',
          type: 'post',
          data: formData,
          processData: false,
          contentType: false,
          success: function(data) {
            // Handle the response data if needed
          },
          error: function(xhr, status, error) {
            console.error('Error adding item to cart:', error);
          }
        });