PayumBundle icon indicating copy to clipboard operation
PayumBundle copied to clipboard

Correct way to fire event when payment has been processed

Open grekpg opened this issue 6 years ago • 2 comments

I'm looking simple and correct way to run my process when payment is finish - captured, cancelled. I think it's a typical requirement.

I don't want to do this in done page - it in my payment method is pending and its user fired. I want when payment gate sends payment finish - background way.

But this is not easy in this bundle.

Events is not fired - so 1 . Add Symfony Events

payum.extension.event_dispatcher:
  class: Payum\Core\Bridge\Symfony\Extension\EventDispatcherExtension
  arguments: ["@event_dispatcher"]
  public: true
  tags:
    - { name: payum.extension, all: true, prepend: true }

documentation has an error - when prepend is true it works when false - here is error https://github.com/Payum/Payum/issues/821

  1. I cannot found the correct event name - we have only 3 events
    const GATEWAY_PRE_EXECUTE = 'payum.gateway.pre_execute';

    const GATEWAY_EXECUTE = 'payum.gateway.execute';

    const GATEWAY_POST_EXECUTE = 'payum.gateway.post_execute';

I add listener PayumEvents::GATEWAY_POST_EXECUTE

I see that almost every operation in this bundle executes some action so before user finish payment my event is fired many times.

in ExecuteEvent I don't know what is happen - i get_class $event->getContext()->getRequest() and have 7 times event fired

 Payum\Core\Request\GetHttpRequest
Payum\Paypal\ExpressCheckout\Nvp\Request\Api\SetExpressCheckout
 Payum\Paypal\ExpressCheckout\Nvp\Request\Api\GetExpressCheckoutDetails
 Payum\Core\Request\Sync
Payum\Paypal\ExpressCheckout\Nvp\Request\Api\AuthorizeToken
Payum\Core\Request\Capture
Payum\Core\Request\Capture

im just moved to paypal website....

ok i make payment - get next 10 times listener fired ?

Payum\Core\Request\GetHttpRequest
Payum\Paypal\ExpressCheckout\Nvp\Request\Api\GetExpressCheckoutDetails
 Payum\Core\Request\Sync
 Payum\Paypal\ExpressCheckout\Nvp\Request\Api\DoExpressCheckoutPayment
Payum\Paypal\ExpressCheckout\Nvp\Request\Api\GetExpressCheckoutDetails
Payum\Paypal\ExpressCheckout\Nvp\Request\Api\GetTransactionDetails
Payum\Core\Request\Sync
 Payum\Core\Request\Capture
 Payum\Core\Request\Capture
Payum\Paypal\ExpressCheckout\Nvp\Request\Api\GetExpressCheckoutDetails

uggh...

please help me - in how I can make a decision when i really get paymentDetails status change.

I just need to fire my process when user paid or cancel payment ...

Maybe it should by new event - PayumEvents::PAYMENT_DONE ? (succeeded or not but we have response )

grekpg avatar Nov 01 '19 12:11 grekpg

What about using Symfony workflow component for payment status field?

Any status change will fire workflow event on which you can listen.

jkabat avatar Nov 04 '19 12:11 jkabat

Use post execute event to get current status as writen here https://github.com/Payum/Payum/blob/master/docs/instant-payment-notification.md and then use symfony workflow to switch status of your payment.

All you need then is to listen to workflow transition into place captured.

Tetragramat avatar Nov 28 '19 17:11 Tetragramat