1 | <?php |
---|
2 | /** |
---|
3 | * PAYGENT B2B MODULE |
---|
4 | * PaymentResponseDataImpl.php |
---|
5 | * |
---|
6 | * Copyright (C) 2007 by PAYGENT Co., Ltd. |
---|
7 | * All rights reserved. |
---|
8 | */ |
---|
9 | |
---|
10 | include_once("jp/co/ks/merchanttool/connectmodule/exception/PaygentB2BModuleConnectException.php"); |
---|
11 | include_once("jp/co/ks/merchanttool/connectmodule/exception/PaygentB2BModuleException.php"); |
---|
12 | include_once("jp/co/ks/merchanttool/connectmodule/util/HttpsRequestSender.php"); |
---|
13 | include_once("jp/co/ks/merchanttool/connectmodule/util/StringUtil.php"); |
---|
14 | include_once("jp/co/ks/merchanttool/connectmodule/entity/ResponseData.php"); |
---|
15 | |
---|
16 | /** |
---|
17 | * Ïnd¶NX |
---|
18 | * |
---|
19 | * @version $Revision: 1.4 $ |
---|
20 | * @author $Author: t-mori $ |
---|
21 | */ |
---|
22 | |
---|
23 | /** |
---|
24 | * d¶pæØè¶ |
---|
25 | */ |
---|
26 | define("PaymentResponseDataImpl__PROPERTIES_REGEX", "="); |
---|
27 | |
---|
28 | /** |
---|
29 | * d¶pæØè |
---|
30 | */ |
---|
31 | define("PaymentResponseDataImpl__PROPERTIES_REGEX_COUNT", 2); |
---|
32 | |
---|
33 | /** |
---|
34 | * üs¶ |
---|
35 | */ |
---|
36 | define("PaymentResponseDataImpl__LINE_SEPARATOR", "\r\n"); |
---|
37 | |
---|
38 | |
---|
39 | class PaymentResponseDataImpl extends ResponseData { |
---|
40 | |
---|
41 | /** Ê ¶ñ*/ |
---|
42 | var $resultStatus; |
---|
43 | |
---|
44 | /** X|XR[h ¶ñ*/ |
---|
45 | var $responseCode; |
---|
46 | |
---|
47 | /** X|XÚ× */ |
---|
48 | var $responseDetail; |
---|
49 | |
---|
50 | /** f[^ array*/ |
---|
51 | var $data; |
---|
52 | |
---|
53 | /** »ÝÌIndex */ |
---|
54 | var $currentIndex; |
---|
55 | |
---|
56 | /** |
---|
57 | * RXgN^ |
---|
58 | */ |
---|
59 | function PaymentResponseDataImpl() { |
---|
60 | $this->data = array(); |
---|
61 | $this->currentIndex = 0; |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | * body ðªð |
---|
66 | * |
---|
67 | * @param X|X{fB |
---|
68 | * @return boolean TRUE: ¬÷A¼FG[R[h |
---|
69 | */ |
---|
70 | function parse($body) { |
---|
71 | |
---|
72 | $line = ""; |
---|
73 | // Ûf[^ðú» |
---|
74 | $this->data = array(); |
---|
75 | $map = array(); |
---|
76 | |
---|
77 | // »ÝÊuðú» |
---|
78 | $this->currentIndex = 0; |
---|
79 | |
---|
80 | // UgîñÌú» |
---|
81 | $this->resultStatus = ""; |
---|
82 | $this->responseCode = ""; |
---|
83 | $this->responseDetail = ""; |
---|
84 | |
---|
85 | // "_html" L[¶ÝtO |
---|
86 | $htmlKeyFlg = false; |
---|
87 | |
---|
88 | // "_htmk" L[l |
---|
89 | $htmlKey = ""; |
---|
90 | |
---|
91 | // "_html" L[o»ÈãÌf[^Û |
---|
92 | $htmlValue = ""; |
---|
93 | |
---|
94 | $lines = split(PaymentResponseDataImpl__LINE_SEPARATOR, $body); |
---|
95 | foreach($lines as $i => $line) { |
---|
96 | $lineItem = StringUtil::split($line, PaymentResponseDataImpl__PROPERTIES_REGEX, |
---|
97 | PaymentResponseDataImpl__PROPERTIES_REGEX_COUNT); |
---|
98 | // ÇI¹ |
---|
99 | $tmpLen = strlen($lineItem[0]) - strlen(ResponseData__HTML_ITEM); |
---|
100 | if ($tmpLen >= 0 |
---|
101 | && strpos($lineItem[0], ResponseData__HTML_ITEM, $tmpLen) |
---|
102 | === $tmpLen) { |
---|
103 | // Key ª "_html" Ìê |
---|
104 | $htmlKey = $lineItem[0]; |
---|
105 | $htmlKeyFlg = true; |
---|
106 | } |
---|
107 | if ($htmlKeyFlg) { |
---|
108 | if (!(strlen($lineItem[0]) - strlen(ResponseData__HTML_ITEM) >= 0 |
---|
109 | && strpos($lineItem[0], ResponseData__HTML_ITEM, |
---|
110 | strlen($lineItem[0]) - strlen(ResponseData__HTML_ITEM)) |
---|
111 | === strlen($lineItem[0]) - strlen(ResponseData__HTML_ITEM))) { |
---|
112 | // "_html" Key ªÇÝæçê½ê |
---|
113 | $htmlValue .= $line; |
---|
114 | $htmlValue .= PaymentResponseDataImpl__LINE_SEPARATOR; |
---|
115 | } |
---|
116 | } else { |
---|
117 | if (0 < count($lineItem)) { |
---|
118 | if ($lineItem[0] == ResponseData__RESULT) { |
---|
119 | // ÊðÝè |
---|
120 | $this->resultStatus = $lineItem[1]; |
---|
121 | } else if ($lineItem[0] == ResponseData__RESPONSE_CODE) { |
---|
122 | // X|XR[hðÝè |
---|
123 | $this->responseCode = $lineItem[1]; |
---|
124 | } else if ($lineItem[0] == ResponseData__RESPONSE_DETAIL) { |
---|
125 | // X|XÚ×ðÝè |
---|
126 | $this->responseDetail = $lineItem[1]; |
---|
127 | } else { |
---|
128 | // MapÉÝè |
---|
129 | $map[$lineItem[0]] = $lineItem[1]; |
---|
130 | } |
---|
131 | } |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | if ($htmlKeyFlg) { |
---|
136 | // "_html" Key ªo»µ½êAÝè |
---|
137 | if (strlen(PaymentResponseDataImpl__LINE_SEPARATOR) <= strlen($htmlValue)) { |
---|
138 | if (strpos($htmlValue, PaymentResponseDataImpl__LINE_SEPARATOR, |
---|
139 | strlen($htmlValue) - strlen(PaymentResponseDataImpl__LINE_SEPARATOR)) |
---|
140 | === strlen($htmlValue) - strlen(PaymentResponseDataImpl__LINE_SEPARATOR)) { |
---|
141 | $htmlValue = substr($htmlValue, 0, |
---|
142 | strlen($htmlValue) - strlen(PaymentResponseDataImpl__LINE_SEPARATOR)); |
---|
143 | } |
---|
144 | } |
---|
145 | $map[$htmlKey] = $htmlValue; |
---|
146 | } |
---|
147 | |
---|
148 | if (0 < count($map)) { |
---|
149 | // Map ªÝè³êÄ¢éê |
---|
150 | $this->data[] = $map; |
---|
151 | } |
---|
152 | |
---|
153 | if (StringUtil::isEmpty($this->resultStatus)) { |
---|
154 | // ʪ ó¶ àµÍ null Ìê |
---|
155 | trigger_error(PaygentB2BModuleConnectException__KS_CONNECT_ERROR |
---|
156 | . ": resultStatus is Nothing.", E_USER_WARNING); |
---|
157 | return PaygentB2BModuleConnectException__KS_CONNECT_ERROR; |
---|
158 | } |
---|
159 | |
---|
160 | return true; |
---|
161 | } |
---|
162 | |
---|
163 | /** |
---|
164 | * data ðªð UgîñÌÝAÏɽf |
---|
165 | * |
---|
166 | * @param data |
---|
167 | * @return boolean TRUE: ¬÷AFALSEF¸s |
---|
168 | */ |
---|
169 | function parseResultOnly($body) { |
---|
170 | |
---|
171 | $line = ""; |
---|
172 | |
---|
173 | // Ûf[^ðú» |
---|
174 | $this->data = array(); |
---|
175 | |
---|
176 | // »ÝÊuðú» |
---|
177 | $this->currentIndex = 0; |
---|
178 | |
---|
179 | // UgîñÌú» |
---|
180 | $this->resultStatus = ""; |
---|
181 | $this->responseCode = ""; |
---|
182 | $this->responseDetail = ""; |
---|
183 | |
---|
184 | $lines = split(PaymentResponseDataImpl__LINE_SEPARATOR, $body); |
---|
185 | foreach($lines as $i => $line) { |
---|
186 | $lineItem = StringUtil::split($line, PaymentResponseDataImpl__PROPERTIES_REGEX); |
---|
187 | // ÇI¹ |
---|
188 | if (strpos($lineItem[0], ResponseData__HTML_ITEM) |
---|
189 | === strlen($lineItem[0]) - strlen(ResponseData__HTML_ITEM)) { |
---|
190 | // Key ª "_html" Ìê |
---|
191 | break; |
---|
192 | } |
---|
193 | |
---|
194 | if (0 < count($lineItem)) { |
---|
195 | // 1s¸ÂÇ(Úª2ÈãÌê) |
---|
196 | if ($lineItem[0] == ResponseData__RESULT) { |
---|
197 | // ÊðÝè |
---|
198 | $this->resultStatus = $lineItem[1]; |
---|
199 | } else if ($lineItem[0] == ResponseData__RESPONSE_CODE) { |
---|
200 | // X|XR[hðÝè |
---|
201 | $this->responseCode = $lineItem[1]; |
---|
202 | } else if ($lineItem[0] == ResponseData__RESPONSE_DETAIL) { |
---|
203 | // X|XÚ×ðÝè |
---|
204 | $this->responseDetail = $lineItem[1]; |
---|
205 | } |
---|
206 | } |
---|
207 | } |
---|
208 | |
---|
209 | if (StringUtil::isEmpty($this->resultStatus)) { |
---|
210 | // ʪ ó¶ àµÍ null Ìê |
---|
211 | trigger_error(PaygentB2BModuleConnectException__KS_CONNECT_ERROR |
---|
212 | . ": resultStatus is Nothing.", E_USER_WARNING); |
---|
213 | return PaygentB2BModuleConnectException__KS_CONNECT_ERROR; |
---|
214 | } |
---|
215 | return true; |
---|
216 | } |
---|
217 | |
---|
218 | /** |
---|
219 | * Ìf[^ðæ¾ |
---|
220 | * |
---|
221 | * @return Map f[^ªÈ¢êANULLðß· |
---|
222 | */ |
---|
223 | function resNext() { |
---|
224 | $map = null; |
---|
225 | |
---|
226 | if ($this->hasResNext()) { |
---|
227 | |
---|
228 | $map =$this->data[$this->currentIndex]; |
---|
229 | |
---|
230 | $this->currentIndex++; |
---|
231 | } |
---|
232 | |
---|
233 | return $map; |
---|
234 | } |
---|
235 | |
---|
236 | /** |
---|
237 | * Ìf[^ª¶Ý·é©»è |
---|
238 | * |
---|
239 | * @return boolean true=¶Ý·é false=¶ÝµÈ¢ |
---|
240 | */ |
---|
241 | function hasResNext() { |
---|
242 | $rb = false; |
---|
243 | |
---|
244 | if ($this->currentIndex < count($this->data)) { |
---|
245 | $rb = true; |
---|
246 | } |
---|
247 | |
---|
248 | return $rb; |
---|
249 | } |
---|
250 | |
---|
251 | /** |
---|
252 | * resultStatus ðæ¾ |
---|
253 | * |
---|
254 | * @return String |
---|
255 | */ |
---|
256 | function getResultStatus() { |
---|
257 | return $this->resultStatus; |
---|
258 | } |
---|
259 | |
---|
260 | /** |
---|
261 | * responseCode ðæ¾ |
---|
262 | * |
---|
263 | * @return String |
---|
264 | */ |
---|
265 | function getResponseCode() { |
---|
266 | return $this->responseCode; |
---|
267 | } |
---|
268 | |
---|
269 | /** |
---|
270 | * responseDetail ðæ¾ |
---|
271 | * |
---|
272 | * @return String |
---|
273 | */ |
---|
274 | function getResponseDetail() { |
---|
275 | return $this->responseDetail; |
---|
276 | } |
---|
277 | |
---|
278 | } |
---|
279 | |
---|
280 | ?> |
---|