Copied!

BeforeDeletePaymentMethodEvent

BeforeDeletePaymentMethodEvent.php : 68
Extends BeforeEvent

Event dispatched before a payment method is deleted.

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

The following first example prevent deletion of any payment method:

final class PaymentMethodEventSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            BeforeDeletePaymentMethodEvent::class => 'onBeforeDeletePaymentMethod',
       ];
    }

    public function onBeforeDeletePaymentMethod(BeforeDeletePaymentMethodEvent $event): void
    {
        // Prevent deletion of payment method
        $event->stopPropagation();
    }
}

The following second example log a warning about the payment method just before its deletion:

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

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

    public function onBeforeDeletePaymentMethod(BeforeDeletePaymentMethodEvent $event): void
    {
        $this->logger->warning(
             'Payment method {name} has been deleted',
             [
                 'name' => $event->getPaymentMethod()->getName()
             ]
        );
    }
}
Tags
See
PaymentMethodServiceInterface::deletePaymentMethod()

Methods

public__construct()

BeforeDeletePaymentMethodEvent.php : 72
public __construct(PaymentMethodInterface $paymentMethod)

Parameters

Name Type Default value Description
$paymentMethod PaymentMethodInterface - -

publicgetPaymentMethod()

BeforeDeletePaymentMethodEvent.php : 80

Returns the payment method to be deleted.

public getPaymentMethod() : PaymentMethodInterface

Return values

PaymentMethodInterface