
function configurePageForCreditMessage() {
    if (typeof braintree == 'undefined' || braintree === '') {
        addBrainTreeLibrary(function () {
            initialiseCreditMessage();
        });
    } else {
        initialiseCreditMessage();
    }
}

function initialiseCreditMessage() {
    if (typeof braintree != 'undefined' && braintree !== '') {
        createClientInstance(CONST.PAYPAL_EXPRESS_ERROR_ID, function () {
            braintree.paypalCheckout.create({
                autoSetDataUserIdToken: shouldRenderPayPalChangePaymentButton,
                client: client
            }, function (paypalCheckoutErr, paypalCheckoutInstance) {
                if (typeof paypal === "undefined") {
                    const commit = paypalIntent === CONST.INTENT_SALE && userAction === 'true';
                    loadSDK(paypalCheckoutInstance, paypalIntent, commit, getPaypalFlow(), function(){
                        hidePayPalPayLaterMessages();
                    });
                }
            });
        });
    }
}

function hidePayPalPayLaterMessages() {
    let payPalPayLaterMessage = document.getElementById(CONST.PAY_PAL_PAY_LATER_MESSAGE);

    if (payPalPayLaterMessage != null && !dropInEnabled && paypal.isFundingEligible(paypal.FUNDING.CREDIT)) {
        payPalPayLaterMessage.style.display = 'none';
    }
}
