예제 #1
0
        public KUser CreateUser(TwilioRequest trequest)
        {
            var u = new KUser
            {
                Mobile = trequest.From,
                Email = _bodyParser.GetSwitchValue("#EMAIL",trequest.Body)
            };

            //var uid = (long)_session.Save(u);

            u = _session.Get<KUser>((long)_session.Save(u));

            var l = new Ledger
            {
                KUserId = u.KUserId,
                MessageSid = trequest.MessageSid,
                Money = 10,
                Description = "Opening bonus",
                TransactionType = "CR"

            };

            _session.Save(l);

            return u;
        }
예제 #2
0
 private decimal GetTransactionNumbers(Ledger arg)
 {
     if (string.Equals(arg.TransactionType, "DR", StringComparison.CurrentCultureIgnoreCase))
     {
         return -arg.Money;
     }
     else if (string.Equals(arg.TransactionType, "CR", StringComparison.CurrentCultureIgnoreCase))
     {
         return arg.Money;
     }
     return arg.Money;
 }
예제 #3
0
        private Response PayUser(TwilioRequest trequest)
        {
            decimal amount;
            var allstrings = trequest.Body.Split(Convert.ToChar(" "));
            if ((allstrings.Count() != 3) || (allstrings[1].Length != 10) || (!decimal.TryParse(allstrings[2], out amount)))
                return _responseManager.GetResponse("INCORRECTPAY", null);
            if (amount > GetBalance(trequest)) return _responseManager.GetResponse("INSUFFICIENTBALANCE", new Dictionary<string, string> { { "amount", Convert.ToString(amount) } });
            var payeeMobile = allstrings[1];
            var payee = _kUserFetcher.GetKUser(payeeMobile) ?? _createKUser.CreateUser(payeeMobile);

            var payerDr = new Ledger
            {
                KUserId = _kUserFetcher.GetKUser(trequest.From).KUserId,
                RelatedKUserId = _kUserFetcher.GetKUser(payee.Mobile).KUserId,
                TransactionType = "DR",
                Money = amount,
                MessageSid = trequest.MessageSid,
                Description = string.Format("Sending money to {0:C}", payeeMobile)
            };

            var payeeCr = new Ledger
            {
                KUserId = _kUserFetcher.GetKUser(payee.Mobile).KUserId,
                RelatedKUserId = _kUserFetcher.GetKUser(trequest.From).KUserId,
                TransactionType = "CR",
                Money = amount,
                MessageSid = trequest.MessageSid,
                Description = string.Format("Receiving money from {0:C}", trequest.To)
            };

            //_session.Save(payee);
            _session.Save(payerDr);
            _session.Save(payeeCr);

            _commClient.SendMessage(payee.Mobile, string.Format("You have received {0:C} from {1}",amount, trequest.From));

            var dict = new Dictionary<string, string>
            {
                {"amount", Convert.ToString(amount)},
                {"bal", Convert.ToString(GetBalance(trequest))}
            };
            return _responseManager.GetResponse("PAYMENTSENT", dict);
        }