magento2 – add codeigniter product to magento 2 with options

On my server I have Magento 2 running and at the same time I have the Codeigniter application.

What I am trying to do is that my Codeigniter users are redirected to my Magento 2 site to complete their transaction from the codeigniter application.

I have created a custom module to receive calls from Codeigniter through Ajax.

In Myself js

I have already defined var productId Y var SiteUrl

var AjaxUrl = SiteUrl + "/ carcomm / index / addproduct / id /" + productId;

Here is my driver

_resultPageFactory = $ resultPageFactory;
$ this -> _ cart = $ cart;
$ this -> _ productRepositoryInterface = $ productRepositoryInterface;
$ this -> _ responseFactory = $ responseFactory;
$ this -> _ url = $ context-> getUrl ();
$ this -> _ logger = $ logger;
father :: __ construction ($ context);
}

public function run ()
{
$ productId = $ this-> getRequest () -> getParam (& # 39; id & # 39;);
$ TotalPrice = $ this-> getRequest () -> getParam (& # 39; price & # 39;);
$ Product = $ this -> _ productRepositoryInterface-> getById ($ productid);
// Define options
$ customOptions = array ();
$ customOptions[0]= array (& # 39; key & # 39; => 1, & # 39; value & # 39; => & # 39; Ford & # 39 ;, & # 39; title & # 39; => & # 39; Car Type & # 39;);
$ customOptions[1]= matrix (& # 39; key & # 39; => 2, & # 39; value & # 39; => & # 39; 02 -01-2019 & # 39;, & # 39; title & # 39; => & # 39; Date of collection & # 39;);
$ customOptions[2]= array (& # 39; key & # 39; => 3, & # 39; value & # 39; => & # 39; Ray Motors & # 39 ;, & # 39; title & # 39; => & # 39; Dealer & # 39;);
// :::::::::::
$ params = array (
& # 39; product & # 39; => $ productId,
& # 39; qty & # 39; => 1,
& # 39; price & # 39; => $ TotalPrice,
& # 39; options & # 39; => $ customOptions
);

$ this -> _ cart-> addProduct ($ Product, $ params);
$ isSaved = $ this -> _ cart-> save ();
$ this -> _ redirect (& # 39; payment / shopping cart / index & # 39;);
}

}?>

The Ajax call is working because I registered the headers in the console and I get 200 ok

However, the product is not adding and the redirect does not work.

I wonder if my approach is not right or if there is some other better approach to achieve it.