public async Task Should_Return_Error_When_Send_Non_Transaction_Id_Request_For_PaymentByCash() { PaymentByCashEntity paymentByCashEntity = new PaymentByCashEntity(); paymentByCashEntity.TransactionId = -1; paymentByCashEntity.CashAmount = 1; var response = await _client.PostAsJsonAsync("Automat/PaymentByCash", paymentByCashEntity); var apiResult = await response.Content.ReadAsAsync <TransactionResult>(); Assert.True(1 == apiResult.Code); Assert.Equal($"TransactionId: {paymentByCashEntity.TransactionId} Message: TransactionId değeri bulunamadı!", apiResult.Message); }
public async Task Should_Return_Error_When_Send_Paid_Transaction_Id_Request_For_PaymentByCash() { PaymentByCashEntity paymentByCashEntity = new PaymentByCashEntity(); paymentByCashEntity.TransactionId = 1; paymentByCashEntity.CashAmount = 1; var response = await _client.PostAsJsonAsync("Automat/PaymentByCash", paymentByCashEntity); var apiResult = await response.Content.ReadAsAsync <TransactionResult>(); Assert.True(1 == apiResult.Code); Assert.Equal($"Bu işlem Gerçekleşmiştir! Transaction id {paymentByCashEntity.TransactionId}", apiResult.Message); }
public async Task Should_Return_Error_When_TransactionAmount_Bigger_Than_CachAmount() { //Arrange var automatFacade = new AutomatFacade(new FakeProductRepository(), new FakeCampaingRepository(), new FakeTransactionRepository()); //Act PaymentByCashEntity paymentByCashEntity = new PaymentByCashEntity(); paymentByCashEntity.CashAmount = 1; paymentByCashEntity.Id = 1; paymentByCashEntity.TransactionId = 1; var result = await automatFacade.PaymentByCash(paymentByCashEntity); //Assert Assert.Equal(1, result.Code); }
public async Task Should_Return_Success_When_Send_Correct_Request_For_PaymentByCash() { var parameter = new ProductSelection(); parameter.Slot = 2; parameter.SugarLevel = 0; parameter.SelectedPieces = 1; var responseProductSelection = await _client.PostAsJsonAsync("Automat/ProductSelection", parameter); var apiProductSelectionResult = await responseProductSelection.Content.ReadAsAsync <ProductSelectionResult>(); PaymentByCashEntity paymentByCashEntity = new PaymentByCashEntity(); paymentByCashEntity.TransactionId = apiProductSelectionResult.TransactionId; paymentByCashEntity.CashAmount = apiProductSelectionResult.TotalAmount; var response = await _client.PostAsJsonAsync("Automat/PaymentByCash", paymentByCashEntity); var apiResult = await response.Content.ReadAsAsync <TransactionResult>(); Assert.True(0 == apiResult.Code); }
public async Task Should_Return_Error_When_Send_Zero_CashAmount_Request_For_PaymentByCash() { var parameter = new ProductSelection(); parameter.Slot = 2; parameter.SugarLevel = 0; parameter.SelectedPieces = 1; var responseProductSelection = await _client.PostAsJsonAsync("Automat/ProductSelection", parameter); var apiProductSelectionResult = await responseProductSelection.Content.ReadAsAsync <ProductSelectionResult>(); PaymentByCashEntity paymentByCashEntity = new PaymentByCashEntity(); paymentByCashEntity.TransactionId = apiProductSelectionResult.TransactionId; paymentByCashEntity.CashAmount = 0; var response = await _client.PostAsJsonAsync("Automat/PaymentByCash", paymentByCashEntity); var apiResult = await response.Content.ReadAsAsync <TransactionResult>(); Assert.True(1 == apiResult.Code); Assert.Equal("Lütfen para giriniz!", apiResult.Message); }
public async Task <TransactionResult> PaymentByCash(PaymentByCashEntity paymentEntity) { TransactionResult transactionResult = new TransactionResult(); try { if (paymentEntity == null) { transactionResult.Code = 1; transactionResult.Message = "null parameter"; return(transactionResult); } if (paymentEntity.CashAmount == 0) { transactionResult.Code = 1; transactionResult.Message = "Lütfen para giriniz!"; return(transactionResult); } var transaction = await _transactionRepository.GetByIdAsync(paymentEntity.TransactionId); if (transaction == null) { transactionResult.TransactionId = paymentEntity.TransactionId; transactionResult.Code = 1; transactionResult.Message = $"TransactionId: {paymentEntity.TransactionId} Message: TransactionId değeri bulunamadı!"; return(transactionResult); } var product = await _productRepository.GetByIdAsync(transaction.Slot); if (product == null) { transactionResult.TransactionId = paymentEntity.TransactionId; transactionResult.Slot = transaction.Slot; transactionResult.Code = 1; transactionResult.Message = $"Slot: {transaction.Slot} Message: Slot bulunamadı!"; return(transactionResult); } if (transaction.IsPaid) { transactionResult.TransactionId = paymentEntity.TransactionId; transactionResult.Code = 1; transactionResult.Message = $"Bu işlem Gerçekleşmiştir! Transaction id {paymentEntity.TransactionId}"; return(transactionResult); } if (paymentEntity.CashAmount < transaction.TransactionAmount) { transactionResult.TransactionId = paymentEntity.TransactionId; transactionResult.Code = 1; transactionResult.Message = "Lütfen yeterli para giriniz!"; return(transactionResult); } var reversedAmount = paymentEntity.CashAmount - transaction.TransactionAmount; transactionResult.TransactionId = paymentEntity.TransactionId; transactionResult.Code = 0; transactionResult.Message = "Başarılı işlem"; transactionResult.PaymentMethod = "NAKIT"; transactionResult.ReversedAmount = reversedAmount; transactionResult.ProdcutName = product.ProductName; transactionResult.Slot = transaction.Slot; product.NumberOfProducts -= transaction.SelectedPieces; product.IsAvailable = product.NumberOfProducts <= 0 ? false : true; await _productRepository.UpdateAsync(product); transaction.IsPaid = true; await _transactionRepository.UpdateAsync(transaction); return(transactionResult); } catch (Exception) { //logging transactionResult.TransactionId = paymentEntity.TransactionId; transactionResult.Code = 1; transactionResult.Message = "Hata oluştu!"; } return(transactionResult); }
public async Task <ActionResult <IEnumerable <TransactionResult> > > PaymentByCash([FromBody] PaymentByCashEntity paymentByCashCardEntity) { var result = await _automatFacade.PaymentByCash(paymentByCashCardEntity); return(Ok(result)); }