1 | <?php |
||
24 | abstract class BasePaymentClient extends BaseClient implements PaymentClientInterface |
||
25 | { |
||
26 | |||
27 | /** |
||
28 | * @inheritdoc |
||
29 | * @throws NotSupportedException |
||
30 | */ |
||
31 | 24 | public function signature(string $data, string $type = null): string |
|
32 | { |
||
33 | 24 | if ($dataSignature = $this->initDataSignature($data, $type)) { |
|
34 | 24 | return $dataSignature->generate(); |
|
35 | } else { |
||
36 | throw new NotSupportedException("Signature data with type: `$type` is not supported!"); |
||
37 | } |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @inheritdoc |
||
42 | * @throws NotSupportedException |
||
43 | */ |
||
44 | 10 | public function validateSignature(string $data, string $expectSignature, string $type = null): bool |
|
45 | { |
||
46 | 10 | if ($dataSignature = $this->initDataSignature($data, $type)) { |
|
47 | 10 | return $dataSignature->validate($expectSignature); |
|
48 | } else { |
||
49 | throw new NotSupportedException("Validate signature with type: `$type` is not supported!"); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Phương thức hổ trợ khởi tạo đối tượng [[DataSignature]] dùng cho việc tạo chữ ký dữ liệu và kiểm tra |
||
55 | * tính hợp lệ của chữ ký dữ liệu. |
||
56 | * |
||
57 | * @param string $data Dữ liệu muốn tạo hoặc kiểm tra tính hợp lệ. |
||
58 | * @param string|null $type Loại chữ ký muốn tạo hoặc sử dụng để kiếm trả tính hợp lệ. Nếu không thiết lập |
||
59 | * có nghĩa là sử dụng loại chữ ký mặc định của cổng thanh toán. |
||
60 | * @return null|DataSignature Trả về NULL nếu như loại chữ ký không được hổ trợ và ngược lại là đối tượng [[DataSignature]]. |
||
61 | */ |
||
62 | abstract protected function initDataSignature(string $data, string $type = null): ?DataSignature; |
||
63 | |||
64 | |||
65 | } |
||
66 |