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.


1 Answer 1


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 you have read our privacy policy.

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