public void MakeWithdrawal(Money amount, string address, Member user, WithdrawalSourceBalance withdrawalSource) { decimal amountInCryptocurrency = Decimal.Zero; Money amountInMoney = Money.Zero; if (withdrawalSource == WithdrawalSourceBalance.MainBalance) { amountInCryptocurrency = ConvertFromMoney(amount); amountInMoney = amount; } else //Wallets { amountInCryptocurrency = amount.ToDecimal(); amountInMoney = ConvertToMoney(amountInCryptocurrency); } CryptocurrencyApiFactory.GetWithdrawalApi(this).TryWithDrawCryptocurrencyFromWallet(amountInCryptocurrency, address, Type); BitcoinIPNManager.AddIPNLog(AppSettings.ServerTime, OperationType.Withdrawal, null, user.Id, address, amountInCryptocurrency, amountInMoney, this.WithdrawalApiProcessor, true); if (withdrawalSource == WithdrawalSourceBalance.MainBalance) { PaymentProportionsManager.MemberPaidOut(amountInMoney, CryptocurrencyTypeHelper.ConvertToPaymentProcessor(Type), user); } AddPaymentProof(amount, user); }
public Money GetMaximumWithdrawalAmount(Member user, WithdrawalSourceBalance withdrawalSource, out string errorMessage) { errorMessage = U6012.PAYOUTREQUESTTOOHIGH; if (withdrawalSource == WithdrawalSourceBalance.MainBalance) { return(PayoutManager.GetMaxPossiblePayout(CryptocurrencyTypeHelper.ConvertToPaymentProcessor(this.CryptocurrencyType), user, out errorMessage)); } else //Wallet { return(user.GetCryptocurrencyBalance(this.Type)); //No limit } }
public Money GetMinimumWithdrawalAmount(Member user, WithdrawalSourceBalance withdrawalSource) { if (withdrawalSource == WithdrawalSourceBalance.MainBalance) { var withdrawLimitInMembership = PayoutLimit.GetGlobalLimitValue(user); var minimumCryptocurrencyWithdraw = WithdrawalMinimum * GetValue(); var list = new List <Money> { minimumCryptocurrencyWithdraw, withdrawLimitInMembership }; return(list.Max()); } else //Wallet { return(new CryptocurrencyMoney(Type, WithdrawalMinimum)); } }
public CryptocurrencyWithdrawRequest(int userId, string address, Money amount, Money amountWithFee, CryptocurrencyType cryptocurrency, WithdrawalSourceBalance sourceBalance) { this.CryptocurrencyCode = cryptocurrency.ToString(); this.UserId = userId; this.Address = address; this.RequestDate = AppSettings.ServerTime; this.Status = WithdrawRequestStatus.Pending; this.Amount = amount; this.AmountWithFee = amountWithFee; this.WithdrawalSourceBalance = sourceBalance; this.CryptocurrencyObject = CryptocurrencyFactory.Get(Cryptocurrency); }
private void ValidateWithdrawal(Member user, string userAddress, decimal amount, WithdrawalSourceBalance withdrawalSource) { if (!WithdrawalEnabled) { throw new MsgException("Withdrawal is currently disabled by the administrator"); } if (CryptocurrencyApi.IsAdministratorAddress(userAddress, WithdrawalApiProcessor)) { throw new MsgException("You can't withdraw to administrator-generated address."); } Money amountInCorrectType = Money.Zero; string errorMessage = String.Empty; //General validation PayoutManager.ValidatePayoutNotConnectedToAmount(user); //Amounts & Balances if (withdrawalSource == WithdrawalSourceBalance.MainBalance) { amountInCorrectType = new Money(amount); //Check the balance if (amountInCorrectType > user.MainBalance) { throw new MsgException(L1.NOTENOUGHFUNDS); } PayoutManager.ValidatePayout(user, amountInCorrectType); PayoutManager.CheckMaxPayout(CryptocurrencyTypeHelper.ConvertToPaymentProcessor(CryptocurrencyType), user, amountInCorrectType); } else //Wallets { amountInCorrectType = new CryptocurrencyMoney(this.Type, amount); //Check the balance if (amountInCorrectType > user.GetCryptocurrencyBalance(CryptocurrencyType)) { throw new MsgException(string.Format(U6012.NOFUNDSINWALLET, CryptocurrencyType.ToString())); } } //Check MIN withdrawal if (amountInCorrectType < GetMinimumWithdrawalAmount(user, withdrawalSource)) { throw new MsgException(U5003.WITHDRAWALMUSTBEHIGHER); } //Check MAX withdrawals if (amountInCorrectType > GetMaximumWithdrawalAmount(user, withdrawalSource, out errorMessage)) { throw new MsgException(errorMessage); } }
/// <summary> /// Final Fee = Processor Fee + Admin Fee /// </summary> /// <param name="cryptocurrencyAmount"></param> /// <param name="userAddress"></param> /// <param name="userId"></param> /// <param name="withdrawalSource"></param> /// <returns></returns> public Money EstimatedWithdrawalFee(decimal cryptocurrencyAmount, string userAddress, int userId, WithdrawalSourceBalance withdrawalSource) { decimal FinalFee = EstimatedWithdrawalFee(cryptocurrencyAmount, userAddress, userId); if (withdrawalSource == WithdrawalSourceBalance.MainBalance) { return(ConvertToMoney(FinalFee)); } else //Wallets { return(new CryptocurrencyMoney(Type, FinalFee)); } }
public string TryMakeWithdrawal(int userId, string address, decimal amount, WithdrawalSourceBalance withdrawalSource) { var successMessage = U6000.REQUESTSENTPLEASEWAIT; var user = new Member(userId); Money amountInMoney; Money amountInCorrectType; decimal amountInCryptocurrency; CryptocurrencyWithdrawRequest request = null; if (withdrawalSource == WithdrawalSourceBalance.MainBalance) { amountInCorrectType = new Money(amount); amountInMoney = new Money(amount); amountInCryptocurrency = ConvertFromMoney(amountInCorrectType); } else //Wallets { amountInCorrectType = new CryptocurrencyMoney(CryptocurrencyType, amount); amountInMoney = ConvertToMoney(amount); amountInCryptocurrency = amount; } //Full Validation ValidateWithdrawal(user, address, amount, withdrawalSource); var amountAfterFee = amountInCorrectType - EstimatedWithdrawalFee(amountInCryptocurrency, address, userId, withdrawalSource); if (amountAfterFee <= Money.Zero) { throw new MsgException("You can't withdraw a negative value."); } if (!IsAutomaticWithdrawal(user, amountInMoney)) { CryptocurrencyWithdrawRequest.ValidatePendingRequests(userId, amountInMoney, this); } user.CashoutsProceed++; if (withdrawalSource == WithdrawalSourceBalance.MainBalance) { user.MoneyCashout += amountAfterFee; user.SubtractFromMainBalance(amountInMoney, String.Format("Requested {0} withdrawal", Type)); user.Save(); request = new CryptocurrencyWithdrawRequest(userId, address, amountAfterFee, amountInMoney, Type, withdrawalSource); } else //Wallets { user.MoneyCashout += ConvertToMoney(amountAfterFee.ToDecimal()); user.SubtractFromCryptocurrencyBalance(Type, amount, String.Format("Requested {0} withdrawal", Type)); user.Save(); request = new CryptocurrencyWithdrawRequest(userId, address, amountAfterFee, new Money(amount), Type, withdrawalSource); } request.Save(); if (IsAutomaticWithdrawal(user, amountInMoney)) { request.Accept(); successMessage = U5003.BTCWITHDRAWSUCCESS.Replace("%n%", amount.ToString() + "."); } return(successMessage); }