-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #325 from mollie/1.18.1
1.18.1
- Loading branch information
Showing
27 changed files
with
320 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Observer/SalesOrderPlaceBefore/RemovePendingPaymentReminders.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Mollie\Payment\Observer\SalesOrderPlaceBefore; | ||
|
||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Magento\Sales\Model\Order; | ||
use Mollie\Payment\Config; | ||
use Mollie\Payment\Service\Order\DeletePaymentReminder; | ||
|
||
class RemovePendingPaymentReminders implements ObserverInterface | ||
{ | ||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @var DeletePaymentReminder | ||
*/ | ||
private $deletePaymentReminder; | ||
|
||
public function __construct( | ||
Config $config, | ||
DeletePaymentReminder $deletePaymentReminder | ||
) { | ||
$this->config = $config; | ||
$this->deletePaymentReminder = $deletePaymentReminder; | ||
} | ||
|
||
/** | ||
* Remove any pending payment reminders. This is to prevent that payment reminders get send if the order was paid | ||
* by a payment method that is not from Mollie. | ||
* | ||
* @param Observer $observer | ||
*/ | ||
public function execute(Observer $observer) | ||
{ | ||
/** @var OrderInterface $order */ | ||
$order = $observer->getData('order'); | ||
|
||
if (!$this->config->automaticallySendSecondChanceEmails($order->getStoreId())) { | ||
return; | ||
} | ||
|
||
$this->deletePaymentReminder->byEmail($order->getCustomerEmail()); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
Service/Order/Lines/Processor/BundleWithoutDynamicPricing.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Mollie\Payment\Service\Order\Lines\Processor; | ||
|
||
use Magento\Bundle\Model\Product\Price; | ||
use Magento\Catalog\Model\Product\Type; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Magento\Sales\Api\Data\OrderItemInterface; | ||
use Mollie\Payment\Helper\General; | ||
|
||
class BundleWithoutDynamicPricing implements ProcessorInterface | ||
{ | ||
/** | ||
* @var General | ||
*/ | ||
private $mollieHelper; | ||
|
||
public function __construct( | ||
General $mollieHelper | ||
) { | ||
$this->mollieHelper = $mollieHelper; | ||
} | ||
|
||
public function process($orderLine, OrderInterface $order, OrderItemInterface $orderItem = null): array | ||
{ | ||
if ( | ||
!$orderItem || | ||
$orderItem->getProductType() !== Type::TYPE_BUNDLE || | ||
!$orderItem->getProduct() || | ||
$orderItem->getProduct()->getPriceType() != Price::PRICE_TYPE_FIXED | ||
) { | ||
return $orderLine; | ||
} | ||
|
||
$forceBaseCurrency = (bool)$this->mollieHelper->useBaseCurrency($order->getStoreId()); | ||
$currency = $forceBaseCurrency ? $order->getBaseCurrencyCode() : $order->getOrderCurrencyCode(); | ||
|
||
$discountAmount = $this->getDiscountAmountWithTax($orderItem, $forceBaseCurrency); | ||
if (!$discountAmount) { | ||
return $orderLine; | ||
} | ||
|
||
// Magento provides us with a discount amount without tax, but calculates with tax in this case. So recalculate | ||
// the unit price, total amount and vat amount. | ||
|
||
$taxPercent = $orderItem->getTaxPercent(); | ||
$unitPrice = $orderLine['totalAmount']['value'] / $orderItem->getQtyOrdered(); | ||
$newVatAmount = (($unitPrice - $discountAmount) / (100 + $taxPercent)) * $taxPercent; | ||
|
||
$orderLine['unitPrice'] = $this->mollieHelper->getAmountArray($currency, $unitPrice); | ||
$orderLine['totalAmount'] = $this->mollieHelper->getAmountArray($currency, $unitPrice - $discountAmount); | ||
$orderLine['vatAmount'] = $this->mollieHelper->getAmountArray($currency, $newVatAmount); | ||
$orderLine['discountAmount'] = $this->mollieHelper->getAmountArray($currency, $discountAmount); | ||
|
||
return $orderLine; | ||
} | ||
|
||
private function getDiscountAmountWithTax(OrderItemInterface $item, bool $forceBaseCurrency) | ||
{ | ||
if ($forceBaseCurrency) { | ||
return abs($item->getBaseDiscountAmount()); | ||
} | ||
|
||
return abs($item->getDiscountAmount()); | ||
} | ||
} |
Oops, something went wrong.