Payment method with custom form in Knockout jsForm Click Event in magento 2Checkout uiComponent (input field)...

How can I get players to stop ignoring or overlooking the plot hooks I'm giving them?

List elements digit difference sort

What are actual Tesla M60 models used by AWS?

An alternative proof of an application of Hahn-Banach

Accountant/ lawyer will not return my call

What was the Kree's motivation in Captain Marvel?

Find longest word in a string: are any of these algorithms good?

Signed and unsigned numbers

Declaring and defining template, and specialising them

Does "Until when" sound natural for native speakers?

Are all players supposed to be able to see each others' character sheets?

How to secure an aircraft at a transient parking space?

Error during using callback start_page_number in lualatex

If I receive an SOS signal, what is the proper response?

Contract Factories

In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?

Virginia employer terminated employee and wants signing bonus returned

Difference on montgomery curve equation between EFD and RFC7748

Why was Goose renamed from Chewie for the Captain Marvel film?

What Happens when Passenger Refuses to Fly Boeing 737 Max?

Why the color red for the Republican Party

Is "conspicuously missing" or "conspicuously" the subject of this sentence?

Why does Captain Marvel assume the people on this planet know this?

How strictly should I take "Candidates must be local"?



Payment method with custom form in Knockout js


Form Click Event in magento 2Checkout uiComponent (input field) rendered multiple times: how do I apply viewmodel functionality to current input field only?Insert custom block at payment Method section In Magento 2Include the cc payment template in other templateCheckout Form - How to wrap multiple elements in a class - Magento 2Magento 2 : Payment Method is Hidden in Admin When Creating Manual OrderMagento 2 Redirect user to a custom payment method from a custom page?magento 2 get the values from custom input elements in checkout page after place order?How do you add custom styling to radio buttons in the shipping method section of Magento 2 checkout?How to add input field in check money order payment method in magento 2?













1















I've created a custom payment method successfully in Magento2. When this custom payment method selected, I need a form to display a text field and submit button that will hit some AJAX Api's using in controller and then show a pop-up based on result API response.



Here is my knockout js file:



RLTS/Custompayment/view/frontend/web/js/view/payment/method-renderer/mycustompayment.js

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

return Component.extend({
defaults: {
template: 'RLTS_Custompayment/payment/mycustompayment'
},
initialize: function () {
this._super();
return this;
},
onSubmit : function () {
var formData = this.source.get(this.getCode() + '-form' );
var formField = this.source.get('customformfield');
console.log(formData);
console.log(formField);
}
});
}
);


And I added my form in ko template as follow:



<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="payment-method-form-wrapper">
<form id="custom-checkout-form" class="form" data-bind="attr: {'id': getCode() + '-form' , 'data-hasrequired': $t('* Required Fields')}">
<input type="text" class="input-text" name="customformfield" placeholder="Custom Form Field" />
<button type="reset">
<span data-bind="i18n: 'Reset'"></span>
</button>
<button type="button" data-bind="click: onSubmit" class="action">
<span data-bind="i18n: 'Submit'"></span>
</button>
</form>
</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">
<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'"></span>
</button>
</div>
</div>
</div>
</div>


Without using form, my payment method is working perfectly fine. How to add custom form and process Ajax calls for it before placing order?










share|improve this question
















bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    1















    I've created a custom payment method successfully in Magento2. When this custom payment method selected, I need a form to display a text field and submit button that will hit some AJAX Api's using in controller and then show a pop-up based on result API response.



    Here is my knockout js file:



    RLTS/Custompayment/view/frontend/web/js/view/payment/method-renderer/mycustompayment.js

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

    return Component.extend({
    defaults: {
    template: 'RLTS_Custompayment/payment/mycustompayment'
    },
    initialize: function () {
    this._super();
    return this;
    },
    onSubmit : function () {
    var formData = this.source.get(this.getCode() + '-form' );
    var formField = this.source.get('customformfield');
    console.log(formData);
    console.log(formField);
    }
    });
    }
    );


    And I added my form in ko template as follow:



    <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="payment-method-form-wrapper">
    <form id="custom-checkout-form" class="form" data-bind="attr: {'id': getCode() + '-form' , 'data-hasrequired': $t('* Required Fields')}">
    <input type="text" class="input-text" name="customformfield" placeholder="Custom Form Field" />
    <button type="reset">
    <span data-bind="i18n: 'Reset'"></span>
    </button>
    <button type="button" data-bind="click: onSubmit" class="action">
    <span data-bind="i18n: 'Submit'"></span>
    </button>
    </form>
    </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">
    <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'"></span>
    </button>
    </div>
    </div>
    </div>
    </div>


    Without using form, my payment method is working perfectly fine. How to add custom form and process Ajax calls for it before placing order?










    share|improve this question
















    bumped to the homepage by Community 5 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      1












      1








      1


      1






      I've created a custom payment method successfully in Magento2. When this custom payment method selected, I need a form to display a text field and submit button that will hit some AJAX Api's using in controller and then show a pop-up based on result API response.



      Here is my knockout js file:



      RLTS/Custompayment/view/frontend/web/js/view/payment/method-renderer/mycustompayment.js

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

      return Component.extend({
      defaults: {
      template: 'RLTS_Custompayment/payment/mycustompayment'
      },
      initialize: function () {
      this._super();
      return this;
      },
      onSubmit : function () {
      var formData = this.source.get(this.getCode() + '-form' );
      var formField = this.source.get('customformfield');
      console.log(formData);
      console.log(formField);
      }
      });
      }
      );


      And I added my form in ko template as follow:



      <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="payment-method-form-wrapper">
      <form id="custom-checkout-form" class="form" data-bind="attr: {'id': getCode() + '-form' , 'data-hasrequired': $t('* Required Fields')}">
      <input type="text" class="input-text" name="customformfield" placeholder="Custom Form Field" />
      <button type="reset">
      <span data-bind="i18n: 'Reset'"></span>
      </button>
      <button type="button" data-bind="click: onSubmit" class="action">
      <span data-bind="i18n: 'Submit'"></span>
      </button>
      </form>
      </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">
      <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'"></span>
      </button>
      </div>
      </div>
      </div>
      </div>


      Without using form, my payment method is working perfectly fine. How to add custom form and process Ajax calls for it before placing order?










      share|improve this question
















      I've created a custom payment method successfully in Magento2. When this custom payment method selected, I need a form to display a text field and submit button that will hit some AJAX Api's using in controller and then show a pop-up based on result API response.



      Here is my knockout js file:



      RLTS/Custompayment/view/frontend/web/js/view/payment/method-renderer/mycustompayment.js

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

      return Component.extend({
      defaults: {
      template: 'RLTS_Custompayment/payment/mycustompayment'
      },
      initialize: function () {
      this._super();
      return this;
      },
      onSubmit : function () {
      var formData = this.source.get(this.getCode() + '-form' );
      var formField = this.source.get('customformfield');
      console.log(formData);
      console.log(formField);
      }
      });
      }
      );


      And I added my form in ko template as follow:



      <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="payment-method-form-wrapper">
      <form id="custom-checkout-form" class="form" data-bind="attr: {'id': getCode() + '-form' , 'data-hasrequired': $t('* Required Fields')}">
      <input type="text" class="input-text" name="customformfield" placeholder="Custom Form Field" />
      <button type="reset">
      <span data-bind="i18n: 'Reset'"></span>
      </button>
      <button type="button" data-bind="click: onSubmit" class="action">
      <span data-bind="i18n: 'Submit'"></span>
      </button>
      </form>
      </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">
      <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'"></span>
      </button>
      </div>
      </div>
      </div>
      </div>


      Without using form, my payment method is working perfectly fine. How to add custom form and process Ajax calls for it before placing order?







      checkout payment-methods forms uicomponent knockoutjs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '17 at 14:13







      saiid

















      asked Nov 16 '17 at 14:04









      saiidsaiid

      6532822




      6532822





      bumped to the homepage by Community 5 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 5 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I am also looking for solution on this . I am going to integrate new payment method in magento checkout ...
          Kindly suggest how can i bind any request call on enter image description here



          on clicking on Next button ...






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "479"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f201868%2fpayment-method-with-custom-form-in-knockout-js%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I am also looking for solution on this . I am going to integrate new payment method in magento checkout ...
            Kindly suggest how can i bind any request call on enter image description here



            on clicking on Next button ...






            share|improve this answer




























              0














              I am also looking for solution on this . I am going to integrate new payment method in magento checkout ...
              Kindly suggest how can i bind any request call on enter image description here



              on clicking on Next button ...






              share|improve this answer


























                0












                0








                0







                I am also looking for solution on this . I am going to integrate new payment method in magento checkout ...
                Kindly suggest how can i bind any request call on enter image description here



                on clicking on Next button ...






                share|improve this answer













                I am also looking for solution on this . I am going to integrate new payment method in magento checkout ...
                Kindly suggest how can i bind any request call on enter image description here



                on clicking on Next button ...







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jul 26 '18 at 8:35









                Ramesh ChauhanRamesh Chauhan

                335




                335






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f201868%2fpayment-method-with-custom-form-in-knockout-js%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

                    How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

                    夢乃愛華...