|
8 | 8 |
|
9 | 9 | class CompletePurchaseRequest extends AbstractRequest |
10 | 10 | { |
11 | | - use HasAmount; |
12 | | - use HasCommon; |
13 | | - |
14 | | - public function getStatus() |
15 | | - { |
16 | | - return $this->getParameter('status'); |
17 | | - } |
18 | | - |
19 | | - public function setStatus($value) |
20 | | - { |
21 | | - return $this->setParameter('status', $value); |
22 | | - } |
23 | | - |
24 | | - public function getResult() |
25 | | - { |
26 | | - return $this->getParameter('result'); |
27 | | - } |
28 | | - |
29 | | - public function setResult($value) |
30 | | - { |
31 | | - return $this->setParameter('result', $value); |
32 | | - } |
33 | | - |
34 | | - public function getOrderdate() |
35 | | - { |
36 | | - return $this->getParameter('orderdate'); |
37 | | - } |
38 | | - |
39 | | - public function setOrderdate($value) |
40 | | - { |
41 | | - return $this->setParameter('orderdate', $value); |
42 | | - } |
43 | | - |
44 | | - public function getAuthcode() |
45 | | - { |
46 | | - return $this->getParameter('authcode'); |
47 | | - } |
48 | | - |
49 | | - public function setAuthcode($value) |
50 | | - { |
51 | | - return $this->setParameter('authcode', $value); |
52 | | - } |
53 | | - |
54 | | - public function getBankcard() |
55 | | - { |
56 | | - return $this->getParameter('bankcoard'); |
57 | | - } |
58 | | - |
59 | | - public function setBankcard($value) |
60 | | - { |
61 | | - return $this->setParameter('bankcoard', $value); |
62 | | - } |
63 | | - |
64 | | - public function getPeriods() |
65 | | - { |
66 | | - return $this->getParameter('periods'); |
67 | | - } |
68 | | - |
69 | | - public function setPeriods($value) |
70 | | - { |
71 | | - return $this->setParameter('periods', $value); |
72 | | - } |
73 | | - |
74 | 11 | public function getData() |
75 | 12 | { |
76 | | - return [ |
77 | | - 'orgno' => $this->getOrgNo(), |
78 | | - 'secondtimestamp' => $this->getSecondTimestamp(), |
79 | | - 'nonce_str' => $this->getNonceStr(), |
80 | | - 'sign' => $this->getSign(), |
81 | | - 'out_trade_no' => $this->getTransactionId(), |
82 | | - 'status' => $this->getStatus(), |
83 | | - 'result' => $this->getResult(), |
84 | | - 'total_fee' => $this->getAmount(), |
85 | | - 'orderdate' => $this->getOrderdate(), |
86 | | - 'authcode' => $this->getAuthcode(), |
87 | | - 'bankcard' => $this->getBankcard(), |
88 | | - 'periods' => $this->getPeriods(), |
89 | | - ]; |
| 13 | + return $this->httpRequest->request->all(); |
90 | 14 | } |
91 | 15 |
|
92 | 16 | /** |
93 | 17 | * @throws InvalidRequestException |
94 | 18 | */ |
95 | 19 | public function sendData($data) |
96 | 20 | { |
97 | | - if ($data['sign'] !== $this->makeHash($data)) { |
| 21 | + if (! hash_equals($this->httpRequest->request->get('sign', ''), $this->makeHash($data))) { |
98 | 22 | throw new InvalidRequestException('Incorrect hash'); |
99 | 23 | } |
100 | 24 |
|
101 | 25 | return $this->response = new CompletePurchaseResponse($this, $data); |
102 | 26 | } |
| 27 | + |
| 28 | + protected function makeHash(array $data) |
| 29 | + { |
| 30 | + $temp = []; |
| 31 | + $keys = [ |
| 32 | + 'authcode', 'bankcard', 'nonce_str', 'orderdate', 'orgno', 'out_trade_no', 'result', 'status', |
| 33 | + 'secondtimestamp', 'total_fee', |
| 34 | + ]; |
| 35 | + |
| 36 | + foreach ($keys as $key) { |
| 37 | + $temp[$key] = $data[$key]; |
| 38 | + } |
| 39 | + |
| 40 | + return parent::makeHash($temp); |
| 41 | + } |
103 | 42 | } |
0 commit comments