Beispiel #1
0
        /// <summary>
        /// Recharge for side chain.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override Empty Recharge(RechargeInput input)
        {
            var chainId       = input.ChainId;
            var amount        = input.Amount;
            var sideChainInfo = State.SideChainInfo[chainId];

            Assert(sideChainInfo != null && sideChainInfo.SideChainStatus == SideChainStatus.Active,
                   "Side chain not found or not able to be recharged.");
            State.IndexingBalance[chainId] = State.IndexingBalance[chainId] + amount;
            if (State.IndexingBalance[chainId] > sideChainInfo.SideChainCreationRequest.IndexingPrice)
            {
                sideChainInfo.SideChainStatus = SideChainStatus.Active;
                State.SideChainInfo[chainId]  = sideChainInfo;
            }

            TransferFrom(new TransferFromInput
            {
                From   = Context.Sender,
                To     = Context.Self,
                Symbol = Context.Variables.NativeSymbol,
                Amount = amount,
                Memo   = "Recharge."
            });
            return(new Empty());
        }
        public ApiResult Save([FromBody] RechargeInput model)
        {
            if (!this.IsFormValid())
            {
                return(ApiResult.Failure(this.FormInvalidReason()));
            }

            var result = Resolve <IRechargeAccountLogService>().Add(model);

            return(ToResult(result));
        }
Beispiel #3
0
        public async Task <string> Recharge(RechargeInput input)
        {
            var payInput = new PayInput
            {
                Body        = "系统充值",
                TotalAmount = input.TotalAmount,
                Subject     = "系统充值",
                CustomData  = new
                {
                    key = "系统充值",
                    uid = AbpSession.ToUserIdentifier().ToUserIdentifierString()
                }.ToJsonString()
            };
            //使用统一支付接口
            var result = await _payAppService.Pay(payInput);

            return((string)(result is string?result : result.ToJsonString()));
        }
        /// <summary>
        /// Recharge for side chain.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override Empty Recharge(RechargeInput input)
        {
            var chainId       = input.ChainId;
            var sideChainInfo = State.SideChainInfo[chainId];

            Assert(sideChainInfo != null && sideChainInfo.SideChainStatus != SideChainStatus.Terminated,
                   "Side chain not found or incorrect side chain status.");

            TransferFrom(new TransferFromInput
            {
                From   = Context.Sender,
                To     = Context.ConvertVirtualAddressToContractAddress(ConvertChainIdToHash(chainId)),
                Symbol = Context.Variables.NativeSymbol,
                Amount = input.Amount,
                Memo   = "Indexing fee recharging."
            });

            long arrearsAmount = 0;

            if (sideChainInfo.SideChainStatus == SideChainStatus.IndexingFeeDebt)
            {
                // arrears
                foreach (var arrears in sideChainInfo.ArrearsInfo)
                {
                    arrearsAmount += arrears.Value;
                    TransferDepositToken(new TransferInput
                    {
                        To     = Address.Parser.ParseFrom(ByteString.FromBase64(arrears.Key)),
                        Symbol = Context.Variables.NativeSymbol,
                        Amount = arrears.Value,
                        Memo   = "Indexing fee recharging."
                    }, chainId);
                }

                var originBalance = GetSideChainIndexingFeeDeposit(chainId);
                Assert(input.Amount + originBalance >= arrearsAmount + sideChainInfo.IndexingPrice,
                       "Indexing fee recharging not enough.");
            }

            sideChainInfo.ArrearsInfo.Clear();
            sideChainInfo.SideChainStatus = SideChainStatus.Active;
            State.SideChainInfo[chainId]  = sideChainInfo;
            return(new Empty());
        }
Beispiel #5
0
        public async Task <string> Recharge(RechargeInput input)
        {
            var user        = AuthHelper.GetCurrentUser();
            var usermanager = AuthHelper.GetUserManager();

            try
            {
                StripeConfiguration.SetApiKey(System.Configuration.ConfigurationManager.AppSettings["StripeApiKey"]);
            }
            catch (Exception ex)
            {
                //log the exception and return the message to the caller
                return(ex.Message);
            }

            return(await System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    var myCharge = new StripeChargeCreateOptions
                    {
                        Amount = input.HoursAdded * PlanHelper.GetPlan(input.PlanID).Rate,
                        Currency = "usd",
                        Description = "Recharge account balance",
                        CustomerId = user.StripeCustomerId,
                    };

                    var chargeService = new StripeChargeService();
                    var stripeCharge = chargeService.Create(myCharge);

                    //Update the account balance in the system
                    user.AccountBalance += input.HoursAdded;
                    user.StripePlanId = input.PlanID;
                    usermanager.Update(user);

                    return stripeCharge.Id;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }));
        }
Beispiel #6
0
        public async Task <string> ChangePlan(RechargeInput input)
        {
            var user        = AuthHelper.GetCurrentUser();
            var usermanager = AuthHelper.GetUserManager();

            try
            {
                StripeConfiguration.SetApiKey(System.Configuration.ConfigurationManager.AppSettings["StripeApiKey"]);
            }
            catch (Exception ex)
            {
                //log the exception and return the message to the caller
                return(ex.Message);
            }

            return(await System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    var cust = new StripeCustomerService().Get(user.StripeCustomerId);
                    if (cust != null)
                    {
                        var sub_svc = new StripeSubscriptionService();
                        var sub = sub_svc.Get(cust.Id, cust.StripeSubscriptionList.Data[0].Id);

                        var options = new StripeSubscriptionUpdateOptions();
                        options.PlanId = input.PlanID;
                        options.Prorate = false;

                        sub_svc.Update(cust.Id, sub.Id, options);
                    }
                    else
                    {
                        throw new ApplicationException("Could not find the customer in stripe to change the plan");
                    }
                    return "Success";
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }));
        }
        /// <summary>
        /// Recharge for side chain.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override Empty Recharge(RechargeInput input)
        {
            var chainId       = input.ChainId;
            var sideChainInfo = State.SideChainInfo[chainId];

            Assert(sideChainInfo != null && sideChainInfo.SideChainStatus != SideChainStatus.Terminated,
                   "Side chain not found or not able to be recharged.");
            var oldBalance = State.IndexingBalance[chainId];
            var newBalance = oldBalance + input.Amount;

            Assert(newBalance >= sideChainInfo.IndexingPrice, "Indexing fee recharging not enough.");
            State.IndexingBalance[chainId] = newBalance;

            TransferFrom(new TransferFromInput
            {
                From   = Context.Sender,
                To     = Context.Self,
                Symbol = Context.Variables.NativeSymbol,
                Amount = input.Amount,
                Memo   = "Indexing fee recharging."
            });

            if (oldBalance < 0)
            {
                // arrears
                foreach (var arrears in sideChainInfo.ArrearsInfo)
                {
                    Transfer(new TransferInput
                    {
                        To     = Address.Parser.ParseFrom(ByteString.FromBase64(arrears.Key)),
                        Symbol = Context.Variables.NativeSymbol,
                        Amount = arrears.Value,
                        Memo   = "Indexing fee recharging."
                    });
                }
            }

            sideChainInfo.ArrearsInfo.Clear();
            sideChainInfo.SideChainStatus = SideChainStatus.Active;
            State.SideChainInfo[chainId]  = sideChainInfo;
            return(new Empty());
        }
Beispiel #8
0
        public string CreateCustomer(RechargeInput c)
        {
            var user        = AuthHelper.GetCurrentUser();
            var usermanager = AuthHelper.GetUserManager();

            try
            {
                StripeConfiguration.SetApiKey(System.Configuration.ConfigurationManager.AppSettings["StripeApiKey"]);

                var myCustomer = new StripeCustomerCreateOptions();
                myCustomer.Email       = user.Email;
                myCustomer.Description = user.Organization + " (" + user.Email + ")";
                myCustomer.SourceToken = c.AuthorizationCode;
                myCustomer.PlanId      = c.PlanID;

                var            customerService = new StripeCustomerService();
                StripeCustomer customer        = customerService.Create(myCustomer);

                //Update the user with the stripe customer id and plan info
                user.StripeCustomerId = customer.Id;
                user.StripePlanId     = c.PlanID;
                user.AccountBalance   = PlanHelper.GetPlan(c.PlanID).Hours;
                usermanager.Update(user);

                return(customer.Id);
            }
            catch (Exception ex)
            {
                //log the exception and return the message to the caller
                throw ex;
            }

            //Create a JIRA epic and store it with the user
            try
            {
                WorkItemController wic = new WorkItemController();
                wic.CreateCustomerBacklog();
            }
            catch { }
        }
Beispiel #9
0
        private bool OperTrade(RechargeInput input, TradeType tradeTyppe)
        {
            var account = _financeAccount.FirstOrDefault(m => m.UserId == input.userId);

            if (account != null)
            {
                if (input.Amount < 0 && account.Blance + input.Amount < 0)
                {
                    throw new UserFriendlyException("账户余额不足, 扣款失败");
                }

                account.Blance = account.Blance + input.Amount;

                FinanceTradeDetail entity = new FinanceTradeDetail();
                entity.UserId           = input.userId;
                entity.Amount           = input.Amount;
                entity.FinanceAccountId = account.Id;
                entity.TradeType        = tradeTyppe.ToString();
                entity.SerialNo         = _tradeManager.GenerateTradeNo(tradeTyppe);
                return(_tradeManager.CreateTrade(entity));
            }
            throw new UserFriendlyException("未找到此账户");
        }
Beispiel #10
0
 public bool CreateDeductionTrade(RechargeInput input)
 {
     input.Amount = Math.Abs(input.Amount) * -1;
     return(OperTrade(input, TradeType.KF));
 }
Beispiel #11
0
 public bool CreateRechargeTrade(RechargeInput input)
 {
     input.Amount = Math.Abs(input.Amount);
     return(OperTrade(input, TradeType.CZ));
 }
        public ServiceResult Add(RechargeInput rechargeAccount)
        {
            #region 安全验证

            if (rechargeAccount == null)
            {
                return(ServiceResult.Failure("对象不能为空"));
            }

            if (rechargeAccount.UserName.IsNullOrEmpty())
            {
                return(ServiceResult.Failure("用户名不能为空!"));
            }

            var user = Resolve <IUserService>().GetSingleByUserNameOrMobile(rechargeAccount.UserName);
            if (user == null)
            {
                return(ServiceResult.Failure("用户不存在"));
            }

            var config = Resolve <IAutoConfigService>().GetList <RechargeAccountConfig>();
            var find   = config.FirstOrDefault(r => r.Id == rechargeAccount.Id);
            if (find == null)
            {
                return(ServiceResult.Failure("配置不存在"));
            }

            #endregion 安全验证

            var moneyConfigs = Resolve <IAutoConfigService>().MoneyTypes();

            var moneyConfig = moneyConfigs.FirstOrDefault(p => p.Id == MoneyTypeConfig.CNY);
            var result      = Resolve <IBillService>().Increase(user, moneyConfig, find.ArriveAmount, "储值充值");
            if (result.Succeeded)
            {
                // 积分,优惠券,消费额
                if (find.DiscountAmount > 0)
                {
                    moneyConfig = moneyConfigs.FirstOrDefault(p => p.Id == MoneyTypeConfig.Point);
                    Resolve <IBillService>().Increase(user, moneyConfig, find.DiscountAmount, "储值充值赠送积分");
                }

                if (find.GiveChangeAmount > 0)
                {
                    moneyConfig = moneyConfigs.FirstOrDefault(p => p.Id == MoneyTypeConfig.ShopAmount);
                    Resolve <IBillService>().Increase(user, moneyConfig, find.GiveChangeAmount, "储值充值赠送消费额");
                }

                if (find.GiveBuyAmount > 0)
                {
                    moneyConfig = moneyConfigs.FirstOrDefault(p => p.Id == MoneyTypeConfig.Preferential);
                    Resolve <IBillService>().Increase(user, moneyConfig, find.GiveBuyAmount, "储值充值赠送优惠券");
                }

                var rechargeModel = new RechargeAccountLog
                {
                    ArriveAmount     = find.ArriveAmount,
                    DiscountAmount   = find.DiscountAmount,
                    GiveBuyAmount    = find.GiveBuyAmount,
                    GiveChangeAmount = find.GiveChangeAmount,
                    CreateTime       = DateTime.Now,
                    StoreAmount      = find.StoreAmount,
                    UserId           = user.Id
                };
                Resolve <IRechargeAccountLogService>().Add(rechargeModel);

                return(ServiceResult.SuccessWithObject("充值成功"));
            }

            return(ServiceResult.Failure("充值失败"));
        }