Copied!

BeforeUpdatePaymentEvent

BeforeUpdatePaymentEvent.php : 76
Extends BeforeEvent

Event that is dispatched before a payment is updated.

Typical use cases are to prevent update of payment or to perform some action before update. See the two examples below.

The following example prevents update of cash payments:

final class PaymentEventSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            BeforeUpdatePaymentEvent::class => 'onBeforeUpdatePayment',
        ];
    }

    public function onBeforeUpdatePayment(BeforeUpdatePaymentEvent $event): void
    {
        $payment = $event->getPayment();
        if ($payment->getMethod()->getType()->getIdentifier() === 'cash') {
            // It's not possible to update cash payment
            $event->stopPropagation();
        }
    }
}

The following example adds addition context information to the payment update struct before update is executed:

final class PaymentEventSubscriber implements EventSubscriberInterface
{
    public function __construct(private PermissionResolver $permissionResolver)
    {
    }

    public static function getSubscribedEvents(): array
    {
        return [
            BeforeUpdatePaymentEvent::class => 'onBeforeUpdatePayment',
        ];
    }

    public function onBeforeUpdatePayment(BeforeUpdatePaymentEvent $event): void
    {
        $updateStruct = $event->getUpdateStruct();
        if ($updateStruct->getTransition() !== null) {
            $context = [
                'updated_by' => $this->permissionResolver->getCurrentUserReference()->getUserId(),
            ];

            $updateStruct->setContext(new ArrayMap($context));
        }
    }
}
Tags
See
PaymentServiceInterface::updatePayment()

Methods

public__construct()

BeforeUpdatePaymentEvent.php : 84
public __construct(PaymentInterface $payment, PaymentUpdateStruct $updateStruct[, PaymentInterface|null $paymentResult = null ])

Parameters

Name Type Default value Description
$payment PaymentInterface - -
$updateStruct PaymentUpdateStruct - -
$paymentResult PaymentInterface|null null -

publicgetPayment()

BeforeUpdatePaymentEvent.php : 97

Returns the payment being updated.

public getPayment() : PaymentInterface

Return values

PaymentInterface

publicgetPaymentResult()

BeforeUpdatePaymentEvent.php : 117

Returns overridden payment.

public getPaymentResult() : PaymentInterface

Returns overridden PaymentServiceInterface::updatePayment() result.

Return values

PaymentInterface

Tags
Throws
UnexpectedValueException

if the payment result is not set

publicgetUpdateStruct()

BeforeUpdatePaymentEvent.php : 105

Returns the data used to update payment.

public getUpdateStruct() : PaymentUpdateStruct

Return values

PaymentUpdateStruct

publichasPaymentResult()

BeforeUpdatePaymentEvent.php : 142

Returns whether the {@see \Ibexa\Contracts\Payment\PaymentServiceInterface::updatePayment()} result has been overridden.

public hasPaymentResult() : bool

Return values

bool

publicisPropagationStopped()

Event.php : 38
public isPropagationStopped() : bool

Return values

bool

publicsetPaymentResult()

BeforeUpdatePaymentEvent.php : 133

Overrides payment.

public setPaymentResult(PaymentInterface|null $paymentResult) : void

Overrides PaymentServiceInterface::updatePayment() execution result.

Parameters

Name Type Default value Description
$paymentResult PaymentInterface|null - -

publicstopPropagation()

Event.php : 50

Stops the propagation of the event to further event listeners.

public stopPropagation() : void

If multiple event listeners are connected to the same event, no further event listener will be triggered once any trigger calls stopPropagation().