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