Copied!

CreatePaymentEvent

CreatePaymentEvent.php : 51
Extends AfterEvent

Event dispatched after a payment is created.

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

The following example logs the creation of the payment:

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

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

    public function onCreatePayment(CreatePaymentEvent $event): void
    {
        $payment = $event->getPaymentResult();

        $this->logger->info(
            'Payment {name} has been created',
            [
                'name' => $payment->getName(),
            ]
        );
    }
 }
Tags
See
PaymentServiceInterface::createPayment()

Methods

public__construct()

CreatePaymentEvent.php : 57
public __construct(PaymentCreateStruct $createStruct, PaymentInterface $paymentResult)

Parameters

Name Type Default value Description
$createStruct PaymentCreateStruct - -
$paymentResult PaymentInterface - -

publicgetCreateStruct()

CreatePaymentEvent.php : 66

Returns create struct used to create payment.

public getCreateStruct() : PaymentCreateStruct

Return values

PaymentCreateStruct

publicgetPaymentResult()

CreatePaymentEvent.php : 74

Returns the payment that has been created.

public getPaymentResult() : PaymentInterface

Return values

PaymentInterface