How to pass a transaction amount to Square payment processing page?

Square has a (new to me) payment system for taking payments. I’m having some trouble with the changes.

The old system was fairly simple – there was an html form, when the form was submitted the default behavior was prevented and data was sent to Square’s servers to generate a token. It was possible to include in the data a transaction amount. When their servers returned a token, it already included transaction approval/disapproval data. Based on that, I could move forward by processing the transaction.

This new system is similar except there’s no way to pass the amount of the transaction to Square’s servers. The token, when generated, is just a reference to the user’s payment method (e.g. a credit card or Google Pay). Every single example provided in their documentation uses a hard-coded amount for the transaction, which in their examples is part of the final state of the process.

I have everything working, except it’s still using hard-coded transaction amounts. I have tried…

A. Storing the transaction amount in local storage… but the final stages of processing are server-side so of course that failed…

B. Storing the transaction amount in a session variable… but when I try to call that variable on the server during processing it’s always empty…

C. Storing the transaction amount in a database table… but then I can’t pass the primary key value for that row…

D. Setting the transaction amount via JavaScript in window.amount because that’s how the sample code passes the idempotencyKey value… but that fails…

E. Setting a hidden form field in the form in the hopes that it will be passed to the server as POST data… and there is POST data sent, but not the hidden form field…

I haven’t tried manipulating the target URL to add GET data because I’m afraid that, even if I try to obfuscate it, it would be too easy a target for tampering.

The code example that I’m using is at https://github.com/square/connect-api-examples/tree/master/connect-examples/v2/php_payment and the example file for final card processing with the hard-coded transaction amount looks like this:

$money = new Money();
// Monetary amounts are specified in the smallest unit of the applicable currency.
// This amount is in cents. It's also hard-coded for $1.00, which isn't very useful.
$money->setAmount(100);

Note that the comments in that code are part of the original, not mine.

This same trend of using a hard-coded value is repeated in the documentation at https://developer.squareup.com/reference/square/payments-api/create-payment for the ‘amount_money’ value.

I really feel like the solution should be set into this block of example code from the form input side of the example but I can’t figure out how to do it.

  <script type="text/javascript">
    window.applicationId =
      "<?php
        echo getenv('SQUARE_APPLICATION_ID');
        ?>";
    window.locationId =
      "<?php
        echo getenv('SQUARE_LOCATION_ID');
        ?>";
    window.currency =
      "<?php
        echo $location_info->getCurrency();
        ?>";
    window.country =
      "<?php
        echo $location_info->getCountry();
        ?>";
    window.idempotencyKey =
      "<?php
        echo Uuid::uuid4();
        ?>";
  </script>

As I mentioned above in list item D., I’ve tried setting a value for window.amount because of the documenation (c.f. https://developer.squareup.com/reference/sdks/web/payments/objects/Money) but that doesn’t work.

Anyone have any ideas? This seems like such a basic thing, I can’t help but think I’m missing the forest for the trees.

Thanks.

(Edited for clarity)