<commit_before><?php

/**
 * Np_Method Class
 * Model for Number Transaction operations.
 * 
 * @package         Np_Method
 * @copyright       Copyright (C) 2012-2013 S.D.O.C. LTD. All rights reserved.
 * @license         GNU Affero Public License version 3 or later; see LICENSE.txt
 */

/**
 * Np_Method Class Definition
 * 
 * @package Np_Method
 * @subpackage Np_MethodResponse
 */
abstract class Np_MethodResponse extends Np_Method {

	/**
	 * Constructor
	 * 
	 * receives options array and sets into body array accordingly
	 * sets parent's $type to "ExecuteResponse"
	 * 
	 * @param array $options 
	 */
	protected function __construct(&$options) {
		parent::__construct($options);

		//SET BODY 
		foreach ($options as $key => $value) {
			switch (ucwords(strtolower($key))) {
				case "Request_trx_no":
				case "Approval_ind":
				case "Reject_reason_code":
					$this->setBodyField($key, $value);
					break;
			}
		}
	}

	protected function checkApprove() {
		if ($this->getBodyField("APPROVAL_IND") === "Y") {
			return TRUE;
		}
		return FALSE;
	}

	/**
	 * override saveToDB to make another
	 * @return type 
	 */
	public function saveToDB() {
		if ($this->checkApprove()) {
			return parent::saveToDB();
		}
		return FALSE;
	}

	public function createXml() {
		$xml = parent::createXml();
		$msgType = $this->getHeaderField('MSG_TYPE');
		$this->addApprovalXml($xml, $msgType);
		$this->addTrxNoXml($xml, $msgType);
		return $xml;
	}
	
	protected function addTrxNoXml(&$xml, $msgType) {
		$xml->$msgType->requestTrxNo = $this->getBodyField('REQUEST_TRX_NO');
		$xml->$msgType->requestRetryDate = $this->getBodyField('REQUEST_RETRY_DATE');
	}
	
	protected function addApprovalXml(&$xml, $msgType) {
		if ($this->checkApprove()) {
			$xml->$msgType->positiveApproval;
			$xml->$msgType->positiveApproval->approvalInd = "Y";
		} else {
			$xml->$msgType->negativeApproval;
			$xml->$msgType->negativeApproval->approvalInd = "N";
			$rejectReasonCode = $this->getBodyField('REJECT_REASON_CODE');
			$xml->$msgType->negativeApproval->rejectReasonCode = ($rejectReasonCode !== NULL) ? $rejectReasonCode : '';
		}
	}
	
	/**
	 * convert Xml data to associative array
	 * 
	 * @param simple_xml $xmlObject simple xml object
	 * 
	 * @return array converted data from hierarchical xml to flat array
	 */
	public function convertArray($xmlObject) {
		$ret = array();
		if (isset($xmlObject->positiveApproval)) {
			$ret['APPROVAL_IND'] = (string) $xmlObject->positiveApproval->approvalInd;
		} else {
			$ret['APPROVAL_IND'] = (string) $xmlObject->positiveApproval->approvalInd;
			$ret['REJECT_REASON_CODE'] = (string) $xmlObject->negativeApproval->rejectReasonCode;
		}
		$ret['REQUEST_TRX_NO'] = (string) $xmlObject->requestTrxNo;
		$ret['REQUEST_RETRY_DATE'] = (string) $xmlObject->requestRetryDate;
		return $ret;
	}


}<commit_msg>fix issue: negative responses send approval_ind empty to internal<commit_after><?php

/**
 * Np_Method Class
 * Model for Number Transaction operations.
 * 
 * @package         Np_Method
 * @copyright       Copyright (C) 2012-2013 S.D.O.C. LTD. All rights reserved.
 * @license         GNU Affero Public License version 3 or later; see LICENSE.txt
 */

/**
 * Np_Method Class Definition
 * 
 * @package Np_Method
 * @subpackage Np_MethodResponse
 */
abstract class Np_MethodResponse extends Np_Method {

	/**
	 * Constructor
	 * 
	 * receives options array and sets into body array accordingly
	 * sets parent's $type to "ExecuteResponse"
	 * 
	 * @param array $options 
	 */
	protected function __construct(&$options) {
		parent::__construct($options);

		//SET BODY 
		foreach ($options as $key => $value) {
			switch (ucwords(strtolower($key))) {
				case "Request_trx_no":
				case "Approval_ind":
				case "Reject_reason_code":
					$this->setBodyField($key, $value);
					break;
			}
		}
	}

	protected function checkApprove() {
		if ($this->getBodyField("APPROVAL_IND") === "Y") {
			return TRUE;
		}
		return FALSE;
	}

	/**
	 * override saveToDB to make another
	 * @return type 
	 */
	public function saveToDB() {
		if ($this->checkApprove()) {
			return parent::saveToDB();
		}
		return FALSE;
	}

	public function createXml() {
		$xml = parent::createXml();
		$msgType = $this->getHeaderField('MSG_TYPE');
		$this->addApprovalXml($xml, $msgType);
		$this->addTrxNoXml($xml, $msgType);
		return $xml;
	}
	
	protected function addTrxNoXml(&$xml, $msgType) {
		$xml->$msgType->requestTrxNo = $this->getBodyField('REQUEST_TRX_NO');
		$xml->$msgType->requestRetryDate = $this->getBodyField('REQUEST_RETRY_DATE');
	}
	
	protected function addApprovalXml(&$xml, $msgType) {
		if ($this->checkApprove()) {
			$xml->$msgType->positiveApproval;
			$xml->$msgType->positiveApproval->approvalInd = "Y";
		} else {
			$xml->$msgType->negativeApproval;
			$xml->$msgType->negativeApproval->approvalInd = "N";
			$rejectReasonCode = $this->getBodyField('REJECT_REASON_CODE');
			$xml->$msgType->negativeApproval->rejectReasonCode = ($rejectReasonCode !== NULL) ? $rejectReasonCode : '';
		}
	}
	
	/**
	 * convert Xml data to associative array
	 * 
	 * @param simple_xml $xmlObject simple xml object
	 * 
	 * @return array converted data from hierarchical xml to flat array
	 */
	public function convertArray($xmlObject) {
		$ret = array();
		if (isset($xmlObject->positiveApproval)) {
			$ret['APPROVAL_IND'] = (string) $xmlObject->positiveApproval->approvalInd;
		} else {
			$ret['APPROVAL_IND'] = (string) $xmlObject->negativeApproval->approvalInd;
			$ret['REJECT_REASON_CODE'] = (string) $xmlObject->negativeApproval->rejectReasonCode;
		}
		$ret['REQUEST_TRX_NO'] = (string) $xmlObject->requestTrxNo;
		$ret['REQUEST_RETRY_DATE'] = (string) $xmlObject->requestRetryDate;
		return $ret;
	}


}
{'fraction_non_alphanumeric': 0.1500522830254444, 'fraction_numerical': 0.003136981526664343, 'mean_word_length': 4.101333333333334, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 48}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6586806', 'n_tokens_mistral': 2127, 'n_tokens_neox': 1886, 'n_words': 398}