accesto / PayumPayU

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

Is it possible to make a recurrent payment without user interaction? #24

Open OleksiiBulba opened 1 year ago

OleksiiBulba commented 1 year ago

From the documentation I see that I can run a recurrent payment completely without a user interaction:

Making payments without user interaction
Prepare payment

        $storage = $this->get('payum')
            ->getStorage('Acme\PaymentBundle\Entity\Payment');

        $payment = $storage->create();

        $payment->setCurrencyCode('PLN');
        $payment->setTotalAmount($order->getPrice() * 100);
        $payment->setDescription($order->getDescription());
        $payment->setClientId(md5($order->getClientId()));
        $payment->setClientEmail($order->getClientEmail());

        $details = array(
            'firstName' => $order->getClientFirstName(),
            'lastName' => $order->getClientLastName(),
        );

        $details['recurring'] = OpenPayUWrapper::RECURRING_STANDARD;

        $payment->setCreditCard($cardDetails); // this is optional
                                                // when set and masked credit card number is not null it will be used for filtering all stored credit cards
                                                // of this user and use this specific one
                                                // specialy useful when user pays for different subscriptions using differen cards
        $payment->setDetails($details);

        $storage->update($payment);
        $captureToken = $this->get('payum')->getTokenFactory()
                ->createCaptureToken(
                    $paymentName,
                    $payment,
                    'acme_payment_done' // the route to redirect after capture;
                );
        $this->get('payum')->getGateway($token->getGatewayName())
                ->execute(new Capture($token));

But when we call createCaptureToken we pass the route where "user" should be redirected after capture. In fact, there are no user to redirect as the capture is done by the cron job. Moreover, Payum throws an HttpRedirect exception which means that we should redirect a user that is "paying".

Is there any way to avoid redirection and complete recurrent payment without a user?

mkurzeja commented 1 year ago

Hi @OleksiiBulba

As you probably noticed, we do not really maintain this code anymore. I will add a badge soon.

None of our current projects is using PayU, and we have no way to test this bundle in practice. As far as we know the regulations for recurring payments changed, and the code might require some adjustments.

If you figured out how to resolve it, please share the solution here.