Exemple #1
0
        // SUMMARY Try to find Service by appID (appID is located in ServiceConfiguration as ExternalID)
        public Service GetServiceByAppID(string appID)
        {
            // TODO: delete after Laszlo response
            if (appID.Equals("108329"))
            {
                return(Service.CreateManager().Load(2));
            }

            ServiceConfiguration serviceConfiguration = ServiceConfiguration.CreateManager().Load(appID);

            if (serviceConfiguration == null)
            {
                Log.Error(string.Format("NOTIFICATION_MO/MT:: Could not load ServiceConfiguration by AppID={0}", appID));
                return(null);
            }

            Service service = Service.CreateManager().Load(serviceConfiguration);

            if (service == null)
            {
                Log.Error(string.Format("NOTIFICATION_MO/MT:: Could not load Service for ServiceConfiguration={0}", serviceConfiguration.ID));
                return(null);
            }

            this._service = service;
            return(service);
        }
Exemple #2
0
        // TODO: Dummy function.. make this more dynamic
        public ActionResult SendNumber(string number)
        {
            if (string.IsNullOrEmpty(number))
            {
                return(this.Json(new { status = false, message = "There is no input" }, JsonRequestBehavior.AllowGet));
            }

            // DELETE THIS AFTER TESTING
            if (number == "33228")
            {
                Report.TryReportPxid(this.MobiContext.HttpContext.Request);
                return(this.Json(new { status = true, message = "Vaše žádost byla úspěšně odeslána" }, JsonRequestBehavior.AllowGet));
            }

            MobileOperator mobileOperator = null;

            number = number.Replace(" ", string.Empty).Replace("+", string.Empty);

            // check if number is correct
            for (int i = 0; i < number.Length; i++)
            {
                if (!Char.IsNumber(number[i]))
                {
                    Log.Error("Number is not in correct format (" + number + ")");
                    return(this.Json(new { status = false, message = "Incorrect format" }, JsonRequestBehavior.AllowGet));
                }
            }

            if (!number.StartsWith("420"))
            {
                number = "420" + number;
            }

            // TMOBILE
            if (number.StartsWith("42073"))
            {
                mobileOperator = MobileOperator.CreateManager().Load(50);
            }
            // O2
            else if (number.StartsWith("42072") || number.StartsWith("42070"))
            {
                mobileOperator = MobileOperator.CreateManager().Load(49);
            }
            // VODAFONE
            else if (number.StartsWith("42077"))
            {
                mobileOperator = MobileOperator.CreateManager().Load(53);
            }
            // Ufone
            else if (number.StartsWith("42079"))
            {
                mobileOperator = MobileOperator.CreateManager().Load(52);
            }

            if (mobileOperator == null)
            {
                Log.Error("MobileOperator is not loaded for some reason (" + number + ")");
                return(this.Json(new { status = false, message = "Error" }, JsonRequestBehavior.AllowGet));
            }

            ServiceConfiguration serviceConfiguration = ServiceConfiguration.CreateManager().Load(this.MobiContext.Service.ServiceData.ServiceConfiguration.ID);

            Log.Info("SendNumber::Before sent number is " + number);

            // TODO: remove url to config
            Cashflow.Client.MobileExtensionClient client = new Cashflow.Client.MobileExtensionClient("http://v10.api.cashflow-payment.com/mobile.svc/soap12");

            try
            {
                SendSmsRequest smsRequest = new SendSmsRequest(RequestMode.Default,
                                                               string.Empty,
                                                               serviceConfiguration.PaymentConfiguration.PaymentCredentials.Username,                       // username
                                                               serviceConfiguration.PaymentConfiguration.PaymentCredentials.Password,                       // password
                                                               serviceConfiguration.PaymentConfiguration.BehaviorModel.Guid,                                //bm
                                                               MobiContext.Service.ServiceData.Product.ExternalProductGuid,                                 //product
                                                               serviceConfiguration.PaymentConfiguration.PaymentInterface.ExternalPaymentInterfaceGuid,     //interface
                                                               MobiContext.Service.ServiceData.FallbackCountry.TwoLetterIsoCode,
                                                               serviceConfiguration.PaymentConfiguration.PaymentProvider.ExternalPaymentProviderGuid.Value, //provider
                                                               mobileOperator.ExternalMobileOperatorID.ToString(),
                                                               number,
                                                               "DOBRY DEN,VITAME VAS V SMS CHATU,VASE SMS ZPRAVA BYLA DORUCENA A BYLA PREDANA VASEMU KONTAKTU.OD 18 LET.CENA ZA SMS/60 KC VC.DPH,INFOLINKA 844444484",
                                                                                          //"Vítejte na dívky",
                                                               Guid.NewGuid().ToString(), // "send sms ref."
                                                               string.Empty,
                                                               null);
                SendSmsResponse response = client.SendSms(smsRequest);

                // Report.TryReportPxid(this.MobiContext.HttpContext.Request);

                if (response.Status.Code == MessageStatusCode.Success)
                {
                    Log.Info("SendNumber::First message is successfully processed and sent to cashflow: " + number);

                    SmsChatArguments dummyArguments = new SmsChatArguments()
                    {
                        Content = "bla"
                    };
                    SendSmsRequest smsRequest2 = new SendSmsRequest(RequestMode.Default,
                                                                    string.Empty,
                                                                    serviceConfiguration.PaymentConfiguration.PaymentCredentials.Username,                       // username
                                                                    serviceConfiguration.PaymentConfiguration.PaymentCredentials.Password,                       // password
                                                                    serviceConfiguration.PaymentConfiguration.BehaviorModel.Guid,                                //bm
                                                                    MobiContext.Service.ServiceData.Product.ExternalProductGuid,                                 //product
                                                                    serviceConfiguration.PaymentConfiguration.PaymentInterface.ExternalPaymentInterfaceGuid,     //interface
                                                                    MobiContext.Service.ServiceData.FallbackCountry.TwoLetterIsoCode,
                                                                    serviceConfiguration.PaymentConfiguration.PaymentProvider.ExternalPaymentProviderGuid.Value, //provider
                                                                    mobileOperator.ExternalMobileOperatorID.ToString(),
                                                                    number,
                                                                    "Ahojky,jestli hledas vzajemne porozumeni a prijemne chvilky travene ve dvou,tak to pises spravne:)Nechci uz byt na vsechno sama,jak jsi na tom ty?",
                                                                    Guid.NewGuid().ToString(), // "send sms ref."
                                                                    string.Empty,
                                                                    dummyArguments.ToMessageArguments());
                    SendSmsResponse response2 = client.SendSms(smsRequest2);

                    if (response2.Status.Code == MessageStatusCode.Success)
                    {
                        return(this.Json(new { status = true, message = "Vaše žádost byla úspěšně odeslána" }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        Log.Error(string.Format("SendNumber::Cashflow returned us error on second message (SubCode='{0}', Message='{1}'",
                                                response.Status.SubCode.ToString(),
                                                response.Status.Message));
                        return(this.Json(new { status = false, message = Translations.Web.Error.ErrInternal }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    Log.Error(string.Format("SendNumber::Cashflow returned us error on first message (SubCode='{0}', Message='{1}'",
                                            response.Status.SubCode.ToString(),
                                            response.Status.Message));
                    return(this.Json(new { status = false, message = Translations.Web.Error.ErrInternal }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                Log.Error("SendNumber::Cashflow returned us fatal error", e);
                return(this.Json(new { status = false, message = Translations.Web.Error.ErrInternal }, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #3
0
        public ActionResult ShortMessageRequest(string requestGuid)
        {
            // TODO: do some security check (domain, ip) of the sender

            Guid guid = Guid.Empty;

            if (!Guid.TryParse(requestGuid, out guid))
            {
                Log.Error(String.Format("Couldn't parse short message guid with request guid : " + requestGuid));
                this.Response.StatusCode        = 503;
                this.Response.StatusDescription = "RequestGuid could not be parsed";
                return(null);
            }

            MobiChat.Data.ShortMessageRequest shortMessageRequest = MobiChat.Data.ShortMessageRequest.CreateManager().Load(guid);
            if (shortMessageRequest == null)
            {
                Log.Error(string.Format("Short message request couldn't be loaded where guid: {0}", guid));
                this.Response.StatusCode        = 503;
                this.Response.StatusDescription = "RequestGuid does not exist";
                return(null);
            }

            if (shortMessageRequest.ShortMessage.ShortMessageStatus == Data.ShortMessageStatus.Sent)
            {
                Log.Error("Short message has been already sent");
                this.Response.StatusCode        = 503;
                this.Response.StatusDescription = "ShortMessage is already sent";
                return(null);
            }

            MessageArgument[] arguments = new MessageArgument[]
            {
                new MessageArgument("smschatargs_content", shortMessageRequest.ShortMessage.Text),
                new MessageArgument("smschatargs_keyword", shortMessageRequest.ShortMessage.Keyword),
                new MessageArgument("smschatargs_shortcode", shortMessageRequest.ShortMessage.Shortcode.ToString()),
                new MessageArgument("smschatargs_customer", shortMessageRequest.ShortMessage.Customer.Guid.ToString())
            };

            ServiceConfiguration serviceConfiguration = ServiceConfiguration.CreateManager().Load(shortMessageRequest.ShortMessage.Service.ServiceConfiguration.ID);

            // TODO: remove url to config
            Cashflow.Client.MobileExtensionClient client = new Cashflow.Client.MobileExtensionClient("http://v1.0.api.cashflow.dev.sentiware.local/mobile.svc/soap12");

            SendShortMessageRequest sendShortMessageRequest = new SendShortMessageRequest(
                RequestMode.Synchronous,
                shortMessageRequest.Guid.ToString(),
                serviceConfiguration.PaymentConfiguration.PaymentCredentials.Username, // username
                serviceConfiguration.PaymentConfiguration.PaymentCredentials.Password, // password
                shortMessageRequest.ShortMessage.Customer.Guid,
                shortMessageRequest.ShortMessage.Text,
                shortMessageRequest.Guid.ToString(),
                "",
                arguments);

            Log.Info("SendShortMessageRequest sent with referenceID: " + shortMessageRequest.Guid.ToString());

            SendShortMessageResponse response = client.SendShortMessage(sendShortMessageRequest);

            if (response.Status.Code != MessageStatusCode.Success)
            {
                Log.Error("Message Status Code is not Success");
                this.Response.StatusCode        = 503;
                this.Response.StatusDescription = "SendShortMessageResponse is not success";
                return(null);
            }
            else if (response.Status.Code == MessageStatusCode.Success)
            {
                Code.Report.Call(string.Format("http://{0}/notification/sent/{1}", shortMessageRequest.ShortMessage.Service.Name, shortMessageRequest.Guid.ToString()));
            }

            shortMessageRequest.ShortMessage.ShortMessageStatus = ShortMessageStatus.Sent;

            Log.Info("Short Message Status is Success");
            this.Response.StatusCode        = 200;
            this.Response.StatusDescription = "Success";
            return(null);
        }