accesto / PayumPayU

Payum component for OpenPayU integration (PayU payments)
10 stars 15 forks source link

Capture action when customer leave PayU after success payment #6

Open wujku opened 8 years ago

wujku commented 8 years ago

How to handle case when customer paid and leave PayU, not going back to the application? I try handle this by event "payum.gateway.post_execute", but notify event with status "completed" no give my payment model (return ArrayObject with details). Do you have the right way to resolve this?

mkurzeja commented 8 years ago

State changes are handled by notification url (notification is sent in background by PayU), not by the return url itself. I will try to find and upload some code examples from our projects.

wujku commented 8 years ago

I'm looking forward to your answer

mkurzeja commented 8 years ago

@wujku I'm not 100% sure but as far as I remember this gateway handles payment notifications. https://github.com/accesto/PayumPayU/blob/master/Action/NotifyAction.php handles the status change, and the post_execute event is triggered.

Just to make sure: are you testing this using a publicly accessible domain/url? Because this won't work for localhost, as PayU can't connect to your host.

wujku commented 8 years ago

@mkurzeja Yes, I used ngrok tunnel for tests. I saw PayU POST requests to notifyAction (with status PENDING and COMPLETED) and I catch post_execute events (by class which I paste below). But only CaptureAction (after user back from shop to application) give me a correct model (e.g. Acme\PaymentBundle\Entity\Payment). NotifyAction for $request->getFirstModel() returns ArrayObject with order details (includes 'completed' status). I would like to modify related object with Acme\PaymentBundle\Entity\Payment after payment is completed.

<?php

namespace Acme\PaymentBundle\Event\Listener\UpdatePaymentStatus

use Payum\Core\Bridge\Symfony\Event\ExecuteEvent;
use Payum\Core\Request\Generic;
use Payum\Core\Request\GetStatusInterface;
use Acme\PaymentBundle\Entity\Payment;

class UpdatePaymentStatus
{
    public function updateStatus(ExecuteEvent $event)
    {
        $request = $event->getContext()->getRequest();

        if ($request instanceof GetStatusInterface && $request instanceof Generic) {
            $payment = $request->getFirstModel();
            if ($request->isCaptured() && $payment instanceof Payment) {
                // payment is completed and succeeded
                // do whatever you want
            }
        }
    }
}
mkurzeja commented 8 years ago

@wujku did you succeed with this issue? If the notify url is executed by PayU then this should work. We would probably need to have the whole codebase of your project and go step by step with xdebug through it so probably it would be better if you could check where it stops.

Basically you need at least to have a breakpoint inside the notify action (action in controller, not Payum action) + inside our NotifyAction from this component + inside your listeners.

mkurzeja commented 7 years ago

Short update: we managed to reproduce this issue on one of our projects and are working on a fix.

wujku commented 7 years ago

I have contact with PayU support at November, regarding issues with sandbox (very long wait for complete response etc.) and they turned it off. I did not check if they activated it back. @mkurzeja problem with notifyAction still exists.

cve commented 6 years ago

I have the same problem

mkurzeja commented 6 years ago

@cve thanks bringing up this topic. We will take a deeper look at it early next month

mkurzeja commented 6 years ago

@cve could you please try it again with current master?

cve commented 6 years ago

@mkurzeja ok, I will try it with next few days and report the results, thanks