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
Methods¶
__construct() ¶
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$payment | PaymentInterface | - | - |
$updateStruct | PaymentUpdateStruct | - | - |
$paymentResult | PaymentInterface|null | null | - |
getPayment() ¶
Returns the payment being updated.
|
|
Return values
getPaymentResult() ¶
Returns overridden payment.
|
|
Returns overridden PaymentServiceInterface::updatePayment() result.
Return values
Tags
getUpdateStruct() ¶
Returns the data used to update payment.
|
|
Return values
hasPaymentResult() ¶
Returns whether the {@see \Ibexa\Contracts\Payment\PaymentServiceInterface::updatePayment()} result has been overridden.
|
|
Return values
bool
isPropagationStopped() ¶
|
|
Return values
bool
setPaymentResult() ¶
Overrides payment.
|
|
Overrides PaymentServiceInterface::updatePayment() execution result.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$paymentResult | PaymentInterface|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().