QuestionQ4

Design and implement optimal solutions for Adobe Commerce to meet business needs

While reviewing a newly created pull request that refactors several custom payment methods, the Architect observes that multiple classes rely on \Magento\Framework\Encryption\EncryptorInterface to decrypt sensitive credential data. The commonly duplicated code is:

Question Image

In every module, the user_secret configuration is declared as follows:

Question Image

The Architect must recommend an optimal approach to eliminate redundant dependencies and duplicated code across the methods.

Which solution should the Architect recommend?

  • A Create a common config service class Vendor\Payment\Gateway\Config\Config under Vendor_Payment and use it as a parent class for all of the Vendor\PaymentModule\Gateway\Config\Config classes and remove $scopeConfig and $encryptor dependencies
  • B Replace all Vendor\PaymentModule\Gateway\Config\Config classes with virtualType of Magento\Payment\Gateway\Config\Config and set <user_secret backend_model=“Magento\Config\Model\Config\Backend\Encrypted” /> under config.xml
  • C Add a plugin after the getValue method of $scopeConfig, remove the $encryptor from dependency and use it in the plugin to decrypt the value if the config name is ‘user_secret’
Explanation

A shared payment gateway configuration base class centralizes retrieval and decryption of the encrypted user_secret. Its payment-method-specific subclasses inherit that behavior and no longer need to declare the repeated scope-config and encryptor dependencies themselves. A virtual type of the generic payment config class does not implement secret decryption, and a plugin on the general configuration getter would apply cross-cutting behavior based on a generic field name rather than encapsulating the payment configuration concern.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!