public async Task <bool> SaveOfflineTopUpTransaction(string employeeEmail, decimal topUpAmount) { var employee = _context.Employees.Find(employeeEmail); employee.Balance = employee.Balance + topUpAmount; var newTransaction = new Transaction { DateTime = DateTime.UtcNow, Amount = topUpAmount, TransactionType = "OPEN", Employee = employee }; try { _context.Add(newTransaction); _context.Update(employee); await _context.SaveChangesAsync(); return(true); } catch (SqlException error) { _logger.LogError("While running this error showed up:", error); return(false); } }
public async Task CreateNewTerminal(Terminal terminal) { try { _context.Add(terminal); await _context.SaveChangesAsync(); } catch (SqlException error) { _logger.LogError("While running this error showed up:", error); } }
public async Task CreateNewProduct(Product product) { try { _context.Add(product); await _context.SaveChangesAsync(); } catch (SqlException error) { _logger.LogError("While running this error showed up:", error); } }
public async Task <string> ExecutePayment(string paymentId, string token, string payerId, string email) { var environment = new SandboxEnvironment("AV8B5CBqWFqiUEBdhbe2rBVqX0RwNjY74nORYSEI3P8WZ-rRzRxXd1H0pA_qrywn0MCZuXzg3x-WwDeY", "EL-1QQduQKljgE0uHFs6WKAM4JtYrbf8CzOisxNCczPvdnkQYQDT1-rCM1W1dYM3Dhu8L9AcwqwhKdZH"); var client = new PayPalHttpClient(environment); PaymentExecuteRequest request = new PaymentExecuteRequest(paymentId); request.RequestBody(new PaymentExecution() { PayerId = payerId }); try { HttpResponse response = await client.Execute(request); var statusCode = response.StatusCode; Payment result = response.Result <Payment>(); //PayerId en payment opslaan in DB var employee = _context.Employees.Find(email); employee.Balance = employee.Balance + 10; Models.Transaction transaction = new Models.Transaction() { Amount = 10, DateTime = DateTime.UtcNow, Employee = employee, employeeEmail = email, ProviderName = "PayPal", ProviderTransactionId = paymentId, TransactionType = "ExternalTopUp" }; try { _context.Add(transaction); _context.Update(employee); await _context.SaveChangesAsync(); return("Complete"); } catch (SqlException error) { _logger.LogError("While running this error showed up:", error); return("Failed"); } } catch (HttpException httpException) { var statusCode = httpException.StatusCode; var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault(); return("Failed"); } }
public bool CreateNewUserWithCard(string cardId, string employeeEmail) { var newEmployee = new Employee { Email = employeeEmail, Balance = 0, CardUid = cardId }; try { _context.Add(newEmployee); _context.SaveChanges(); RemoveCardFromNewCards(cardId); return(true); } catch (SqlException error) { _logger.LogError("While running this error showed up:", error); return(false); } }