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