1 | <?php |
||
8 | class Api |
||
9 | { |
||
10 | /** |
||
11 | * @var \Payum\Core\HttpClientInterface |
||
12 | */ |
||
13 | protected $client; |
||
14 | |||
15 | /** |
||
16 | * @var \Http\Message\MessageFactory |
||
17 | */ |
||
18 | protected $messageFactory; |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $options = []; |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $heads = [ |
||
29 | 'Version', |
||
30 | 'MerCode', |
||
31 | 'MerName', |
||
32 | 'Account', |
||
33 | 'MsgId', |
||
34 | 'ReqDate', |
||
35 | 'Signature', |
||
36 | 'ReferenceID', |
||
37 | 'RspCode', |
||
38 | 'RspMsg', |
||
39 | 'RspDate', |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $cdata = [ |
||
46 | 'Merchanturl', |
||
47 | 'FailUrl', |
||
48 | 'ServerUrl', |
||
49 | 'GoodsName', |
||
50 | 'MsgId', |
||
51 | 'RspMsg', |
||
52 | 'Msg', |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * @param array $options |
||
57 | * @param \Payum\Core\HttpClientInterface $client |
||
58 | * @param \Http\Message\MessageFactory $messageFactory |
||
59 | * |
||
60 | * @throws \Payum\Core\Exception\InvalidArgumentException if an option is invalid |
||
61 | */ |
||
62 | 4 | public function __construct(array $options, HttpClientInterface $client, MessageFactory $messageFactory) |
|
68 | |||
69 | /** |
||
70 | * getApiEndpoint. |
||
71 | * |
||
72 | * @return string |
||
73 | */ |
||
74 | public function getApiEndpoint($type = 'capture') |
||
86 | |||
87 | /** |
||
88 | * createTransaction. |
||
89 | * |
||
90 | * @param array $params |
||
91 | * @return array |
||
92 | */ |
||
93 | 1 | public function createTransaction(array $params) |
|
94 | { |
||
95 | $supportedParams = [ |
||
96 | 1 | 'Version' => $this->options['Version'], |
|
97 | 1 | 'MerCode' => $this->options['MerCode'], |
|
98 | 1 | 'MerName' => $this->options['MerName'], |
|
99 | 1 | 'Account' => $this->options['Account'], |
|
100 | 1 | 'MsgId' => null, |
|
101 | 1 | 'ReqDate' => date('YmdHis'), |
|
102 | |||
103 | 1 | 'MerBillNo' => null, |
|
104 | 1 | 'GatewayType' => '01', |
|
105 | 1 | 'Date' => date('Ymd'), |
|
106 | 1 | 'CurrencyType' => 156, |
|
107 | 1 | 'Amount' => 0, |
|
108 | 1 | 'Lang' => 'GB', |
|
109 | 1 | 'Merchanturl' => null, |
|
110 | 1 | 'FailUrl' => null, |
|
111 | 1 | 'Attach' => null, |
|
112 | /* |
||
113 | * 说明:存放商户所选择订单支 付接口加密方式。 |
||
114 | * 5#订单支付采用 Md5 的摘要 讣证方式 |
||
115 | */ |
||
116 | 1 | 'OrderEncodeType' => 5, |
|
117 | /* |
||
118 | *返回给商户其所选用的交易 返回签名方式 |
||
119 | *16#Md5WithRsa 数字签 名方式 |
||
120 | *17#Md5数字签名方式 |
||
121 | */ |
||
122 | 1 | 'RetEncodeType' => 17, |
|
123 | /* |
||
124 | * Server to Server 返回。 |
||
125 | * 1#S2S返回 |
||
126 | */ |
||
127 | 1 | 'RetType' => 1, |
|
128 | 1 | 'ServerUrl' => null, |
|
129 | 1 | 'BillEXP' => null, |
|
130 | 1 | 'GoodsName' => null, |
|
131 | 1 | 'IsCredit' => null, |
|
132 | 1 | 'BankCode' => null, |
|
133 | 1 | 'ProductType' => null, |
|
134 | 1 | ]; |
|
135 | |||
136 | 1 | $params = array_filter(array_replace( |
|
137 | 1 | $supportedParams, |
|
138 | 1 | array_intersect_key($params, $supportedParams) |
|
139 | 1 | )); |
|
140 | |||
141 | return [ |
||
142 | 1 | 'pGateWayReq' => $this->generatGetwayRequest($params), |
|
143 | 1 | ]; |
|
144 | } |
||
145 | |||
146 | /** |
||
147 | * getTransactionData. |
||
148 | * |
||
149 | * @param mixed $params |
||
150 | * @return array |
||
151 | */ |
||
152 | public function getTransactionData(array $params) |
||
156 | |||
157 | /** |
||
158 | * Verify if the hash of the given parameter is correct. |
||
159 | * |
||
160 | * @param array $params |
||
161 | * @return bool |
||
162 | */ |
||
163 | public function verifyHash(array $params) |
||
167 | |||
168 | /** |
||
169 | * parseResponse. |
||
170 | * |
||
171 | * @param string $response |
||
172 | * @return string |
||
173 | */ |
||
174 | 2 | public function parseResponse($response) |
|
187 | |||
188 | /** |
||
189 | * isSandbox. |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | 1 | public function isSandbox() |
|
197 | |||
198 | /** |
||
199 | * generateTestingResponse. |
||
200 | * |
||
201 | * @param array $params |
||
202 | * @return array |
||
203 | */ |
||
204 | 1 | public function generateTestingResponse($params = []) |
|
234 | |||
235 | /** |
||
236 | * generatGetwayRequest. |
||
237 | * |
||
238 | * @param array $params |
||
239 | * @return string |
||
240 | */ |
||
241 | 2 | protected function generatGetwayRequest($params) |
|
252 | |||
253 | /** |
||
254 | * convertToXML. |
||
255 | * |
||
256 | * @param array $params |
||
257 | * @return string |
||
258 | */ |
||
259 | 2 | protected function convertToXML($params) |
|
272 | |||
273 | /** |
||
274 | * split. |
||
275 | * |
||
276 | * @param array $params |
||
277 | * @return array |
||
278 | */ |
||
279 | 2 | protected function split($params) |
|
294 | |||
295 | /** |
||
296 | * addCdata. |
||
297 | * |
||
298 | * @param array $params |
||
299 | * @return array |
||
300 | */ |
||
301 | 2 | protected function addCdata($params) |
|
311 | |||
312 | /** |
||
313 | * calculateHash. |
||
314 | * |
||
315 | * @param array $params |
||
316 | * @return string |
||
317 | */ |
||
318 | 2 | protected function calculateHash(array $params) |
|
329 | |||
330 | /** |
||
331 | * parseResultTags. |
||
332 | * |
||
333 | * @param string $paymentResult |
||
334 | * @return array |
||
335 | */ |
||
336 | 2 | protected function parseResultTags($paymentResult) |
|
345 | } |
||
346 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.