I want to create some function that when payment transition is successfully done. Is there a method for that or how can i handle that transition ?
NOTE : I’m using Mollie plugin
Maybe Mollie has a Webhook, not sure about that.
Or create your own plugin, subscribe to the Event and execute your code.
Actually, i am trying to create my own plugin for this situation but the bad part is every method i’ve tried didn’t fix my problem yet.
All i’m asking is state_enter.order_transaction.state.paid
is this one the correct method for to handle „paid“ statement ?
use Psr\Log\LoggerInterface;
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemEntity;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity;
use Shopware\Core\Checkout\Payment\PaymentState;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\System\StateMachine\Event\StateMachineTransitionEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class OrderSubscriber implements EventSubscriberInterface
{
private EntityRepository $orderTransactionRepository;
private EntityRepository $orderRepository;
private LoggerInterface $logger;
private string $partnerToken;
private string $userToken;
public function __construct(
EntityRepository $orderTransactionRepository,
EntityRepository $orderRepository,
LoggerInterface $logger,
string $partnerToken,
string $userToken
) {
$this->orderTransactionRepository = $orderTransactionRepository;
$this->orderRepository = $orderRepository;
$this->logger = $logger;
$this->partnerToken = $partnerToken;
$this->userToken = $userToken;
}
public static function getSubscribedEvents(): array
{
return [
'state_enter.order_transaction.state.paid' => 'onOrderPaid',
];
}
public function onOrderPaid(StateMachineTransitionEvent $event): void
{
$transactionId = $event->getEntityId();
$transaction = $this->orderTransactionRepository->search(
(new Criteria([$transactionId]))
->addAssociation('order.lineItems')
->addAssociation('order.billingAddress.country')
->addAssociation('paymentMethod'),
$event->getContext()
)->first();
if (!$transaction instanceof OrderTransactionEntity) {
return;
}
$order = $transaction->getOrder();
if (!$order instanceof OrderEntity) {
return;
}
check the file vendor/shopware/core/Checkout/Order/OrderEvents.php here you can find all events which are triggered by shopware.
you could also create a custom flow event and configure it in flow builder
2 „Gefällt mir“