2

What is a proper way to implement offline payment method in Magento 2.2.*?

I did it old style like in module magento/module-offline-payments and it is working.

My payment model extends Magento\Payment\Model\Method\AbstractMethod.

I wonder that Magento\Payment\Model\Method\AbstractMethod is deprecated and a suggestion is that custom payment method should extend Magento\Payment\Model\Method\Adapter but I don't want to make integration with any payment provider gateway.

In Magento 2 guides I found only integration with the third-party approach:

https://devdocs.magento.com/guides/v2.2/payments-integrations/bk-payments-integrations.html

Sample:

https://github.com/magento/magento2-samples/tree/master/sample-module-payment-gateway

1

Instead of using the AbstractMethod, what Magento wants you to do is either implement a virtual type of the façade you mention, or implement the interfaces directly.

  • Magento\Payment\Model\MethodInterface
  • Magento\Quote\Api\Data\PaymentMethodInterface

Most of the massive amount of methods are simple getters/setters, and AbstractMethod comes to the rescue by providing basic implementation of that.

However, Magento no longer likes inheritance - it's bad for tracking dependencies and can lead to complications with testing. Instead they now prefer composition.

You can read more about the pros and cons of Composition over Inheritance on wikipedia.

You can still utilize the façade by following the tutorial. Obviously you don't perform authorization, capture, or voiding so you can set false to those on the virtual type, and you shouldn't have to worry about implementing commands for them.

  • Hi @navarr, but what about the config in di.xml for the offline payment method ? Do we need to write anything about them also ?? – Parth Thakkar Aug 7 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.