0

I'm trying to add a new field via KO in the payment method where paymentdata is collected. Right now all I see is the agreement_id as part of it's parameter. Now I added another parameter which is the subscription_id. But upon clicking the proceed button it say

Property "SubscriptionIds" does not have accessor method "getSubscriptionIds" in class "Magento\Quote\Api\Data\PaymentExtensionInterface".

Now I can't find this class in vendor/magento/module-quote/Api/Data. I need to overwrite this class right now it's being defined in the generated folder the content is this

<?php
namespace Magento\Quote\Api\Data;

/**
 * Extension class for @see \Magento\Quote\Api\Data\PaymentInterface
 */
class PaymentExtension extends \Magento\Framework\Api\AbstractSimpleObject implements PaymentExtensionInterface
{
    /**
     * @return string[]|null
     */
    public function getAgreementIds()
    {
        return $this->_get('agreement_ids');
    }

    /**
     * @param string[] $agreementIds
     * @return $this
     */
    public function setAgreementIds($agreementIds)
    {
        $this->setData('agreement_ids', $agreementIds);
        return $this;
    }
}

But I can't find this in the vendor folder even though I looked in the vendor/magento/module-quote/Api/Data

Any idea on how to override this? As I need to retrieve the new parameter when submitting the order in the payment method page

1 Answer 1

0

First of all, you cannot override PaymentExtensionInterface - it is generated piece of code.

If you want to define a new field, similar to agreement_ids you should create extension_attributes.xml file in your Company/Module/etc directory with a content like this:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="Magento\Quote\Api\Data\PaymentInterface">
        <attribute code="subscription_id" type="string" />
    </extension_attributes>
</config>

Getters and setters for subscribtion_id attribute will be generated by Magento and will be present in PaymentExtensionInterface.

You can find more info here: https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_new_field.html

Unfortunately, example in docs is more about shipping than billing step form, but take a look at Magento's checkout-agreements module for some ideas.

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.