|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yansongda\Pay\Config; |
|
6
|
|
|
|
|
7
|
|
|
use Yansongda\Pay\Pay; |
|
8
|
|
|
|
|
9
|
|
|
class UnipayConfig implements ConfigInterface |
|
10
|
|
|
{ |
|
11
|
|
|
public function __construct( |
|
12
|
|
|
public string $mch_id, |
|
13
|
|
|
public string $mch_cert_path, |
|
14
|
|
|
public string $mch_cert_password, |
|
15
|
|
|
public string $unipay_public_cert_path, |
|
16
|
|
|
public string $return_url, |
|
17
|
|
|
public string $notify_url, |
|
18
|
|
|
public string $mch_secret_key = '', |
|
19
|
|
|
public int $mode = Pay::MODE_NORMAL, |
|
20
|
|
|
) { |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function toArray(): array |
|
24
|
|
|
{ |
|
25
|
|
|
return [ |
|
26
|
|
|
'mch_id' => $this->mch_id, |
|
27
|
|
|
'mch_secret_key' => $this->mch_secret_key, |
|
28
|
|
|
'mch_cert_path' => $this->mch_cert_path, |
|
29
|
|
|
'mch_cert_password' => $this->mch_cert_password, |
|
30
|
|
|
'unipay_public_cert_path' => $this->unipay_public_cert_path, |
|
31
|
|
|
'return_url' => $this->return_url, |
|
32
|
|
|
'notify_url' => $this->notify_url, |
|
33
|
|
|
'mode' => $this->mode, |
|
34
|
|
|
]; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public static function fromArray(array $config): self |
|
38
|
|
|
{ |
|
39
|
|
|
return new self( |
|
40
|
|
|
mch_id: $config['mch_id'] ?? '', |
|
41
|
|
|
mch_cert_path: $config['mch_cert_path'] ?? '', |
|
42
|
|
|
mch_cert_password: $config['mch_cert_password'] ?? '', |
|
43
|
|
|
unipay_public_cert_path: $config['unipay_public_cert_path'] ?? '', |
|
44
|
|
|
return_url: $config['return_url'] ?? '', |
|
45
|
|
|
notify_url: $config['notify_url'] ?? '', |
|
46
|
|
|
mch_secret_key: $config['mch_secret_key'] ?? '', |
|
47
|
|
|
mode: $config['mode'] ?? Pay::MODE_NORMAL, |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|