Event dispatched before payment method is created.
Typical use cases are to modify the payment method create struct before executing operation, or o completely override payment method creation logic. See the two examples below.
The following first example forces the struct to create an available payment method, then let the default payment method creation treats this struct:
final class PaymentMethodEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
BeforeCreatePaymentMethodEvent::class => 'onBeforeCreatePaymentMethod',
];
}
public function onBeforeCreatePaymentMethod(BeforeCreatePaymentMethodEvent $event): void
{
$createStruct = $event->getCreateStruct();
// Enable payment method by default
$createStruct->setEnabled(true);
}
}
The following second example sets its own payment method, and cancels the default payment method creation process:
final class PaymentMethodEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
BeforeCreatePaymentMethodEvent::class => 'onBeforeCreatePaymentMethod',
];
}
public function onBeforeCreatePaymentMethod(BeforeCreatePaymentMethodEvent $event): void
{
// ...
$event->setPaymentMethodResult($paymentMethod);
$event->stopPropagation();
}
}
Tags
Methods¶
__construct() ¶
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$createStruct | PaymentMethodCreateStruct | - | - |
$paymentMethodResult | PaymentMethodInterface|null | null | - |
getCreateStruct() ¶
Returns the original payment method create struct.
|
|
Returns the original payment method creation structure passed to PaymentMethodServiceInterface::createPaymentMethod() method.
Return values
getPaymentMethodResult() ¶
Returns overridden payment method.
|
|
Returns overridden PaymentMethodServiceInterface::createPaymentMethod() result.
Return values
Tags
hasPaymentMethodResult() ¶
Checks if payment method is overridden.
|
|
Returns whether the PaymentMethodServiceInterface::createPaymentMethod() result is overridden.
Return values
bool
setPaymentMethodResult() ¶
Overrides payment method.
|
|
Overrides PaymentMethodServiceInterface::createPaymentMethod() execution result.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$paymentMethodResult | PaymentMethodInterface|null | - | - |