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
|
|
|
namespace yiiviet\payment\vnpayment; |
9
|
|
|
|
10
|
|
|
use Yii; |
11
|
|
|
|
12
|
|
|
use yii\base\InvalidConfigException; |
13
|
|
|
|
14
|
|
|
use yiiviet\payment\BasePaymentClient; |
15
|
|
|
use yiiviet\payment\HashDataSignature; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Lớp PaymentClient hổ trợ tạo và kiểm tra chữ ký dữ liệu và có các thuộc tính kết nối đến cổng thanh toán VnPayment |
19
|
|
|
* |
20
|
|
|
* @method PaymentGateway getGateway() |
21
|
|
|
* |
22
|
|
|
* @property PaymentGateway $gateway |
23
|
|
|
* |
24
|
|
|
* @author Vuong Minh <[email protected]> |
25
|
|
|
* @since 1.0 |
26
|
|
|
*/ |
27
|
|
|
class PaymentClient extends BasePaymentClient |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string Mã TMN được dùng để gửi lên VnPayment xác định là yêu cầu từ bạn. |
32
|
|
|
* Nó thường được dùng khi gọi [[request()]] ở [[PaymentGateway]]. |
33
|
|
|
* Nó do VnPayment cấp khi thực hiện tích hợp website của bạn. |
34
|
|
|
*/ |
35
|
|
|
public $tmnCode; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string Thuộc tính dùng để tạo và kiểm tra chữ ký dữ liệu. |
39
|
|
|
* Nó do VnPayment cấp khi thực hiện tích hợp website của bạn. |
40
|
|
|
*/ |
41
|
|
|
public $hashSecret; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var int Mã loại hàng mặc định của website bạn bán. |
45
|
|
|
*/ |
46
|
|
|
public $defaultOrderType; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @inheritdoc |
50
|
|
|
* @throws InvalidConfigException |
51
|
|
|
* @since 1.0.3 |
52
|
|
|
*/ |
53
|
7 |
|
public function init() |
54
|
|
|
{ |
55
|
7 |
|
if ($this->tmnCode === null) { |
56
|
|
|
throw new InvalidConfigException('Property `tmnCode` must be set!'); |
57
|
|
|
} |
58
|
|
|
|
59
|
7 |
|
if ($this->hashSecret === null) { |
60
|
|
|
throw new InvalidConfigException('Property `hashSecret` must be set!'); |
61
|
|
|
} |
62
|
|
|
|
63
|
7 |
|
parent::init(); |
64
|
7 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @inheritdoc |
68
|
|
|
* @throws \yii\base\InvalidConfigException |
69
|
|
|
*/ |
70
|
3 |
|
protected function initDataSignature(string $data, string $type = null): ?\yiiviet\payment\DataSignature |
71
|
|
|
{ |
72
|
3 |
|
$data = $this->hashSecret . $data; |
73
|
|
|
|
74
|
3 |
|
return Yii::createObject([ |
75
|
3 |
|
'class' => HashDataSignature::class, |
76
|
3 |
|
'hashAlgo' => $type, |
77
|
3 |
|
], [$data]); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|