I have two custom Payment Methods which are almost same to each other just APIs are different which are set in admin setting now when only one payment method is enabled then it works perfectly but when I enable both of them and tried to do checkout then it gives me an error which you can see in image
Type Error occurred when creating object: ElarabyCreditCardGatewayCommandGatewayCommand, ElarabyCreditCardGatewayCommandGatewayCommand::__construct(): Argument #2 ($transferFactory) must be of type ElarabyCreditCardGatewayHttpTransferFactoryInterface, ElarabyVodafoneCashGatewayHttpTransferFactory given, called in /mnt/data/home/783787.cloudwaysapps.com/ushuhnnkct/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 121
now when I open this
ElarabyCreditCardGatewayCommandGatewayCommand
<?php
/**
* Copyright (c) 2016-2020 CreditCard
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace ElarabyCreditCardGatewayCommand;
use MagentoPaymentGatewayCommandCommandException;
use MagentoPaymentGatewayCommandInterface;
use MagentoPaymentGatewayErrorMapperErrorMessageMapperInterface;
use MagentoPaymentGatewayHelperSubjectReader;
use MagentoPaymentGatewayHttpClientInterface;
use MagentoPaymentGatewayRequestBuilderInterface;
use MagentoPaymentGatewayResponseHandlerInterface;
use MagentoPaymentGatewayValidatorResultInterface;
use MagentoPaymentGatewayValidatorValidatorInterface;
use ElarabyCreditCardGatewayHttpTransferFactoryInterface;
use PsrLogLoggerInterface;
/**
* Replaces MagentoPaymentGatewayCommandGatewayCommand
* because we need a way to pass the payment object along side gateway data
*/
class GatewayCommand implements CommandInterface
{
/**
* @var BuilderInterface
*/
private $requestBuilder;
/**
* @var TransferFactoryInterface
*/
private $transferFactory;
/**
* @var ClientInterface
*/
private $client;
/**
* @var HandlerInterface
*/
private $handler;
/**
* @var ValidatorInterface
*/
private $validator;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var ErrorMessageMapperInterface
*/
private $errorMessageMapper;
/**
* @param BuilderInterface $requestBuilder
* @param TransferFactoryInterface $transferFactory
* @param ClientInterface $client
* @param LoggerInterface $logger
* @param HandlerInterface|null $handler
* @param ValidatorInterface|null $validator
* @param ErrorMessageMapperInterface|null $errorMessageMapper
*/
public function __construct(
BuilderInterface $requestBuilder,
TransferFactoryInterface $transferFactory,
ClientInterface $client,
LoggerInterface $logger,
HandlerInterface $handler = null,
ValidatorInterface $validator = null,
ErrorMessageMapperInterface $errorMessageMapper = null
) {
$this->requestBuilder = $requestBuilder;
$this->transferFactory = $transferFactory;
$this->client = $client;
$this->handler = $handler;
$this->validator = $validator;
$this->logger = $logger;
$this->errorMessageMapper = $errorMessageMapper;
}
/**
* @inheritDoc
*/
public function execute(array $commandSubject)
{
$writer = new Zend_Log_Writer_Stream(BP . '/var/log/GatewayCommandCC.log');
$logger = new Zend_Log();
$logger->addWriter($writer);
$logger->info('1111');
$payment = SubjectReader::readPayment($commandSubject);
$logger->info('2222');
// @TODO implement exceptions catching
$transferO = $this->transferFactory->create(
$this->requestBuilder->build($commandSubject),
$payment
);
$logger->info('3333');
$response = $this->client->placeRequest($transferO);
$logger->info('4444');
$logger->info(print_r($response,1));
if ($this->validator !== null) {
$result = $this->validator->validate(
array_merge($commandSubject, ['response' => $response])
);
if (!$result->isValid()) {
$this->processErrors($result);
}
}
if ($this->handler !== null) {
$this->handler->handle(
$commandSubject,
$response
);
}
return null;
}
/**
* @param ResultInterface $result
* @throws CommandException
*/
private function processErrors(ResultInterface $result)
{
$messages = [];
$errorsSource = array_merge($result->getErrorCodes(), $result->getFailsDescription());
foreach ($errorsSource as $errorCodeOrMessage) {
$errorCodeOrMessage = (string) $errorCodeOrMessage;
// error messages mapper can be not configured if payment method doesn't have custom error messages.
if ($this->errorMessageMapper !== null) {
$mapped = (string) $this->errorMessageMapper->getMessage($errorCodeOrMessage);
if (!empty($mapped)) {
$messages[] = $mapped;
$errorCodeOrMessage = $mapped;
}
}
$this->logger->critical('Payment Error: ' . $errorCodeOrMessage);
}
throw new CommandException(
!empty($messages)
? __(implode(PHP_EOL, $messages))
: __('Transaction has been declined. Please try again later.')
);
}
}
when I even change the Variable $transferFactory
to transferFactoryy
then it dont even process that class and start giving error.
then I do not find anything which can cause that issue any help will be really appreciated
Note
both of the extensions are almost same just Extension name needs to change