|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link https://github.com/yiiviet/yii2-payment |
|
4
|
|
|
* @copyright Copyright (c) 2017 Yii Viet |
|
5
|
|
|
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php) |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace yiiviet\payment; |
|
10
|
|
|
|
|
11
|
|
|
use Yii; |
|
12
|
|
|
|
|
13
|
|
|
use GatewayClients\DataInterface; |
|
14
|
|
|
|
|
15
|
|
|
use yii\base\ActionFilter; |
|
16
|
|
|
use yii\di\Instance; |
|
17
|
|
|
use yii\web\ForbiddenHttpException; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Lớp VerifyFilter dùng để xác thực tính hợp lệ của dữ liệu đầu vào. |
|
21
|
|
|
* |
|
22
|
|
|
* @property DataInterface $verifiedData Đối tượng chứa các thuộc tính dữ liệu đã được xác minh tính hợp lệ. |
|
23
|
|
|
* |
|
24
|
|
|
* @author Vuong Minh <[email protected]> |
|
25
|
|
|
* @since 1.0.2 |
|
26
|
|
|
*/ |
|
27
|
|
|
class VerifyFilter extends ActionFilter |
|
28
|
|
|
{ |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var \yiiviet\payment\PaymentGatewayInterface Đối tượng cổng thanh toán dùng để xác thực tính hợp lệ của dữ liệu đầu vào. |
|
32
|
|
|
*/ |
|
33
|
|
|
public $gateway; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string Lệnh muốn thực thi xác thực tính hợp lệ của dữ liệu đầu vào. |
|
37
|
|
|
*/ |
|
38
|
|
|
public $command; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var \yii\web\Request Đối tượng request dùng để lấy các dữ liệu đầu vào, nếu không thiết lập mặc định sẽ lấy `request` component trong `app`. |
|
42
|
|
|
*/ |
|
43
|
|
|
public $request = 'request'; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @inheritdoc |
|
47
|
|
|
* @throws \yii\base\InvalidConfigException |
|
48
|
|
|
*/ |
|
49
|
|
|
public function init() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->request = Instance::ensure($this->request, 'yii\web\Request'); |
|
52
|
|
|
|
|
53
|
|
|
parent::init(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @inheritdoc |
|
58
|
|
|
* @throws ForbiddenHttpException |
|
59
|
|
|
*/ |
|
60
|
|
|
public function beforeAction($action) |
|
61
|
|
|
{ |
|
62
|
|
|
if (($verifiedData = $this->gateway->verifyRequest($this->command, $this->request)) instanceof DataInterface) { |
|
63
|
|
|
$this->_verifiedData = $verifiedData; |
|
64
|
|
|
|
|
65
|
|
|
return true; |
|
66
|
|
|
} else { |
|
67
|
|
|
throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.')); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @var DataInterface Đối tượng tập hợp các thuộc tính dữ liệu đã xác thực. |
|
74
|
|
|
* @see [[getVerifiedData()]] |
|
75
|
|
|
*/ |
|
76
|
|
|
private $_verifiedData; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Phương thức hổ trợ lấy dữ liệu đã xác thực tính hợp lệ. |
|
80
|
|
|
* |
|
81
|
|
|
* @return null|DataInterface Đối tượng chứa các thuộc tính dữ liệu đã xác thực. |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getVerifiedData(): ?DataInterface |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->_verifiedData; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|