Ejemplo n.º 1
0
        private bool ClearCache(string cacheKey, ref MoUssdReceiver receiver)
        {
            bool clearCache;

            this._configurationHelper.ClearCache(cacheKey);
            clearCache       = true;
            receiver.Message = "0";
            return(clearCache);
        }
Ejemplo n.º 2
0
        /*
         * Get the session id and Response message as parameter
         * Create sender object and send ussd with appropriate parameters
         **/

        private string loadObjectSender(string sessionId, string responseMessage, MoUssdReceiver receiver, string chargingAmount = "0")
        {
            string password           = _configurationHelper.Password; // Configuration.GetSection("BDApps:password").Value;
            string destinationAddress = receiver.SourceAddress;
            string ussdOperation      = string.Empty;

            if (!string.IsNullOrEmpty(sessionId))
            {
                ussdOperation = receiver.UssdOperation;
                if (receiver.Message == "0")
                {
                    ussdOperation = "mt-fin";
                }
                else
                {
                    ussdOperation = "mt-cont";
                }
            }
            string applicationId = receiver.ApplicationId;
            string encoding      = receiver.Encoding;
            string version       = receiver.Version;

            try
            {
                // Create the sender object server url
                string       ussdServer = _configurationHelper.MtUssdSenderServer; // Configuration.GetSection("BDApps:MtUssdSenderServer").Value;
                string       smsServer  = _configurationHelper.MtSmsSenderServer;  // Configuration.GetSection("BDApps:MtSmsSenderServer").Value;
                string       response   = string.Empty;
                MtUssdSender sender     = new MtUssdSender(ussdServer, smsServer); // Application ussd-mt sending http url

                if (string.IsNullOrEmpty(sessionId))
                {
                    chargingAmount = this._configurationHelper.SmsChargeAmount;
                    response       = sender.sms(applicationId, password, version, responseMessage,
                                                destinationAddress, encoding, chargingAmount);
                }
                else
                {
                    response = sender.ussd(applicationId, password, version, responseMessage,
                                           sessionId, ussdOperation, destinationAddress, encoding, chargingAmount);
                }
                return(response);
            }
            catch (Exception ex)
            {
                //throws when failed sending or receiving the ussd
                //error_log("USSD ERROR: {ex->getStatusCode()} | {ex->getStatusMessage()}");
                //return null;
                throw ex;
            }
        }
Ejemplo n.º 3
0
        public string SendIndivualSMSNotificationByMSISDN(string subscriber)
        {
            string         pbNumbers   = this.GetAllDrawNumbersBySubscriberId(subscriber);
            string         response    = this._configurationHelper.SmsKeyword + " " + pbNumbers;
            MoUssdReceiver smsReceiver = new MoUssdReceiver();

            smsReceiver.ApplicationId = this._configurationHelper.ApplicationId;
            smsReceiver.Password      = this._configurationHelper.Password;
            smsReceiver.SourceAddress = "tel:" + subscriber;
            smsReceiver.Message       = response;
            smsReceiver.Version       = "1.0";
            smsReceiver.Encoding      = "0";

            return(this.SendMessage(smsReceiver));
        }
Ejemplo n.º 4
0
        private string GetSubscriptionMenu(MoUssdReceiver receiver, string prevMsg, string message)
        {
            if (prevMsg == _configurationHelper.MenuLevel1 && receiver.getMessage() != "0")
            {
                if (receiver.getMessage().ToUpper().StartsWith(_configurationHelper.SmsKeyword))
                {
                    message = _configurationHelper.MenuLevel2;
                }
                else
                {
                    throw new Exception("Invalid Format.");
                }
            }

            return(message);
        }
Ejemplo n.º 5
0
        private string GetSubscriptionConfirmationMenu(MoUssdReceiver receiver, string message)
        {
            if (receiver.getMessage() == "1") //// Subscribe
            {
                message = _configurationHelper.MenuLevel3;
            }
            else if (receiver.getMessage() == "2") //// unsubscribe
            {
                message = _configurationHelper.MenuLevel4;
            }
            else if (receiver.getMessage() == "3") //// add more
            {
                message = _configurationHelper.MenuLevel1;
            }

            return(message);
        }
Ejemplo n.º 6
0
        private void RunCheckerProcess(MoUssdReceiver receiver, string cacheKey, ref bool clearCache, ref string response, ref string message, string sessionId)
        {
            var numbers = receiver.getMessage();

            if (string.IsNullOrEmpty(sessionId))// for SMS check
            {
                string smsKeyword            = _configurationHelper.SmsKeyword;
                string subscriptionKeyword   = _configurationHelper.SubscriptionKeyword;
                string unSubscriptionKeyword = _configurationHelper.UnSubscriptionKeyword;

                if (numbers.ToUpper().Trim().Contains(subscriptionKeyword))
                {
                    string chargeAmount = _configurationHelper.SubscriptionChargeAmount;
                    UpdateSubscription(receiver.SourceAddress, true);
                    message    = _configurationHelper.SubscriptionConfirmMsg + _configurationHelper.UnSubscriptionMsg;
                    response   = loadObjectSender(sessionId, message, receiver, chargeAmount);
                    clearCache = ClearCache(cacheKey, ref receiver);
                }
                else if (numbers.ToUpper().Trim().Contains(unSubscriptionKeyword))
                {
                    UpdateSubscription(receiver.SourceAddress, false);
                    message = _configurationHelper.UnSubscriptionConfirmMsg;
                }
                else if (numbers.ToUpper().Trim().Contains(smsKeyword))
                {
                    message = _configurationHelper.SMSLevel1;
                    message = CheckPBNumbers(numbers) + "\r\n" + message;
                }
                else
                {
                    message = receiver.getMessage();
                }
            }
            else
            {
                message = CheckPBNumbers(numbers) + "\r\n" + message;
            }
        }
        public MoUssdReceiver(MoUssdReceiver moUssdReceiver)
        {
            this.SourceAddress = moUssdReceiver.SourceAddress;
            this.Message       = moUssdReceiver.Message;
            this.RequestId     = moUssdReceiver.RequestId;
            this.ApplicationId = moUssdReceiver.ApplicationId;
            this.Encoding      = moUssdReceiver.Encoding;
            this.Version       = moUssdReceiver.Version;
            this.SessionId     = moUssdReceiver.SessionId;
            this.UssdOperation = moUssdReceiver.UssdOperation;
            this.VlrAddress    = moUssdReceiver.VlrAddress;

            if (!((string.IsNullOrEmpty(this.SourceAddress) && string.IsNullOrEmpty(this.Message))))
            {
                throw new Exception("Some of the required parameters are not provided");
            }
            else
            {
                // Success received response
                //var responses = array("statusCode" => "S1000", "statusDetail" => "Success");
                //    header("Content-type: application/json");
                //    echo json_encode($responses);
            }
        }
Ejemplo n.º 8
0
        public string SendMessage(MoUssdReceiver receiver)
        {
            //// TODO:: Check http session in netcore
            string cacheKey   = "PrevMsg_" + receiver.SessionId;
            bool   clearCache = false;
            string prevMsg    = _configurationHelper.CacheTryGetValueSet(cacheKey, receiver.Message);
            string response   = string.Empty;
            string message    = string.Empty;
            string sessionId  = receiver.SessionId;
            string dialNo     = _configurationHelper.USSDDialNo;

            if (receiver.getMessage() == dialNo)
            {
                message = _configurationHelper.MenuLevel1;
            }
            else if (prevMsg.Contains(_configurationHelper.MenuLevel2) && receiver.getMessage() != "0")
            {
                message = GetSubscriptionConfirmationMenu(receiver, message);
            }
            else if (prevMsg.Contains(_configurationHelper.MenuLevel3) && receiver.getMessage() == "1")//// Subscriptions
            {
                message = "Thanks for subscription. We will notify you every 3 months after draw.\r\n";

                UpdateSubscription(receiver.getAddress(), true);
                clearCache = ClearCache(cacheKey, ref receiver);
            }
            else if (prevMsg.Contains(_configurationHelper.MenuLevel4) && receiver.getMessage() == "1")//// Subscriptions
            {
                message = "You have unsubcribed successfully";
                UpdateSubscription(receiver.getAddress(), false);
                clearCache = ClearCache(cacheKey, ref receiver);
            }
            else if (receiver.getMessage() == "0")
            {
                string responseExitMsg = "Thanks for using our service.";
                message    = responseExitMsg;
                clearCache = ClearCache(cacheKey, ref receiver);
            }
            else
            {
                try
                {
                    message = GetSubscriptionMenu(receiver, prevMsg, message);

                    RunCheckerProcess(receiver, cacheKey, ref clearCache, ref response, ref message, sessionId);
                }
                catch (Exception ex)
                {
                    message = @"Unable to validate.Please try again. Error:" + ex.Message;
                    ClearCache(cacheKey, ref receiver);
                }
            }

            if (!clearCache)
            {
                _configurationHelper.AddCache(cacheKey, message);
            }

            response = loadObjectSender(sessionId, message, receiver);
            return(response);
        }