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

Release #771

Merged
merged 18 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f5993fc
Bugfix: Prevent the store credit to be restored twice after cancelati…
michielgerritsen Mar 25, 2024
a3312bf
Bugfix: Mark subscription items as onetime purchase #764
michielgerritsen Apr 2, 2024
87209cf
Bugfix: Add support for Reward Points
michielgerritsen Apr 8, 2024
a7984dd
Improvement: Better Apple Pay comment
michielgerritsen Apr 8, 2024
1ce4597
Bugfix: Allow method to be null
michielgerritsen Apr 8, 2024
d903667
Feature: New payment method Alma
michielgerritsen Apr 11, 2024
94a1661
Bugfix: Load translations in queue #767
michielgerritsen Apr 11, 2024
8a96779
Bugfix: Save shipping method for Apple Pay #768
michielgerritsen Apr 11, 2024
d4b5f13
Bugfix: Add adjustment when the difference is rounded 0.01 cents
michielgerritsen Apr 11, 2024
a599329
Merge branch 'bugfix/save-shipping-method-for-applepay' into release-…
michielgerritsen Apr 18, 2024
df274a5
Merge branch 'bugfix/load-translations-in-queue' into release-week-15
michielgerritsen Apr 18, 2024
d5d084f
Merge branch 'feature/new-method-alma' into release-week-15
michielgerritsen Apr 18, 2024
16dd0c2
Merge branch 'bugfix/allow-method-to-be-null' into release-week-15
michielgerritsen Apr 18, 2024
4f7910f
Merge branch 'improvement/better-applepay-comment' into release-week-15
michielgerritsen Apr 18, 2024
4aaeeee
Merge branch 'bugfix/reward-points' into release-week-15
michielgerritsen Apr 18, 2024
1f200cf
Merge branch 'bugfix/mark-subscription-items-as-onetime-purchase' int…
michielgerritsen Apr 18, 2024
d29e239
Merge branch 'bugfix/prevent-double-credit-restore' into release-week-15
michielgerritsen Apr 18, 2024
2ae14ed
Merge branch 'bugfix/adjustment-for-mini-numbers' into release-week-15
michielgerritsen Apr 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading