How to Send Custom Field Data in additional data of custom payment method magento 2?

  • author-img Nidhi Arora
  • 4 years
How to Send Custom Field Data in additional data of custom payment method magento 2
image_pdfPrintimage_printSave as PDF

Sometime you may need to send custom field data from custom payment method of magento2. i.e. you may need to add an extra field on checkout payment page. Mainly there is three required field in custom payment module like credit card number, cvv, expiration data. If you want to send an extra field data to Model file of your module you can override magento getData method as follows.

1. Look up for a file called cc-form.js in your magento installation under vendor\magento\module-payment\view\frontend\web\js\view\payment.

2. You will see getData function which we will override in our module payment_module_code-method.js as below.

getData: function () {

var data = {

'method': this.getCode(),

'additional_data': {

'cc_cid': this.creditCardVerificationNumber(),

'cc_ss_start_month': this.creditCardSsStartMonth(),

'cc_ss_start_year': this.creditCardSsStartYear(),

'cc_ss_issue': this.creditCardSsIssue(),

'cc_type': this.creditCardType(),

'cc_exp_year': this.creditCardExpYear(),

'cc_exp_month': this.creditCardExpMonth(),

'cc_number': this.creditCardNumber(),

'cc_token': $('#' + this.getCode() + '_cc_token').val(),


return data;


You can see I am sending cc_token an custom field value with additional data to Model file of magento2 custom module. And you can fectch this value in model file as using below code.

public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount)


$info = $this->getInfoInstance();

$paymentInfo = $info->getAdditionalInformation()['data']['additional_data'];



If you are having any doubts, feel free to contact us at [email protected] . However, if you do have any additional tips or method on this “How to”, you can suggest them in the comment section below.

Stay tuned for more “How to” blog on Magento 2. Till then Happy Magento 2 Coding!

Free Webinar

Join us for a FREE webinar