# Creating a function after payment is successfully done

**URL:** <https://forum.shopware.com/t/creating-a-function-after-payment-is-successfully-done/107460>\
**Category:** Shopware 6 (English)\
**Tags:** programming\
**Created:** [23. Juni 2025 um 13:19 UTC](https://forum.shopware.com/t/creating-a-function-after-payment-is-successfully-done/107460 "2025-06-23T13:19:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![code.bach](https://avatars.discourse-cdn.com/v4/letter/c/47e85d/32.png) [@code.bach](https://forum.shopware.com/u/code.bach)\
**Post date:** [23. Juni 2025 um 13:19 UTC](https://forum.shopware.com/t/creating-a-function-after-payment-is-successfully-done/107460/1 "2025-06-23T13:19:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Max\_Shop](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Max\_Shop](https://forum.shopware.com/u/Max_Shop)\
**Post date:** [23. Juni 2025 um 14:23 UTC](https://forum.shopware.com/t/creating-a-function-after-payment-is-successfully-done/107460/2 "2025-06-23T14:23:21Z")

</div>

Maybe Mollie has a Webhook, not sure about that.

Or create your own plugin, subscribe to the Event and execute your code.

> **[Listening to Events | Shopware Documentation](https://developer.shopware.com/docs/guides/plugins/plugins/plugin-fundamentals/listening-to-events.html)**
>
> Documentation for Shopware developers

---

<div class="post-metadata">

**Author:** ![code.bach](https://avatars.discourse-cdn.com/v4/letter/c/47e85d/32.png) [@code.bach](https://forum.shopware.com/u/code.bach)\
**Post date:** [23. Juni 2025 um 14:48 UTC](https://forum.shopware.com/t/creating-a-function-after-payment-is-successfully-done/107460/3 "2025-06-23T14:48:56Z")

</div>

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 ?

```auto
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;
        }

```

---

<div class="post-metadata">

**Author:** ![vitalij.mik](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/vitalij.mik/32/14987_2.png) [@vitalij.mik](https://forum.shopware.com/u/vitalij.mik)\
**Post date:** [24. Juni 2025 um 06:09 UTC](https://forum.shopware.com/t/creating-a-function-after-payment-is-successfully-done/107460/4 "2025-06-24T06:09:31Z")

</div>

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

> **[Add custom flow actions | Shopware Documentation](https://developer.shopware.com/docs/guides/plugins/apps/flow-builder/add-custom-flow-actions-from-app-system.html)**
>
> Documentation for Shopware developers
