<?php
/**
 * @copyright ONE/DEPO Project
 * @license   PHP License 3.01 <http://www.php.net/license/3_01.txt>
 */

// # マーチャントの設定ファイルを読み込む

include_once BASE_DIR . "/webapp/config/merchant.inc.php";

if (INPUT_CARD_INFO) {
define('CONFIG_PATH', $CONFIG_PATH);
define('MERCHANT_ID', $MERCHANT_ID);
define('PASS_PHRASE', $PASS_PHRASE);
define('ENCODE',      $ENCODE);
define('TXN_TYPE',    $TXN_TYPE);
define('PAYTO_URL',   $PAYTO_URL);
}

/**
 * 秘密の質問テーブル関連
 *
 * @package     Onedepo.Logic.Seller
 * @author      netnee H.Watanabe<hiroshi.watanabe@netnee.jp>
 * @access      public
 */
class Onedepo_Logic_Seller
{
    var $dbaccess;
    
    var $t;
    
    
    var $merchant_id;
    var $pass_phrase;
    var $encode;
    var $paytourl;
    var $txn_type;
    var $MIblock;
    var $MI;
    var $MI_SIG;
    var $QUERY_MI;
    var $dt;

    var $card_number;
    var $card_exp;
    var $card_name;
    var $bankdata;
    var $bankmessage;
    
    function Onedepo_Logic_Seller() {

		if (!INPUT_CARD_INFO) return;

        # トランザクションオブジェクトを作成
        $this->t = new Transaction;

        # 設定ファイル jpgwclient.conf によりオブジェクトを設定
        $this->t->setServer(CONFIG_PATH);

        $this->merchant_id = MERCHANT_ID;
        $this->pass_phrase = PASS_PHRASE;
        $this->encode      = ENCODE;
        $this->txn_type    = TXN_TYPE;
        $this->paytourl    = PAYTO_URL;
    }
    
    function chackEnabledCard( $membercd, $cardno, $cardexp_year, $cardexp_mon)
    {

		if (!INPUT_CARD_INFO) return;

        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Logic_Seller#ChackEnabledCard";
        
        $orderid = 'S' . $membercd . '-' .date("YmdHis");
        $request = array(
            "order-id"      =>  $orderid,
            "amount"        =>  555,
            "card-number"   =>  $cardno,
            "card-exp"      =>  $cardexp_mon . '/' . substr($cardexp_year,2)
        );
        $result = $this->t->doTransaction("authonly", $request);

        // 与信成功
        if($result['MStatus'] == 'success') {
            
            // キャンセル
            $request = array(
                "order-id"      =>  $orderid,
                "txn-type"      =>  "authonly"
            );
            $result = $this->t->doTransaction("void", $request);
        }
        
        return $result;
    }

}