0

Magento 2 : Saved Credit cards in a dropdown in custom payment

From the above link, i have successfully created select field with credit card details dropdown in the checkout page.Can i know how i can attach (or post that data) those details to payment object while placing order in magento2.

I have added the code in my payment model

   public function assignData(\Magento\Framework\DataObject $data)
       {
          parent::assignData($data);
          $post = $data->getData()['additional_data'];
          $this->getInfoInstance()->setAdditionalData($post);
          return $this;
       }

Is the correct way?

1 Answer 1

1

Yes its correct method , There is 2 table quote_payment , sales_order_payment both are stored value.

quote_payment store value for quote of your cart , sales_order_payment store your order payment related information. but storing information after placing order field name is same as table field name. you are setting all information in additional_information.

add below method in test-method.js add method :

 getData: function() {
   return {
    'method': this.item.method,
    'additional_data': {
      'test_field':jQuery('#'+this.getCode()+'test_field').val(),
                }
            };
        }

in your_html.html file (Namespace\Modulename\view\frontend\web\template\payment) :

if your payment method code is test_payment then your field id is same with like test_payment_test_field.

you get this data in payment.php file (Namespace/Modulename/Model/Payment.php)

 public function assignData(\Magento\Framework\DataObject $data)
 {
    parent::assignData($data);
    $post = $data->getData()['additional_data'];
 }

Here $post is your posted form value array from checkout page.

9
  • I will give a try and update you
    – S.Venky
    Nov 11, 2017 at 13:08
  • Okay on Monday.
    – Yogesh
    Nov 11, 2017 at 13:09
  • We are getting the $post = $data->getData()['additional_data']; but we are not using or assigning to it.
    – S.Venky
    Nov 11, 2017 at 13:30
  • Post your payment.php code
    – Yogesh
    Nov 11, 2017 at 13:31
  • I have edited my question.please check
    – S.Venky
    Nov 11, 2017 at 13:39

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.