source: branches/feature-module-paygent/data/downloads/module/mdl_paygent/jp/co/ks/merchanttool/connectmodule/entity/PaymentResponseDataImpl.php @ 15162

Revision 15162, 6.5 KB checked in by naka, 17 years ago (diff)

ペイジェント決済モジュール

Line 
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
10include_once("jp/co/ks/merchanttool/connectmodule/exception/PaygentB2BModuleConnectException.php");
11include_once("jp/co/ks/merchanttool/connectmodule/exception/PaygentB2BModuleException.php");
12include_once("jp/co/ks/merchanttool/connectmodule/util/HttpsRequestSender.php");
13include_once("jp/co/ks/merchanttool/connectmodule/util/StringUtil.php");
14include_once("jp/co/ks/merchanttool/connectmodule/entity/ResponseData.php");
15
16/**
17 * ŒˆÏŒn‰ž“š“d•¶ˆ—ƒNƒ‰ƒX
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
39class PaymentResponseDataImpl extends ResponseData {
40
41    /** ˆ—Œ‹‰Ê •¶Žš—ñ*/
42    var $resultStatus;
43
44    /** ƒŒƒXƒ|ƒ“ƒXƒR[ƒ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     * ƒRƒ“ƒXƒgƒ‰ƒNƒ^
58     */
59    function PaymentResponseDataImpl() {
60        $this->data = array();
61        $this->currentIndex = 0;
62    }
63
64    /**
65     * body ‚𕪉ð
66     *
67     * @param ƒŒƒXƒ|ƒ“ƒXƒ{ƒfƒB
68     * @return boolean TRUE: ¬Œ÷A‘¼FƒGƒ‰[ƒ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        // ƒŠƒUƒ‹ƒgî•ñ‚̏‰Šú‰»
81        $this->resultStatus = "";
82        $this->responseCode = "";
83        $this->responseDetail = "";
84       
85        // "_html" ƒL[‘¶Ýƒtƒ‰ƒO
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ƒ|ƒ“ƒXƒR[ƒ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 ‚𕪉𠃊ƒUƒ‹ƒgî•ñ‚̂݁A•Ï”‚É”½‰f
165     *
166     * @param data
167     * @return boolean TRUE: ¬Œ÷AFALSEFŽ¸”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        // ƒŠƒUƒ‹ƒgî•ñ‚̏‰Šú‰»
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                // 1s‚¸‚“Ǎž(€–ڐ”‚ª2ˆÈã‚̏ꍇ)
196                if ($lineItem[0] == ResponseData__RESULT) {
197                    // ˆ—Œ‹‰Ê‚ðÝ’è
198                    $this->resultStatus = $lineItem[1];
199                } else if ($lineItem[0] == ResponseData__RESPONSE_CODE) {
200                    // ƒŒƒXƒ|ƒ“ƒXƒR[ƒ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?>
Note: See TracBrowser for help on using the repository browser.