示例#1
0
        public async Task <Result <PaymentRequest> > CreatePaymentRequest(PaymentRequest paymentRequest)
        {
            if (paymentRequest.Amount <= 0)
            {
                return new Result <PaymentRequest> {
                           Success = false, Message = "Payment must be greater than zero."
                }
            }
            ;

            var balanceResult = await _accountData.GetBalance(paymentRequest.AccountId);

            if (!balanceResult.Success)
            {
                return new Result <PaymentRequest> {
                           Success = false, Message = balanceResult.Message
                }
            }
            ;

            if (paymentRequest.Amount > balanceResult.Entity)
            {
                paymentRequest.Status = PaymentStatus.Closed;

                paymentRequest.ClosedReason = PaymentConstants.NotEnoughFunds;

                await _paymentsData.Add(paymentRequest);

                if (await _paymentsData.Commit() > 0)
                {
                    return(new Result <PaymentRequest> {
                        Entity = paymentRequest, Message = paymentRequest.ClosedReason, Success = false
                    });
                }

                return(new Result <PaymentRequest> {
                    Entity = paymentRequest, Message = PaymentConstants.CouldNotBeSaved, Success = false
                });
            }

            paymentRequest.Status = PaymentStatus.Pending;

            await _paymentsData.Add(paymentRequest);

            await _paymentsData.Commit();

            return(new Result <PaymentRequest> {
                Entity = paymentRequest, Success = true, Message = "Payment request created successfully."
            });
        }
示例#2
0
        public async Task <Result <decimal> > GetBalance(int accountId)
        {
            var result = await _accountData.GetBalance(accountId);

            if (result.Success)
            {
                return new Result <decimal> {
                           Entity = result.Entity, Success = true
                }
            }
            ;
            else
            {
                return new Result <decimal> {
                           Success = false, Message = result.Message
                }
            };
        }
    }