Skip to content

Commit

Permalink
Merge pull request #654 from mollie/release/2.27.0
Browse files Browse the repository at this point in the history
Release/2.27.0
  • Loading branch information
Marvin-Magmodules authored Jun 13, 2023
2 parents d0c6b4f + ce136df commit 9fce3c5
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 18 deletions.
10 changes: 8 additions & 2 deletions Model/Client/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
22 changes: 15 additions & 7 deletions Model/Client/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
*/
class Payments extends AbstractModel
{

const CHECKOUT_TYPE = 'payment';
const TRANSACTION_TYPE_WEBHOOK = 'webhook';
const TRANSACTION_TYPE_SUBSCRIPTION = 'subscription';

/**
* @var MollieHelper
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 44 additions & 0 deletions Service/Order/Lines/Generator/ShippingDiscount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Mollie\Payment\Service\Order\Lines\Generator;

use Magento\Sales\Api\Data\OrderInterface;
use Mollie\Api\Types\OrderLineType;
use Mollie\Payment\Helper\General;

class ShippingDiscount implements GeneratorInterface
{
/**
* @var General
*/
private $mollieHelper;

public function __construct(
General $mollieHelper
) {
$this->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;
}
}
5 changes: 2 additions & 3 deletions Service/Order/Reorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@
<comment><![CDATA[<strong>Optional</strong> Comma separated list of emailaddresses. Leave empty to disable.]]></comment>
<validate>validate-emails</validate>
<depends>
<field id="enabled">1</field>
<field id="enable_second_chance_email">1</field>
</depends>
</field>
</group>
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<default>
<payment>
<mollie_general>
<version>v2.26.0</version>
<version>v2.27.0</version>
<active>0</active>
<enabled>0</enabled>
<type>test</type>
Expand Down
1 change: 1 addition & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
<item name="magento_giftcard" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\MagentoGiftCard</item>
<item name="magento_giftwrapping" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\MagentoGiftWrapping</item>
<item name="geissweb_euvat" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\GeisswebEuvat</item>
<item name="cart_rule_discount" xsi:type="object">Mollie\Payment\Service\Order\Lines\Generator\ShippingDiscount</item>
</argument>
</arguments>
</type>
Expand Down
2 changes: 1 addition & 1 deletion etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
</event>
<event name="sales_model_service_quote_submit_success">
<observer name="mollie_attach_payment_token_to_order" instance="Mollie\Payment\Observer\SalesModelServiceQuoteSubmitSuccess\AttachPaymentTokenToOrder" />
<observer name="mollie_starttransaction_for_paymentlink_orders" instance="Mollie\Payment\Observer\SalesModelServiceQuoteSubmitSuccess\StartTransactionForPaymentLinkOrders" />
</event>
<event name="mollie_start_transaction">
<observer name="mollie_save_pending_payment_reminder" instance="Mollie\Payment\Observer\MollieStartTransaction\SavePendingOrder" />
Expand All @@ -46,7 +47,6 @@
</event>
<event name="checkout_submit_all_after">
<observer name="mollie_starttransaction_for_instant_purchase_orders" instance="Mollie\Payment\Observer\CheckoutSubmitAllAfter\StartTransactionForInstantPurchaseOrders" />
<observer name="mollie_starttransaction_for_paymentlink_orders" instance="Mollie\Payment\Observer\CheckoutSubmitAllAfter\StartTransactionForPaymentLinkOrders" />
</event>
<event name="sales_quote_item_set_product">
<observer name="mollie_add_subscription_product_type_options" instance="Mollie\Payment\Observer\SalesQuoteItemSetProduct\SetSubscriptionDataOnBuyRequest" />
Expand Down

0 comments on commit 9fce3c5

Please sign in to comment.