Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to configure custom availability gateway validator #5857

Closed
ytorbyk opened this issue Jul 28, 2016 · 12 comments
Closed

Impossible to configure custom availability gateway validator #5857

ytorbyk opened this issue Jul 28, 2016 · 12 comments
Assignees
Labels
bug report Component: Payment Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@ytorbyk
Copy link
Member

ytorbyk commented Jul 28, 2016

Preconditions

Magento 2.1.0 is used

Steps to reproduce

I try to add custom availability validator to gateway validator pool
<virtualType name="MyPaymentValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool"> <arguments> <argument name="validators" xsi:type="array"> <item name="availability" xsi:type="string">Vendor\Name\Gateway\Validator\AvailabilityValidator</item> </argument> </arguments> </virtualType>

Expected result

  1. Passed validator has to be used on \Magento\Payment\Model\Method\Adapter::isAvailable method call.

Actual result

  1. The validator is never used/called

It is caused because result of $this->getInfoInstance() method call is always null (inside the
\Magento\Payment\Model\Method\Adapter::isAvailable method).

@vzabaznov vzabaznov self-assigned this Jul 28, 2016
@vzabaznov vzabaznov removed their assignment Jul 28, 2016
@YevSent
Copy link
Contributor

YevSent commented Jul 28, 2016

Hi @ytorbyk, please, post DI configuration for virtual type of your custom payment adapter.

@ytorbyk
Copy link
Member Author

ytorbyk commented Jul 28, 2016

Here it is:
<virtualType name="MyPaymentAdapter" type="Magento\Payment\Model\Method\Adapter"> <arguments> <argument name="code" xsi:type="const">Vendor\Name\Gateway\Config\ConfigProvider::CODE</argument> <argument name="formBlockType" xsi:type="string">Magento\Payment\Block\Form\Cc</argument> <argument name="infoBlockType" xsi:type="string">Vendor\Name\Block\Payment\Info</argument> <argument name="valueHandlerPool" xsi:type="object">MyPaymentValueHandlerPool</argument> <argument name="validatorPool" xsi:type="object">MyPaymentValidatorPool</argument> <argument name="commandPool" xsi:type="object">MyPaymentCommandPool</argument> </arguments> </virtualType>

You can check this bug even on Braintree payment method, just try to add availability validator to the braintree validator pool.

@YevSent
Copy link
Contributor

YevSent commented Jul 28, 2016

Looks like configuration is correct. We will investigate this issue, but strange behaviour because on the latest develop branch the getInfoInstance in the \Magento\Payment\Model\Method\Adapter::isAvailable method returns Payment object.

@ytorbyk
Copy link
Member Author

ytorbyk commented Jul 28, 2016

I tested locally on the latest commit on the develop branch with the same result.
db9e0f Alexander Akimov on 7/21/16 at 12:55 (committed by GitHub) Merge pull request #165 from magento-qmt/PR

https://dl.dropboxusercontent.com/u/2008499/Screen%20Shot%202016-07-28%20at%2016.21.50.png
https://dl.dropboxusercontent.com/u/2008499/Screen%20Shot%202016-07-28%20at%2016.24.13.png

Thank for quick response.
Let me know if you need any additional information.

@YevSent
Copy link
Contributor

YevSent commented Jul 28, 2016

Could you check the same behaviour for one of Magento payments, for example, Braintree? Just to check $this->getInfoInstance() won't be empty in isAvailable method. Even don't need to specify `availability validator.
PS. Links to screenshots are broken.
Thanks.

@ytorbyk
Copy link
Member Author

ytorbyk commented Jul 28, 2016

Yes, I have checked on Braintree payment method. The result on the those screenshots, $this->getInfoInstance() is empty.

@YevSent
Copy link
Contributor

YevSent commented Jul 29, 2016

Hi, @ytorbyk.
I more detailed investigated this issue and found follow things:

  1. The $this->getInfoInstance() will return null if setInfoInstance not called yet, for example, \Magento\Payment\Model\MethodList::getAvailableMethods.
  2. \Magento\Payment\Model\Method\Adapter::isAvailable should try to get payment instance only when payment already set to quote.

I've created internal ticket MAGETWO-56115.

@YevSent YevSent added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report labels Jul 29, 2016
@ytorbyk
Copy link
Member Author

ytorbyk commented Jul 29, 2016

Yes, thank you.

One more thing, availability validator should be called even if payment isn't set to quote yet, shouldn't it? Moreover, quote has to be always passed to the validator if it is already created. Is it correct?

@YevSent
Copy link
Contributor

YevSent commented Jul 29, 2016

availability validator should be called even if payment isn't set to quote yet, shouldn't it?

In the current implementation - no, because \Magento\Payment\Gateway\Data\PaymentDataObjectFactory expects InfoInterface not null.

quote has to be passed to the validator if it is already created

Not quote, but payment.

@ytorbyk
Copy link
Member Author

ytorbyk commented Jul 29, 2016

So if payment is not set to quote the validator cannot reach quote, correct?

If yes.
What about case when availability depends on quote/quote items? Payment method shouldn't be (in some cases) in result of \Magento\Payment\Model\MethodList::getAvailableMethods method.

@YevSent
Copy link
Contributor

YevSent commented Jul 29, 2016

Validator works with quote payment, not with a quote https://github.com/magento/magento2/blob/develop/app/code/Magento/Payment/Model/Method/Adapter.php#L274.

What about case when availability depends on quote/quote items?

This logic should be specified in the quote module, not in payment. Payment shouldn't depend on quote details.

mmansoor-magento pushed a commit that referenced this issue Aug 26, 2016
…lity gateway validator

 - Added check for payment info instance availability
mmansoor-magento pushed a commit that referenced this issue Aug 26, 2016
mmansoor-magento pushed a commit that referenced this issue Aug 26, 2016
Fixed issues:
 - MAGETWO-56344: [Github] #5902 Braintree doesn't work when using table prefixing
 - MAGETWO-55953: Exception occurs when tracking shipment with invalid FedEx tracking number
- MAGETWO-56801: [GITHUB] Fixed column description for "website_id" column #4388
- MAGETWO-56745: [Github] PayPal Express Checkout "Display on Shopping Cart -> NO" does not work
- MAGETWO-56467: Free shipping threshold fields are mixed up in UPS and Fedex configurations
- MAGETWO-56342: [Github] #5910 Braintree sandbox errors when using alternative Merchant Account ID
- MAGETWO-56115: [Github] #5857 Impossible to configure custom availability gateway validator
- MAGETWO-54134: CE module depends on EE code
- MAGETWO-56447: UPS not providing shipping rates for Puerto Rico
@alena-marchenko
Copy link

Hi @ytorbyk

Fix for MAGETWO-56115 ticket is already merged to develop branch.
Closing the issue, please feel free to reopen if the issue still reproducible for you.

gabrieldagama pushed a commit to gabrieldagama/magento2 that referenced this issue Aug 31, 2020
Resolved Issues:
- MC-34467: Updated jQuery File Upload plugin
- MC-34174: Adding sorting validation
- MC-35076: Catalog Event Update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Payment Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests

4 participants