Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event sylius.payment.post_complete not triggered after a Paypal Express Checkout payment #8109

Closed
Adraesh opened this issue May 26, 2017 · 3 comments
Labels
Documentation Documentation related issues and PRs - requests, fixes, proposals. Stale Issues and PRs with no recent activity, about to be closed soon.

Comments

@Adraesh
Copy link
Contributor

Adraesh commented May 26, 2017

I don't know if it's an issue but I noticed that the event sylius.payment.post_complete was never triggered after I performed a Paypal Express Checkout payment (through sandbox), so basically, the Order "paymentState" was never "paid".

I managed to force and dispatch the sylius.payment.post_complete event by creating a listener on the event kernel.response and by targeting the desired controller's action as bellow:

app.payum.after_capture:
        class: AppBundle\EventListener\PayumAfterCaptureListener
        arguments: ["@sylius.repository.order", "@event_dispatcher"]
        tags:
            - { name: kernel.event_listener, event: kernel.response, method: onKernelResponse }
<?php

namespace AppBundle\EventListener;

use Sylius\Bundle\CoreBundle\Doctrine\ORM\OrderRepository;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;

class PayumAfterCaptureListener
{
	private $orderRepository;
	private $eventDispatcher;

	public function __construct(OrderRepository $orderRepository, EventDispatcherInterface $eventDispatcher)
	{
		$this->orderRepository = $orderRepository;
		$this->eventDispatcher = $eventDispatcher;
	}

	public function onKernelResponse(FilterResponseEvent $event)
    {
    	$request = $event->getRequest();
    	if ($request->attributes->get('_controller') === 'sylius.controller.payum:afterCaptureAction')
    	{
    		if ($request->getSession()->getFlashBag()->has('info'))
    		{
    			$message = $request->getSession()->getFlashBag()->get('info')[0];
    			if ($message === 'sylius.payment.completed')
    			{
    				$order = $this->orderRepository->find($request->getSession()->get('sylius_order_id'));
    				if ($order)
    				{
    					$payment = $order->getPayments()->first();
    					if ($payment)
    					{
	    					$event = new ResourceControllerEvent($payment);
	    					$this->eventDispatcher->dispatch('sylius.payment.post_complete', $event);
	    				}
    				}

    				$request->getSession()->getBag('flashes')->add('info', $message);
    			}
    		}
    	}
    }
}

I assume it's not the most beautiful thing, but it's working.

@pjedrzejewski pjedrzejewski added Documentation Documentation related issues and PRs - requests, fixes, proposals. and removed Potential Bug labels May 29, 2017
@pjedrzejewski
Copy link
Member

@Adraesh This event is a ResourceController event, which should be only used for manipulating the interaction of user with the UI/API. If you want to customize the business logic, you should use StateMachine - http://docs.sylius.org/en/latest/customization/state_machine.html. This guarantees you that it will be fired everytime payment is completed - no matter which gateway you use.

@Adraesh
Copy link
Contributor Author

Adraesh commented May 31, 2017

@pjedrzejewski Hi!

I don't know if I understand clearly what you are saying (my bad), but when you are saying "which should be only used for manipulating the interaction of user with the UI/API" this is exactly my case:

  • The User through the Front finish the Cart/Order/Payment flow, click on Pay being redirected to PayPal, pay and come back to the shop => If I am not using the kernel.response event related to sylius.controller.payum:afterCaptureAction action and dispatch manually the sylius.payment.post_complete event, the PaymentPostCompleteEvent is never triggered.

Do you think that it is normal that the PaymentPostCompleteEvent is not triggered by default after a PayPal payment ?

@stale
Copy link

stale bot commented Dec 4, 2017

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Issues and PRs with no recent activity, about to be closed soon. label Dec 4, 2017
@stale stale bot closed this as completed Dec 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Documentation related issues and PRs - requests, fixes, proposals. Stale Issues and PRs with no recent activity, about to be closed soon.
Projects
None yet
Development

No branches or pull requests

3 participants