Skip to content

Commit 5df4fdb

Browse files
committed
Merge pull request #13 from alexandernst/master
Fix Payments handler not handling redirects
2 parents 8cd8533 + 16abb83 commit 5df4fdb

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

src/Payum/YiiExtension/PaymentController.php

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,59 @@
22
namespace Payum\YiiExtension;
33

44
use Payum\Core\Request\BinaryMaskStatusRequest;
5+
use Payum\Core\Request\InteractiveRequestInterface;
56
use Payum\Core\Request\Http\RedirectUrlInteractiveRequest;
67
use Payum\Core\Request\SecuredCaptureRequest;
8+
use Payum\Core\Exception\LogicException;
79

810
class PaymentController extends \CController
911
{
12+
public function init()
13+
{
14+
parent::init();
15+
16+
\Yii::app()->attachEventHandler('onException', array($this, 'handleException'));
17+
}
18+
1019
public function actionCapture()
1120
{
1221
$token = $this->getPayum()->getHttpRequestVerifier()->verify($_REQUEST);
1322
$payment = $this->getPayum()->getRegistry()->getPayment($token->getPaymentName());
1423

15-
$payment->execute($status = new BinaryMaskStatusRequest($token));
24+
$status = new BinaryMaskStatusRequest($token);
25+
$payment->execute($status);
1626

17-
if ($interactiveRequest = $payment->execute(new SecuredCaptureRequest($token), true)) {
18-
if ($interactiveRequest instanceof RedirectUrlInteractiveRequest) {
19-
$this->redirect($interactiveRequest->getUrl(), true);
20-
}
21-
22-
throw new \LogicException('Unsupported interactive request', null, $interactiveRequest);
23-
}
27+
$capture = new SecuredCaptureRequest($token);
28+
$payment->execute($capture);
2429

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

2732
$this->redirect($token->getAfterUrl());
2833
}
2934

35+
public function handleException(\CExceptionEvent $event)
36+
{
37+
if (false == $event->exception instanceof InteractiveRequestInterface) {
38+
return;
39+
}
40+
41+
$interactiveRequest = $event->exception;
42+
43+
if ($interactiveRequest instanceof RedirectUrlInteractiveRequest) {
44+
$this->redirect($interactiveRequest->getUrl(), true);
45+
$event->handled = true;
46+
return;
47+
}
48+
49+
$ro = new \ReflectionObject($interactiveRequest);
50+
51+
$event->exception = new LogicException(
52+
sprintf('Cannot convert interactive request %s to Yii response.', $ro->getShortName()),
53+
null,
54+
$interactiveRequest
55+
);
56+
}
57+
3058
/**
3159
* @return \Payum\YiiExtension\PayumComponent
3260
*/

0 commit comments

Comments
 (0)