Skip to content

Commit

Permalink
Merge pull request #692 from mollie/release/2.31.0
Browse files Browse the repository at this point in the history
Release/2.31.0
  • Loading branch information
Marvin-Magmodules authored Sep 25, 2023
2 parents cecd809 + 23c91dd commit 2c0d39a
Show file tree
Hide file tree
Showing 46 changed files with 563 additions and 295 deletions.
13 changes: 12 additions & 1 deletion Block/Applepay/Shortcut/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Magento\Framework\View\Element\Template;
use Magento\Store\Model\ScopeInterface;
use Mollie\Payment\Config;
use Mollie\Payment\Service\Mollie\ApplePay\SupportedNetworks;

class Button extends Template implements ShortcutInterface
{
Expand All @@ -16,21 +17,26 @@ class Button extends Template implements ShortcutInterface
* @var Session
*/
private $checkoutSession;

/**
* @var Config
*/
private $config;
/**
* @var SupportedNetworks
*/
private $supportedNetworks;

public function __construct(
Template\Context $context,
Session $checkoutSession,
Config $config,
SupportedNetworks $supportedNetworks,
array $data = []
) {
parent::__construct($context, $data);
$this->checkoutSession = $checkoutSession;
$this->config = $config;
$this->supportedNetworks = $supportedNetworks;
}

/**
Expand Down Expand Up @@ -87,4 +93,9 @@ public function getButtonClasses(): string

return implode(' ', $classes);
}

public function getSupportedNetworks(): array
{
return $this->supportedNetworks->execute((int)$this->_storeManager->getStore()->getId());
}
}
11 changes: 2 additions & 9 deletions Block/Form/Pointofsale.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

use Magento\Framework\View\Element\Template\Context;
use Magento\Payment\Block\Form;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Terminal;
use Mollie\Payment\Logger\MollieLogger;
use Mollie\Payment\Service\Mollie\MollieApiClient;

/**
Expand All @@ -27,21 +27,15 @@ class Pointofsale extends Form
* @var MollieApiClient
*/
private $mollieApiClient;
/**
* @var MollieLogger
*/
private $logger;

public function __construct(
Context $context,
MollieApiClient $mollieApiClient,
MollieLogger $logger,
array $data = []
) {
parent::__construct($context, $data);

$this->mollieApiClient = $mollieApiClient;
$this->logger = $logger;
}

/**
Expand All @@ -62,8 +56,7 @@ public function getTerminals(): array
try {
$mollieApiClient = $this->mollieApiClient->loadByStore((int)$storeId);
$terminals = $mollieApiClient->terminals->page();
} catch (\Mollie\Api\Exceptions\ApiException $exception) {
$this->logger->addErrorLog('terminals', $exception->getMessage());
} catch (ApiException $exception) {
return [];
}

Expand Down
68 changes: 20 additions & 48 deletions Block/Info/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ class Base extends Info
* @var DateTime\TimezoneInterface
*/
private $timezone;

/**
* @var Registry
*/
private $registry;

/**
* @var PriceCurrencyInterface
*/
Expand All @@ -66,23 +64,17 @@ public function __construct(
$this->price = $price;
}

/**
* @return bool|string
*/
public function getCheckoutType()
public function getCheckoutType(): ?string
{
try {
return $this->getInfo()->getAdditionalInformation('checkout_type');
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
return false;
return null;
}
}

/**
* @return bool|string
*/
public function getExpiresAt()
public function getExpiresAt(): ?string
{
try {
if ($expiresAt = $this->getInfo()->getAdditionalInformation('expires_at')) {
Expand All @@ -92,80 +84,67 @@ public function getExpiresAt()
$this->mollieHelper->addTolog('error', $e->getMessage());
}

return false;
return null;
}

/**
* @param int|null $storeId
* @return bool|string
* @param mixed $storeId
*/
public function getPaymentLink($storeId = null)
public function getPaymentLink($storeId = null): ?string
{
if ($checkoutUrl = $this->getCheckoutUrl()) {
return $this->mollieHelper->getPaymentLinkMessage($checkoutUrl, $storeId);
}

return false;
return null;
}

/**
* @return bool|string
*/
public function getCheckoutUrl()
public function getCheckoutUrl(): ?string
{
try {
return $this->getInfo()->getAdditionalInformation('checkout_url');
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
return false;
return null;
}
}

/**
* @return bool|string
*/
public function getPaymentStatus()
public function getPaymentStatus(): ?string
{
try {
return $this->getInfo()->getAdditionalInformation('payment_status');
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
return false;
return null;
}
}

/**
* @return bool|string
*/
public function getDashboardUrl()
public function getDashboardUrl(): ?string
{
try {
return $this->getInfo()->getAdditionalInformation('dashboard_url');
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
return false;
return null;
}
}

public function getChangePaymentStatusUrl(): string
public function getChangePaymentStatusUrl(): ?string
{
try {
return (string)$this->getInfo()->getAdditionalInformation('mollie_change_payment_state_url');
} catch (\Exception $exception) {
return '';
return null;
}
}

/**
* @return bool|string
*/
public function getMollieId()
public function getMollieId(): ?string
{
try {
return $this->getInfo()->getAdditionalInformation('mollie_id');
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
return false;
return null;
}
}

Expand All @@ -189,10 +168,9 @@ public function isBuyNowPayLaterMethod(): bool
}

/**
* @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getPaymentImage()
public function getPaymentImage(): string
{
$code = $this->getInfo()->getMethod();
if (strpos($code, 'mollie_methods_') !== false) {
Expand All @@ -202,10 +180,7 @@ public function getPaymentImage()
return $code . '.svg';
}

/**
* @return string|null
*/
public function getOrderId()
public function getOrderId(): ?string
{
try {
return $this->getInfo()->getParentId();
Expand Down Expand Up @@ -240,10 +215,7 @@ public function formatPrice($amount)
return $this->price->format($amount);
}

/**
* @return OrderInterface|null
*/
private function getOrder()
private function getOrder(): ?OrderInterface
{
return $this->registry->registry('current_order');
}
Expand Down
13 changes: 12 additions & 1 deletion Block/Product/View/ApplePay.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,34 @@
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template;
use Mollie\Payment\Config;
use Mollie\Payment\Service\Mollie\ApplePay\SupportedNetworks;

class ApplePay extends Template
{
/**
* @var Registry
*/
private $registry;

/**
* @var Config
*/
private $config;
/**
* @var SupportedNetworks
*/
private $supportedNetworks;

public function __construct(
Template\Context $context,
Registry $registry,
Config $config,
SupportedNetworks $supportedNetworks,
array $data = []
) {
parent::__construct($context, $data);
$this->registry = $registry;
$this->config = $config;
$this->supportedNetworks = $supportedNetworks;
}

public function getProductName(): string
Expand Down Expand Up @@ -81,4 +87,9 @@ public function getButtonClasses()

return implode(' ', $classes);
}

public function getSupportedNetworks(): array
{
return $this->supportedNetworks->execute((int)$this->_storeManager->getStore()->getId());
}
}
2 changes: 1 addition & 1 deletion Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public function pointofsaleAllowedCustomerGroups(int $storeId = null)
* @param null|int|string $storeId
* @return string
*/
public function getMethodTitle($method, $storeId = null)
public function getMethodTitle($method, $storeId = null): string
{
return $this->getPath($this->addMethodToPath(static::PAYMENT_METHOD_PAYMENT_TITLE, $method), $storeId);
}
Expand Down
2 changes: 1 addition & 1 deletion Controller/ApplePay/ShippingMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function execute()
'shipping_methods' => array_map(function ($method) {
return [
'identifier' => $method->getCarrierCode() . '_' . $method->getMethodCode(),
'label' => $method->getCarrierTitle(),
'label' => $method->getMethodTitle() . ' - ' . $method->getCarrierTitle(),
'amount' => number_format($method->getPriceInclTax(), 2, '.', ''),
'detail' => '',
];
Expand Down
13 changes: 10 additions & 3 deletions Model/Client/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
use Magento\Framework\Model\AbstractModel;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Invoice;
use Magento\Sales\Model\OrderRepository;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Resources\Payment as MolliePayment;
use Mollie\Api\Types\PaymentStatus;
use Mollie\Payment\Helper\General as MollieHelper;
use Mollie\Payment\Model\Adminhtml\Source\InvoiceMoment;
use Mollie\Payment\Model\Client\Payments\ProcessTransaction;
use Mollie\Payment\Service\Mollie\DashboardUrl;
use Mollie\Payment\Service\Mollie\Order\CanRegisterCaptureNotification;
Expand Down Expand Up @@ -386,9 +384,18 @@ public function processTransaction(Order $order, $mollieApi, $type = 'webhook',
$payment->setCurrencyCode($order->getBaseCurrencyCode());
$payment->setIsTransactionClosed(true);

if ($this->canRegisterCaptureNotification->execute($order) ||
if ($this->canRegisterCaptureNotification->execute($order, $paymentData) ||
$type != static::TRANSACTION_TYPE_WEBHOOK
) {
if ($paymentData->getAmountCaptured() != 0.0) {
$order->addCommentToStatusHistory(
__(
'Successfully captured an amount of %1.',
$order->getBaseCurrency()->formatTxt($paymentData->getAmountCaptured())
)
);
}

$payment->registerCaptureNotification($order->getBaseGrandTotal(), true);
}

Expand Down
Loading

0 comments on commit 2c0d39a

Please sign in to comment.