Skip to content

Commit

Permalink
Fixed an issue where Mollie order statuses couldn't be taken over by …
Browse files Browse the repository at this point in the history
…Shopware anymore. Fixed an issue where order status updates through the Shopware API wouldn't ship the order to Klarna on the right status.
  • Loading branch information
Reinder committed Jun 29, 2020
1 parent aad002b commit 8f96f2b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Components/MollieApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function create($shopId = null)

// add plugin name and version
$this->apiClient->addVersionString(
'MollieShopware/1.5.14'
'MollieShopware/1.5.15'
);
}
catch (\Exception $ex) {
Expand Down
6 changes: 6 additions & 0 deletions Components/Services/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ protected function getCreditCardToken()
*/
public function updateOrderStatus(\Shopware\Models\Order\Order $order, $transactionId)
{
$orderId = null;
$paymentId = null;

/** @var TransactionRepository $transactionRepo */
Expand All @@ -635,9 +636,14 @@ public function updateOrderStatus(\Shopware\Models\Order\Order $order, $transact
$transaction = $transactionRepo->find($transactionId);

if ($transaction !== null) {
$orderId = $transaction->getMollieId();
$paymentId = $transaction->getMolliePaymentId();
}

if ($orderId !== null) {
$this->checkOrderStatus($order);
}

return $this->checkPaymentStatus($order, $paymentId);
}

Expand Down
12 changes: 1 addition & 11 deletions Controllers/Frontend/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,6 @@ public function notifyAction()
$paymentService = $this->container
->get('mollie_shopware.payment_service');

try {
$order = $this->getOrder();
}
catch(\Exception $e) {
Notifier::notifyException(
$e->getMessage(),
$e
);
}

if (
$transactionNumber !== ''
&& ($order === null || !$order instanceof \Shopware\Models\Order\Order)
Expand Down Expand Up @@ -310,7 +300,7 @@ public function notifyAction()
);
}
} else {
Notifier::notifyException(
Notifier::notifyOk(
'Order not found'
);
}
Expand Down
2 changes: 2 additions & 0 deletions MollieShopware.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public function install(InstallContext $context)

/**
* @param UpdateContext $context
*
* @throws Exception
*/
public function update(UpdateContext $context)
{
Expand Down
1 change: 1 addition & 0 deletions Resources/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
</service>

<service id="mollie_shopware.subscriber.order_backend" class="MollieShopware\Subscriber\OrderBackendSubscriber">
<argument type="service" id="mollie_shopware.order_service" />
<tag name="shopware.event_subscriber" />
</service>

Expand Down
37 changes: 29 additions & 8 deletions Subscriber/OrderBackendSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
use MollieShopware\Components\Config;
use MollieShopware\Components\Helpers\LogHelper;
use MollieShopware\Components\Logger;
use MollieShopware\Components\Services\OrderService;
use Shopware\Models\Order\Order;

class OrderBackendSubscriber implements SubscriberInterface
{
/** @var OrderService */
private $orderService;

public static function getSubscribedEvents()
{
return [
Expand All @@ -18,6 +23,11 @@ public static function getSubscribedEvents()
];
}

public function __construct(OrderService $orderService)
{
$this->orderService = $orderService;
}

/**
* Catch mailvariables when the confirmation email is triggered and store
* them in the database to use them when the order is fully processed.
Expand Down Expand Up @@ -103,28 +113,39 @@ public function onOrderApiPut(\Enlight_Hook_HookArgs $args)
return true;
}

/** @var Order $order */
$order = null;

/** @var int|string $orderId */
$orderId = $request->getParam('id');

/** @var bool $numberAsId */
$numberAsId = (bool) $request->getParam('useNumberAsId', 0);

if (empty($orderId)) {
return true;
}

if ($numberAsId === true) {
$order = $this->orderService->getOrderByNumber($orderId);
}

if ($order !== null) {
$orderId = $order->getId();
}

return $this->shipOrderToMollie($orderId);
}

private function shipOrderToMollie($orderId)
{
/** @var \Shopware\Models\Order\Order $order */
$order = null;

try {
/** @var \MollieShopware\Components\Services\OrderService $orderService */
$orderService = Shopware()->Container()
->get('mollie_shopware.order_service');

/** @var \Shopware\Models\Order\Order $order */
$order = $orderService->getOrderById($orderId);
$order = $this->orderService->getOrderById($orderId);
} catch (\Exception $e) {
LogHelper::logMessage($e->getMessage(), LogHelper::LOG_ERROR, $e);
//
}

if ($order === null) {
Expand All @@ -134,7 +155,7 @@ private function shipOrderToMollie($orderId)
$mollieId = null;

try {
$mollieId = $orderService->getMollieOrderId($order);
$mollieId = $this->orderService->getMollieOrderId($order->getId());
} catch (\Exception $e) {
LogHelper::logMessage($e->getMessage(), LogHelper::LOG_ERROR, $e);
}
Expand Down
8 changes: 4 additions & 4 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<label lang="de">Mollie</label>
<label lang="nl">Mollie</label>

<version>1.5.14</version>
<version>1.5.15</version>
<copyright>(c) Mollie B.V.</copyright>
<author>Kiener E-commerce</author>
<link>https://www.kiener.nl</link>

<description lang="en">Plugin to allow iDeal payments using the Mollie API (1.5.14)</description>
<description lang="nl">Plugin die iDealbetalingen via de Mollie API doorgeeft (1.5.14)</description>
<description lang="de">Plugin um Zahlungen mit der Mollie API zu ermöglichen (1.5.14)</description>
<description lang="en">Plugin to allow iDeal payments using the Mollie API (1.5.15)</description>
<description lang="nl">Plugin die iDealbetalingen via de Mollie API doorgeeft (1.5.15)</description>
<description lang="de">Plugin um Zahlungen mit der Mollie API zu ermöglichen (1.5.15)</description>

<compatibility minVersion="5.3.0"/>
</plugin>

0 comments on commit 8f96f2b

Please sign in to comment.