Skip to content

Commit

Permalink
Merge pull request #13 from alexandernst/master
Browse files Browse the repository at this point in the history
Fix Payments handler not handling redirects
  • Loading branch information
makasim committed Jul 17, 2014
2 parents 8cd8533 + 16abb83 commit 5df4fdb
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions src/Payum/YiiExtension/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,59 @@
namespace Payum\YiiExtension;

use Payum\Core\Request\BinaryMaskStatusRequest;
use Payum\Core\Request\InteractiveRequestInterface;
use Payum\Core\Request\Http\RedirectUrlInteractiveRequest;
use Payum\Core\Request\SecuredCaptureRequest;
use Payum\Core\Exception\LogicException;

class PaymentController extends \CController
{
public function init()
{
parent::init();

\Yii::app()->attachEventHandler('onException', array($this, 'handleException'));
}

public function actionCapture()
{
$token = $this->getPayum()->getHttpRequestVerifier()->verify($_REQUEST);
$payment = $this->getPayum()->getRegistry()->getPayment($token->getPaymentName());

$payment->execute($status = new BinaryMaskStatusRequest($token));
$status = new BinaryMaskStatusRequest($token);
$payment->execute($status);

if ($interactiveRequest = $payment->execute(new SecuredCaptureRequest($token), true)) {
if ($interactiveRequest instanceof RedirectUrlInteractiveRequest) {
$this->redirect($interactiveRequest->getUrl(), true);
}

throw new \LogicException('Unsupported interactive request', null, $interactiveRequest);
}
$capture = new SecuredCaptureRequest($token);
$payment->execute($capture);

$this->getPayum()->getHttpRequestVerifier()->invalidate($token);

$this->redirect($token->getAfterUrl());
}

public function handleException(\CExceptionEvent $event)
{
if (false == $event->exception instanceof InteractiveRequestInterface) {
return;
}

$interactiveRequest = $event->exception;

if ($interactiveRequest instanceof RedirectUrlInteractiveRequest) {
$this->redirect($interactiveRequest->getUrl(), true);
$event->handled = true;
return;
}

$ro = new \ReflectionObject($interactiveRequest);

$event->exception = new LogicException(
sprintf('Cannot convert interactive request %s to Yii response.', $ro->getShortName()),
null,
$interactiveRequest
);
}

/**
* @return \Payum\YiiExtension\PayumComponent
*/
Expand Down

0 comments on commit 5df4fdb

Please sign in to comment.