Event that is dispatched before a payment is created.
Typical use case is to attach additional context data to payment.
The following example adds channel context to the payment create struct:
namespace App\EventSubscriber;
use Ibexa\Contracts\Core\Collection\ArrayMap;
use Ibexa\Contracts\Payment\Payment\Event\BeforeCreatePaymentEvent;
use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessServiceInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
final class PaymentEventSubscriber implements EventSubscriberInterface
{
public function __construct(private SiteAccessServiceInterface $siteAccessService)
{
}
public static function getSubscribedEvents(): array
{
return [
BeforeCreatePaymentEvent::class => 'onBeforeCreatePayment',
];
}
public function onBeforeCreatePayment(BeforeCreatePaymentEvent $event): void
{
$context = [
'channel' => $this->siteAccessService->getCurrent()?->name,
];
$createStruct = $event->getCreateStruct();
$createStruct->setContext(new ArrayMap($context));
}
}
Tags
Methods¶
__construct() ¶
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$createStruct | PaymentCreateStruct | - | - |
$paymentResult | PaymentInterface|null | null | - |
getCreateStruct() ¶
Returns the original payment create struct passed to {@see \Ibexa\Contracts\Payment\PaymentServiceInterface::createPayment()} method.
|
|
Return values
getPaymentResult() ¶
Returns overridden {@see \Ibexa\Contracts\Payment\PaymentServiceInterface::createPayment()} result.
|
|
Return values
Tags
hasPaymentResult() ¶
Returns whether the {@see \Ibexa\Contracts\Payment\PaymentServiceInterface::createPayment()} result has been overridden.
|
|
Return values
bool
isPropagationStopped() ¶
|
|
Return values
bool
setPaymentResult() ¶
Sets the payment result that will be returned by {@see \Ibexa\Contracts\Payment\PaymentServiceInterface::createPayment()}.
|
|
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().