SC_ValueCard.php 7.27 KB
<?php

//ini_set('include_path', DATA_PATH.'module/nusoap/'. PATH_SEPARATOR . ini_get('include_path'));
require_once 'nusoap/nusoap.php';

define('VALUECARD_WSDL', 'https://211.122.217.9/soap/services/DealService?wsdl');
//define('VALUECARD_WSDL', 'https://localhost:8443/soap/services/DealService?wsdl');
//define('VALUECARD_WSDL', 'http://localhost:8080/soap/services/DealService?wsdl');

define('VALUECARD_ENDPOINT', 'https://211.122.217.9/soap/services/DealService');
//define('VALUECARD_ENDPOINT', 'https://localhost:8443/soap/services/DealService');
//define('VALUECARD_ENDPOINT', 'http://localhost:8080/soap/services/DealService');

define('VALUECARD_ACCESSKEY', 'r4KQyq8Q6H9x5XsDQa5MuiooN3WU');
define('VALUECARD_TERMID', '3061399854321');

/**
 * バリューカードのクラスです。
 *
 */
class SC_ValueCard {
    
    var $useValueCard = false;
    var $dealInfo;
    var $errorMessage;
    var $balanceTotal;
    
    var $authed = false;
    private $success = false;
    
    function __construct() {
        
        
    }
    
    static function getSessionInstance() {
        
        if (isset($_SESSION['valuecard'])) {
            return $_SESSION['valuecard'];
        } else {
            $obj = new SC_ValueCard();
            $_SESSION['valuecard'] = $obj;
            return $obj;
        }
    }
    
    static function clearSession() {
        unset($_SESSION['valuecard']);
    }
    
    function isAuthed() {
        return $this->authed;
    }
    
    function isSuccess() {
        return $this->success;
    }

    /**
     * 残高照会を実行します。
     *
     * @return unknown
     */
    function doGetBalance() {
        
        $param = array(
            'accessKey' => $this->accessKey,
            'termId' => $this->termId,
            'cardNo' => $this->cardNo,
            'pinCode' => $this->pinCode
        );
        
        $this->success = false;
        $this->soapRequest('getBalance', $param);
        if (! $this->success) {
            return;
        }
        
        //print_r($this->dealInfo);
        
        if ($this->dealInfo['resultCode'] == 200) {
            $this->authed = true;
            $this->balanceTotal = $this->dealInfo['balanceTotal']; 
            return; 
        }
        if ($this->dealInfo['resultCode'] == 504) {
            $this->authed = true;
            $this->balanceTotal = 0;
            return;
        }
        
        $this->authed = false;
        $this->success = false;
        return;
    }
    
    /**
     * 利用を実行します。
     *
     * @param unknown_type $volume
     */
    function doWithdraw() {
        
        $param = array(
            'accessKey' => $this->accessKey,
            'dealInfo' => array(
                'termId' => $this->termId,
                'receiptNo' => $this->receiptNo,
                'cardNo' => $this->cardNo,
                'pinCode' => $this->pinCode,
                'reqId' => $this->reqId),
            'volume' => $this->volume
        );
        
        $this->soapRequest('withdraw', $param);
        if (! $this->success) {
            return;
        }
        
        //print_r($this->dealInfo);
        
        if ($this->dealInfo['resultCode'] == 200) {
            $this->success = true;
            return;
        }
        
        $this->success = false;
        return;
    }

    function doDeposit() {
        
        $param = array(
            'accessKey' => $this->accessKey,
            'dealInfo' => array(
                'termId' => $this->termId,
                'receiptNo' => $this->receiptNo,
                'cardNo' => $this->cardNo,
                'reqId' => $this->reqId,
                'pinCode' => $this->pinCode),
            'volume' => $this->volume,
            'valueType' => $this->valueType
        );
        
        $this->soapRequest('deposit', $param);
        if (! $this->success) {
            return;
        }
        
        //print_r($this->dealInfo);
        
        if ($this->dealInfo['resultCode'] == 200) {
            $this->success = true;
            return;
        }
        
        $this->success = false;
        return;
    }

    function doActivate() {
        
        $param = array(
            'accessKey' => $this->accessKey,
            'dealInfo' => array(
                'termId' => $this->termId,
                'receiptNo' => $this->receiptNo,
                'cardNo' => $this->cardNo,
                'reqId' => $this->reqId,
                'pinCode' => $this->pinCode),
            'volume' => $this->volume,
            'valueType' => $this->valueType
        );
        
        $this->soapRequest('activate', $param);
        if (! $this->success) {
            return;
        }
        
        //print_r($this->dealInfo);
        
        if ($this->dealInfo['resultCode'] == 200) {
            $this->success = true;
            return;
        }
        
        $this->success = false;
        return;
    }
    
    function doForceCancel() {
        
        $param = array(
            'accessKey' => $this->accessKey,
            'dealInfo' => array(
                'termId' => $this->termId,
                'receiptNo' => $this->receiptNo,
                'cardNo' => $this->cardNo,
                'reqId' => $this->reqId,
                'pinCode' => $this->pinCode),
            'reqClassCanceled' => $this->reqClassCanceled,
            'reqIdCanceled' => $this->reqIdCanceled
        );
        
        $this->soapRequest('forceCancel', $param);
        if (! $this->success) {
            return;
        }
        
        //print_r($this->dealInfo);
        
        if ($this->dealInfo['resultCode'] == 200) {
            $this->success = true;
            return;
        }
        
        $this->success = false;
        return;
    }

    function doDepositCancel() {
        
        $param = array(
            'accessKey' => $this->accessKey,
            'dealInfo' => array(
                'termId' => $this->termId,
                'receiptNo' => $this->receiptNo,
                'cardNo' => $this->cardNo,
                'reqId' => $this->reqId,
                'pinCode' => $this->pinCode),
            'dealNoCanceled' => $this->dealNoCanceled,
            'volumeCanceled' => $this->volumeCanceled,
            'valueType' => $this->valueType
        );
        
        $this->soapRequest('depositCancel', $param);
        if (! $this->success) {
            return;
        }
        
        //print_r($this->dealInfo);
        
        if ($this->dealInfo['resultCode'] == 200) {
            $this->success = true;
            return;
        }
        
        $this->success = false;
        return;
    }
    
    /**
     * SOAPリクエストを実行します。
     *
     * @param unknown_type $method
     * @param unknown_type $param
     */
    private function soapRequest($method, $param) {
        
        $client = new nusoap_client(VALUECARD_ENDPOINT, false);
        $result = $client->call($method, $param, 'http://services.soap.valuecardservice.com');
        $err = $client->getError();
        if ($err || $client->fault) {
            $this->success = false;
            $this->errorMessage = '残高センターの接続に失敗しました。';
            return;
        }
        
        $this->dealInfo = $result;
        $this->success = true;
        
        return;
    }
    
}

?>