diff --git a/Model/Client/Orders.php b/Model/Client/Orders.php
index 441db272864..c97677ffce0 100644
--- a/Model/Client/Orders.php
+++ b/Model/Client/Orders.php
@@ -565,9 +565,15 @@ public function createShipment(Order\Shipment $shipment, OrderInterface $order)
}
}
} catch (\Exception $e) {
- $this->mollieHelper->addTolog('error', $e->getMessage());
+ $message = __(
+ 'Unable to ship order "%1" due to error: %2',
+ $order->getIncrementId(),
+ $e->getMessage()
+ );
+
+ $this->mollieHelper->addTolog('error', $message);
throw new LocalizedException(
- __('Mollie API: %1', $e->getMessage())
+ $message
);
}
diff --git a/Model/Client/Payments.php b/Model/Client/Payments.php
index 598a57c9714..f01b5362a5f 100644
--- a/Model/Client/Payments.php
+++ b/Model/Client/Payments.php
@@ -40,8 +40,9 @@
*/
class Payments extends AbstractModel
{
-
const CHECKOUT_TYPE = 'payment';
+ const TRANSACTION_TYPE_WEBHOOK = 'webhook';
+ const TRANSACTION_TYPE_SUBSCRIPTION = 'subscription';
/**
* @var MollieHelper
@@ -253,7 +254,7 @@ public function startTransaction(Order $order, $mollieApi)
// Order is paid immediately (eg. Credit Card with Components, Apple Pay), process transaction
if ($payment->isPaid()) {
- $this->processTransaction->execute($order, 'webhook');
+ $this->processTransaction->execute($order, static::TRANSACTION_TYPE_WEBHOOK);
}
return $payment->getCheckoutUrl();
@@ -331,7 +332,9 @@ public function processTransaction(Order $order, $mollieApi, $type = 'webhook',
$status = $paymentData->status;
$payment = $order->getPayment();
- if ($type == 'webhook' && $payment->getAdditionalInformation('payment_status') != $status) {
+ if (in_array($type, [static::TRANSACTION_TYPE_WEBHOOK, static::TRANSACTION_TYPE_SUBSCRIPTION]) &&
+ $payment->getAdditionalInformation('payment_status') != $status
+ ) {
$payment->setAdditionalInformation('payment_status', $status);
$this->orderRepository->save($order);
}
@@ -351,12 +354,16 @@ public function processTransaction(Order $order, $mollieApi, $type = 'webhook',
$this->saveAdditionalInformationDetails->execute($payment, $paymentData->details);
}
- if (!$payment->getIsTransactionClosed() && $type == 'webhook') {
+ if (!$payment->getIsTransactionClosed() &&
+ in_array($type, [static::TRANSACTION_TYPE_WEBHOOK, static::TRANSACTION_TYPE_SUBSCRIPTION])
+ ) {
if ($order->isCanceled()) {
$order = $this->mollieHelper->uncancelOrder($order);
}
- if (abs($amount - $orderAmount['value']) < 0.01) {
+ if (abs($amount - $orderAmount['value']) < 0.01 ||
+ $type == static::TRANSACTION_TYPE_SUBSCRIPTION
+ ) {
$payment->setTransactionId($transactionId);
$payment->setCurrencyCode($order->getBaseCurrencyCode());
$payment->setIsTransactionClosed(true);
@@ -440,7 +447,7 @@ public function processTransaction(Order $order, $mollieApi, $type = 'webhook',
}
}
if ($status == 'canceled' || $status == 'failed' || $status == 'expired') {
- if ($type == 'webhook') {
+ if (in_array($type, [static::TRANSACTION_TYPE_WEBHOOK, static::TRANSACTION_TYPE_SUBSCRIPTION])) {
$this->cancelOrder->execute($order, $status);
$this->transactionProcessor->process($order, null, $paymentData);
}
@@ -482,9 +489,10 @@ public function orderHasUpdate(OrderInterface $order, MollieApiClient $mollieApi
*/
public function checkCheckoutSession(Order $order, $paymentToken, $paymentData, $type)
{
- if ($type == 'webhook') {
+ if (in_array($type, [static::TRANSACTION_TYPE_WEBHOOK, static::TRANSACTION_TYPE_SUBSCRIPTION])) {
return;
}
+
if ($this->checkoutSession->getLastOrderId() != $order->getId()) {
if ($paymentToken && isset($paymentData->metadata->payment_token)) {
if ($paymentToken == $paymentData->metadata->payment_token) {
diff --git a/Observer/CheckoutSubmitAllAfter/StartTransactionForPaymentLinkOrders.php b/Observer/SalesModelServiceQuoteSubmitSuccess/StartTransactionForPaymentLinkOrders.php
similarity index 92%
rename from Observer/CheckoutSubmitAllAfter/StartTransactionForPaymentLinkOrders.php
rename to Observer/SalesModelServiceQuoteSubmitSuccess/StartTransactionForPaymentLinkOrders.php
index fc237c8b173..bdcdc1678ff 100644
--- a/Observer/CheckoutSubmitAllAfter/StartTransactionForPaymentLinkOrders.php
+++ b/Observer/SalesModelServiceQuoteSubmitSuccess/StartTransactionForPaymentLinkOrders.php
@@ -4,7 +4,7 @@
* See COPYING.txt for license details.
*/
-namespace Mollie\Payment\Observer\CheckoutSubmitAllAfter;
+namespace Mollie\Payment\Observer\SalesModelServiceQuoteSubmitSuccess;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
diff --git a/Service/Order/Lines/Generator/ShippingDiscount.php b/Service/Order/Lines/Generator/ShippingDiscount.php
new file mode 100644
index 00000000000..03171803f67
--- /dev/null
+++ b/Service/Order/Lines/Generator/ShippingDiscount.php
@@ -0,0 +1,44 @@
+mollieHelper = $mollieHelper;
+ }
+
+ public function process(OrderInterface $order, array $orderLines): array
+ {
+ if (!$order->getShippingDiscountAmount()) {
+ return $orderLines;
+ }
+
+ $forceBaseCurrency = (bool)$this->mollieHelper->useBaseCurrency($order->getStoreId());
+ $currency = $forceBaseCurrency ? $order->getBaseCurrencyCode() : $order->getOrderCurrencyCode();
+ $amount = abs($order->getData(($forceBaseCurrency ? 'base_' : '') . 'shipping_discount_amount'));
+
+ $orderLines[] = [
+ 'type' => OrderLineType::TYPE_DISCOUNT,
+ 'name' => __('Magento Discount'),
+ 'quantity' => 1,
+ 'unitPrice' => $this->mollieHelper->getAmountArray($currency, -$amount),
+ 'totalAmount' => $this->mollieHelper->getAmountArray($currency, -$amount),
+ 'vatRate' => '0.00',
+ 'vatAmount' => $this->mollieHelper->getAmountArray($currency, '0.00'),
+ ];
+
+ return $orderLines;
+ }
+}
diff --git a/Service/Order/Reorder.php b/Service/Order/Reorder.php
index d892333e0ff..fc02bc067cb 100644
--- a/Service/Order/Reorder.php
+++ b/Service/Order/Reorder.php
@@ -159,9 +159,8 @@ private function recreate(
$this->orderCreate->setData('account', ['email' => $originalOrder->getCustomerEmail()]);
$this->orderCreate->initFromOrder($originalOrder);
- if ($originalOrder->getCustomerGroupId() === null) {
- $this->orderCreate->getQuote()->getCustomer()->setGroupId(0);
- }
+ $customerGroupId = $originalOrder->getCustomerGroupId() ?? 0;
+ $this->orderCreate->getQuote()->getCustomer()->setGroupId($customerGroupId);
$order = $this->orderCreate->createOrder();
diff --git a/Test/Integration/Observer/CheckoutSubmitAllAfter/StartTransactionForPaymentLinkOrdersTest.php b/Test/Integration/Observer/CheckoutSubmitAllAfter/StartTransactionForPaymentLinkOrdersTest.php
index 2fe5ce97a72..78fff6a7045 100644
--- a/Test/Integration/Observer/CheckoutSubmitAllAfter/StartTransactionForPaymentLinkOrdersTest.php
+++ b/Test/Integration/Observer/CheckoutSubmitAllAfter/StartTransactionForPaymentLinkOrdersTest.php
@@ -8,7 +8,7 @@
use Magento\Framework\Event\Observer;
use Mollie\Payment\Model\Mollie;
-use Mollie\Payment\Observer\CheckoutSubmitAllAfter\StartTransactionForPaymentLinkOrders;
+use Mollie\Payment\Observer\SalesModelServiceQuoteSubmitSuccess\StartTransactionForPaymentLinkOrders;
use Mollie\Payment\Test\Integration\IntegrationTestCase;
class StartTransactionForPaymentLinkOrdersTest extends IntegrationTestCase
diff --git a/composer.json b/composer.json
index 17c6370ae76..888279918bc 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
{
"name": "mollie/magento2",
"description": "Mollie Payment Module for Magento 2",
- "version": "2.26.0",
+ "version": "2.27.0",
"keywords": [
"mollie",
"payment",
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index c23e7cdc7fe..f5f086bd0a4 100644
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -359,7 +359,7 @@
Optional Comma separated list of emailaddresses. Leave empty to disable.]]>
validate-emails
- 1
+ 1
diff --git a/etc/config.xml b/etc/config.xml
index 403b26c8d23..39c93749202 100644
--- a/etc/config.xml
+++ b/etc/config.xml
@@ -3,7 +3,7 @@
- v2.26.0
+ v2.27.0
0
0
test
diff --git a/etc/di.xml b/etc/di.xml
index 3fa66fcb8d5..573987a7e20 100644
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -148,6 +148,7 @@
- Mollie\Payment\Service\Order\Lines\Generator\MagentoGiftCard
- Mollie\Payment\Service\Order\Lines\Generator\MagentoGiftWrapping
- Mollie\Payment\Service\Order\Lines\Generator\GeisswebEuvat
+ - Mollie\Payment\Service\Order\Lines\Generator\ShippingDiscount
diff --git a/etc/events.xml b/etc/events.xml
index 3fb21fd1eb7..8d0cdb035cf 100644
--- a/etc/events.xml
+++ b/etc/events.xml
@@ -28,6 +28,7 @@
+
@@ -46,7 +47,6 @@
-