protected function addApprovalXml(&$xml, $msgType) { $route = Application_Model_General::getDateTimeInSqlFormat(Application_Model_General::getRouteTimeByReqId($this->getHeaderField("REQUEST_ID"))); if ($this->getBodyField("APPROVAL_IND") == "Y") { $xml->{$msgType}->positiveApproval; $xml->{$msgType}->positiveApproval->approvalInd = "Y"; $xml->{$msgType}->positiveApproval->routeDateTime = $route; } else { $xml->{$msgType}->negativeApproval; $xml->{$msgType}->negativeApproval->approvalInd = "N"; $rejectReasonCode = $this->getBodyField('REJECT_REASON_CODE'); $xml->{$msgType}->negativeApproval->rejectReasonCode = $rejectReasonCode !== NULL ? $rejectReasonCode : ''; } }
/** * sets status = 0 to any "Check_response" requests that have timedout * * @return int number of affected rows */ public static function setTimeoutChecks($msg_type = "Check", $time = 1, $checkTransferTimeNotExists = false) { // $setTimeOutArray = array('Check'=>'30','Check_response'=>'30','Request'=>'30',); $dateInTimeStamp = time() - $time * 60; $compareTime = Application_Model_General::getDateTimeInSqlFormat($dateInTimeStamp); $tbl = new Application_Model_DbTable_Requests(Np_Db::master()); $update_arr = array('status' => 0); $where_arr = array('last_transaction =?' => $msg_type, 'last_request_time < ?' => $compareTime, 'status =?' => 1); if ($checkTransferTimeNotExists) { $where_arr[] = "transfer_time IS NULL OR transfer_time = ''"; } $res = $tbl->update($update_arr, $where_arr); return $res; }
/** * method triggered after internal response to NPG * * @param object $internalResponseObject */ public function postInternalRequest($internalResponseObject) { if ($this->getHeaderField("TO") == Application_Model_General::getSettings('InternalProvider')) { if (isset($internalResponseObject->connect_time)) { $connect_time = $internalResponseObject->connect_time; } else { $connect_time = time(); } $updateArray = array('connect_time' => Application_Model_General::getDateTimeInSqlFormat($connect_time)); $whereArray = array('request_id =?' => $this->getHeaderField("REQUEST_ID")); $tbl = new Application_Model_DbTable_Requests(Np_Db::master()); return $tbl->update($updateArray, $whereArray); } return true; }
/** * overridden from parent * * inserts row to database * * @return type */ public function saveToDB() { //this is a request from provider! //save a new row in Requests DB if ($this->getHeaderField("FROM") != Application_Model_General::getSettings('InternalProvider')) { try { $flags = new stdClass(); $flags->publish_type = $this->getBodyField("PUBLISH_TYPE"); $tbl = new Application_Model_DbTable_Requests(Np_Db::master()); $data = array('request_id' => $this->getHeaderField("REQUEST_ID"), 'from_provider' => $this->getHeaderField("TO"), 'to_provider' => $this->getHeaderField("FROM"), 'status' => 1, 'last_transaction' => $this->getHeaderField("MSG_TYPE"), 'phone_number' => $this->getBodyField("NUMBER"), 'disconnect_time' => Application_Model_General::getDateTimeInSqlFormat($this->getBodyField("DISCONNECT_TIME")), 'connect_time' => Application_Model_General::getDateTimeInSqlFormat($this->getBodyField("CONNECT_TIME")), 'transfer_time' => Application_Model_General::getDateTimeInSqlFormat(), 'flags' => json_encode($flags)); return $tbl->insert($data); } catch (Exception $e) { error_log("Error on create record in transactions table: " . $e->getMessage()); } } return TRUE; }
/** * create data to post to the internal * * @param Np_Method $request the request to create post data from * * @return void * * @todo refatoring to bridge classes */ protected function createPostData(Np_Method $request) { $ack = $request->getAck(); $rejectReasonCode = $request->getRejectReasonCode(); $idValue = $request->getIDValue(); if ($this->params['FROM'] != Application_Model_General::getSettings('InternalProvider')) { $provider = $this->params['FROM']; } else { $provider = $this->params['TO']; } if (!$rejectReasonCode || $rejectReasonCode === "" || $rejectReasonCode == " ") { $rejectReasonCode = "OK"; } if (empty($idValue)) { $idValue = "no details"; } $ret = array('number' => $this->params['PHONE_NUMBER'], 'provider' => $provider, 'msg_type' => $this->params['MSG_TYPE'], 'msgType' => $this->params['MSG_TYPE'], 'reqId' => $this->params['REQUEST_ID'], 'more' => array('identification_value' => $idValue, 'resultCode' => $rejectReasonCode, 'ack' => $ack)); if (isset($this->params['PHONE_NUMBER'])) { $ret['number'] = $ret['phone_number'] = $this->params['PHONE_NUMBER']; } if (isset($this->params['NUMBER_TYPE'])) { $ret['more']['number_type'] = $this->params['NUMBER_TYPE']; if ($ret['more']['number_type'] == "R") { unset($ret['number'], $ret['phone_number']); $ret['more']['to_number'] = $this->params['TO_NUMBER']; $ret['more']['from_number'] = $this->params['FROM_NUMBER']; } } if (Application_Model_General::isMsgResponse($this->params['MSG_TYPE'])) { $ret['more']['approval_ind'] = $this->params['APPROVAL_IND']; } $msg_type = strtoupper($this->params['MSG_TYPE']); if ($msg_type == "KD_UPDATE_RESPONSE") { $ret['more']['KD_update_type'] = $this->params['KD_UPDATE_TYPE']; } if ($msg_type == "EXECUTE_RESPONSE" && isset($this->params['DISCONNECT_TIME'])) { $ret['more']['disconnect_time'] = $this->params['DISCONNECT_TIME']; } if ($msg_type == "REQUEST" || $msg_type == "UPDATE") { if (!is_numeric($this->params['PORT_TIME'])) { // convert to unix timestamp in case is format as full datetime $transfer_time = strtotime($this->params['PORT_TIME']); } else { $transfer_time = $this->params['PORT_TIME']; } // all the cases for backward compatibility $ret['port_time'] = $ret['more']['port_time'] = $ret['transfer_time'] = $ret['more']['transfer_time'] = $transfer_time; } if (isset($ret['more']['approval_ind']) && $ret['more']['approval_ind'] == 'Y' && ($msg_type == "REQUEST_RESPONSE" || $msg_type == "UPDATE_RESPONSE") && Application_Model_General::getSettings('InternalProvider') == $this->params['TO']) { $transfer_time = Application_Model_General::getFieldFromRequests('transfer_time', $this->params['REQUEST_ID'], 'request_id'); $ret['more']['transfer_time'] = Application_Model_General::getDateTimeInTimeStamp($transfer_time); } if ($msg_type == "PUBLISH") { $ret['more']['donor'] = $this->params['DONOR']; $ret['more']['publish_type'] = $this->params['PUBLISH_TYPE']; if (isset($this->params['DISCONNECT_TIME'])) { $ret['more']['disconnect_time'] = $this->params['DISCONNECT_TIME']; } if (isset($this->params['CONNECT_TIME'])) { $ret['more']['connect_time'] = $this->params['CONNECT_TIME']; } } if ($msg_type == "CANCEL_PUBLISH") { $ret['more']['donor'] = $this->params['DONOR']; } if ($msg_type == "PUBLISH_RESPONSE") { $ret['more']['approval_ind'] = $this->params['APPROVAL_IND']; if (isset($this->params['ROUTE_TIME'])) { $ret['more']['route_time'] = Application_Model_General::getDateTimeInSqlFormat($this->params['ROUTE_TIME']); } } if ($msg_type == "CANCEL_PUBLISH_RESPONSE") { $ret['more']['msg_type'] = "Cancel_Publish_response"; $ret['more']['approval_ind'] = $this->params['APPROVAL_IND']; $ret['more']['route_time'] = Application_Model_General::getDateTimeInSqlFormat($this->params['ROUTE_TIME']); } if ($msg_type == "INQUIRE_NUMBER_RESPONSE") { $ret['more']['approval_ind'] = $this->params['APPROVAL_IND']; $ret['more']['current_operator'] = isset($this->params['CURRENT_OPERATOR']) ? $this->params['CURRENT_OPERATOR'] : ' '; } if ($msg_type == "DB_SYNCH_REQUEST") { $ret['more']['from_date'] = $this->params['FROM_DATE']; $ret['more']['to_date'] = $this->params['TO_DATE']; } if ($msg_type == "DB_SYNCH_RESPONSE") { $ret['more']['file_name'] = $this->params['FILE_NAME']; } // let's keep on backward backward compatibility (b/c) - all more fields should be also in the root foreach ($ret['more'] as $k => $v) { if (!isset($ret[$k])) { $ret[$k] = $v; } } // b/c if (!isset($ret['msgDesc'])) { $ret['desc'] = ''; } // b/c if (!isset($ret['more']['msgDesc'])) { $ret['more']['msgDesc'] = ''; } return $ret; }
/** * saveTransactionDB saves data to Transactions table in db * @return bool db Success or Failure */ protected function saveTransactionsDB($TRX = FALSE) { $tbl = new Application_Model_DbTable_Transactions(Np_Db::master()); if ($TRX != FALSE) { $trxNo = $TRX; } else { $trxNo = $this->request->getHeaderField("TRX_NO"); } $msgType = $this->request->getHeaderField("MSG_TYPE"); $portTime = $this->request->getBodyField('PORT_TIME'); $rejectReasonCode = $this->request->getRejectReasonCode(); $reqId = $this->request->getHeaderField('REQUEST_ID'); if ($trxNo) { $data = array('trx_no' => $trxNo, 'request_id' => $reqId, 'message_type' => $msgType, 'ack_code' => $this->request->getAck(), 'target' => $this->request->getHeaderField("TO")); if (!$rejectReasonCode || $rejectReasonCode === NULL || $rejectReasonCode == "") { // do nothing } else { $data['reject_reason_code'] = $rejectReasonCode; } if ($msgType == "Update" || $msgType == "Request") { $data['requested_transfer_time'] = Application_Model_General::getDateTimeInSqlFormat($portTime); } if ($msgType == "Publish") { $data['donor'] = Application_Model_General::getDonorByReqId($reqId); } $res = $tbl->insert($data); return $res; } else { //this request if from internal - have to add trx_no //save to Transactions table trx_no has to be consisten to id of the table $adapter = $tbl->getAdapter(); $adapter->beginTransaction(); try { $temp_trx_no = Application_Model_General::createRandKey(14); if (isset($this->data['request_id'])) { $reqId = $this->data['request_id']; } $row_insert = array('trx_no' => $temp_trx_no, 'request_id' => $reqId, 'message_type' => $this->request->getHeaderField("MSG_TYPE"), 'ack_code' => $this->request->getAck(), 'target' => $this->request->getHeaderField("TO")); if (!$rejectReasonCode || $rejectReasonCode === NULL || $rejectReasonCode == "") { // do nothing } else { $row_insert['reject_reason_code'] = $rejectReasonCode; } if ($msgType == "Update" || $msgType == "Request" || $msgType == "Check" && Application_Model_General::isAutoCheck($reqId)) { $row_insert['requested_transfer_time'] = Application_Model_General::getDateTimeInSqlFormat($portTime); } if ($msgType == "Publish") { $row_insert['donor'] = Application_Model_General::getDonorByReqId($reqId); } $_id = $tbl->insert($row_insert); $id = substr("00000000000" . $_id, -12, 12); $trx_no = Application_Model_General::getSettings('InternalProvider') . $id; $ret = $tbl->update(array('trx_no' => $trx_no), "id = " . $_id); $this->request->setTrxNo($trx_no); $adapter->commit(); return true; } catch (Exception $e) { error_log("Error on create record in transactions table: " . $e->getMessage()); $adapter->rollBack(); return false; } } }
/** * * @param type $reqID the request id * @param type $requestedTransferTime the requested port time * @param type $msgType the transaction message type * @return type Number of rows affected */ public static function updateTransactions($reqID, $requestedTransferTime, $msgType) { $tbl = new Application_Model_DbTable_Transactions(Np_Db::master()); $update_arr = array('requested_transfer_time' => Application_Model_General::getDateTimeInSqlFormat($requestedTransferTime)); $where_arr = array('request_id =?' => $reqID, 'message_type =?' => $msgType); $res = $tbl->update($update_arr, $where_arr); return $res; }