public ActionResult resetBalance()
        {
            int playToken = 0;
            Int32.TryParse(Request.Params["play_token"], out playToken);
            int freePlayToken = 0;
            Int32.TryParse(Request.Params["free_play_token"], out freePlayToken);

            var diffPlayToken = playToken - CurrentUser.play_token;

            coin_transaction transaction = new coin_transaction();
            transaction.order_id = Guid.NewGuid().ToString();
            transaction.customer_account_id = CurrentUser.Id;
            transaction.amount = diffPlayToken;
            transaction.description = GoPlayConstantValues.S_RESETBALANCE_DESCRIPTION;
            transaction.status = Helper.GetDescription(TransactionStatus.Success);

            var diffFreePlayToken = freePlayToken - CurrentUser.free_play_token;
            free_coin_transaction freeTransaction = new free_coin_transaction();
            freeTransaction.order_id = Guid.NewGuid().ToString();
            freeTransaction.customer_account_id = CurrentUser.Id;
            freeTransaction.amount = diffFreePlayToken;
            freeTransaction.description = GoPlayConstantValues.S_RESETBALANCE_DESCRIPTION;
            freeTransaction.status = Helper.GetDescription(TransactionStatus.Success);

            var api = GoPlayApi.Instance;
            if (api.CreateCoinTransaction(transaction).Data != null
                && api.CreateFreeCoinTransaction(freeTransaction) > 0)
                this.Flash(string.Format(GoPlayConstantValues.S_RESETBALANCE_SUCCESS, freePlayToken, playToken), FlashLevel.Success);
            else
                this.Flash("Account balance was reset fail", FlashLevel.Error);

            return RedirectToAction("profile", "account");
        }
示例#2
0
 public APIUpointParamModel(coin_transaction trans, string itemDescription = null)
 {
     secret_token = ConfigurationManager.AppSettings["UPOINT_SECRET_TOKEN"];
     Guid order_temp = Guid.NewGuid();
     Guid.TryParse(trans.order_id, out order_temp);
     trx_id = order_temp.ToString("N");//convert guid to hex
     item = !string.IsNullOrEmpty(itemDescription) ? itemDescription : trans.description;
     decimal GtokenRate = 0;
     decimal.TryParse(ConfigurationManager.AppSettings["IDR_PER_GTOKEN_RATE"], out GtokenRate);
     amount = trans.amount.HasValue ? trans.amount.Value * GtokenRate : 0;
 }
示例#3
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);
            }
        }
        public object purchasePlayToken(PartnerViewModel param)
        {
            var api = GoPlayApi.Instance;
            string username = param.username;
            var user = api.GetUserByUserName(username).Data;
            //string status = param.status;
            string token = param.token;
            decimal amount = 0;

            var partner = api.GetPartner(ConfigurationManager.AppSettings["PARTNER_CLIENT_ID"]).Data;
            ErrorCodes? err = null;
            if (partner == null)
            {
                err = ErrorCodes.INVALID_PARTNER_ID;
            }
            else if (user == null)
            {
                err = ErrorCodes.NON_EXISTING_USER;
            }
            else
            {
                string tokenRawString = username + param.amount + partner.client_id;
                string generatedToken = Helper.CalculateMD5Hash(tokenRawString);

                if (generatedToken != token)
                    err = ErrorCodes.INVALID_TOKEN;

                decimal.TryParse(param.amount, out amount);
                if (amount <= 0)
                    err = ErrorCodes.INSUFFICIENT_AMOUNT;
            }
            if (err == null)
            {
                var transaction = new coin_transaction()
                {
                    order_id = Guid.NewGuid().ToString(),
                    customer_account_id = user.id,
                    amount = amount,
                    price = amount,
                    partner_account_id = partner.id,
                    description = string.Format("You received {0} Play Token from {1}", Helper.displayDecimal(amount), partner.name),
                    status = Helper.GetDescription(TransactionStatus.Success)
                };
                var result = api.CreateCoinTransaction(transaction);
                if (!result.HasData)
                    err = result.Error;
                else
                {
                    var tokenTrans = new TokenTransactionJson()
                    {
                        token_type = GoPlayConstantValues.S_PLAY_TOKEN,
                        transaction_type = ConstantValues.S_TRANSACTION_TYPE_CONSUMPTION,
                        username = user.username,
                        order_id = transaction.order_id,
                        description = transaction.description,
                        amount = transaction.amount
                    };
                    api.GTokenAPITransaction(new GtokenModelTransactionAction()
                    {
                        enumAction = EGtokenAction.RecordTransaction,
                        ip_address = Request.UserHostAddress,
                        token_transaction = tokenTrans
                    });
                }

            }

            api.LogApi("1", "/partner/purchase-play-token",
               err == null,
               Request.UserAgent != null ? Request.UserAgent.ToString() : string.Empty,
               0, user == null ? 0 : user.id,
               HttpContext.Request.UserHostAddress,
               err.ToErrorCode(), JsonConvert.SerializeObject(param));

            return JsonConvert.SerializeObject(new
            {
                success = err == null,
                message = err.ToErrorMessage(),
                error_code = err.ToErrorCode()
            });
        }
 /// <summary>
 /// Create full fields
 /// </summary>
 /// <param name="db"></param>
 /// <param name="coinTrans">entity</param>
 /// <returns></returns>
 public int CreateCoinTransaction(IDbConnection db, coin_transaction coinTrans)
 {
     string sql = @"INSERT INTO coin_transaction(
     customer_account_id, receiver_account_id, amount, partner_account_id, 
     game_id, credit_type_id, package_id, description, 
     status, topup_card_id, order_id, payment_method, sender_account_id, 
     gtoken_package_id, paypal_redirect_urls, paypal_payment_id, price, 
     ip_address, country_code, telkom_order_id, use_gtoken)
     VALUES (
     @customer_account_id, @receiver_account_id, @amount, @partner_account_id, 
     @game_id, @credit_type_id, @package_id, @description, 
     @status, @topup_card_id, @order_id, @payment_method, @sender_account_id, 
     @gtoken_package_id, @paypal_redirect_urls, @paypal_payment_id, @price, 
     @ip_address, @country_code, @telkom_order_id, @use_gtoken)
      RETURNING id";
     return db.Query<int>(sql, coinTrans).FirstOrDefault();
 }
        private coin_transaction CreateCoinTrans(decimal playTokenAmount)
        {
            var coinTransaction = new coin_transaction();
            coinTransaction.order_id = Guid.NewGuid().ToString();
            coinTransaction.customer_account_id = this.user.id;
            coinTransaction.amount = -1 * playTokenAmount;
            coinTransaction.game_id = this.game.id;

            if (this.exchangeOption is CreditType)
            {
                coinTransaction.credit_type_id = this.exchangeOption.id;
            }
            else if (this.exchangeOption is Package)
            {
                coinTransaction.package_id = exchangeOption.id;
            }
            coinTransaction.status = "payment_created";
            coinTransaction.description = String.Format("Exchange for {0} in {1}", exchangeOption.name, game.name);

            var country_name = String.Empty;
            ip.GetCountryCode(c => coinTransaction.country_code = c, n => country_name = n);
            coinTransaction.ip_address = ip.ToString();
            var api = GoPlayApi.Instance;

            return api.CreateCoinTransaction(coinTransaction).Data;

        }
 private coin_transaction GenerateCoinTransaction(GtokenPackage package = null)
 {
     bool debug = false;
     bool.TryParse(ConfigurationManager.AppSettings["UPOINT_DEBUG"], out debug);
     decimal? totalAmount = 0;
     decimal? gtokenAmount = 0;
     var transaction = new coin_transaction()
     {
         order_id = Guid.NewGuid().ToString(),
         customer_account_id = 3,//TODO/CurrentUser.Id,
     };
     if (package != null)
     {
         transaction.gtoken_package_id = package.id;
         transaction.description = package.name;
     }
     if (!debug && package != null)
     {
         var user = GoPlayApi.Instance.GetUserById(CurrentUser.Id).Data;
         gtokenAmount = package.GetPlayToken(user);
         totalAmount = package.price;
     }
     transaction.amount = gtokenAmount;
     transaction.price = totalAmount;
     return transaction;
 }
 private void UpdateTransactionFail(coin_transaction trans, string err)
 {
     trans.status = Helper.GetDescription(TransactionStatus.Failure);
     trans.description += "Error: " + err;
     GoPlayApi.Instance.UpdateCoinTransaction(trans.id, trans.status, trans.description, trans.telkom_order_id);
 }
        public coin_transaction CreateCoinTrans(ApplicationUser user, topup_card card)
        {
            var api = GoPlayApi.Instance;
            var transaction = new coin_transaction();
            transaction.order_id = Guid.NewGuid().ToString();
            transaction.customer_account_id = user.Id;
            transaction.amount = card.amount;
            transaction.price = card.amount;
            transaction.payment_method = "Top Up Card";
            transaction.status = "success";
            transaction.description = String.Format("You topped up {0} Play Token", Helper.displayDecimal(card.amount));
            transaction.topup_card_id = card.id;
            transaction.created_at = DateTime.UtcNow;

            IPAddress ip = WebIpHelper.GetClientIp(Request);
            var country_name = String.Empty;
            ip.GetCountryCode(c => transaction.country_code = c, n => country_name = n);
            transaction.ip_address = ip.ToString();

            api.CreateCoinTransaction(transaction);
            return transaction;
        }
        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;
        }
        private coin_transaction CreateCoinTransactionEntity(GtokenPackage package, decimal playTokenAmount, decimal totalAmount)
        {
            var transaction = new coin_transaction();

            transaction.order_id = Guid.NewGuid().ToString();
            transaction.customer_account_id = CurrentUser.Id;
            transaction.amount = playTokenAmount;
            transaction.price = totalAmount;
            transaction.payment_method = "PayPal";
            transaction.gtoken_package_id = package.id;
            transaction.description = String.Format("You topped up {0} Play Token", Helper.displayDecimal(playTokenAmount));
            transaction.status = "payment_pending";
            transaction.use_gtoken = false;

            IPAddress ip = WebIpHelper.GetClientIp(Request);
            var country_name = String.Empty;
            ip.GetCountryCode(c => transaction.country_code = c, n => country_name = n);
            transaction.ip_address = ip.ToString();

            return transaction;
        }
示例#12
0
        public ActionResult Transfer(TransferModel model)
        {
            var param = HttpContext.Request.Params;
            var api = GoPlayApi.Instance;
            model.senderId = CurrentUser.Id;
            model.maxAmount = CurrentUser.play_token;
            customer_account receiver = null;
            var errors = model.IsValid(out receiver);
            string description = string.Empty;

            if (!ModelState.IsValid || (errors != null && errors.Any()))
            {
                if (errors != null && errors.Any())
                {
                    foreach (var error in errors)
                    {
                        ModelState.AddModelError(error.Item1, error.Item2);
                    }
                }
                return Json(new { errors = Errors(ModelState) });
            }
            else if (model.forValidate)
            {
                return Json(new { correct = true });
            }
            else
            {
                //# Save 2 coin_transactions (positive and negative) to Gtoken using record API
                //# Then, we will save them to GoPlay DB later

                #region Sender transaction, negative amount
                description = string.Format(GoPlayConstantValues.S_TRANSFER_TOKEN_DESCRIPTION,
                     model.playTokenAmount,
                     receiver.GetDisplayName());
                coin_transaction sendingTransaction = new coin_transaction(CurrentUser.Id, receiver.id, description);
                sendingTransaction.amount = model.playTokenAmount * -1;
                sendingTransaction.use_gtoken = true;

                TokenTransactionJson transactionJSON = new TokenTransactionJson(CurrentUser.UserName, sendingTransaction.order_id, sendingTransaction.description, sendingTransaction.amount.Value, GoPlayConstantValues.S_PLAY_TOKEN);
                var isRecordGtoken = api.GTokenAPITransaction(new GtokenModelTransactionAction
                {
                    enumAction = EGtokenAction.RecordTransaction,
                    token_transaction = transactionJSON
                });

                if (!isRecordGtoken.Succeeded)
                {
                    ModelState.AddModelError(GoPlayConstantValues.S_RECEIVER_ID, isRecordGtoken.Error.Value.ToErrorMessage());
                    return Json(new { errors = Errors(ModelState) });
                }
                #endregion

                #region Receiver transaction, positive amount
                description = string.Format(GoPlayConstantValues.S_RECEIVE_TOKEN_DESCRIPTION,
                     model.playTokenAmount,
                     CurrentUser.GetDisplayName());
                coin_transaction receivingTransaction = new coin_transaction(receiver.id, CurrentUser.Id, description);
                receivingTransaction.amount = model.playTokenAmount;

                transactionJSON = new TokenTransactionJson(receiver.username, receivingTransaction.order_id, receivingTransaction.description, receivingTransaction.amount.Value, GoPlayConstantValues.S_PLAY_TOKEN);
                isRecordGtoken = api.GTokenAPITransaction(new GtokenModelTransactionAction
                {
                    enumAction = EGtokenAction.RecordTransaction,
                    token_transaction = transactionJSON
                });

                if (!isRecordGtoken.Succeeded)
                {
                    ModelState.AddModelError(GoPlayConstantValues.S_RECEIVER_ID, isRecordGtoken.Error.Value.ToErrorMessage());
                    return Json(new { errors = Errors(ModelState) });
                }
                #endregion

                //Save to DB this coin_transaction if all Gtoken work well
                api.CreateTransferCoinTransaction(sendingTransaction);
                api.CreateTransferCoinTransaction(receivingTransaction);
            }

            description = string.Format(GoPlayConstantValues.S_TRANSFER_TOKEN_DESCRIPTION,
                model.playTokenAmount,
                receiver.GetDisplayName());

            return Json(new { correct = true, message = description, amount = -model.playTokenAmount });
        }
示例#13
0
        public int CreateTransferCoinTransaction(coin_transaction coinTrans)
        {
            var repo = Repo.Instance;
            using (var db = repo.OpenConnectionFromPool())
            {
                var newId = repo.CreateCoinTransaction(db, coinTrans.customer_account_id, coinTrans.receiver_account_id.Value,
                    coinTrans.amount.Value, coinTrans.description, coinTrans.order_id, coinTrans.use_gtoken, coinTrans.status);
                if (newId > 0)
                    StormFlushedCoinTransaction(newId, coinTrans.status);

                return newId;
            }
        }
示例#14
0
 public Result<coin_transaction> CreateCoinTransaction(coin_transaction coinTrans)
 {
     var repo = Repo.Instance;
     coinTrans.created_at = DateTime.UtcNow;
     using (var db = repo.OpenConnectionFromPool())
     {
         var newId = repo.CreateCoinTransaction(db, coinTrans);
         if (newId > 0)
             StormFlushedCoinTransaction(newId, coinTrans.status);
         return repo.GetCoinTransactionById(db, newId);
     }
 }