Event dispatched before a payment method is updated.
Typical use case are to modify the payment method update struct before executing operation or completely override payment method update logic. See the two examples below.
The following first example capitalizes the first character of each word in each names of the payment method to update:
final class PaymentMethodEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
BeforeUpdatePaymentMethodEvent::class => 'onBeforeUpdatePaymentMethod',
];
}
public function onBeforeUpdatePaymentMethod(BeforeUpdatePaymentMethodEvent $event): void
{
$updateStruct = $event->getUpdateStruct();
foreach ($updateStruct->getNames() ?? [] as $languageCode => $name) {
if ($name !== null) {
// Capitalize payment method name
$updateStruct->setName($languageCode, ucwords($name));
}
}
}
}
The following second example sets its own payment method, and cancel the default payment method update process:
final class PaymentMethodEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
BeforeUpdatePaymentMethodEvent::class => 'onBeforeUpdatePaymentMethod',
];
}
public function onBeforeUpdatePaymentMethod(BeforeUpdatePaymentMethodEvent $event): void
{
// ...
$event->setPaymentMethodResult($paymentMethod);
$event->stopPropagation();
}
}
Tags
Methods¶
__construct() ¶
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$paymentMethod | PaymentMethodInterface | - | - |
$updateStruct | PaymentMethodUpdateStruct | - | - |
$paymentMethodResult | PaymentMethodInterface|null | null | - |
getPaymentMethod() ¶
Returns the payment method being updated.
|
|
Return values
getPaymentMethodResult() ¶
Returns overridden payment method.
|
|
Returns overridden PaymentMethodServiceInterface::updatePaymentMethod() result.
Return values
Tags
getUpdateStruct() ¶
Returns the data used to update payment method.
|
|
Return values
hasPaymentMethodResult() ¶
Checks if payment method is overridden.
|
|
Returns whether the PaymentMethodServiceInterface::updatePaymentMethod() result is overridden.
Return values
bool
isPropagationStopped() ¶
|
|
Return values
bool
setPaymentMethodResult() ¶
Overrides payment method.
|
|
Overrides PaymentMethodServiceInterface::updatePaymentMethod() execution result.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$paymentMethodResult | PaymentMethodInterface|null | - | - |
stopPropagation() ¶
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().