Skip to content

Commit

Permalink
BP-1488 - have one single config that set the client mode - code review
Browse files Browse the repository at this point in the history
  • Loading branch information
LucianTuriacArnia committed Oct 18, 2023
1 parent c34693e commit ce4dac5
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions Model/Adapter/BuckarooAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,38 @@ private function setClientSdk($paymentMethod = null): void
/** @var Account $configProviderAccount */
$configProviderAccount = $this->configProviderFactory->get('account');
$storeId = $this->storeManager->getStore()->getId();
$clientMode = Config::TEST_MODE;
$accountMode = $configProviderAccount->getActive($storeId);
$clientMode = $this->getClientMode($accountMode, $storeId, $paymentMethod);

$this->buckaroo = new BuckarooClient(new DefaultConfig(
$this->encryptor->decrypt($configProviderAccount->getMerchantKey()),
$this->encryptor->decrypt($configProviderAccount->getSecretKey()),
$clientMode,
null,
null,
null,
null,
$this->productMetadata->getName() . ' - ' . $this->productMetadata->getEdition(),
$this->productMetadata->getVersion(),
'Buckaroo',
'Magento2',
Data::BUCKAROO_VERSION,
str_replace('_', '-', $this->localeResolver->getLocale())
));
}

/**
* Get client mode base on account mode and payment method mode
*
* @param int $accountMode
* @param int $storeId
* @param string $paymentMethod
* @return string
* @throws Exception
*/
private function getClientMode(int $accountMode, int $storeId, string $paymentMethod): string
{
$clientMode = Config::TEST_MODE;

if ($accountMode == Enablemode::ENABLE_OFF) {
throw new Exception(__('The Buckaroo Module is OFF'));
Expand All @@ -187,21 +217,7 @@ private function setClientSdk($paymentMethod = null): void
}
}

$this->buckaroo = new BuckarooClient(new DefaultConfig(
$this->encryptor->decrypt($configProviderAccount->getMerchantKey()),
$this->encryptor->decrypt($configProviderAccount->getSecretKey()),
$clientMode,
null,
null,
null,
null,
$this->productMetadata->getName() . ' - ' . $this->productMetadata->getEdition(),
$this->productMetadata->getVersion(),
'Buckaroo',
'Magento2',
Data::BUCKAROO_VERSION,
str_replace('_', '-', $this->localeResolver->getLocale())
));
return $clientMode;
}

/**
Expand Down

0 comments on commit ce4dac5

Please sign in to comment.