I have created three custom form fields in checkout payment section.

I have followed this link to create form fields (How to add additional field to checkout payment (Magento 2)).

Now want to know how to save these fields data in the database.



You can add getData method in your js file:

getData: function() {
            return {
                'method': "methodcode",
                'additional_data': {
                    'customfield1': $('#'+this.getCode()+'_customfield1').val(),
                    'customfield2': $('#'+this.getCode()+'_customfield2').val(),

then you can get these fields in additional data param in your payment model:

namespace Namespace\ModuleName\Model;

class Payment extends \Magento\Payment\Model\Method\Cc
  public function assignData()
     $post = $data->getData()['additional_data'];
     // write your custom code

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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