config = $config; $this->objectManager = $objectManager; $this->avsDefaultAdapter = $avsDefaultAdapter; $this->cvvDefaultAdapter = $cvvDefaultAdapter; } /** * Creates instance of CVV code verification. * Exception will be thrown if CVV mapper does not implement PaymentVerificationInterface. * * @param string $paymentCode * @return PaymentVerificationInterface * @throws ConfigurationMismatchException */ public function createPaymentCvv($paymentCode) { return $this->create($this->cvvDefaultAdapter, $paymentCode, 'cvv_ems_adapter'); } /** * Creates instance of AVS code verification. * Exception will be thrown if AVS mapper does not implement PaymentVerificationInterface. * * @param string $paymentCode * @return PaymentVerificationInterface * @throws ConfigurationMismatchException */ public function createPaymentAvs($paymentCode) { return $this->create($this->avsDefaultAdapter, $paymentCode, 'avs_ems_adapter'); } /** * Creates instance of PaymentVerificationInterface. * Default implementation will be returned if payment method does not implement PaymentVerificationInterface. * * @param PaymentVerificationInterface $defaultAdapter * @param string $paymentCode * @param string $configKey * @return PaymentVerificationInterface * @throws ConfigurationMismatchException If payment verification instance * does not implement PaymentVerificationInterface. */ private function create(PaymentVerificationInterface $defaultAdapter, $paymentCode, $configKey) { $this->config->setMethodCode($paymentCode); $verificationClass = $this->config->getValue($configKey); if ($verificationClass === null) { return $defaultAdapter; } $mapper = $this->objectManager->create($verificationClass); if (!$mapper instanceof PaymentVerificationInterface) { throw new ConfigurationMismatchException( __('%1 must implement %2', $verificationClass, PaymentVerificationInterface::class) ); } return $mapper; } }