# Updates der CustomFields in OrderTransactions

**URL:** <https://forum.shopware.com/t/updates-der-customfields-in-ordertransactions/95472>\
**Category:** Shopware 6 (German)\
**Created:** [26. Juli 2022 um 08:58 UTC](https://forum.shopware.com/t/updates-der-customfields-in-ordertransactions/95472 "2022-07-26T08:58:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zellenkur](https://avatars.discourse-cdn.com/v4/letter/z/df788c/32.png) [@zellenkur](https://forum.shopware.com/u/zellenkur)\
**Post date:** [26. Juli 2022 um 08:58 UTC](https://forum.shopware.com/t/updates-der-customfields-in-ordertransactions/95472/1 "2022-07-26T08:58:13Z")

</div>

Liebe Community,

wir schreiben ein Plugin, das in das Event `state_enter.order_transaction.state.paid` eingeklingt ist. Wenn PayPal nun eine Transaktion macht, greifen wir die OrderTransaction und deren CustomFields ab, um an die `swag_paypal_resource_id` zu kommen.

Nur exisitiert diese zum Zeitpunkt des Events noch nicht, sondern kommt einige Sekunden später durch ein Update der OrderTransaction rein.

Was kann ich tun, um direkt nach einer Bestellung nun die PayPal Resource ID abzugreifen?

Gibt es vielleicht ein anderes Event, das hier besser wäre?

Hier der verkürzte Code, um den es geht:

```auto
class OrderTransactionStatePaidListener implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            'state_enter.order_transaction.state.paid' => 'onOrderTransactionStatePaid',
        ];
    }

    public function onOrderTransactionStatePaid(OrderStateMachineStateChangeEvent $event): void
    {
        // We do not get all associations within the event so we need
        // to make our own request to get missed data
        $order = $this->getOrder($event->getOrder()->getId(), $event->getContext());
        $orderTransaction = $order->getTransactions()->first();

        if (strpos($orderTransaction->getPaymentMethod()->getHandlerIdentifier(), 'PayPal') !== false) {
            $customFields = $orderTransaction->getCustomFields();
            // PayPal Resource ID gibt es zu diesem Zeitpunkt noch nicht :(
            $transactionkey = (array_key_exists('swag_paypal_resource_id', $customFields)) ? $customFields['swag_paypal_resource_id'] : '';
        }
}

```

Liebe Grüße  
Sebastian
