Copied!

CreatePaymentMethodEvent

CreatePaymentMethodEvent.php : 49
Extends AfterEvent

Event dispatched after payment method is created.

Typical use case is to perform additional operations after payment method creation (e.g. logging, cache purge, reindexing, etc.)

The following example log the creation of the payment method:

final class PaymentMethodEventSubscriber implements EventSubscriberInterface
{
    private function __construct(private LoggerInterface $logger)
    {
    }

    public static function getSubscribedEvents(): array
    {
       return [
           CreatePaymentMethodEvent::class => 'onCreatePaymentMethod',
       ];
    }

   public function onCreatePaymentMethod(CreatePaymentMethodEvent $event): void
   {
       $paymentMethod = $event->getPaymentMethodResult();

       $this->logger->info(
         'Payment method {name} has been created',
         [
             'name' => $paymentMethod->getName()
         ]
       );
   }
}

Methods

public__construct()

CreatePaymentMethodEvent.php : 55
public __construct(PaymentMethodCreateStruct $createStruct, PaymentMethodInterface $paymentMethodResult)

Parameters

Name Type Default value Description
$createStruct PaymentMethodCreateStruct - -
$paymentMethodResult PaymentMethodInterface - -

publicgetCreateStruct()

CreatePaymentMethodEvent.php : 64

Returns create struct used to create payment method.

public getCreateStruct() : PaymentMethodCreateStruct

Return values

PaymentMethodCreateStruct

publicgetPaymentMethodResult()

CreatePaymentMethodEvent.php : 72

Returns created payment method.

public getPaymentMethodResult() : PaymentMethodInterface

Return values

PaymentMethodInterface