public virtual async Task <bool> BuyProduct(BuyProductReq buyProductReq, string userName) { bool payResult = await Pay(buyProductReq, userName); if (!payResult) { return(false); } // buy product id gets validated int the overwritten Pay method List <PurchaseItemReq> purchaseItems = new List <PurchaseItemReq> { new PurchaseItemReq { Price = buyProductReq.Price, Username = userName, StoreItemId = buyProductReq.Id, Quantity = buyProductReq.Quantity, } }; EmptyResult checkoutResult = await _storeAPICalls.CheckoutBasketAsync(purchaseItems); if (checkoutResult == null) { return(false); } return(true); }
public virtual async Task <bool> BuyProduct(BuyProductReq buyProductReq, string userName) { double accountBalance = _transactionDAO.GetAccountbalance(userName); if (accountBalance < buyProductReq.Price) { return(false); } DepositRequest depositRequest = new DepositRequest { Amount = buyProductReq.Price, Reason = TRANSACTION_REASON, ReceiverId = TRANSACTION_RECIVER_ID, SenderId = userName }; bool payResult = _transactionDAO.Pay(depositRequest); if (!payResult) { return(false); } List <PurchaseItemReq> purchaseItems = new List <PurchaseItemReq> { new PurchaseItemReq { Price = buyProductReq.Price, Username = userName, StoreItemId = buyProductReq.Id, Quantity = buyProductReq.Quantity, } }; EmptyResult checkoutResult = await _storeAPICalls.CheckoutBasketAsync(purchaseItems); if (checkoutResult == null) { return(false); } return(true); }