Skip to main content
added 75 characters in body
Source Link
Sohel Rana
  • 36.1k
  • 3
  • 73
  • 91
/*browser:true*/
/*global define*/
define(
    [
        'Magento_Checkout/js/view/payment/default',
        'Magento_Customer/js/customer-data',
        'Magento_Checkout/js/model/quote'
    ],
    function (Component, CustomercustomerData, quote) {
        'use strict';

        return Component.extend({
            defaults: {
                template: 'TestVendor_TestPayment/payment/testpayment'
            },

            /** Returns send check to info */
            getMailingAddress: function() {
                return window.checkoutConfig.payment.checkmo.mailingAddress;
            },
            isDisplayed:function () {
                var customer = customerData.get('customer');
                console.log(Customercustomer().firstname);

                var totals = quote.getTotals()();
                var grand_total;
                if (totals) {
                    grand_total = totals.grand_total;
                } else {
                    grand_total = quote.grand_total;
                }

                console.log(grand_total);
                return false;true;
            }

        });
    }
);
 
/*browser:true*/
/*global define*/
define(
    [
        'Magento_Checkout/js/view/payment/default',
        'Magento_Customer/js/customer-data',
        'Magento_Checkout/js/model/quote'
    ],
    function (Component, Customer, quote) {
        'use strict';

        return Component.extend({
            defaults: {
                template: 'TestVendor_TestPayment/payment/testpayment'
            },

            /** Returns send check to info */
            getMailingAddress: function() {
                return window.checkoutConfig.payment.checkmo.mailingAddress;
            },
            isDisplayed:function () {
                console.log(Customer);

                var totals = quote.getTotals()();
                var grand_total;
                if (totals) {
                    grand_total = totals.grand_total;
                } else {
                    grand_total = quote.grand_total;
                }

                console.log(grand_total);
                return false;
            }

        });
    }
);
 
/*browser:true*/
/*global define*/
define(
    [
        'Magento_Checkout/js/view/payment/default',
        'Magento_Customer/js/customer-data',
        'Magento_Checkout/js/model/quote'
    ],
    function (Component, customerData, quote) {
        'use strict';

        return Component.extend({
            defaults: {
                template: 'TestVendor_TestPayment/payment/testpayment'
            },

            /** Returns send check to info */
            getMailingAddress: function() {
                return window.checkoutConfig.payment.checkmo.mailingAddress;
            },
            isDisplayed:function () {
                var customer = customerData.get('customer');
                console.log(customer().firstname);

                var totals = quote.getTotals()();
                var grand_total;
                if (totals) {
                    grand_total = totals.grand_total;
                } else {
                    grand_total = quote.grand_total;
                }

                console.log(grand_total);
                return true;
            }

        });
    }
);
added 157 characters in body
Source Link
Sohel Rana
  • 36.1k
  • 3
  • 73
  • 91
/*browser:true*/
/*global define*/
define(
    [
        'Magento_Checkout/js/view/payment/default',
        'Magento_Customer/js/customer-data',
        'Magento_Checkout/js/model/quote'
    ],
    function (Component, Customer, quote) {
        'use strict';

        return Component.extend({
            defaults: {
                template: 'TestVendor_TestPayment/payment/testpayment'
            },

            /** Returns send check to info */
            getMailingAddress: function() {
                return window.checkoutConfig.payment.checkmo.mailingAddress;
            },
            isDisplayed:function () {
                //console.log(Customer);

 you can modify your custom logic          var totals = quote.getTotals()();
                var grand_total;
                if (totals) {
                    grand_total = totals.grand_total;
                } else {
                    grand_total = quote.grand_total;
                }

                console.log(grand_total);
                return false;
            }

        });
    }
); 

define(
    [
        'Magento_Checkout/js/view/payment/default'
    ],
    function (Component) {
        'use strict';

        return Component.extend({
            defaults: {
                template: 'TestVendor_TestPayment/payment/testpayment'
            },

            /** Returns send check to info */
            getMailingAddress: function() {
                return window.checkoutConfig.payment.checkmo.mailingAddress;
            },
            isDisplayed:function () {
                // you can modify your custom logic
                return false;
            }

        });
    }
);
/*browser:true*/
/*global define*/
define(
    [
        'Magento_Checkout/js/view/payment/default',
        'Magento_Customer/js/customer-data',
        'Magento_Checkout/js/model/quote'
    ],
    function (Component, Customer, quote) {
        'use strict';

        return Component.extend({
            defaults: {
                template: 'TestVendor_TestPayment/payment/testpayment'
            },

            /** Returns send check to info */
            getMailingAddress: function() {
                return window.checkoutConfig.payment.checkmo.mailingAddress;
            },
            isDisplayed:function () {
                console.log(Customer);

                var totals = quote.getTotals()();
                var grand_total;
                if (totals) {
                    grand_total = totals.grand_total;
                } else {
                    grand_total = quote.grand_total;
                }

                console.log(grand_total);
                return false;
            }

        });
    }
); 

Source Link
Sohel Rana
  • 36.1k
  • 3
  • 73
  • 91

Try follwoing way:

TestVendor/TestPayment/view/frontend/web/js/view/payment/method-renderer/testpayment-method.js

define(
    [
        'Magento_Checkout/js/view/payment/default'
    ],
    function (Component) {
        'use strict';

        return Component.extend({
            defaults: {
                template: 'TestVendor_TestPayment/payment/testpayment'
            },

            /** Returns send check to info */
            getMailingAddress: function() {
                return window.checkoutConfig.payment.checkmo.mailingAddress;
            },
            isDisplayed:function () {
                // you can modify your custom logic
                return false;
            }

        });
    }
);

TestVendor/TestPayment/view/frontend/web/template/payment/testpayment.html

<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
    <div class="payment-method-title field choice">
        <input type="radio"
               name="payment[method]"
               class="radio"
               data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/>
        <label data-bind="attr: {'for': getCode()}" class="label"><span data-bind="text: getTitle()"></span></label>
    </div>
    <div class="payment-method-content">
        <!-- ko foreach: getRegion('messages') -->
        <!-- ko template: getTemplate() --><!-- /ko -->
        <!--/ko-->
        <div class="payment-method-billing-address">
            <!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
            <!-- ko template: getTemplate() --><!-- /ko -->
            <!--/ko-->
        </div>
        <div class="checkout-agreements-block">
            <!-- ko foreach: $parent.getRegion('before-place-order') -->
            <!-- ko template: getTemplate() --><!-- /ko -->
            <!--/ko-->
        </div>
        <div class="actions-toolbar">
            <div class="primary">
                <!-- ko if: isDisplayed() -->
                <button class="action primary checkout"
                        type="submit"
                        data-bind="
                        click: placeOrder,
                        attr: {title: $t('Place Order')},
                        css: {disabled: !isPlaceOrderActionAllowed()},
                        enable: (getCode() == isChecked())
                        "
                        disabled>
                    <span data-bind="i18n: 'Place Order'">
                </button>
                <!-- /ko -->
            </div>
        </div>
    </div>
</div>

Run following command

php bin/magento setup:static-content:deploy

Clear cache.