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()
            ¶
__construct()
            ¶
    
        |  |  | 
Parameters
| Name | Type | Default value | Description | 
|---|---|---|---|
| $createStruct | PaymentCreateStruct | - | - | 
| $paymentResult | PaymentInterface|null | null | - | 
                 getCreateStruct()
            ¶
getCreateStruct()
            ¶
    
        Returns the original payment create struct.
|  |  | 
Returns the original payment create struct passed to PaymentServiceInterface::createPayment() method.
Return values
                 getPaymentResult()
            ¶
getPaymentResult()
            ¶
    
        Returns overridden payment result.
|  |  | 
Returns overridden PaymentServiceInterface::createPayment() result.
Return values
Tags
                 hasPaymentResult()
            ¶
hasPaymentResult()
            ¶
    
        Returns if payment result is an override.
|  |  | 
Returns whether the PaymentServiceInterface::createPayment() result has been overridden.
Return values
bool
                 isPropagationStopped()
            ¶
isPropagationStopped()
            ¶
    
        |  |  | 
Return values
bool
                 setPaymentResult()
            ¶
setPaymentResult()
            ¶
    
        Sets the payment result.
|  |  | 
Sets the payment result that will be returned by PaymentServiceInterface::createPayment().
Parameters
| Name | Type | Default value | Description | 
|---|---|---|---|
| $paymentResult | PaymentInterface|null | - | - | 
                 stopPropagation()
            ¶
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().