magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.55k stars 9.32k forks source link

Deprecated \Magento\Payment\Model\Method\AbstractMethod #5304

Closed rikterbeek closed 8 years ago

rikterbeek commented 8 years ago

Hi,

I see that the class AbstractMethod in Magento\Payment\Model\Method is going to be deprecated but it is used for all payment methods. This class is even used by native Magento core in Magento\Payment\Model\Method\Cc. What class do you need to use instead ?

Regards, Rik Adyen

orlangur commented 8 years ago

Hi @rikterbeek, look at https://github.com/magento/magento2/blob/develop/app/code/Magento/Vault/Model/Method/Vault.php, for instance. You must not extend AbstractMethod class in your own payment method but just implement Magento\Payment\Model\MethodInterface interface.

Note that https://github.com/magento/magento2/blob/develop/app/code/Magento/Payment/Model/Method/Cc.php#L15 class is deprecated as well.

rikterbeek commented 8 years ago

Hi @orlangur,

Thanks for this information. It is not totally clear now how to implement a payment method in the new structure do you have any technical documentation available about adding a payment method in the new way ?

Regards, Rik Adyen

joni-jones commented 8 years ago

Hi @rikterbeek, the dev documentation in a process, but you can use https://github.com/magento/magento2-samples/tree/master/sample-module-payment-gateway as an example. Also, a current version of Braintree is implemented in a new way.

hungpvdev commented 8 years ago

Hi @joni-jones ,

The latest commit in https://github.com/magento/magento2-samples/tree/master/sample-module-payment-gateway is 3 months ago. Both master and 2.1 branch. Actually 2.1 is even with master for now. Will this sample work in 2.1.0???

My client want payment extension support both 2.0.x and 2.x? Is this possible??? I have seen a lot of bug relate to checkout since 2.0.7 to 2.1.0 for now. Some of them are fixed but they are fixed in new patch only.

joni-jones commented 8 years ago

Hi @hungpvdev, yes, it still should works. According to a second question, it depends on your implementation. If it will work with 2.0.7 it also should work with 2.1, but, really, before 2.1 release, were fixed a lot of bugs for checkout module also.

andreaschiffo commented 8 years ago

i think the Magento API is supposed to ease the development of a new Patment Module but the complete lack of documentation, comments in the code, and any kind of explanation on how the flow works or is intended to work, make the operation a lot harder. This is my humble opinion: its could be the one of a noob Magento developer but believe me its not so verbose

rahulvramesh commented 8 years ago

While https://github.com/magento/magento2-samples/tree/master/sample-module-payment-gateway Integrating With cc-form.js , On Credit Card From Year And Month Is Not Listing. Is That An Issue ?

csdougliss commented 8 years ago

Totally agree here - trying to develop a new payment method and it's not very clear

joni-jones commented 8 years ago

@rahulvramesh this isn't an issue. Some integrations don't have these fields, for example, Braintree PayPal.

mariohosmar commented 7 years ago

I think magento should improve its documentation, adding a new payment method seems so obvious, dummy and common to implement all over the world but it is so complicated to achieve with the lack of information on it, and what it is worse the lack of info available is not clear at all.

orlangur commented 7 years ago

@mariohosmar did you try to use Braintree implementation for reference?

From https://github.com/magento/magento2/issues/7420 it does not look that hard. While not every significant topic is covered in documentation yet there are quite a lot of blog posts in the Web also.

rikterbeek commented 7 years ago

Hi @orlangur @mariohosmar

Have a look at our solution we support many payment methods and implemented against the latest specs of magento2. See https://github.com/adyen/adyen-magento2

Regards, Rik Adyen

flancer64 commented 6 years ago

Use \Magento\Payment\Model\Method\Adapter as a base instead of deprecated \Magento\Payment\Model\Method\AbstractMethod

floorz commented 6 years ago

Does this new approach to adding Payment Methods apply to Offline Payment Methods, such as one similar to Purchase Order?

I ask because I've gotten pretty far down the line using the deprecated approach which shows my payment method in the checkout, but after converting it over to the Adapter approach the method no longer shows in checkout.

orlangur commented 6 years ago

@floorz new approach should be preferable for both online/offline methods.

after converting it over to the Adapter approach the method no longer shows in checkout

This needs to be tracked down to an exact issue with debugger.

seyuf commented 4 years ago

@flancer64 the Adapter seems to not be the right replacement in every caseMagento\Payment\Model\MethodInterface is. Indeed \Magento\Payment\Model\Method\Adapter forces one to set a gateway command Pool. It would be nice if @orlangur could confirm this... Also the deprecated AbstractMethod seems to be still predominately present in magento code base so i assume, we still have some months/year before this is definitely gone?

Edit It seems that one can use \Magento\Payment\Model\Method\Adapter and through config.xml disable command as follow <can_capture>0</can_capture> the command execution is still called but the code will exit at https://github.com/magento/magento2/blob/4dfb6da5408199bf1323fde699af049e1fc99668/app/code/Magento/Payment/Model/Method/Adapter.php#L528

 if (!$this->canPerformCommand($commandCode)) {
            return null;
        }
mmihalev commented 4 years ago

Does this new approach to adding Payment Methods apply to Offline Payment Methods, such as one similar to Purchase Order?

I ask because I've gotten pretty far down the line using the deprecated approach which shows my payment method in the checkout, but after converting it over to the Adapter approach the method no longer shows in checkout.

@floorz Can you please share how you converted the offline payment method to use the Adapter class?

mattkammersell commented 1 year ago

Does this new approach to adding Payment Methods apply to Offline Payment Methods, such as one similar to Purchase Order? I ask because I've gotten pretty far down the line using the deprecated approach which shows my payment method in the checkout, but after converting it over to the Adapter approach the method no longer shows in checkout.

@floorz Can you please share how you converted the offline payment method to use the Adapter class?

@mmihalev - I just had to go through this, I had to implement the Facade, including the Command and Config pool, I just emptied out the Command pool in di.xml and did this implementation of the getConfig method in the ConfigProviderInterface:

    return [
        'payment' => [ self::CODE => [] ]
    ];

Another key was these config values:

<can_capture>0</can_capture>
<can_use_checkout>1</can_use_checkout>
<is_gateway>0</is_gateway>

Hope that helps.