Skip to content

Commit

Permalink
[ECP-8944] Payment Methods Helper Unit Test (#2532)
Browse files Browse the repository at this point in the history
* [ECP-8889] Writing Unit test

* [ECP-8944] Committing changes to the PaymentMethods Unit test

* [ECP-8944] Committing changes to the PaymentMethods Unit test

* [ECP-8944] Committing changes to the PaymentMethods Unit test

* [ECP-8944] Committing changes to the PaymentMethods Unit test

* [ECP-8944] Committing changes to the PaymentMethods Unit test

* [ECP-8944] Committing changes to the PaymentMethods Unit test

* [ECP-8944] Committing changes to the PaymentMethods Unit test

* [ECP-8944] Committing changes to the PaymentMethods Unit test

* [ECP-8944] Handling Exceptions as Adyen Exception - Solving issues thrown by SonarCloud

* [ECP-8944] Committing changes to the PaymentMethods Unit test

* [ECP-8944] Committing changes to the PaymentMethods Unit test

* [ECP-8944] Committing changes to the PaymentMethods Unit test

---------

Co-authored-by: Can Demiralp <ecandemiralp@gmail.com>
  • Loading branch information
khushboo-singhvi and candemiralp authored Mar 7, 2024
1 parent 7c428b8 commit b8cd621
Show file tree
Hide file tree
Showing 2 changed files with 1,116 additions and 29 deletions.
26 changes: 14 additions & 12 deletions Helper/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@

use Adyen\AdyenException;
use Adyen\Client;
use Adyen\ConnectionException;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Model\Notification;
use Adyen\Payment\Model\Ui\Adminhtml\AdyenMotoConfigProvider;
use Adyen\Payment\Model\Ui\AdyenPayByLinkConfigProvider;
use Adyen\Payment\Model\Ui\AdyenPosCloudConfigProvider;
use Adyen\Util\ManualCapture;
use Exception;
use Magento\Framework\App\Area;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
Expand Down Expand Up @@ -128,7 +131,7 @@ public function getPaymentMethods(int $quoteId, ?string $country = null, ?string
$quote = $this->quoteRepository->getActive($quoteId);
// If quote cannot be found early return the empty paymentMethods array
if (empty($quote)) {
return [];
return '';
}

$this->setQuote($quote);
Expand Down Expand Up @@ -215,27 +218,26 @@ protected function getCurrentPaymentAmount(): float
$total = $this->chargedCurrency->getQuoteAmountCurrency($this->getQuote())->getAmount();

if (!is_numeric($total)) {
throw new \Exception(
$exceptionMessage =
sprintf(
'Cannot retrieve a valid grand total from quote ID: `%s`. Expected a numeric value.',
$this->getQuote()->getEntityId()
)
);
throw new AdyenException($exceptionMessage);
}

$total = (float)$total;

if ($total >= 0) {
return $total;
}

throw new \Exception(
$exceptionMessage =
sprintf(
'Cannot retrieve a valid grand total from quote ID: `%s`. Expected a float >= `0`, got `%f`.',
$this->getQuote()->getEntityId(),
$total
)
);
);
throw new AdyenException($exceptionMessage);
}

protected function getCurrentCountryCode(Store $store): string
Expand Down Expand Up @@ -279,7 +281,7 @@ protected function getPaymentMethodsResponse(array $requestParams, Store $store)
// return empty result
return [];
}
catch (\Adyen\ConnectionException $e) {
catch (ConnectionException $e) {
$this->adyenLogger->error(
"Connection to the endpoint failed. Check the Adyen Live endpoint prefix configuration."
);
Expand Down Expand Up @@ -353,7 +355,7 @@ protected function showLogosPaymentMethods(array $paymentMethods, array $payment
// Explicitly setting theme
$themeCode = "Magento/blank";

$themeId = $this->design->getConfigurationDesignTheme(\Magento\Framework\App\Area::AREA_FRONTEND);
$themeId = $this->design->getConfigurationDesignTheme(Area::AREA_FRONTEND);
if (!empty($themeId)) {
$theme = $this->themeProvider->getThemeById($themeId);
if ($theme && !empty($theme->getCode())) {
Expand All @@ -364,7 +366,7 @@ protected function showLogosPaymentMethods(array $paymentMethods, array $payment
$params = [];
$params = array_merge(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'area' => Area::AREA_FRONTEND,
'_secure' => $this->request->isSecure(),
'theme' => $themeCode
],
Expand Down Expand Up @@ -690,8 +692,8 @@ public function getBoletoStatus(Order $order, Notification $notification, string
// check if paid amount is the same as orginal amount
$originalAmount =
isset($boletobancario['originalAmount']) ?
trim((string) $boletobancario['originalAmount']) :
"";
trim((string) $boletobancario['originalAmount']) :
"";
$paidAmount = isset($boletobancario['paidAmount']) ? trim((string) $boletobancario['paidAmount']) : "";

if ($originalAmount != $paidAmount) {
Expand Down
Loading

0 comments on commit b8cd621

Please sign in to comment.