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
Methods¶
__construct() ¶
BeforeDeletePaymentMethodEvent.php
:
72
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$paymentMethod | PaymentMethodInterface | - | - |
getPaymentMethod() ¶
BeforeDeletePaymentMethodEvent.php
:
80
Returns the payment method to be deleted.
|
|
Return values
isPropagationStopped() ¶
Event.php
:
38
|
|
Return values
bool
stopPropagation() ¶
Event.php
:
50
Stops the propagation of the event to further event listeners.
|
|
If multiple event listeners are connected to the same event, no further event listener will be triggered once any trigger calls stopPropagation().