Example #1
0
        public async Task Wire([Summary("The amount of funds you wish to send.")] decimal amount,
                               [Summary("The user you wish to send funds to.")] SocketGuildUser user)
        {
            if (BankingHelpers.IsBelowMinimum(amount))
            {
                await InlineReply(Context.Message, $"The minimum amount you can send is `{_options.Currency}{BankingHelpers.MinimumAmount:N2}`");

                return;
            }

            var payerAccount = await _bankingService.GetOrCreateAccount(Context.User);

            var payeeAccount = await _bankingService.GetOrCreateAccount(user);

            if (!payerAccount.CanAfford(amount))
            {
                await InlineReply(Context.Message, "You don't have enough funds to make that transaction");

                return;
            }

            await _bankingService.Withdraw(payerAccount, amount);

            await _bankingService.Deposit(payeeAccount, amount);

            await ReplyAsync($"Transaction successful! {Context.User.Mention} sent `{_options.Currency}{amount:N2}` to {user.Mention}");
        }
Example #2
0
        public void Deposit_ValidData_ReturnsSuccess()
        {
            var paymentData = new DepositData()
            {
                AccountNumber  = _data.ValidSenderAccountNumber,
                Amount         = "200",
                OperationTitle = "WOW deposit"
            };
            var response = _service.Deposit(paymentData);

            Assert.AreEqual(ResponseStatus.Success, response.ResponseStatus);
        }
Example #3
0
        public async Task <BetResult> EndBet(Bet bet, bool result)
        {
            var wagers = (await GetWagersByBetId(bet.Id)).ToList();

            var wagerResults = new List <WagerResult>();

            Fraction.TryParse(bet.ForOdds, out var forOdds);
            Fraction.TryParse(bet.AgainstOdds, out var againstOdds);

            if (wagers.Any())
            {
                foreach (var wager in wagers)
                {
                    var returns = 0.00M;

                    if (result == wager.InFavour)
                    {
                        returns = wager.InFavour
                            ? wager.Stake.CalculateWinnings(forOdds)
                            : wager.Stake.CalculateWinnings(againstOdds);
                    }

                    var bankAccount = await _bankingService.GetAccount(wager.UserId);

                    var wagerResult = wager.ToWagerResult(returns);

                    wagerResults.Add(wagerResult);

                    await _bankingService.Deposit(bankAccount, returns);
                }
            }

            var betResult = bet.ToBetResult(wagerResults);

            bet.HasEnded = true;

            await _betRepository.Update(bet);

            await _wagerRepository.DeleteRange(wagers);

            return(betResult);
        }
Example #4
0
        public IActionResult Deposit([FromBody] double amount)
        {
            if (amount < _bankingService.GetBankOperationMinAmoun())
            {
                return(BadRequest(OperationDetails.Error("Deposit error")));
            }

            var result = _bankingService.Deposit(new BankOperation(_userIdentityService.GetUserId(User.Claims), amount));

            return(result.Succeeded == true ? (IActionResult)Ok(result) : BadRequest(result));
        }
Example #5
0
        public async Task <IActionResult> Deposit(TransactionVM transaction)
        {
            try
            {
                var bankAccount = await _bankingService.GetBankAccountInfo(BankAccount.UserName);

                await _bankingService.Deposit(bankAccount, transaction.Amount);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #6
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                try
                {
                    foreach (AccountModel account in Accounts)
                    {
                        _bankingService.Deposit(account.Amount, account.AccountId);
                    }
                    return(RedirectToPage("./AccountDetails"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                    return(Page());
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }