13

I've set up a new payment method in Magento 2 with a custom payment method field (like "po_number" from magento/offline-payment-methods). And front end is working perfectly fine (field showing up, validation, etc.).

However, if I want to place the order Magento the WebAPI request throws the following error:

"Property \"CustomField\" does not have corresponding setter in class \"Magento\Quote\Api\Data\PaymentInterface\".

It seems that Magento validates the custom field against the core payment interface where methods like getPoNumber and setPoNumber are defined.

I already tried to add the custom field via extension attributes:

<extension_attributes for="Magento\Quote\Api\Data\PaymentInterface">
    <attribute code="custom_field" type="Vendor\Module\Api\Data\MethodInterface[]" />
</extension_attributes>

and created the interface with the specific methods:

<?php
namespace Vendor\Module\Api\Data;
use Magento\Framework\Api\ExtensibleDataInterface;
interface MethodInterface extends ExtensibleDataInterface
{
    public function setCustomField($customField);
    public function getCustomField();
}

But this doesn't work. Magento still validates against the core payment interface.

The question now is, how to get Magento to accept the custom payment method field? Any pointers are much appreciated :)

1
  • I'm also interested, I used same approach (extension_attributes) but no success, then I dropped the idea and I used set/getAdditionalInformation('custom_field') instead of using custom field.
    – carco
    Commented Apr 13, 2016 at 13:01

1 Answer 1

3

Magento2 is not well-architectured here. What I did is I passed them as extension_attributes of additional_data, then assigned that information in the assignData() method so it gets persisted. Later I retrieve such information in the capture() method and use it. You can have a look here: Openpay PaymentMethod

0

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.