public List<Tuple<string, string>> IsValid(out customer_account receiver)
        {
            var api = GoPlayApi.Instance;
            List<Tuple<string, string>> errors = new List<Tuple<string,string>>();

            receiver = api.GetUserById(this.receiverId).Data;
            if (receiver == null)
            {
                Tuple<string, string> error = new Tuple<string, string>(GoPlayConstantValues.S_RECEIVER_ID, ErrorCodes.RECEIVER_ACCOUNT_NOT_EXIST.ToErrorMessage());
                errors.Add(error);
            }
            else if (this.receiverId == this.senderId)
            {
                Tuple<string, string> error = new Tuple<string, string>(GoPlayConstantValues.S_RECEIVER_ID, ErrorCodes.SENDING_TO_SELF.ToErrorMessage());
                errors.Add(error);
            }

            if (playTokenAmount < GoPlayConstantValues.D_MIN_AMOUNT
                || this.maxAmount < playTokenAmount)
            {
                Tuple<string, string> error = new Tuple<string, string>(GoPlayConstantValues.S_PLAY_TOKEN_AMOUNT, ErrorCodes.INSUFFICIENT_PLAY_TOKEN_AMOUNT.ToErrorMessage());
                errors.Add(error);
            }
            else
            {
                Regex re = new Regex(GoPlayConstantValues.S_DECIMAL_REGEX);
                if (!re.IsMatch(playTokenAmount.ToString()))
                {
                    Tuple<string, string> error = new Tuple<string, string>(GoPlayConstantValues.S_PLAY_TOKEN_AMOUNT, ErrorCodes.INVALID_DECIMAL_PRECISION.ToErrorMessage());
                    errors.Add(error);
                }
            }

            return errors;
        }
示例#2
0
       public static Profile GetForm(customer_account user)
       {
           if (user == null)
               return null;

           Profile profile = new Profile
           {
               uid = user.id,
               account = user.username,
               email = user.email,
               nickname = user.nickname,
               gender = user.gender,
               vip = user.vip,
               avatar = user.GetValidAvatarUrl(),
               country_code = user.country_code,
               bio = user.bio ?? string.Empty,
               gtoken = user.play_token,
               free_gtoken = user.free_play_token,
               goplay_token = user.play_token,
               free_goplay_token = user.free_play_token
           };

           profile = Helper.FullFillEmptyFields<Profile>(profile);

           return profile;
       }
示例#3
0
 public decimal getPrice(customer_account user = null)
 {
     if (user == null || !user.HasDiscount())
     {
         return this.price.Value;
     }
     return Math.Round(this.price.Value * 0.9m, 2);
 }
示例#4
0
 public decimal? GetPlayToken(customer_account user = null)
 {
     if (user == null || !user.HasDiscount())
         return this.play_token_amount;
     if (!this.price.HasValue)
         return null;
     var price = this.price.Value * (decimal)1.1;
     return Math.Round(price, 2);
 }
 public BaseExchangeHandler(customer_account user, Game game, dynamic exchangeOption, int amount, IPAddress ip)
 {
     this.user = user;
     this.game = game;
     this.exchangeOption = exchangeOption;
     this.inGameAmount = amount;
     this.coinTransaction = null;
     this.creditTransaction = null;
     this.ip = ip;
 }
示例#6
0
 public Result<Package> RetrieveExchangeHandler(customer_account user,
     Game game, decimal amount, CreditType creditType = null, GoPlay.Models.Package package = null)
 {
     //    var exchangeHandlers = {
     //    '8b1d8776e813536ecfy': MineManiaExchangeHandler,
     //    'ob5d4579e123381ecfy': SushiZombieExchangeHandler,
     //    '853461dsfwdgf85m0op': SlamdunkExchangeHandler,
     //    'c4c8d825a0ee6a78': FishingHeroExchangeHandler
     //        return exchangeHandlers.get(game.guid, StandardExchangeHandler)(user, game, exchangeOption, amount)
     //}
     return null;
 }
示例#7
0
        public Tuple<decimal, decimal> calculatePlayToken(customer_account user, decimal purchaseAmount)
        {
            /*  If the exchange option allows free play Token:
                Calculate the maximum purchase capacity with free Play Token
                If capacity is sufficient, purchase all with free Play Token
                Else purchase with free Play Token as much as possible, push the rest to Play Token balance

              Given the purchase amount, be it the whole if free Play Token isn't allowed or is zero, or the remaining amount after free Play Token purchase
              Calculate the maximum purchase capacity with Play Token
              if capacity is sufficient, purchase with Play Token
              Else the balance is insufficient, return (0, 0)

              :return: Return a tuple of (freePlayToken, playToken) which indicates how much the transaction will cost the use
              if (0, 0) is return, the balance is insufficient */

            if (this.free_exchange_rate.HasValue && this.free_exchange_rate.Value > 0)
            {
                var maxCapacity = this.calculateInGameAmount(user.free_play_token.Value, "free_play_token");
                maxCapacity = Math.Round(maxCapacity, 2);
                if (maxCapacity >= purchaseAmount)
                {
                    var freePlayToken = purchaseAmount / this.free_play_token_value;
                    freePlayToken = Math.Round(freePlayToken, 3);
                    return Tuple.Create(freePlayToken, 0m);
                }
            }

            if (this.exchange_rate.HasValue && this.exchange_rate.Value > 0)
            {
                var maxCapacity = calculateInGameAmount(user.play_token.Value, "play_token");
                maxCapacity = Math.Round(maxCapacity, 2);
                if (maxCapacity >= purchaseAmount)
                {
                    var playToken = purchaseAmount / play_token_value;
                    playToken = Math.Round(playToken, 3);
                    return Tuple.Create(0m, playToken);
                }

            }
            return Tuple.Create(0m, 0m);
        }
示例#8
0
 public static CustomerAccountProfile GetForm(customer_account user)
 {
     if (user == null)
         return null;
     return new CustomerAccountProfile
     {
         uid = user.id,
         account = user.username,
         email = user.email,
         nickname = user.nickname,
         gender = user.gender,
         vip = user.vip,
         avatar = user.GetValidAvatarUrl(),
         country_code = user.country_code,
         bio = user.bio ?? string.Empty,
         gtoken = user.play_token,
         free_gtoken = user.free_play_token,
         goplay_token = user.play_token,
         free_goplay_token = user.free_play_token
     };
 }
示例#9
0
        public void AddActiveGamerScheme(customer_account customer, coin_transaction coinTransaction)
        {
            var repo = Repo.Instance;
            using (var db = repo.OpenConnectionFromPool())
            {
                var reward = repo.GetActiveGamerScheme(db, customer.id).Data;
                if (reward == null)
                {
                    customer_account inviter = repo.GetCustomerByUserName(db, customer.inviter_username).Data;
                    reward = new active_gamer_scheme
                    {
                        customer_account_id = customer.id,
                        inviter_id = inviter.id,
                        balance = 0
                    };
                    repo.CreateActiveGamerScheme(db, reward);
                }

                if (reward.is_archived)
                    return;

                reward.balance += coinTransaction.amount;
                repo.UpdateActiveGamerScheme(db, reward);
            }
        }
示例#10
0
        public bool SetPassword(customer_account user, string password)
        {
            string salt = BCryptHelper.GenerateSalt();
            string hashpwd = BCryptHelper.HashPassword(password, salt);
            byte[] bytes = System.Text.Encoding.Default.GetBytes(hashpwd);

            string pwd = System.Text.Encoding.UTF8.GetString(bytes);
            string unhashed_pwd = password;

            var repo = Repo.Instance;
            using (var db = repo.OpenTransactionFromPool())
            {
                return repo.UpdateUserPassword(db, user.id, pwd, unhashed_pwd);
            }
        }
示例#11
0
        public string GenPasswordResetCode(customer_account customer)
        {
            var repo = Repo.Instance;
            using (var db = repo.OpenConnectionFromPool())
            {
                var verificationTokens = repo.GetValidVerificationToken(db, customer.id).Data;
                if (verificationTokens != null && verificationTokens.Any())
                {
                    foreach (var item in verificationTokens)
                    {
                        repo.UpdateVerificationStatus(db, item.customer_account_id, false);
                    }
                }

                var verificationToken = new verification_token()
                {
                    code = Guid.NewGuid().ToString(),
                    customer_account_id = customer.id,
                    is_valid = true
                };

                if (repo.CreateVerificationToken(db, verificationToken))
                    return verificationToken.code;
            }
            return string.Empty;
        }
示例#12
0
        public void AddInviter(string gtokenSession, customer_account self, int inviter_id, string inviter_username)
        {
            self.inviter_username = inviter_username;
            self.referred_at = DateTime.UtcNow;
            SendRequest(gtokenSession, self.id, inviter_id, ConstantValues.S_ACCEPTED);

            var repo = Repo.Instance;
            using (var db = repo.OpenConnectionFromPool())
            {
                Repo.Instance.UpdateCustomerAccount(db, self.id, inviter_username, self.referred_at.Value);
            }

        }
 private void checkUserLocale(GoPlayApi api, customer_account user)
 {
     if (Session["locale"] != null)
     {
         if (user.locale != Session["locale"].ToString())
         {
             api.SetUserLocale(user.id, Session["locale"].ToString());
         }
     }
 }
        private async Task<ActionResult> loginUser(GoPlayApi api, customer_account user, string returnURL, bool remember_account)
        {
            checkUserLocale(api, user);
            var applicationUser = new ApplicationUser()
            {
                Id = user.id,
                Email = user.email,
                UserName = user.username
            };

            await SignInAsync(applicationUser, remember_account);
            if (string.IsNullOrEmpty(user.country_code) || user.country_code == "ZW")
            {
                IPAddress ip = WebIpHelper.GetClientIp(Request);
                if (ip.Equals(IPAddress.Parse("127.0.0.1")))
                {
                    user.country_code = "SG";
                    user.country_name = "Singapore";
                }
                else
                {
                    ip.GetCountryCode(c => user.country_code = c, n => user.country_name = n);
                }
            }
            api.UpdateCustomerAccount(user.id, user.country_code, user.country_name, DateTime.UtcNow);


            if (!String.IsNullOrEmpty(returnURL))
            {
                return RedirectToLocal(returnURL);
            }
            return Redirect("Profile");
        }
示例#15
0
        public static BaseExchangeHandlerInterface retrieveExchangeHandler(customer_account user, Game game, dynamic exchangeOption, int amount, IPAddress ip)
        {
            var exchangeHandlers = new Dictionary<string, BaseExchangeHandlerInterface>();
            exchangeHandlers.Add("8b1d8776e813536ecfy", new MineManiaExchangeHandler(user, game, exchangeOption, amount, ip));
            exchangeHandlers.Add("ob5d4579e123381ecfy", new SushiZombieExchangeHandler(user, game, exchangeOption, amount, ip));
            exchangeHandlers.Add("853461dsfwdgf85m0op", new SlamdunkExchangeHandler(user, game, exchangeOption, amount, ip));
            exchangeHandlers.Add("c4c8d825a0ee6a78", new FishingHeroExchangeHandler(user, game, exchangeOption, amount, ip));

            if (exchangeHandlers.Keys.Contains(game.guid))
            {
                return exchangeHandlers[game.guid];
            }
            return new StandardExchangeHandler(user, game, exchangeOption, amount, ip);

        }
示例#16
0
 public void Calculate(dynamic generic,
     out decimal freePlaytoken,
     out decimal playtoken,
     customer_account user, int in_game_amount)
 {
     CalculatePlayToken(generic, out freePlaytoken, out playtoken, user, in_game_amount);
 }
示例#17
0
        public bool ExchangeHandlerValidation(dynamic exchangeOption,
            out List<Tuple<string, string>> result,
            Game game, customer_account user)
        {
            result = new List<Tuple<string, string>>();
            if (exchangeOption == null)
            {
                result.Add(Tuple.Create<string, string>("exchange_option_id", "Exchange Option has been removed"));
                return false;
            }

            if (exchangeOption.is_archived)
            {
                result.Add(Tuple.Create<string, string>("exchange_option_id", "Exchange Option has been removed"));
            }

            if (exchangeOption.game != game.id)
            {
                result.Add(Tuple.Create<string, string>("exchange_option_id", "Exchange Option does not belong to game"));
            }

            RBAC rbac = new RBAC(CurrentUser.Id);
            if (!rbac.HasRole(GoPlayConstantValues.S_ROLE_GAME_ADMIN) && !rbac.HasRole(GoPlayConstantValues.S_ROLE_ADMIN))
            {
                if (!game.is_active || game.is_archived)
                {
                    result.Add(Tuple.Create<string, string>("exchange_option_id", "Exchange Option has been removed"));
                }
            }

            int in_game_amount = 0;
            bool isParse = Int32.TryParse(exchangeOption.inGameAmount, out in_game_amount);
            if (!isParse)
            {
                result.Add(Tuple.Create<string, string>("exchange_option_id", "Exchange amount needs to be a positive integer"));
            }

            if (in_game_amount == 0)
            {
                result.Add(Tuple.Create<string, string>("exchange_option_id", "Exchange amount is required"));
            }

            if (!result.Any())
            {
                decimal freePlayToken = 0;
                decimal playToken = 0;
                GoPlayApi.Instance.Calculate(exchangeOption, out freePlayToken, out playToken,
                    user, in_game_amount);

                if (playToken == 0 && freePlayToken == 0)
                    result.Add(Tuple.Create<string, string>("exchange_option_id", "Insufficient Balance"));
                else
                    return true;
            }

            return false;
        }
示例#18
0
        public void CalculatePlayToken(dynamic generic,
            out decimal freePlaytoken, out decimal playtoken,
            customer_account user, decimal purchaseAmount)
        {
            freePlaytoken = 0;
            playtoken = 0;
            if (generic.free_exchange_rate > 0)
            {
                decimal maxCapacity = CalculateInGameAmount(generic, user.free_play_token.Value, "free_play_token");
                maxCapacity = Math.Round(maxCapacity, 2);

                if (maxCapacity >= purchaseAmount)
                {
                    freePlaytoken = Math.Round(purchaseAmount / generic.free_exchange_rate, 3);
                    playtoken = 0;
                    return;
                }
            }

            if (generic.exchange_rate > 0)
            {
                decimal maxCapacity = CalculateInGameAmount(generic, user.play_token.Value, "play_token");
                maxCapacity = Math.Round(maxCapacity, 2);

                if (maxCapacity >= purchaseAmount)
                {
                    playtoken = Math.Round(purchaseAmount / generic.exchange_rate, 3);
                    freePlaytoken = 0;
                    return;
                }
            }
        }
示例#19
0
        public SlamdunkExchangeHandler(customer_account user, Game game, object exchangeOption, int amount, IPAddress ip)
            : base(user, game, exchangeOption, amount, ip)
        {

        }
        private string CreateGTokenTransaction(coin_transaction coinTransaction, GtokenPackage package, customer_account user, decimal totalAmount)
        {
            var gTokenTransaction = GoPlayApi.Instance.CreateGTokenTransaction(new GTokenTransaction
            {
                username = CurrentUser.UserName,
                order_id = coinTransaction.order_id,
                original_price = package.getPrice(user),
                original_final_amount = totalAmount,
                original_currency = ConstantCommon.DEFAULT_PAYPAL_CURRENCY,
                currency = ConstantValues.S_CURRENCY_SGD,
                discount_percentage = user.HasDiscount() ? 0.1m : 0,
                payment_method = "PayPal",
                description = coinTransaction.description,
                status = ConstantValues.S_PENDING,
                revenue_percentage = decimal.Parse(ConfigurationManager.AppSettings["REVENUE_PERCENTAGE"].ToString())
            });

            if (!gTokenTransaction.Succeeded)
            {
                return string.Empty;
            }

            return gTokenTransaction.Data.transaction.gtoken_transaction_id;
        }