Site icon Hip-Hop Website Design and Development

Woocommerce Checkout Web page Whole Worth Inside Google Pay Script

I’ve the next Google Pay script under and I’m making an attempt to exchange the 1.00 for totalPrice with the overall worth (quantity) on the checkout web page of my commonplace Woocommerce/Wordpress web site:

<script>
    let paymentsClient = null;

    operate getGooglePaymentsClient() {
        if ( paymentsClient === null ) {
            paymentsClient = new google.funds.api.PaymentsClient({setting: 'TEST'});
        }
        return paymentsClient;
    }

    operate 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(operate(response) {
                if (response.end result) {
                    addGooglePayButton();
                }
            })
            .catch(operate(err) {
                // present error in developer console for debugging
                console.error(err);
            });
    }

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

    operate onGooglePaymentButtonClicked() {
        const paymentDataRequest = {
            apiVersion: 2,
            apiVersionMinor: 0,
            allowedPaymentMethods: [{
                type: 'CARD',
                parameters: {
                    allowedAuthMethods: ["PAN_ONLY", "CRYPTOGRAM_3DS"],
                    allowedCardNetworks: ["AMEX", "DISCOVER", "INTERAC", "JCB", "MASTERCARD", "VISA"]
                },
                tokenizationSpecification: {
                    sort: 'PAYMENT_GATEWAY',
                    parameters: {
                        'gateway': 'gatewayservices',
                        'gatewayMerchantId': '[MerchantID]' // This worth is situated within the account info settings web 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(operate(paymentData) {
                // deal with the response
                processPayment(paymentData);
            })
            .catch(operate(err) {
                // present error in developer console for debugging
                console.error(err);
            });
    }

    operate processPayment(paymentData) {
        console.log(paymentData);
    }
</script>