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() ¶
BeforeCreatePaymentEvent.php
:
64
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$createStruct | PaymentCreateStruct | - | - |
$paymentResult | PaymentInterface|null | null | - |
getCreateStruct() ¶
BeforeCreatePaymentEvent.php
:
74
Returns the original payment create struct passed to {@see \Ibexa\Contracts\Payment\PaymentServiceInterface::createPayment()} method.
|
|
Return values
getPaymentResult() ¶
BeforeCreatePaymentEvent.php
:
84
Returns overridden {@see \Ibexa\Contracts\Payment\PaymentServiceInterface::createPayment()} result.
|
|
Return values
Tags
hasPaymentResult() ¶
BeforeCreatePaymentEvent.php
:
108
Returns whether the {@see \Ibexa\Contracts\Payment\PaymentServiceInterface::createPayment()} result has been overridden.
|
|
Return values
bool
setPaymentResult() ¶
BeforeCreatePaymentEvent.php
:
99
Sets the payment result that will be returned by {@see \Ibexa\Contracts\Payment\PaymentServiceInterface::createPayment()}.
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$paymentResult | PaymentInterface|null | - | - |