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); }
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); } }
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 void AddPaymentProof(Money amountInMoney, Member user) { var paymentType = IsAutomaticWithdrawal(user, amountInMoney) ? PaymentType.Instant : PaymentType.Manual; PaymentProof.Add(user.Id, amountInMoney, paymentType, CryptocurrencyTypeHelper.ConvertToPaymentProcessor(Type)); }