Skip to content

[Issue] add missing PaymentMethodInterface #33008

Open
@m2-assistant

Description

@m2-assistant

This issue is automatically created based on existing pull request: #33003: add missing PaymentMethodInterface


Description (*)

During checkout payment information details can be requested via
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Checkout/Model/PaymentInformationManagement.php#L185

which uses

        $paymentDetails->setPaymentMethods($this->paymentMethodManagement->getList($cartId));

According to https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Checkout/Api/Data/PaymentDetailsInterface.php#L25 this should be an array of \Magento\Quote\Api\Data\PaymentMethodInterface

Any Payment Methods based on https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Payment/Model/Method/Adapter.php would technically not be valid due to the missing interface. The interface methods are already implemented. As the Adapter class already includes these methods this should not be a breaking change.

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes N/A

Manual testing scenarios (*)

  1. Test checkout with different payment methods

Additional Information to reproduce the issue

we have tried to debug the code. According to the interface app/code/Magento/Checkout/Api/Data/PaymentDetailsInterface.php:

/**
* @return \Magento\Quote\Api\Data\PaymentMethodInterface[]
*/
public function getPaymentMethods();

The overriding/implemented method should return the object of the class \Magento\Quote\Api\Data\PaymentMethodInterface[]. And we can see it is implemented in the below class:

public function getPaymentMethods()
{
return $this->getData(self::PAYMENT_METHODS);
}

Which internally calls the $this->getData(self::PAYMENT_METHODS);:

public function getData($key = '', $index = null)
{
if ($key === self::CUSTOM_ATTRIBUTES) {
throw new \LogicException("Custom attributes array should be retrieved via getCustomAttributes() only.");
} elseif ($key === '') {
/** Represent model data and custom attributes as a flat array */
$customAttributes = isset($this->_data[self::CUSTOM_ATTRIBUTES])
? $this->_data[self::CUSTOM_ATTRIBUTES]
: [];
$this->convertCustomAttributeValues($customAttributes);
$data = array_merge($this->_data, $customAttributes);
unset($data[self::CUSTOM_ATTRIBUTES]);
} else {
$data = parent::getData($key, $index);
if ($data === null) {
/** Try to find necessary data in custom attributes */
$data = isset($this->_data[self::CUSTOM_ATTRIBUTES][$key])
? $this->_data[self::CUSTOM_ATTRIBUTES][$key]
: null;
if ($data instanceof \Magento\Framework\Api\AttributeValue) {
$data = $data->getValue();
}
if (null !== $index && isset($data[$index])) {
return $data[$index];
}
}
}
return $data;
}

Which is returning the mixed array as shown in the below screenshot:

image

I think you are talking about the same thing it should return the object of \Magento\Quote\Api\Data\PaymentMethodInterface[] but it is returning the mixed array.

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Metadata

Metadata

Assignees

Labels

Area: FrameworkComponent: PaymentIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: PR in progressProgress: ready for devReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions