1

In my custom payment method there is 1 checkbox as seen below:

enter image description here

In the Admin Settings, if I set it to disable then I don't want to show it.

Following div is for that field.

form.html

<div class="payfull_form-group use-3d-wrapper" style="">
    <div class="custom-input">
      <div class="custom-checkbox">
        <label class="custom-label empty-payfull_label"></label>
        <label class="custom-label_checkbox">
          <input name="use3d" id="use3d" value="1" type="checkbox">
          Use 3D secure Payments System
        </label>
      </div>
    </div>
  </div>

How can I achieve that?

6
  • How about your issue now? Commented Jan 9, 2017 at 10:08
  • Solved thanks for helping me. I have created helper file and config file. In config file I have used helper because there i have defined my function. Thanks again Commented Jan 9, 2017 at 10:14
  • If my answer helped you solving your problem, please accept it as the solution. Commented Jan 9, 2017 at 10:20
  • I have accepted In first part of code u define function get3DSecure() Which is not working for me. Commented Jan 9, 2017 at 10:29
  • You have used the Js and html logic? Commented Jan 9, 2017 at 10:30

1 Answer 1

2

If you have already the payment, you can follow the same logic:

In your Payment Config Provider, you add the 3D Secure config:

/**
 * {@inheritdoc}
 */
public function getConfig()
{
    return $this->method->isAvailable() ? [
        'payment' => [
            'your_payment_code' => [
                ......
                '3DSecure' => $this->get3DSecure()
            ],
        ],
    ] : [];
}
/**
* Get config from admin
*/
public function get3DSecure()
{
    //Data from system.xml fields
    return $this->getConfigData('3dsecure');
}

Navigate to the Js payment method render, we can get from checkout global variable:

/*browser:true*/
/*global define*/
define(
    [
        'Magento_Checkout/js/view/payment/default'
    ],
    function (Component) {
        'use strict';

        return Component.extend({
            defaults: {
                template: 'YourModule_Payment/payment/custompayment'
            },

            get3DSecure: function() {
                return window.checkoutConfig.payment.paymentcustom.3DSecure;
            },

            isEnable3DSecure: function() {
              if(this.get3DSecure()) {
                return true;
              }
              return false;
            }

        });
    }
);

In your html template, we can check:

      <!-- ko if: isEnable3DSecure() -->
            <div class="payfull_form-group use-3d-wrapper" style="">
                <div class="custom-input">
                    <div class="custom-checkbox">
                        <label class="custom-label empty-payfull_label"></label>
                        <label class="custom-label_checkbox">
                        <input name="use3d" id="use3d" value="1" type="checkbox">
                        Use 3D secure Payments System
                        </label>
                    </div>
                </div>
            </div>
      <!-- /ko -->

Read more: http://devdocs.magento.com/guides/v2.1/howdoi/checkout/checkout_payment.html

14
  • I have not created any Payment Config Provider. Please tell me where and why we have to create. Commented Jan 7, 2017 at 11:46
  • Which tutorial you follow to create a custom payment? Commented Jan 7, 2017 at 11:49
  • I don't remember now. Commented Jan 7, 2017 at 11:50
  • Now, you payment can show? Can you update you answer with the payment folder structure? You can use this tool to generate your payment: cedcommerce.com/magento-2-module-creator/payment-module Commented Jan 7, 2017 at 11:52
  • Right I have created with this tool already. Yes, my payment method is showing at checkout page. Commented Jan 7, 2017 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.