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\momo; |
9
|
|
|
|
10
|
|
|
use Yii; |
11
|
|
|
|
12
|
|
|
use yii\base\InvalidConfigException; |
13
|
|
|
|
14
|
|
|
use yiiviet\payment\BasePaymentClient; |
15
|
|
|
use yiiviet\payment\DataSignature; |
16
|
|
|
use yiiviet\payment\HmacDataSignature; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Lớp PaymentClient chứa các thuộc tính dùng để hổ trợ [[PaymentGateway]] kết nối đến MOMO. |
20
|
|
|
* |
21
|
|
|
* @method PaymentGateway getGateway() |
22
|
|
|
* @property PaymentGateway $gateway |
23
|
|
|
* |
24
|
|
|
* @author Vuong Minh <[email protected]> |
25
|
|
|
* @since 1.0 |
26
|
|
|
*/ |
27
|
|
|
class PaymentClient extends BasePaymentClient |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Thuộc tính dùng để khai báo kết nối đến MOMO khi tạo [[request()]] ở [[PaymentGateway]]. |
31
|
|
|
* Nó do MOMO cấp khi đăng ký tích hợp website. |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
public $partnerCode; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Thuộc tính dùng để khai báo kết nối đến MOMO khi tạo [[request()]] ở [[PaymentGateway]]. |
39
|
|
|
* Nó do MOMO cấp khi đăng ký tích hợp website. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
public $accessKey; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Thuộc tính được dùng để tạo chữ ký dữ liệu khi tạo [[request()]] ở [[PaymentGateway]]. |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
public $secretKey; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritdoc |
54
|
|
|
* @throws InvalidConfigException |
55
|
|
|
*/ |
56
|
|
|
public function init() |
57
|
|
|
{ |
58
|
|
|
if ($this->partnerCode === null) { |
59
|
|
|
throw new InvalidConfigException('Property `partnerCode` must be set!'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if ($this->accessKey === null) { |
63
|
|
|
throw new InvalidConfigException('Property `accessKey` must be set!'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if ($this->secretKey === null) { |
67
|
|
|
throw new InvalidConfigException('Property `secretKey` must be set!'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
parent::init(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @inheritdoc |
75
|
|
|
* @return DataSignature|null|object |
76
|
|
|
* @throws \yii\base\InvalidConfigException |
77
|
|
|
*/ |
78
|
|
|
protected function initDataSignature(string $data, string $type = null): ?DataSignature |
79
|
|
|
{ |
80
|
|
|
return Yii::createObject([ |
81
|
|
|
'class' => HmacDataSignature::class, |
82
|
|
|
'key' => $this->secretKey, |
83
|
|
|
'hmacAlgo' => 'sha256' |
84
|
|
|
]); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|