Response Validator is a component of the Magento payment provider gateway that performs gateway response verification. This may include low level data formatting, security verification, and even execution of some business logic required by the store configuration.
Response Validator returns a Result object, containing validation result as Boolean value and errors description as a list of Phrase.
Response Validator must implement
Result class must implement
A payment provider integration can have multiple response validators, that should be added to the provider’s validators’ pool using dependency injection.
- \Magento\Payment\Gateway\Validator\AbstractValidator: an abstract class with ability to create a Result object. Can be inherited from by particular response validator implementations.
- \Magento\Payment\Gateway\Validator\ValidatorComposite: a chain of Validator objects, which are executed one by one and the result gets aggregated into one Result object.
- \Magento\Payment\Gateway\Validator\Result: base class for Result object. You still have an ability to create a Result of your own, but the default one covers the most amount of cases.
In the following example the a response validator is implemented and added to the pool of the Braintree payment provider request validators.
Pool of validators
The following sample demonstrates defining a validator’s pool and adding validators to this pool for the Braintree payment provider in
(This code sample was created for demonstration only, the real Braintree configuration is different).