<?php
require_once('config.php');

class APICardDeposit extends System {

	/*-------------------------------------------------------------------------
	 * @function_name: ロジックのコンストラクタ
	* @parameter	: なし
	* @return		: なし
	-------------------------------------------------------------------------*/
	function __construct() {
		parent::__construct();
	}

	function action() {

		// 変数宣言部
		$rtn			= array(PARAM_RESULT => array());
		$xml			= NO_STRING;
		$cardHolderId	= $this -> getDataPost(PARAM_CARD_HOLDER_ID);
		$amount			= $this -> getDataPost(PARAM_AMOUNT);

		try {

			// 			if($cardHolderId == NO_STRING) {
			// 				throw new Exception(NO_STRING);
			// 			}

			$xml =	'<DepositToCard><Cardholderid>' . $cardHolderId . '</Cardholderid><Amount>' . $amount . '</Amount><TransactionType>0</TransactionType><CurrencyCode>USD</CurrencyCode><SettlementAmount>0</SettlementAmount><SettlementCurrencyCode>USD</SettlementCurrencyCode><TransactionDescription>Deposit To Card API</TransactionDescription></DepositToCard>';
			// 			$xml =	'<DepositToCard><Cardholderid>400000542107</Cardholderid><Amount>1000</Amount><TransactionType>0</TransactionType><CurrencyCode>GBP</CurrencyCode><SettlementAmount>0</SettlementAmount><SettlementCurrencyCode>GBP</SettlementCurrencyCode><TransactionDescription>Deposit To Card API</TransactionDescription></DepositToCard>';

			// 送信データの生成
			$post = array('Username'			=> VAR_CARD_API_USER_NAME
					, 'Password'		=> VAR_CARD_API_PASSWORD
					, 'APISigniture'	=> 'DepositToCard'
					, 'MessageID'		=> $this -> getSequenceNo(CARD_MESSAGE_ID)
					, 'Data'			=> $xml
			);

			// ポスト送信
			$url				= VAR_CARD_API_URL;

			$client				= new SoapClient($url);
			$result				= $client -> Process($post);
			$rtn[PARAM_DATA]	= $result;
			$result				= simplexml_load_string($result -> ProcessResult);

			$result				= get_object_vars($result);

			// エラーがないか確認する
			if($this -> getColumnData($result, 'ErrorCode') == '0000') {	// 取得成功

				$rtn[PARAM_RESULT]	= PARAM_SUCCESS;
				$rtn[PARAM_CODE]	= $this -> getColumnData($result, 'ErrorCode');

			} else {													// 取得失敗
				$rtn[PARAM_RESULT]	= PARAM_NG;
				$rtn[PARAM_CODE]	= $this -> getColumnData($result, 'ErrorCode');
			}

		} catch(Exception $e) {
			$rtn[PARAM_RESULT]	= PARAM_NG;
			$rtn[PARAM_CODE]	= '9999';
		}

		return $rtn;
	}
}
?>
