forked from Payum/PayumYiiExtension
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PaymentController.php
70 lines (59 loc) · 2.26 KB
/
PaymentController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Payum\Yii2Extension;
use Yii;
use Payum\Core\Exception\LogicException;
use Payum\Core\Reply\HttpRedirect;
use Payum\Core\Reply\ReplyInterface;
use Payum\Core\Request\Authorize;
use Payum\Core\Request\Capture;
use Payum\Core\Request\Notify;
use Payum\Core\Request\Refund;
use Payum\Core\Reply\HttpResponse;
class PaymentController extends \yii\web\Controller
{
public function actionCapture()
{
/** @var \Payum\Core\Payum $payum */
$token = $this->getPayum()->getHttpRequestVerifier()->verify($_REQUEST);
$gateway = $this->getPayum()->getGateway($token->getGatewayName());
/** @var \Payum\Core\GatewayInterface $gateway */
if ($reply = $gateway->execute(new Capture($token), true)) {
if ($reply instanceof HttpRedirect) {
return $this->redirect($reply->getUrl());
}
throw new \LogicException('Unsupported reply', null, $reply);
}
/** @var \Payum\Core\Payum $payum */
$this->getPayum()->getHttpRequestVerifier()->invalidate($token);
$this->redirect($token->getAfterUrl());
}
public function actionAuthorize()
{
$token = $this->getPayum()->getHttpRequestVerifier()->verify($_REQUEST);
$gateway = $this->getPayum()->getGateway($token->getGatewayName());
$gateway->execute($capture = new Authorize($token));
$this->getPayum()->getHttpRequestVerifier()->invalidate($token);
$this->redirect($token->getAfterUrl());
}
public function actionNotify()
{
$token = $this->getPayum()->getHttpRequestVerifier()->verify($_REQUEST);
$gateway = $this->getPayum()->getGateway($token->getGatewayName());
$gateway->execute($capture = new Notify($token));
}
public function actionRefund()
{
$token = $this->getPayum()->getHttpRequestVerifier()->verify($_REQUEST);
$this->getPayum()->getHttpRequestVerifier()->invalidate($token);
$gateway = $this->getPayum()->getGateway($token->getGatewayName());
$gateway->execute($capture = new Refund($token));
$this->redirect($token->getAfterUrl());
}
/**
* @return \Payum\YiiExtension\PayumComponent
*/
protected function getPayum()
{
return \Yii::$app->payum;
}
}