/** * method to create request row in the table including unique request id * save to request table request_id has to be consisten to id of the table * * @return mixed request_id string or FALSE */ protected function createRequestId() { $tbl = new Application_Model_DbTable_Requests(Np_Db::master()); $adapter = $tbl->getAdapter(); $adapter->beginTransaction(); try { // we create temp request id because it build from the mysql internal id $temp_request_id = Application_Model_General::createRandKey(21); if (strtoupper($this->params['MSG_TYPE']) != 'UP_SYSTEM' && strtoupper($this->params['MSG_TYPE']) != 'DOWN_SYSTEM') { $row_insert = array('request_id' => $temp_request_id, 'status' => 1, 'last_transaction' => $this->params["MSG_TYPE"], 'phone_number' => $this->params["PHONE_NUMBER"]); if (isset($this->params['MSG_TYPE']) == 'CHECK') { // && isset($this->params['IDENTIFICATION_VALUE'])) { $flags = array(); if (isset($this->params['identification_value'])) { $this->params['identification_value'] = $this->params['IDENTIFICATION_VALUE']; } if (isset($this->params['NUMBER_TYPE'])) { $flags['number_type'] = $this->params['NUMBER_TYPE']; } if (!empty($flags)) { $row_insert['flags'] = json_encode($flags); } } } else { $row_insert = array('request_id' => $temp_request_id, 'status' => 1, 'last_transaction' => $this->params["MSG_TYPE"]); } // we set to from & to as the direction of number transfer if (strtoupper($this->params['MSG_TYPE']) != 'RETURN_NUMBER') { $row_insert['from_provider'] = $this->params["TO_PROVIDER"]; $row_insert['to_provider'] = $this->params["FROM_PROVIDER"]; } else { $row_insert['from_provider'] = $this->params["FROM_PROVIDER"]; $row_insert['to_provider'] = $this->params["TO_PROVIDER"]; } if (isset($this->params["AUTO_CHECK"]) && $this->params["AUTO_CHECK"]) { $row_insert['auto_check'] = 1; // $row_insert['transfer_time'] = Application_Model_General::getDateTimeInSqlFormat($this->params['PORT_TIME']); } $_id = $tbl->insert($row_insert); $id = substr("0000" . $_id, -5, 5); $request_id = "NP" . $this->params['FROM_PROVIDER'] . $this->params['TO_PROVIDER'] . date("ymd") . $id . "0001"; //ZZZZ $tbl->update(array('request_id' => $request_id), "id = " . $_id); $adapter->commit(); return $request_id; } catch (Exception $e) { error_log("Cannot create request ID. Reason: " . $e->getMessage()); $adapter->rollBack(); } return FALSE; }
/** * 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; } } }