2

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.

Thanks

1 Answer 1

0

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 agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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