Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIPRES-544 general performance issues #1053

Closed
wants to merge 10 commits into from
16 changes: 6 additions & 10 deletions mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Mollie\Subscription\Validator\CanProductBeAddedToCartValidator;
use Mollie\Utility\ExceptionUtility;
use Mollie\Utility\PsVersionUtility;
use Mollie\Utility\VersionUtility;
use Mollie\Verification\IsPaymentInformationAvailable;
use PrestaShop\PrestaShop\Core\Localization\Locale\Repository;
use Symfony\Component\Dotenv\Dotenv;
Expand Down Expand Up @@ -546,7 +547,7 @@ public function hookDisplayAdminOrder($params)
*/
public function hookPaymentOptions($params)
{
if (version_compare(_PS_VERSION_, '1.7.0.0', '<')) {
if (VersionUtility::isPsVersionLessThan('1.7.0.0')) {
return [];
}

Expand All @@ -566,21 +567,16 @@ public function hookPaymentOptions($params)

$methods = $paymentMethodService->getMethodsForCheckout();

foreach ($methods as $method) {
/** @var MolPaymentMethod|null $paymentMethod */
$paymentMethod = $paymentMethodRepository->findOneBy(['id_payment_method' => (int) $method['id_payment_method']]);
$availableMethods = $paymentMethodRepository->findAllBy(['id_payment_method' => array_column($methods, 'id_payment_method')]);

if (!$paymentMethod) {
foreach ($availableMethods as $method) {
if (!$method) {
continue;
}

$paymentMethod->method_name = $method['method_name'];

try {
$paymentOptions[] = $paymentOptionsHandler->handle($paymentMethod);
$paymentOptions[] = $paymentOptionsHandler->handle($method);
} catch (Exception $exception) {
// TODO handle payment fee exception and other exceptions with custom exception throw

$logger->error(sprintf('%s - Error while handling payment options', self::FILE_NAME), [
'exceptions' => ExceptionUtility::getExceptions($exception),
]);
Expand Down
1 change: 1 addition & 0 deletions src/Adapter/ToolsAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Mollie\Adapter;

use PrestaShop\PrestaShop\Core\Localization\Locale;
use Tools;

if (!defined('_PS_VERSION_')) {
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/Line.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public function getCategory()
*
* @return Line
*/
public function setCategory($category)
public function setCategory(string $category): Line
{
$this->category = $category;

Expand Down
8 changes: 4 additions & 4 deletions src/DTO/Object/Amount.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,31 @@ public function __construct($currency, $value)
/**
* @return string
*/
public function getCurrency()
public function getCurrency(): string
{
return $this->currency;
}

/**
* @param string $currency
*/
public function setCurrency($currency)
public function setCurrency(string $currency)
{
$this->currency = $currency;
}

/**
* @return string
*/
public function getValue()
public function getValue(): string
{
return number_format($this->value, 2, '.', '');
}

/**
* @param float $value
*/
public function setValue($value)
public function setValue(float $value)
{
$this->value = $value;
}
Expand Down
64 changes: 40 additions & 24 deletions src/DTO/OrderData.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ public function getAmount()

/**
* @param Amount $amount
*
* @return void
*/
public function setAmount($amount)
public function setAmount(Amount $amount): void
{
$this->amount = $amount;
}
Expand All @@ -161,104 +163,118 @@ public function getRedirectUrl()

/**
* @param mixed $redirectUrl
*
* @return void
*/
public function setRedirectUrl($redirectUrl)
public function setRedirectUrl($redirectUrl): void
{
$this->redirectUrl = $redirectUrl;
}

/**
* @return mixed
* @return string
*/
public function getWebhookUrl()
public function getWebhookUrl(): string
{
return $this->webhookUrl;
}

/**
* @param mixed $webhookUrl
*
* @return void
*/
public function setWebhookUrl($webhookUrl)
public function setWebhookUrl($webhookUrl): void
{
$this->webhookUrl = $webhookUrl;
}

/**
* @return string
*/
public function getMethod()
public function getMethod(): string
{
return $this->method;
}

/**
* @param string $method
*
* @return void
*/
public function setMethod($method)
public function setMethod(string $method): void
{
$this->method = $method;
}

/**
* @return array
*/
public function getMetadata()
public function getMetadata(): array
{
return $this->metadata;
}

/**
* @param array $metadata
*
* @return void
*/
public function setMetadata($metadata)
public function setMetadata(array $metadata): void
{
$this->metadata = $metadata;
}

/**
* @return string
*/
public function getLocale()
public function getLocale(): string
{
return $this->locale;
}

/**
* @param string $locale
*
* @return void
*/
public function setLocale($locale)
public function setLocale(string $locale): void
{
$this->locale = $locale;
}

/**
* @return string
*/
public function getCustomerId()
public function getCustomerId(): string
{
return $this->customerId;
}

/**
* @param string $customerId
*
* @return void
*/
public function setCustomerId($customerId)
public function setCustomerId(string $customerId): void
{
$this->customerId = $customerId;
}

/**
* @return Address
*/
public function getBillingAddress()
public function getBillingAddress(): Address
{
return $this->billingAddress;
}

/**
* @param Address $billingAddress
*
* @return void
*/
public function setBillingAddress($billingAddress)
public function setBillingAddress(Address $billingAddress): void
{
$this->billingAddress = $billingAddress;
}
Expand All @@ -284,7 +300,7 @@ public function getBillingPhoneNumber()
*
* @return self
*/
public function setBillingPhoneNumber($billingPhoneNumber)
public function setBillingPhoneNumber($billingPhoneNumber): OrderData
{
$this->billingPhoneNumber = $billingPhoneNumber;

Expand All @@ -304,7 +320,7 @@ public function getDeliveryPhoneNumber()
*
* @return self
*/
public function setDeliveryPhoneNumber($deliveryPhoneNumber)
public function setDeliveryPhoneNumber($deliveryPhoneNumber): OrderData
{
$this->deliveryPhoneNumber = $deliveryPhoneNumber;

Expand All @@ -314,55 +330,55 @@ public function setDeliveryPhoneNumber($deliveryPhoneNumber)
/**
* @param Address $shippingAddress
*/
public function setShippingAddress($shippingAddress)
public function setShippingAddress(Address $shippingAddress)
{
$this->shippingAddress = $shippingAddress;
}

/**
* @return string
*/
public function getOrderNumber()
public function getOrderNumber(): string
{
return $this->orderNumber;
}

/**
* @param string $orderNumber
*/
public function setOrderNumber($orderNumber)
public function setOrderNumber(string $orderNumber)
{
$this->orderNumber = $orderNumber;
}

/**
* @return string
*/
public function getEmail()
public function getEmail(): string
{
return $this->email;
}

/**
* @param string $email
*/
public function setEmail($email)
public function setEmail(string $email)
{
$this->email = $email;
}

/**
* @return Line[]
*/
public function getLines()
public function getLines(): array
{
return $this->lines;
}

/**
* @param Line[] $lines
*/
public function setLines($lines)
public function setLines(array $lines)
{
$this->lines = $lines;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(PaymentMethodRepositoryInterface $paymentMethodRepos
/**
* {@inheritdoc}
*/
public function isGranted(array $record)
public function isGranted(array $record): bool
{
$molPayment = $this->paymentMethodRepository->getPaymentBy('cart_id', (int) \Cart::getCartIdByOrderId($record['id_order']));

Expand Down
28 changes: 16 additions & 12 deletions src/Service/PaymentMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,17 @@ public function savePaymentMethod($method)
*/
public function getMethodsForCheckout()
{
$apiKey = EnvironmentUtility::getApiKey();
if (!$apiKey || $this->module->getApiClient() === null) {
return [];
}
/* @phpstan-ignore-next-line */
if (false === Configuration::get(Config::MOLLIE_STATUS_AWAITING)) {
if (!EnvironmentUtility::getApiKey()
|| $this->module->getApiClient() === null
|| !Configuration::get(Config::MOLLIE_STATUS_AWAITING)
) {
return [];
}
$apiEnvironment = Configuration::get(Config::MOLLIE_ENVIRONMENT);
$methods = $this->methodRepository->getMethodsForCheckout($apiEnvironment, $this->shop->getShop()->id) ?: [];

$methods = $this->methodRepository->getMethodsForCheckout(
Configuration::get(Config::MOLLIE_ENVIRONMENT),
$this->shop->getShop()->id
) ?: [];

$isSubscriptionOrder = $this->subscriptionOrder->validate($this->cartAdapter->getCart());
$sequenceType = $isSubscriptionOrder ? SequenceType::SEQUENCETYPE_FIRST : null;
Expand All @@ -230,27 +231,30 @@ public function getMethodsForCheckout()

$methods = $this->removeNotSupportedMethods($methods, $mollieMethods);

$paymentMethods = $this->methodRepository->findAllBy(['id_payment_method' => array_column($methods, 'id_payment_method')]);

foreach ($methods as $index => $method) {
/** @var MolPaymentMethod|null $paymentMethod */
$paymentMethod = $this->methodRepository->findOneBy(['id_payment_method' => (int) $method['id_payment_method']]);
$paymentMethod = $paymentMethods[$method['id_payment_method']] ?? null;

if (!$paymentMethod || !$this->paymentMethodRestrictionValidation->isPaymentMethodValid($paymentMethod)) {
unset($methods[$index]);

continue;
}

$image = json_decode($method['images_json'], true);

$methods[$index]['image'] = $image;

if (CustomLogoUtility::isCustomLogoEnabled($method['id_method'])) {
if ($this->creditCardLogoProvider->logoExists()) {
$methods[$index]['image']['custom_logo'] = $this->creditCardLogoProvider->getLogoPathUri();
}
}
}

$methods = $this->paymentMethodSortProvider->getSortedInAscendingWayForCheckout($methods);

return $methods;
return $this->paymentMethodSortProvider->getSortedInAscendingWayForCheckout($methods);
}

/**
Expand Down
Loading