source: branches/feature-module-update/data/downloads/module/mdl_epsilon/mdl_epsilon.php @ 16582

Revision 16582, 13.6 KB checked in by nanasess, 16 years ago (diff)

ライセンス表記変更

  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24/**
25 *
26 * @copyright   2000-2007 LOCKON CO.,LTD. All Rights Reserved.
27 * @version CVS: $Id:mdl_epsilon.php 15532 2007-08-31 14:39:46Z nanasess $
28 * @link        http://www.lockon.co.jp/
29 *
30 */
31require_once(MODULE_PATH . "mdl_epsilon/mdl_epsilon.inc");
32
33$arrPayment = array(
34    1 => 'クレジット',
35    2 => 'コンビニ'
36);
37
38$arrCredit = array(
39    1 => 'VISA, MASTER, Diners',
40    2 => 'JCB, AMEX'
41);
42
43//ページ管理クラス
44class LC_Page {
45    //コンストラクタ
46    function LC_Page() {
47        //メインテンプレートの指定
48        $this->tpl_mainpage = MODULE_PATH . 'mdl_epsilon/mdl_epsilon.tpl';
49        $this->tpl_subtitle = 'イプシロン決済モジュール';
50        global $arrPayment;
51        $this->arrPayment = $arrPayment;
52        global $arrCredit;
53        $this->arrCredit = $arrCredit;
54        global $arrConvenience;
55        $this->arrConvenience = $arrConvenience;
56    }
57}
58$objPage = new LC_Page();
59$objView = new SC_AdminView();
60$objQuery = new SC_Query();
61
62// コンビニ入金チェック
63lfEpsilonCheck();
64
65// 認証確認
66$objSess = new SC_Session();
67sfIsSuccess($objSess);
68
69// パラメータ管理クラス
70$objFormParam = new SC_FormParam();
71$objFormParam = lfInitParam($objFormParam);
72// POST値の取得
73$objFormParam->setParam($_POST);
74
75// 汎用項目を追加(必須!!)
76sfAlterMemo();
77
78switch($_POST['mode']) {
79case 'edit':
80    // 入力エラー判定
81    $objPage->arrErr = lfCheckError();
82
83    // エラーなしの場合にはデータを更新
84    if(count($objPage->arrErr) == 0) {
85        // データ更新
86        lfUpdPaymentDB();
87
88        // javascript実行
89        $objPage->tpl_onload = 'alert("登録完了しました。\n基本情報>支払方法設定より詳細設定をしてください。"); window.close();';
90    }
91    break;
92case 'module_del':
93    // 汎用項目の存在チェック
94    if(sfColumnExists("dtb_payment", "memo01")){
95        // データの削除フラグをたてる
96        $objQuery->query("UPDATE dtb_payment SET del_flg = 1 WHERE module_id = ?", array(MDL_EPSILON_ID));
97    }
98    break;
99default:
100    // データのロード
101    lfLoadData();
102    break;
103}
104
105$objPage->arrForm = $objFormParam->getFormParamList();
106
107$objView->assignobj($objPage);                  //変数をテンプレートにアサインする
108$objView->display($objPage->tpl_mainpage);      //テンプレートの出力
109//-------------------------------------------------------------------------------------------------------
110/* パラメータ情報の初期化 */
111function lfInitParam($objFormParam) {
112    $objFormParam->addParam("契約コード", "code", INT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
113    $objFormParam->addParam("接続先URL", "url", URL_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "URL_CHECK"));
114    $objFormParam->addParam("利用決済", "payment", "", "", array("EXIST_CHECK"));
115    $objFormParam->addParam("利用クレジット", "credit");
116    $objFormParam->addParam("利用コンビニ", "convenience");
117    return $objFormParam;
118}
119
120// エラーチェックを行う
121function lfCheckError(){
122    global $objFormParam;
123
124    $arrErr = $objFormParam->checkError();
125
126    // 利用クレジット、利用コンビニのエラーチェック
127    $arrChkPay = $_POST["payment"];
128    foreach((array)$arrChkPay as $key => $val){
129        // 利用クレジット
130        if($val == 1 and count($_POST["credit"]) <= 0){
131            $arrErr["credit"] = "利用クレジットが選択されていません。<br />";
132        }
133        // 利用コンビニ
134        if($val == 2 and count($_POST["convenience"]) <= 0){
135            $arrErr["convenience"] = "利用コンビニが選択されていません。<br />";
136        }
137    }
138
139    // ssl対応判定
140    if(!extension_loaded('openssl') and ereg( "^https://", $_POST["url"] )){
141        $arrErr["url"] = "このサーバーはSSLに対応していません。<br>httpで接続してください。";
142    }
143
144    // 接続チェックを行う
145    if(count($arrErr) == 0) $arrErr = lfChkConnect();
146
147    return $arrErr;
148}
149
150// 接続チェックを行う
151function lfChkConnect(){
152    global $objQuery;
153    global $objPage;
154
155    $arrRet = array();
156
157    // メールアドレス取得
158    $email = $objQuery->getone("SELECT email03 FROM dtb_baseinfo");
159
160    // 契約コード
161    (in_array(1, (array)$_POST["payment"])) ? $cre = "1" : $cre = "0";
162    (in_array(2, (array)$_POST["payment"])) ? $con = "1" : $con = "0";
163    $st_code = $cre . "0" . $con . "00-0000-00000";
164
165    // 送信データ生成
166    $arrSendData = array(
167        'contract_code' => $_POST["code"],      // 契約コード
168        'user_id' => "connect_test",            // ユーザID
169        'user_name' => "接続テスト",         // ユーザ名
170        'user_mail_add' => $email,              // メールアドレス
171        'st_code' => $st_code,                  // 決済区分
172        'process_code' => '3',                  // 処理区分(固定)
173        'xml' => '1',                           // 応答形式(固定)
174    );
175
176    // データ送信
177    $arrXML = sfPostPaymentData($_POST["url"], $arrSendData, false);
178    if($arrXML == "") {
179        $arrRet["url"] = "接続できませんでした。<br>";
180        return $arrRet;
181    }
182
183    // エラーがあるかチェックする
184    $err_code = sfGetXMLValue($arrXML,'RESULT','ERR_CODE');
185    switch ($err_code) {
186        case "":
187            break;
188        case "607":
189            $arrRet["code"] = "契約コードが違います。<br>";
190            return $arrRet;
191        default :
192            $arrRet["service"] = sfGetXMLValue($arrXML,'RESULT','ERR_DETAIL');
193            return $arrRet;
194    }
195
196    // コンビニ指定があればコンビニ分ループし、チェックを行う
197    if(count($_POST["convenience"]) > 0){
198        foreach($_POST["convenience"] as $key => $val){
199            // 送信データ生成
200            $arrSendData['conveni_code'] = $val;            // コンビニコード
201            $arrSendData['user_tel'] = "0300000000";        // ダミー電話番号
202            $arrSendData['user_name_kana'] = "送信テスト";   // ダミー氏名(カナ)
203            $arrSendData['haraikomi_mail'] = 0;             // 払込メール(送信しない)
204
205            // データ送信
206            $arrXML = sfPostPaymentData($_POST["url"], $arrSendData, false);
207            if($arrXML == "") {
208                $arrRet["url"] = "接続できませんでした。<br>";
209                return $arrRet;
210            }
211
212            // エラーがあるかチェックする
213            $err_code = sfGetXMLValue($arrXML,'RESULT','ERR_CODE');
214            if($err_code != ""){
215                $arrRet["service"] = sfGetXMLValue($arrXML,'RESULT','ERR_DETAIL');
216                return $arrRet;
217            }
218        }
219    }
220
221    return $arrRet;
222}
223
224// 登録データを読み込む
225function lfLoadData(){
226    global $objFormParam;
227
228    //データを取得
229    $arrRet = lfGetPaymentDB(" AND del_flg = '0'");
230
231    // 値をセット
232    $objFormParam->setParam($arrRet[0]);
233
234    // 画面表示用にデータを変換
235    $arrDisp = array();
236    foreach($arrRet as $key => $val){
237        // 利用決済を表示用に変換
238        $arrDisp["payment"][$key] = $val["payment"];
239
240        // クレジットの決済区分を取得
241        if($val["payment"] == 1) $credit = $val["payment_code"];
242
243        // コンビニ
244        if($val["payment"] == 2) $arrDisp["convenience"] = $val["convenience"];
245    }
246    $objFormParam->setParam($arrDisp);
247    $objFormParam->splitParamCheckBoxes("convenience");
248
249    // クレジット
250    if(substr($credit, 0, 1)) $arrCredit["credit"][] = 1;
251    if(substr($credit, 1, 1)) $arrCredit["credit"][] = 2;
252    $objFormParam->setParam($arrCredit);
253}
254
255// DBからデータを取得する
256function lfGetPaymentDB($where = "", $arrWhereVal = array()){
257    global $objQuery;
258
259    $arrVal = array(MDL_EPSILON_ID);
260    $arrVal = array_merge($arrVal, $arrWhereVal);
261
262    $arrRet = array();
263    $sql = "SELECT
264                module_id,
265                memo01 as code,
266                memo02 as url,
267                memo03 as payment,
268                memo04 as payment_code,
269                memo05 as convenience
270            FROM dtb_payment WHERE module_id = ? " . $where;
271    $arrRet = $objQuery->getall($sql, $arrVal);
272
273    return $arrRet;
274}
275
276
277// データの更新処理
278function lfUpdPaymentDB(){
279    global $objQuery;
280    global $objSess;
281
282    // 利用コンビニにチェックが入っている場合には、ハイフン区切りに編集する
283    $convCnt = count($_POST["convenience"]);
284    if($convCnt > 0){
285        $convenience = $_POST["convenience"][0];
286        for($i = 1 ; $i < $convCnt ; $i++){
287            $convenience .= "-" . $_POST["convenience"][$i];
288        }
289    }
290
291    // del_flgを削除にしておく
292    $del_sql = "UPDATE dtb_payment SET del_flg = 1 WHERE module_id = ? ";
293    $arrDel = array(MDL_EPSILON_ID);
294    $objQuery->query($del_sql, $arrDel);
295
296    // データ登録
297    foreach($_POST["payment"] as $key => $val){
298        // ランクの最大値を取得する
299        $max_rank = $objQuery->getone("SELECT max(rank) FROM dtb_payment");
300
301        // 支払方法データを取得
302        $arrPaymentData = lfGetPaymentDB("AND memo03 = ?", array($val));
303
304        // クレジットにチェックが入っていればクレジットを登録する
305        if($val == 1){
306            (in_array(1, $_POST["credit"])) ? $visa = "1" : $visa = "0";
307            (in_array(2, $_POST["credit"])) ? $jcb = "1" : $jcb = "0";
308            $arrData = array(
309                "payment_method" => "Epsilonクレジット"
310                ,"fix" => 3
311                ,"creator_id" => $objSess->member_id
312                ,"create_date" => "now()"
313                ,"update_date" => "now()"
314                ,"upper_rule" => 500000
315                ,"module_id" => MDL_EPSILON_ID
316                ,"module_path" => MODULE_PATH . "mdl_epsilon/card.php"
317                ,"memo01" => $_POST["code"]
318                ,"memo02" => $_POST["url"]
319                ,"memo03" => $val
320                ,"memo04" => $visa . $jcb . "000-0000-00000"
321                ,"del_flg" => "0"
322                ,"charge_flg" => "2"
323                ,"upper_rule_max" => CHARGE_MAX
324
325            );
326        }
327
328        // コンビニにチェックが入っていればコンビニを登録する
329        if($val == 2){
330
331            // セブンイレブンのみ選択した場合には利用上限を30万にする。
332            if(count($_POST["convenience"]) == 1 and $_POST["convenience"][0] == 11) {
333                $upper_rule_max = SEVEN_CHARGE_MAX;
334                ($arrPaymentData["upper_rule"] > $upper_rule_max or $arrPaymentData["upper_rule"] == "") ? $upper_rule = $upper_rule_max : $upper_rule = $arrPaymentData["upper_rule"];
335            }else{
336                $upper_rule_max = CHARGE_MAX;
337                $upper_rule = $upper_rule_max;
338            }
339
340            $arrData = array(
341                "payment_method" => "Epsilonコンビニ"
342                ,"fix" => 3
343                ,"creator_id" => $objSess->member_id
344                ,"create_date" => "now()"
345                ,"update_date" => "now()"
346                ,"upper_rule" => $upper_rule
347                ,"module_id" => MDL_EPSILON_ID
348                ,"module_path" => MODULE_PATH . "mdl_epsilon/convenience.php"
349                ,"memo01" => $_POST["code"]
350                ,"memo02" => $_POST["url"]
351                ,"memo03" => $val
352                ,"memo04" => "00100-0000-00000"
353                ,"memo05" => $convenience
354                ,"del_flg" => "0"
355                ,"charge_flg" => "1"
356                ,"upper_rule_max" => $upper_rule_max
357            );
358        }
359
360        // データが存在していればUPDATE、無ければINSERT
361        if(count($arrPaymentData) > 0){
362            $objQuery->update("dtb_payment", $arrData, " module_id = '" . MDL_EPSILON_ID . "' AND memo03 = '" . $val ."'");
363        }else{
364            $arrData["rank"] = $max_rank + 1;
365            $objQuery->insert("dtb_payment", $arrData);
366        }
367    }
368}
369
370// コンビニ入金確認処理
371function lfEpsilonCheck(){
372    global $objQuery;
373
374    // trans_code を指定されていて且つ、入金済みの場合
375    if($_POST["trans_code"] != "" and $_POST["paid"] == 1 and $_POST["order_number"] != ""){
376        // ステータスを入金済みに変更する
377        $sql = "UPDATE dtb_order SET status = 6, update_date = now() WHERE order_id = ? AND memo04 = ? ";
378        $objQuery->query($sql, array($_POST["order_number"], $_POST["trans_code"]));
379
380        // POSTの内容を全てログ保存
381        $log_path = DATA_PATH . "logs/epsilon.log";
382        gfPrintLog("epsilon conveni start---------------------------------------------------------", $log_path);
383        foreach($_POST as $key => $val){
384            gfPrintLog( "\t" . $key . " => " . $val, $log_path);
385        }
386        gfPrintLog("epsilon conveni end-----------------------------------------------------------", $log_path);
387
388        //応答結果を表示
389        echo "1";
390    }
391}
392
393?>
Note: See TracBrowser for help on using the repository browser.