How to manipulate cart in an app using external inventory?

Hi Everyone,

i am trying to develop an app which will use a kind of external inventory.
I created an app-theme-extension and created a block to check if a unit of the product exists in my inventory and if yes, i will add it to the cart and proceed to the purchase. See the code of my block below.

My code is not working and i got the error : Uncaught (in promise) ReferenceError: cart is not defined
isn’t it possible to use cart as an object ?

Do you think this is the best approach ?

<button
typ=“button”
class=“shopify-payment-button__button”
style=“background-color:{{ block.settings.background-color }};color:{{ block.settings.color }}”
onclick=“checkInventory()”

{{ ‘myapp.addToBasketButton.label’ | t }}

{% schema %}
{
“name”: “My app Product”,
“target”: “section”,
“settings”: [
{ “type”: “product”, “id”: “product”, “label”: “product”, “autofill”: true },
{ “type”: “color”, “id”: “color”, “label”: “Button Color”, “default”: “#FFFFFF” },
{ “type”: “color”, “id”: “background-color”, “label”: “Button background Color”, “default”: “#168F30” }
]
}
{% endschema %}