Exemple #1
0
        internal void LogTransaction(LoanManagementSystemAPI.Response.COMMAND RESPONSE_COMMAND, decimal?AMOUNT = 0)
        {
            string msg = "";

            try
            {
                var last_accessed = DateTime.Now;
                using (var command = new SqlCommand())
                {
                    command.CommandText = "[usp_SaveTransactionLog]";

                    command.Parameters.AddWithValue("@TYPE", RESPONSE_COMMAND.TYPE);
                    command.Parameters.AddWithValue("@TXNID", RESPONSE_COMMAND.TXNID);
                    command.Parameters.AddWithValue("@MSISDN", RESPONSE_COMMAND.MSISDN);
                    command.Parameters.AddWithValue("@RESULT", RESPONSE_COMMAND.RESULT);
                    command.Parameters.AddWithValue("@ERRORCODE", RESPONSE_COMMAND.ERRORCODE);
                    command.Parameters.AddWithValue("@ERRORDESCRIPTION", RESPONSE_COMMAND.ERRORDESCRIPTION);
                    command.Parameters.AddWithValue("@FLAG", RESPONSE_COMMAND.FLAG);
                    command.Parameters.AddWithValue("@CONTENT", RESPONSE_COMMAND.CONTENT);
                    command.Parameters.AddWithValue("@AMOUNT", AMOUNT);

                    var result = Save(command);

                    msg = result;
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
        }
        public IHttpActionResult PostByMomoNumber([FromBody] COMMAND command)
        {
            if (command == null)
            {
                return(BadRequest("Wrong Input body. Please check and try again"));
            }

            var momotransaction = new MomoTransaction
            {
                AMOUNT              = command.AMOUNT,
                TYPE                = command.TYPE,
                TXNID               = command.TXNID,
                MSISDN              = command.MSISDN,
                COMPANYNAME         = command.COMPANYNAME,
                CUSTOMERREFERENCEID = command.CUSTOMERREFERENCEID
            };

            string responseTime = DateTime.UtcNow.ToString("dd-MM-yyyy h:mm:ss tt");
            var    response     = new LoanManagementSystemAPI.Response.COMMAND
            {
                TYPE   = momotransaction.TYPE,
                TXNID  = momotransaction.TXNID,
                RefID  = momotransaction.RefID,
                MSISDN = momotransaction.MSISDN,
            };

            var isValidRef = services.ValidateCustomerReferenceID(momotransaction.CUSTOMERREFERENCEID);

            if (isValidRef)
            {
                var result = services.PostMomoTransaction(momotransaction);

                if (result == "Success")
                {
                    response.RESULT           = "TS";
                    response.ERRORCODE        = "error000";
                    response.ERRORDESCRIPTION = "Successful transaction";
                    response.FLAG             = "Y";
                    response.CONTENT          = $"Transaction (TXNID: {momotransaction.TXNID}) submitted successfully ({responseTime}).";
                    services.LogTransaction(response, momotransaction.AMOUNT);//this logs transaxtions
                    return(Ok(response));
                }
                else
                {
                    response.RESULT           = "TF";
                    response.ERRORCODE        = "error100";
                    response.ERRORDESCRIPTION = "General Error";
                    response.FLAG             = "N";
                    response.CONTENT          = $"Transaction (TXNID: {momotransaction.TXNID}) has failed ({responseTime}).";
                    services.LogTransaction(response, momotransaction.AMOUNT);
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, response)));
                }
            }
            else
            {
                response.RESULT           = "TF";
                response.ERRORCODE        = "error010";
                response.ERRORDESCRIPTION = "Invalid Customer Reference Number";
                response.FLAG             = "N";
                response.CONTENT          = $"Transaction (TXNID: {momotransaction.TXNID}) has failed ({responseTime}).";
                services.LogTransaction(response, momotransaction.AMOUNT);
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, response)));
            }
        }