Skip to content

Commit

Permalink
Merge pull request #703 from mollie/release/2.32.0
Browse files Browse the repository at this point in the history
Release/2.32.0
  • Loading branch information
Marvin-Magmodules authored Oct 23, 2023
2 parents 2c0d39a + 072b1b3 commit 7d0333d
Show file tree
Hide file tree
Showing 39 changed files with 699 additions and 162 deletions.
4 changes: 2 additions & 2 deletions Block/Product/View/ApplePay.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public function getStoreName(): string

public function getCountryCode(): string
{
return $this->_scopeConfig->getValue('general/country/default');
return $this->_scopeConfig->getValue('general/country/default') ?? '';
}

public function getCurrencyCode(): string
{
return $this->_storeManager->getStore()->getCurrentCurrency()->getCode();
return $this->_storeManager->getStore()->getCurrentCurrency()->getCode() ?? '';
}

public function isEnabled(): bool
Expand Down
30 changes: 20 additions & 10 deletions Controller/Adminhtml/Action/SelfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Framework\Controller\Result\JsonFactory;
use Mollie\Payment\Helper\General as MollieHelper;
use Mollie\Payment\Helper\Tests as TestsHelper;
use Mollie\Payment\Service\Mollie\SelfTests\AbstractSelfTest;

/**
* Class Compatibility
Expand All @@ -35,26 +36,24 @@ class SelfTest extends Action
* @var MollieHelper
*/
private $mollieHelper;

/**
* Compatibility constructor.
*
* @param Context $context
* @param JsonFactory $resultJsonFactory
* @param TestsHelper $testsHelper
* @param MollieHelper $mollieHelper
* @var AbstractSelfTest[]
*/
private $tests;

public function __construct(
Context $context,
JsonFactory $resultJsonFactory,
TestsHelper $testsHelper,
MollieHelper $mollieHelper
MollieHelper $mollieHelper,
array $tests
) {
$this->request = $context->getRequest();
$this->resultJsonFactory = $resultJsonFactory;
$this->testsHelper = $testsHelper;
$this->mollieHelper = $mollieHelper;
parent::__construct($context);
$this->tests = $tests;
}

/**
Expand All @@ -73,8 +72,19 @@ public function execute()
return $this->getPhpApiErrorMessage($result);
}

$compatibilityResult = $this->testsHelper->compatibilityChecker();
$result->setData(['success' => true, 'msg' => implode('<br/>', $compatibilityResult)]);
$messages = [];
foreach ($this->tests as $test) {
$test->execute();

$messages = array_merge($messages, $test->getMessages());
}

$output = '';
foreach ($messages as $message) {
$output .= '<div class="mollie-' . $message['type'] . '">' . $message['message'] . '</div>';
}

$result->setData(['success' => true, 'msg' => $output]);
return $result;
}

Expand Down
52 changes: 52 additions & 0 deletions Controller/ApplePay/AppleDeveloperMerchantidDomainAssociation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Mollie\Payment\Controller\ApplePay;

use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Filesystem\Driver\File;
use Magento\Framework\Module\Dir;

class AppleDeveloperMerchantidDomainAssociation implements HttpGetActionInterface
{
/**
* @var ResultFactory
*/
private $resultFactory;
/**
* @var File
*/
private $driverFile;
/**
* @var Dir
*/
private $moduleDir;

public function __construct(
ResultFactory $resultFactory,
File $driverFile,
Dir $moduleDir
) {
$this->resultFactory = $resultFactory;
$this->driverFile = $driverFile;
$this->moduleDir = $moduleDir;
}

public function execute()
{
$path = $this->moduleDir->getDir('Mollie_Payment');
$contents = $this->driverFile->fileGetContents($path . '/apple-developer-merchantid-domain-association');

$response = $this->resultFactory->create(ResultFactory::TYPE_RAW);
$response->setHeader('Content-Type', 'text/plain');
$response->setContents($contents);

return $response;
}
}
5 changes: 2 additions & 3 deletions Controller/Checkout/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ public function execute()
// That can happen for Apple Pay and Credit Card. In that case, Mollie immediately sends a webhook,
// but we are not ready to process it yet.
if ($this->orderLockService->isLocked($order)) {
$this->mollieHelper->addTolog('info', 'Order is locked, skipping webhook');
continue;
throw new \Exception('Order is locked, skipping webhook', 425);
}

$order->setMollieTransactionId($transactionId);
Expand All @@ -112,7 +111,7 @@ public function execute()
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());

return $this->getErrorResponse(503);
return $this->getErrorResponse($e->getCode() ?: 503);
}
}

Expand Down
1 change: 0 additions & 1 deletion Cron/SendPendingPaymentReminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public function __construct(
$this->sortOrderFactory = $sortOrderFactory;
$this->dateTime = $dateTime;
$this->paymentReminder = $paymentReminder;
$this->config = $config;
}

public function execute()
Expand Down
4 changes: 2 additions & 2 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,11 @@ public function useImage($storeId = null)
}

/**
* @param $method
* @param string $method
*
* @return mixed
*/
public function getIssuerListType($method)
public function getIssuerListType(string $method): string
{
$methodXpath = str_replace('%method%', $method, self::XPATH_ISSUER_LIST_TYPE);
return $this->getStoreConfig($methodXpath);
Expand Down
68 changes: 1 addition & 67 deletions Helper/Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Mollie\Payment\Model\Mollie as MollieModel;
use Mollie\Payment\Service\Mollie\Compatibility\CompatibilityTestInterface;

/**
* Class Tests
Expand All @@ -18,32 +17,16 @@
*/
class Tests extends AbstractHelper
{
const XML_PATH_BANKTRANSFER_ACTIVE = 'payment/mollie_methods_banktransfer/active';
const XML_PATH_BANKTRANSFER_STATUS_PENDING = 'payment/mollie_methods_banktransfer/order_status_pending';

/**
* @var MollieModel
*/
private $mollieModel;
/**
* @var CompatibilityTestInterface[]
*/
private $tests;

/**
* Tests constructor.
*
* @param Context $context
* @param MollieModel $mollieModel
* @param array $tests
*/
public function __construct(
Context $context,
MollieModel $mollieModel,
array $tests
MollieModel $mollieModel
) {
$this->mollieModel = $mollieModel;
$this->tests = $tests;
parent::__construct($context);
}

Expand Down Expand Up @@ -125,53 +108,4 @@ public function getMethods($testKey = null, $liveKey = null)

return $results;
}

/**
* @return array
*/
public function compatibilityChecker()
{
$results = [];
if (class_exists('Mollie\Api\CompatibilityChecker')) {
$compatibilityChecker = new \Mollie\Api\CompatibilityChecker();
if (!$compatibilityChecker->satisfiesPhpVersion()) {
$minPhpVersion = $compatibilityChecker::MIN_PHP_VERSION;
$msg = __('Error: The client requires PHP version >= %1, you have %2.', $minPhpVersion, PHP_VERSION);
$results[] = '<span class="mollie-error">' . $msg . '</span>';
} else {
$msg = __('Success: PHP version: %1.', PHP_VERSION);
$results[] = '<span class="mollie-success">' . $msg . '</span>';
}

if (!$compatibilityChecker->satisfiesJsonExtension()) {
$msg = __('Error: PHP extension JSON is not enabled.') . '<br/>';
$msg .= __('Please make sure to enable "json" in your PHP configuration.');
$results[] = '<span class="mollie-error">' . $msg . '</span>';
} else {
$msg = __('Success: JSON is enabled.');
$results[] = '<span class="mollie-success">' . $msg . '</span>';
}
} else {
$msg = __('Error: Mollie CompatibilityChecker not found.') . '<br/>';
$results[] = '<span class="mollie-error">' . $msg . '</span>';
}

$bankTransferActive = $this->scopeConfig->isSetFlag(static::XML_PATH_BANKTRANSFER_ACTIVE);
$bankTransferStatus = $this->scopeConfig->getValue(static::XML_PATH_BANKTRANSFER_STATUS_PENDING);
if ($bankTransferActive && $bankTransferStatus == 'pending_payment') {
$msg = __('Warning: We recommend to use a unique payment status for pending Banktransfer payments');
$results[] = '<span class="mollie-error">' . $msg . '</span>';
}

if (stripos(__DIR__, 'app/code') !== false) {
$msg = __('Warning: We recommend to install the Mollie extension using Composer, currently it\'s installed in the app/code folder.');
$results[] = '<span class="mollie-error">' . $msg . '</span>';
}

foreach ($this->tests as $test) {
$results = $test->execute($results);
}

return $results;
}
}
4 changes: 2 additions & 2 deletions Model/Adminhtml/Backend/SaveApiKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(

public function beforeSave()
{
// Save the unecrypted value so we can test it.
// Save the unencrypted value so we can test it.
$value = (string)$this->getValue();

parent::beforeSave();
Expand All @@ -76,7 +76,7 @@ private function saveApiKey(): void
{
/** @var ApiKeyFallbackInterface $model */
$model = $this->apiKeyFallbackFactory->create();
$model->setApikey($this->getOldValue());
$model->setApikey($this->_encryptor->encrypt($this->getOldValue()));
$model->setMode($this->getPath() === 'payment/mollie_general/apikey_live' ? 'live' : 'test');

$this->apiKeyFallbackRepository->save($model);
Expand Down
5 changes: 3 additions & 2 deletions Model/Client/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function startTransaction(OrderInterface $order, $mollieApi)
$this->processResponse($order, $mollieOrder);

// Order is paid immediately (eg. Credit Card with Components, Apple Pay), process transaction
if ($mollieOrder->isPaid()) {
if ($mollieOrder->isAuthorized() || $mollieOrder->isPaid()) {
$this->processTransaction->execute($order, 'webhook');
}

Expand Down Expand Up @@ -757,7 +757,8 @@ public function createOrderRefund(Order\Creditmemo $creditmemo, Order $order)
}
}

if (!$creditmemo->getAllItems() || $this->adjustmentFee->doNotRefundInMollie()) {
$shouldRefund = $addShippingToRefund || !$creditmemo->getAllItems();
if (!$shouldRefund || $this->adjustmentFee->doNotRefundInMollie()) {
return $this;
}

Expand Down
10 changes: 7 additions & 3 deletions Model/Client/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function startTransaction(OrderInterface $order, $mollieApi)
$this->processResponse($order, $payment);

// Order is paid immediately (eg. Credit Card with Components, Apple Pay), process transaction
if ($payment->isPaid()) {
if ($payment->isAuthorized() || $payment->isPaid()) {
$this->processTransaction->execute($order, static::TRANSACTION_TYPE_WEBHOOK);
}

Expand Down Expand Up @@ -314,10 +314,14 @@ public function processResponse(OrderInterface $order, $payment)
);
}

$status = $this->mollieHelper->getPendingPaymentStatus($order);
$message = __('Customer redirected to Mollie');
if ($order->getPayment()->getMethodInstance()->getCode() == 'mollie_methods_paymentlink') {
$message = __('Created Mollie Checkout Url');
}

$status = $this->mollieHelper->getPendingPaymentStatus($order);
$order->addStatusToHistory($status, $message, false);
$order->setState(Order::STATE_PENDING_PAYMENT);
$order->addStatusToHistory($status, __('Customer redirected to Mollie'), false);
$this->linkTransactionToOrder->execute($payment->id, $order);
$this->orderRepository->save($order);
}
Expand Down
2 changes: 1 addition & 1 deletion Model/Client/Payments/Processors/SuccessfulPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private function handlePayment(OrderInterface $magentoOrder, Payment $molliePaym
$payment->setTransactionId($magentoOrder->getMollieTransactionId());
$payment->setIsTransactionClosed(true);

if ($this->canRegisterCaptureNotification->execute($magentoOrder, $molliePayment) ||
if ($this->canRegisterCaptureNotification->execute($magentoOrder, $molliePayment) &&
$type != Payments::TRANSACTION_TYPE_SUBSCRIPTION
) {
if ($molliePayment->getAmountCaptured() != 0.0) {
Expand Down
17 changes: 14 additions & 3 deletions Model/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,13 @@ public function getOrderIdsByTransactionId(string $transactionId): array
* Get list of Issuers from API
*
* @param MollieApiClient|null $mollieApi
* @param $method
* @param $issuerListType
* @param string $method
* @param string $issuerListType
* @param int $count for internal use only
*
* @return array|null
*/
public function getIssuers(MollieApiClient $mollieApi = null, $method, $issuerListType): ?array
public function getIssuers(MollieApiClient $mollieApi = null, string $method, string $issuerListType, int $count = 0): ?array
{
$issuers = [];
if (empty($mollieApi) || $issuerListType == 'none') {
Expand All @@ -597,6 +598,16 @@ public function getIssuers(MollieApiClient $mollieApi = null, $method, $issuerLi
try {
$issuers = $mollieApi->methods->get($methodCode, ['include' => 'issuers'])->issuers;

// If the list can't be retrieved for some reason, try again.
if (!$issuers && $count == 0) {
$this->mollieHelper->addTolog(
'error',
'Retrieving method issuers gave an issue. Retrying.' . var_export($issuers, true)
);

return $this->getIssuers($mollieApi, $method, $issuerListType, 1);
}

if (!$issuers) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion Model/MollieConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function getActiveMethods(MollieApiClient $mollieApi, CartInterface $cart
* @param array $config
* @return array
*/
private function getIssuers(MollieApiClient $mollieApi, $code, array $config)
private function getIssuers(MollieApiClient $mollieApi, string $code, array $config): array
{
$issuerListType = $this->mollieHelper->getIssuerListType($code);
$config['payment']['issuersListType'][$code] = $issuerListType;
Expand Down
2 changes: 1 addition & 1 deletion Model/OrderLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public function getOrderLineByItemId($itemId)
* @param bool $addShipping
* @return array
*/
public function getCreditmemoOrderLines(CreditmemoInterface $creditmemo, $addShipping)
public function getCreditmemoOrderLines(CreditmemoInterface $creditmemo, bool $addShipping): array
{
$orderLines = [];

Expand Down
Loading

0 comments on commit 7d0333d

Please sign in to comment.