Skip to content

Commit

Permalink
Merge pull request #772 from mollie/release/2.37.0
Browse files Browse the repository at this point in the history
Release/2.37.0
  • Loading branch information
Marvin-Magmodules authored Apr 18, 2024
2 parents ad83c2a + 0c30e2b commit f2ac6c2
Show file tree
Hide file tree
Showing 46 changed files with 764 additions and 44 deletions.
1 change: 1 addition & 0 deletions .github/workflows/templates/magento/configure-mollie.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bin/magento config:set payment/mollie_methods_kbc/active 1 &
bin/magento config:set payment/mollie_methods_klarnasliceit/active 1 &
bin/magento config:set payment/mollie_methods_paypal/active 1 &
bin/magento config:set payment/mollie_methods_przelewy24/active 1 &
bin/magento config:set payment/mollie_methods_alma/active 1 &
bin/magento config:set payment/mollie_methods_bancontact/active 1 &
bin/magento config:set payment/mollie_methods_belfius/active 1 &
bin/magento config:set payment/mollie_methods_eps/active 1 &
Expand Down
18 changes: 12 additions & 6 deletions Controller/ApplePay/ShippingMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,45 @@
use Magento\Quote\Api\ShippingMethodManagementInterface;
use Magento\Quote\Model\Quote\Address;
use Magento\Quote\Model\Quote\Address\Total as AddressTotal;
use Mollie\Payment\Service\Magento\ChangeShippingMethodForQuote;

class ShippingMethods extends Action
{
/**
* @var CartRepositoryInterface
*/
private $cartRepository;

/**
* @var GuestCartRepositoryInterface
*/
private $guestCartRepository;

/**
* @var ShippingMethodManagementInterface
*/
private $shippingMethodManagement;

/**
* @var CheckoutSession
*/
private $checkoutSession;
/**
* @var ChangeShippingMethodForQuote
*/
private $changeShippingMethodForQuote;

public function __construct(
Context $context,
CartRepositoryInterface $cartRepository,
ShippingMethodManagementInterface $shippingMethodManagement,
CheckoutSession $checkoutSession,
GuestCartRepositoryInterface $guestCartRepository
GuestCartRepositoryInterface $guestCartRepository,
ChangeShippingMethodForQuote $changeShippingMethodForQuote
) {
parent::__construct($context);
$this->shippingMethodManagement = $shippingMethodManagement;
$this->guestCartRepository = $guestCartRepository;
$this->cartRepository = $cartRepository;
$this->checkoutSession = $checkoutSession;
$this->changeShippingMethodForQuote = $changeShippingMethodForQuote;
}

public function execute()
Expand All @@ -66,8 +70,10 @@ public function execute()
$address->setPostcode($this->getRequest()->getParam('postalCode'));

if ($this->getRequest()->getParam('shippingMethod')) {
$address->setCollectShippingRates(true);
$address->setShippingMethod($this->getRequest()->getParam('shippingMethod')['identifier']);
$this->changeShippingMethodForQuote->execute(
$address,
$this->getRequest()->getParam('shippingMethod')['identifier']
);
}

$cart->setPaymentMethod('mollie_methods_applepay');
Expand Down
5 changes: 3 additions & 2 deletions Helper/General.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2018 Magmodules.eu. All rights reserved.
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

Expand Down Expand Up @@ -620,6 +620,7 @@ public function getAllActiveMethods($storeId)
$activeMethods = [];
$methodCodes = [
'mollie_methods_applepay',
'mollie_methods_alma',
'mollie_methods_bancontact',
'mollie_methods_banktransfer',
'mollie_methods_belfius',
Expand Down
24 changes: 24 additions & 0 deletions Model/Methods/Alma.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Model\Methods;

use Mollie\Payment\Model\Mollie;

/**
* Class Alma
*
* @package Mollie\Payment\Model\Methods
*/
class Alma extends Mollie
{
/**
* Payment method code
*
* @var string
*/
const CODE = 'mollie_methods_alma';
}
5 changes: 3 additions & 2 deletions Model/MollieConfigProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2018 Magmodules.eu. All rights reserved.
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

Expand Down Expand Up @@ -34,6 +34,7 @@ class MollieConfigProvider implements ConfigProviderInterface
*/
private $methodCodes = [
'mollie_methods_applepay',
'mollie_methods_alma',
'mollie_methods_bancontact',
'mollie_methods_banktransfer',
'mollie_methods_belfius',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Mollie\Payment\Observer\AdminhtmlSalesOrderCreateProcessItemBefore;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Exception\NoSuchEntityException;

class SetPurchaseTypeOnCreateOrderItem implements ObserverInterface
{
/**
* @var ProductRepositoryInterface
*/
private $productRepository;

public function __construct(
ProductRepositoryInterface $productRepository
) {
$this->productRepository = $productRepository;
}

public function execute(Observer $observer)
{
/** @var RequestInterface $request */
$request = $observer->getData('request_model');

if ($request->has('item') && !$request->getPost('update_items')
) {
$itemsChanged = false;
$items = $request->getPost('item');
foreach ($items as $item => $requestData) {
if (!$this->productAllowsOneTimePurchase($item)) {
continue;
}

$itemsChanged = true;
$items[$item]['purchase'] = 'onetime';
}

if ($itemsChanged) {
$request->setPostValue('item', $items);
}
}
}

private function productAllowsOneTimePurchase(int $productId): bool
{
try {
$product = $this->productRepository->getById($productId);
} catch (NoSuchEntityException $e) {
return false;
}

return !!$product->getData('mollie_subscription_product');
}
}
37 changes: 37 additions & 0 deletions Plugin/CustomerBalance/Observer/PreventDoubleCreditRevert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Mollie\Payment\Plugin\CustomerBalance\Observer;

use Magento\Framework\Event\Observer;
use Magento\Sales\Api\Data\OrderInterface;

class PreventDoubleCreditRevert
{
public function aroundExecute($subject, callable $proceed, Observer $observer)
{
$order = $observer->getData('order');
if (!$order ||
!$order instanceof OrderInterface ||
!$order->getPayment()
) {
return $proceed($observer);
}

if ($observer->getEvent()->getName() == 'restore_quote' &&
$this->isMollieOrder($order)
) {
return $subject;
}

return $proceed($observer);
}

private function isMollieOrder(OrderInterface $order): bool
{
$payment = $order->getPayment();

return strstr($payment->getMethod(), 'mollie_methods_') !== false;
}
}
11 changes: 11 additions & 0 deletions Queue/Handler/TransactionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Mollie\Payment\Queue\Handler;

use Magento\Framework\Phrase;
use Magento\Framework\Phrase\RendererInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Mollie\Payment\Api\Data\TransactionToProcessInterface;
use Mollie\Payment\Config;
Expand All @@ -19,6 +21,10 @@ class TransactionProcessor
* @var OrderRepositoryInterface
*/
private $orderRepository;
/**
* @var RendererInterface
*/
private $phraseRenderer;
/**
* @var Config
*/
Expand All @@ -30,12 +36,14 @@ class TransactionProcessor

public function __construct(
OrderRepositoryInterface $orderRepository,
RendererInterface $phraseRenderer,
Config $config,
Mollie $mollieModel
) {
$this->orderRepository = $orderRepository;
$this->config = $config;
$this->mollieModel = $mollieModel;
$this->phraseRenderer = $phraseRenderer;
}

public function execute(TransactionToProcessInterface $data): void
Expand All @@ -44,6 +52,9 @@ public function execute(TransactionToProcessInterface $data): void
$order = $this->orderRepository->get($data->getOrderId());
$order->setMollieTransactionId($data->getTransactionId());

// Make sure the translations are loaded
Phrase::setRenderer($this->phraseRenderer);

$this->mollieModel->processTransactionForOrder($order, $data->getType());
} catch (\Throwable $throwable) {
$this->config->addToLog('error', [
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Mollie requires no minimum costs, no fixed contracts, no hidden costs. At Mollie
## Supported Mollie Payment Methods

- Apple Pay (direct)
- Alma
- Bancontact
- Bank transfer
- Belfius Pay Button
Expand Down
51 changes: 51 additions & 0 deletions Service/Magento/ChangeShippingMethodForQuote.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Mollie\Payment\Service\Magento;

use Magento\Checkout\Api\Data\ShippingInformationInterface;
use Magento\Checkout\Api\Data\ShippingInformationInterfaceFactory;
use Magento\Checkout\Api\ShippingInformationManagementInterface;
use Magento\Quote\Api\Data\AddressInterface;

class ChangeShippingMethodForQuote
{
/**
* @var ShippingInformationManagementInterface
*/
private $shippingInformationManagement;
/**
* @var ShippingInformationInterfaceFactory
*/
private $shippingInformationFactory;

public function __construct(
ShippingInformationManagementInterface $shippingInformationManagement,
ShippingInformationInterfaceFactory $shippingInformationFactory
) {
$this->shippingInformationManagement = $shippingInformationManagement;
$this->shippingInformationFactory = $shippingInformationFactory;
}

public function execute(AddressInterface $address, string $identifier): void
{
$address->setCollectShippingRates(true);
$address->setShippingMethod($identifier);

[$carrierCode, $methodCode] = explode('_', $identifier);
$shippingInformation = $this->shippingInformationFactory->create([
'data' => [
ShippingInformationInterface::SHIPPING_ADDRESS => $address,
ShippingInformationInterface::SHIPPING_CARRIER_CODE => $carrierCode,
ShippingInformationInterface::SHIPPING_METHOD_CODE => $methodCode,
],
]);

$this->shippingInformationManagement->saveAddressInformation($address->getQuoteId(), $shippingInformation);
}
}
11 changes: 9 additions & 2 deletions Service/Mollie/GetMollieStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ public function __construct(
$this->getMollieStatusResultFactory = $getMollieStatusResultFactory;
}

public function execute(int $orderId): GetMollieStatusResult
public function execute(int $orderId, string $transactionId = null): GetMollieStatusResult
{
$order = $this->orderRepository->get($orderId);
$transactionId = $order->getMollieTransactionId();
if ($transactionId === null) {
$transactionId = $order->getMollieTransactionId();
}

if ($transactionId === null) {
throw new \Exception('No transaction ID found for order ' . $orderId);
}

$mollieApi = $this->mollieApiClient->loadByStore((int)$order->getStoreId());

if (substr($transactionId, 0, 4) == 'ord_') {
Expand Down
6 changes: 3 additions & 3 deletions Service/Mollie/GetMollieStatusResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class GetMollieStatusResult
*/
private $status;
/**
* @var string
* @var string|null
*/
private $method;

public function __construct(
string $status,
string $method
string $method = null
) {
$method = str_replace('mollie_methods_', '', $method);

Expand All @@ -34,7 +34,7 @@ public function getStatus(): string
return $this->status;
}

public function getMethod(): string
public function getMethod(): ?string
{
return $this->method;
}
Expand Down
3 changes: 2 additions & 1 deletion Service/Mollie/PaymentMethods.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/**
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/
Expand All @@ -26,6 +26,7 @@ public function __construct(
*/
private $methods = [
'mollie_methods_applepay',
'mollie_methods_alma',
'mollie_methods_bancontact',
'mollie_methods_banktransfer',
'mollie_methods_belfius',
Expand Down
Loading

0 comments on commit f2ac6c2

Please sign in to comment.