Copied!

BeforeDeletePaymentEvent

BeforeDeletePaymentEvent.php : 69
Extends BeforeEvent

Event that is dispatched before a payment is deleted.

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

The following first example prevents deletion of any payment:

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

    public function onBeforeDeletePayment(BeforeDeletePaymentEvent $event): void
    {
        // Prevent deletion of payment
        $event->stopPropagation();
    }
}

The second example logs a warning about the payment just before its deletion:

final class PaymentEventSubscriber implements EventSubscriberInterface
{
    private function __construct(private LoggerInterface $logger)
    {
    }

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

    public function onBeforeDeletePayment(BeforeDeletePaymentEvent $event): void
    {
        $this->logger->warning(
             'Payment {identifier} has been deleted',
             [
                 'name' => $event->getPayment()->getIdentifier(),
             ]
        );
    }
}
Tags
See
PaymentServiceInterface::deletePayment()

Methods

public__construct()

BeforeDeletePaymentEvent.php : 73
public __construct(PaymentInterface $payment)

Parameters

Name Type Default value Description
$payment PaymentInterface - -

publicgetPayment()

BeforeDeletePaymentEvent.php : 81

Returns the payment to be deleted.

public getPayment() : PaymentInterface

Return values

PaymentInterface

publicisPropagationStopped()

Event.php : 38
public isPropagationStopped() : bool

Return values

bool

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().