Skip to content

Commit

Permalink
Add minimum amount validation
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo committed Sep 12, 2024
1 parent 13f24de commit b91a794
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Api/TpayConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public function isAllowSpecific(): bool;

public function getSpecificCountry(): array;

public function getMinOrderTotal(): int;
public function getMinOrderTotal(): float;

public function getMaxOrderTotal(): int;
public function getMaxOrderTotal(): float;

public function getMagentoVersion(): string;

Expand Down
2 changes: 2 additions & 0 deletions Api/TpayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface TpayInterface

public function isCustomerLoggedIn(): bool;

public function isTpayAvailable();

/** @param string $orderId */
public function getCustomerId($orderId);

Expand Down
2 changes: 1 addition & 1 deletion Model/TpayConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(

public function getConfig(): array
{
if (!$this->paymentMethod->isAvailable()) {
if (!$this->paymentMethod->isTpayAvailable()) {
return [];
}

Expand Down
17 changes: 17 additions & 0 deletions Model/TpayPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,23 @@ public function isCartValid(?float $grandTotal = null): bool
return !is_null($grandTotal);
}

public function isTpayAvailable(?CartInterface $quote = null)
{
if (!$this->configurationProvider->isTpayActive()) {
return false;
}

$minAmount = $this->configurationProvider->getMinOrderTotal();
$maxAmount = $this->configurationProvider->getMaxOrderTotal();
$amount = (float) $this->getCheckout()->getQuote()->getBaseGrandTotal();

if ($amount < $minAmount || ($maxAmount && $amount > $maxAmount)) {
return false;
}

return $this->isAvailable($quote);
}

protected function checkBlikAmount(): bool
{
return (bool) ($this->getCheckoutTotal() >= $this->minAmountBlik);
Expand Down
8 changes: 4 additions & 4 deletions Provider/ConfigurationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ public function useSandboxMode(?int $storeId = null): bool
return (bool) $this->getConfigData('general_settings/use_sandbox', $storeId);
}

public function getMinOrderTotal(): int
public function getMinOrderTotal(): float
{
return (int) $this->getConfigData('sale_settings/min_order_total');
return (float) ($this->getConfigData('sale_settings/min_order_total') ?? 0.01);
}

public function getMaxOrderTotal(): int
public function getMaxOrderTotal(): float
{
return (int) $this->getConfigData('sale_settings/max_order_total');
return (float) $this->getConfigData('sale_settings/max_order_total');
}

public function getCardSaveEnabled(): bool
Expand Down

0 comments on commit b91a794

Please sign in to comment.