Woocommerce Checkout Page Total Price Inside Google Pay Script

I have the following Google Pay script below and I am trying to replace the 1.00 for totalPrice with the total price (number) on the checkout page of my standard Woocommerce/Wordpress website:

script
    let paymentsClient = null;

    function getGooglePaymentsClient() {
        if ( paymentsClient === null ) {
            paymentsClient = new google.payments.api.PaymentsClient({environment: 'TEST'});
        }
        return paymentsClient;
    }

    function onGooglePayLoaded() {
        const paymentsClient = getGooglePaymentsClient();
        paymentsClient.isReadyToPay({
            apiVersion: 2,
            apiVersionMinor: 0,
            allowedPaymentMethods: [
                {
                    type: 'CARD',
                    parameters: {
                        allowedAuthMethods: [PAN_ONLY, CRYPTOGRAM_3DS],
                        allowedCardNetworks: [AMEX, DISCOVER, INTERAC, JCB, MASTERCARD, VISA]
                    }
                }
            ]
        })
            .then(function(response) {
                if (response.result) {
                    addGooglePayButton();
                }
            })
            .catch(function(err) {
                // show error in developer console for debugging
                console.error(err);
            });
    }

    function addGooglePayButton() {
        const paymentsClient = getGooglePaymentsClient();
        const button =
            paymentsClient.createButton({onClick: onGooglePaymentButtonClicked});
        document.getElementById('container').appendChild(button);
    }

    function onGooglePaymentButtonClicked() {
        const paymentDataRequest = {
            apiVersion: 2,
            apiVersionMinor: 0,
            allowedPaymentMethods: [{
                type: 'CARD',
                parameters: {
                    allowedAuthMethods: [PAN_ONLY, CRYPTOGRAM_3DS],
                    allowedCardNetworks: [AMEX, DISCOVER, INTERAC, JCB, MASTERCARD, VISA]
                },
                tokenizationSpecification: {
                    type: 'PAYMENT_GATEWAY',
                    parameters: {
                        'gateway': 'gatewayservices',
                        'gatewayMerchantId': '[MerchantID]' // This value is located in the account information settings page
                    }
                }
            }],
            transactionInfo: {
                countryCode: 'US',
                currencyCode: 'USD',
                totalPriceStatus: 'FINAL',
                totalPrice: '1.00'  // HOW WOULD I REPLACE THE 1.00 WITH THE ACTUAL TOTAL ON THE CHECKOUT PAGE
            },
            merchantInfo: {
                merchantId: '01234567890123456789',
            },
            emailRequired: true
        }

        const paymentsClient = getGooglePaymentsClient();
        paymentsClient.loadPaymentData(paymentDataRequest)
            .then(function(paymentData) {
                // handle the response
                processPayment(paymentData);
            })
            .catch(function(err) {
                // show error in developer console for debugging
                console.error(err);
            });
    }

    function processPayment(paymentData) {
        console.log(paymentData);
    }
/script

Topic woocommerce-offtopic Wordpress javascript google

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.