Skip to content

Commit

Permalink
REWORK review annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
estafilarakis committed Feb 21, 2020
1 parent 712beb9 commit e777d68
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
10 changes: 5 additions & 5 deletions src/Helper/SettingsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function hasActiveCountries(): bool
*/
public function minimumAmount(): float
{
return (float)$this->getSettingFloatValue('minimumAmount');
return $this->getSettingFloatValue('minimumAmount');
}

/**
Expand All @@ -80,17 +80,17 @@ public function minimumAmount(): float
*/
public function maximumAmount(): float
{
return (float)$this->getSettingFloatValue('maximumAmount');
return $this->getSettingFloatValue('maximumAmount');
}

/**
* Get the minimum amount for using the payment method.
* Get the minimum order count for using the payment method.
*
* @return float
* @return int
*/
public function minimumOrderCount(): int
{
return (int)$this->getSettingIntValue('quorumOrders');
return $this->getSettingIntValue('quorumOrders');
}

/**
Expand Down
27 changes: 11 additions & 16 deletions src/Methods/InvoicePaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Plenty\Modules\Frontend\Services\AccountService;
use Plenty\Modules\Frontend\Services\SystemService;
use Plenty\Modules\Order\Contracts\OrderRepositoryContract;
use Plenty\Modules\Order\Models\OrderAmount;
use Plenty\Plugin\Application;
use Plenty\Modules\Frontend\Contracts\Checkout;
use Plenty\Modules\Payment\Method\Contracts\PaymentMethodService;
Expand Down Expand Up @@ -82,21 +81,18 @@ public function isActive( BasketRepositoryContract $basketRepositoryContract):bo

$isGuest = !($this->accountService->getIsAccountLoggedIn() && $basket->customerId > 0);
$contact = null;
if(!$isGuest && $basket->customerId > 0) {
if(!$isGuest) {
try {
$contact = $contactRepo->findContactById($basket->customerId, ['orderSummary']);
} catch(\Exception $ex) {}
}
$amount = $amount = pluginApp(OrderAmount::class);
$amount->currency = $basket->currency;
$amount->invoiceTotal = $basket->basketAmount;


return $helper->respectsAllLimitations(
pluginApp(SettingsHelper::class, [$this->settings, $this->systemService->getPlentyId()]),
$isGuest,
$amount,
$this->checkout->getShippingCountryId(),
$isGuest,
$basket->basketAmount,
$basket->currency,
$this->checkout->getCustomerInvoiceAddressId(),
$this->checkout->getCustomerShippingAddressId(),
$contact
Expand Down Expand Up @@ -224,9 +220,10 @@ public function isSwitchableTo(int $orderId = null):bool

return $helper->respectsAllLimitations(
pluginApp(SettingsHelper::class, [$this->settings, $order->plentyId]),
$contact === null,
$order->amount,
$order->deliveryAddress->countryId,
$contact === null || $contact->singleAccess === "1",
$order->amount->invoiceTotal,
$order->amount->currency,
$order->billingAddress->id,
$order->deliveryAddress->id,
$contact
Expand All @@ -245,20 +242,18 @@ public function isSwitchableTo(int $orderId = null):bool
$basket = $basketRepo->load();
$isGuest = !($this->accountService->getIsAccountLoggedIn() && $basket->customerId > 0);
$contact = null;
if(!$isGuest && $basket->customerId > 0) {
if(!$isGuest) {
try {
$contact = $contactRepo->findContactById($basket->customerId, ['orderSummary']);
} catch(\Exception $ex) {}
}
$amount = pluginApp(OrderAmount::class);
$amount->currency = $basket->currency;
$amount->invoiceTotal = $basket->basketAmount;

return $helper->respectsAllLimitations(
pluginApp(SettingsHelper::class, [$this->settings, $this->systemService->getPlentyId()]),
$isGuest,
$amount,
$this->checkout->getShippingCountryId(),
$isGuest,
$basket->basketAmount,
$basket->currency,
$this->checkout->getCustomerInvoiceAddressId(),
$this->checkout->getCustomerShippingAddressId(),
$contact
Expand Down
23 changes: 12 additions & 11 deletions src/Services/InvoiceLimitationsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Plenty\Modules\Account\Contact\Models\Contact;
use Plenty\Modules\Account\Contact\Models\ContactAllowedMethodOfPayment;
use Plenty\Modules\Frontend\Contracts\CurrencyExchangeRepositoryContract;
use Plenty\Modules\Order\Models\OrderAmount;

/**
* Class InvoiceLimitationsService
Expand All @@ -21,9 +20,10 @@ class InvoiceLimitationsService
* Get whether all payment method limitations are respected or not.
*
* @param SettingsHelper $settingsHelper The setting helper
* @param bool $isGuest Whether or not the current customer is a guest or not
* @param OrderAmount $amount The total amount
* @param int $shippingCountryId The ID of the shipping country
* @param bool $isGuest Whether or not the current customer is a guest or not
* @param float $amount The total amount
* @param string $currency The current currency
* @param int $billingAddressId The ID of the billing address
* @param int $deliveryAddressId The ID of the delivery address
* @param Contact|null $contact The contact instance, if customer is not a quest
Expand All @@ -32,9 +32,10 @@ class InvoiceLimitationsService
*/
public function respectsAllLimitations(
SettingsHelper $settingsHelper,
bool $isGuest,
OrderAmount $amount,
int $shippingCountryId,
bool $isGuest,
float $amount,
string $currency = 'EUR',
int $billingAddressId = null,
int $deliveryAddressId = null,
Contact $contact = null
Expand All @@ -58,7 +59,7 @@ public function respectsAllLimitations(
}

// Third: Check the addresses
// Addresses are equal when: $deliveryAddressId === null || $billingAddressId === $deliveryAddressId
// Addresses are equal when: $deliveryAddressId === null || $billingAddressId === $deliveryAddressId
if($settingsHelper->shouldHaveIdenticalAddresses() && $deliveryAddressId !== null && $billingAddressId !== $deliveryAddressId) {
return false;
}
Expand All @@ -76,19 +77,19 @@ public function respectsAllLimitations(
}
}

if($amount->invoiceTotal > 0.0) {
if($amount > 0.0) {
/** @var CurrencyExchangeRepositoryContract $currencyService */
$currencyService = pluginApp(CurrencyExchangeRepositoryContract::class);

// Fifth: Check minimum amount
$minAmount = (float)$currencyService->convertFromDefaultCurrency($amount->currency, $settingsHelper->minimumAmount());
if($minAmount > 0.0 && $minAmount > $amount->invoiceTotal) {
$minAmount = (float)$currencyService->convertFromDefaultCurrency($currency, $settingsHelper->minimumAmount());
if($minAmount > 0.0 && $minAmount > $amount) {
return false;
}

// Sixth: Check maximum amount
$maxAmount = (float)$currencyService->convertFromDefaultCurrency($amount->currency, $settingsHelper->maximumAmount());
if($maxAmount > 0.0 && $maxAmount < $amount->invoiceTotal) {
$maxAmount = (float)$currencyService->convertFromDefaultCurrency($currency, $settingsHelper->maximumAmount());
if($maxAmount > 0.0 && $maxAmount < $amount) {
return false;
}
}
Expand Down

0 comments on commit e777d68

Please sign in to comment.