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

Ap 264 add psp reference on authorization success notification #143

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions Components/Manager/OrderManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace AdyenPayment\Components\Manager;

use Doctrine\ORM\EntityManager;
use Shopware\Models\Order\Order;
use Shopware\Models\Order\Status;

final class OrderManager implements OrderManagerInterface
{
/**
* @var EntityManager
*/
private $modelManager;

public function __construct(EntityManager $modelManager)
{
$this->modelManager = $modelManager;
}

public function save(Order $order)
{
$this->modelManager->persist($order);
$this->modelManager->flush($order);
}

public function updatePspReference(Order $order, string $pspReference)
{
$order = $order->setTransactionId($pspReference);
$this->modelManager->persist($order);
}

public function updatePayment(Order $order, string $pspReference, Status $paymentStatus)
{
$order->setPaymentStatus($paymentStatus);
$order = $order->setTransactionId($pspReference);
$this->modelManager->persist($order);
}
}
15 changes: 15 additions & 0 deletions Components/Manager/OrderManagerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace AdyenPayment\Components\Manager;

use Shopware\Models\Order\Order;
use Shopware\Models\Order\Status;

interface OrderManagerInterface
{
public function save(Order $order);
public function updatePspReference(Order $order, string $pspReference);
public function updatePayment(Order $order, string $pspReference, Status $paymentStatus);
}
16 changes: 11 additions & 5 deletions Controllers/Frontend/Process.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use AdyenPayment\Components\Manager\AdyenManager;
use AdyenPayment\Models\Enum\PaymentResultCodes;
use AdyenPayment\Utils\RequestDataFormatter;
use Shopware\Components\CSRFWhitelistAware;
Expand All @@ -15,7 +14,7 @@
class Shopware_Controllers_Frontend_Process extends Shopware_Controllers_Frontend_Payment implements CSRFWhitelistAware
{
/**
* @var AdyenManager
* @var \AdyenPayment\Components\Manager\AdyenManager
*/
private $adyenManager;

Expand All @@ -38,6 +37,10 @@ class Shopware_Controllers_Frontend_Process extends Shopware_Controllers_Fronten
* @var Logger
*/
private $logger;
/**
* @var \AdyenPayment\Components\Manager\OrderManagerInterface
*/
private $orderManager;


/**
Expand All @@ -55,6 +58,7 @@ public function preDispatch()
$this->basketService = $this->get('adyen_payment.components.basket_service');
$this->orderMailService = $this->get('adyen_payment.components.order_mail_service');
$this->logger = $this->get('adyen_payment.logger');
$this->orderManager = $this->get('AdyenPayment\Components\Manager\OrderManager');
}

/**
Expand Down Expand Up @@ -142,9 +146,11 @@ private function handleReturnResult(array $result, $order)
break;
}

$order->setPaymentStatus($paymentStatus);
$order->setTransactionId($result['pspReference']);
$this->getModelManager()->persist($order);
$this->orderManager->updatePayment(
$order,
(string) ($result['pspReference'] ?? ''),
$paymentStatus
);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions Resources/services/managers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
class="AdyenPayment\Components\NotificationManager">
<argument type="service" id="models"/>
</service>
<service id="AdyenPayment\Components\Manager\OrderManager">
<argument type="service" id="models"/>
</service>
<service id="AdyenPayment\Components\Manager\OrderManagerInterface" alias="AdyenPayment\Components\Manager\OrderManager" />
<service id="adyen_payment.components.text_notification_manager"
class="AdyenPayment\Components\TextNotificationManager">
<argument type="service" id="models"/>
Expand Down
4 changes: 4 additions & 0 deletions Resources/services/subscribers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,9 @@
<tag name="shopware.event_subscriber"/>
<argument type="service" id="adyen_payment.logger.notifications"/>
</service>
<service id="AdyenPayment\Subscriber\Notification\UpdateOrderPsPSubscriber">
<argument type="service" id="AdyenPayment\Components\Manager\OrderManager"/>
<tag name="shopware.event_subscriber"/>
</service>
</services>
</container>
1 change: 0 additions & 1 deletion Subscriber/Cronjob/ProcessNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public static function getSubscribedEvents()
public function runCronjob(Shopware_Components_Cron_CronJob $job)
{
$textNotifications = $this->fifoTextNotificationLoader->get();

$this->incomingNotificationManager->convertNotifications($textNotifications);

/** @var \Generator<NotificationProcessorFeedback> $feedback */
Expand Down
49 changes: 49 additions & 0 deletions Subscriber/Notification/UpdateOrderPsPSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace AdyenPayment\Subscriber\Notification;

use AdyenPayment\Components\Manager\OrderManagerInterface;
use AdyenPayment\Models\Event;
use Enlight\Event\SubscriberInterface;
use Enlight_Event_EventArgs;

class UpdateOrderPsPSubscriber implements SubscriberInterface
{
/**
* @var OrderManagerInterface
*/
private $orderManager;

public function __construct(OrderManagerInterface $orderManager)
{
$this->orderManager = $orderManager;
}

public static function getSubscribedEvents(): array
{
return [
Event::NOTIFICATION_PROCESS_AUTHORISATION => '__invoke',
];
}

public function __invoke(Enlight_Event_EventArgs $args)
{
/**
* @var \Shopware\Models\Order\Order $order
* @var \AdyenPayment\Models\Notification $notification
*/
$order = $args->get('order');
$notification = $args->get('notification');
if (!$notification->isSuccess()) {
return;
}

if ($order->getTransactionId() === $notification->getPspReference()) {
return;
}

$this->orderManager->updatePspReference($order, $notification->getPspReference());
}
}