public void removeReceiptValidator() { if (this.receiptValidator != null) { this.receiptValidator = null; } }
public void Credit_Card_Required_Fields() { var validation = new ReceiptValidation(Substitute.For <ISpotReservationCheck>()).Validate( new Receipt { MakeCardPayment = true }).Result; Assert.Contains("Payment is required and must be at least $0.01.", validation); Assert.Contains("Credit card number is required.", validation); Assert.Contains("Expiration month is required.", validation); Assert.Contains("Expiration year is required.", validation); Assert.Contains("CVV is required.", validation); var goodValidation = new ReceiptValidation(Substitute.For <ISpotReservationCheck>()).Validate( new Receipt { ThisPayment = .01m, MakeCardPayment = true, CardPayment = new ReceiptCardPayment { CardNumber = "1234", ExpirationMonth = "12", ExpirationYear = "12", Cvv = "123" } }).Result; Assert.DoesNotContain("Payment is required and must be at least $5.00.", goodValidation); Assert.DoesNotContain("Credit card number is required.", goodValidation); Assert.DoesNotContain("Expiration month is required.", goodValidation); Assert.DoesNotContain("Expiration year is required.", goodValidation); Assert.DoesNotContain("CVV is required.", goodValidation); }
public void SetReceiptValidator(ReceiptValidation receiptValidator) { Debug.Log("IAP ===>>> Recipt Validator set"); if (receiptValidator != null) { this.receiptValidator = null; } this.receiptValidator = receiptValidator; this.isReceiptValidating = false; }
public void Run(APIGatewayProxyRequest request, APIGatewayProxyResponse response, FinanceUser user) { var receipt = JsonConvert.DeserializeObject <Receipt>(request.Body); var dbClient = new AmazonDynamoDBClient(); var logger = new ConsoleLogger(); var receiptDbClient = new DatabaseClient <ReceiptSaveResult>(dbClient, logger); var spotReservationDbClient = new DatabaseClient <SpotReservation>(dbClient, logger); var vendorDbClient = new DatabaseClient <Vendor>(dbClient, logger); var qboClient = new QuickBooksOnlineClient(PrivateAccounting.Constants.LakelandMiPuebloRealmId, new DatabaseClient <QuickBooksOnlineConnection>(dbClient, logger), logger); var allActiveCustomers = qboClient .QueryAll <Customer>("select * from customer") .ToDictionary(x => x.Id); var activeVendors = new ActiveVendorSearch() .GetActiveVendors(allActiveCustomers, vendorDbClient) .ToList(); var spotClient = new DatabaseClient <Spot>(dbClient, logger); var spotReservationCheck = new SpotReservationCheck(spotClient, spotReservationDbClient, activeVendors, allActiveCustomers); var validation = new ReceiptValidation(spotReservationCheck).Validate(receipt).Result; if (validation.Any()) { response.StatusCode = 400; response.Body = new JObject { { "error", JArray.FromObject(validation) } }.ToString(); return; } var taxRate = new Tax().GetTaxRate(qboClient, PropertyRentalManagement.Constants.QUICKBOOKS_RENTAL_TAX_RATE); var cardPayment = new CardPayment(logger, Configuration.CLOVER_MI_PUEBLO_PRIVATE_TOKEN); var receiptService = new ReceiptSave(receiptDbClient, qboClient, taxRate, spotReservationDbClient, logger, cardPayment); string customerId = receipt.Customer.Id; if (string.IsNullOrWhiteSpace(customerId)) { var customer = new Customer { DisplayName = receipt.Customer.Name }; customer = qboClient.Create(customer); customerId = customer.Id.ToString(); } var vendor = activeVendors.FirstOrDefault(x => x.QuickBooksOnlineId.GetValueOrDefault().ToString() == customerId) ?? vendorDbClient.Create(VendorService.CreateModel(int.Parse(customerId), null, null, null)); receipt.Id = string.IsNullOrWhiteSpace(receipt.Id) ? Guid.NewGuid().ToString() : receipt.Id; // Needed until UI is deployed. var receiptResult = receiptService.SaveReceipt(receipt, customerId, user.FirstName, user.LastName, user.Email, vendor, IpLookup.GetIp(request)); response.Body = JsonConvert.SerializeObject(receiptResult); }
public void Run(APIGatewayProxyRequest request, APIGatewayProxyResponse response, FinanceUser user) { var validation = new List <string>(); var rentalDate = request.QueryStringParameters != null && request.QueryStringParameters.ContainsKey("rentalDate") ? request.QueryStringParameters["rentalDate"] : string.Empty; var databaseClient = new DatabaseClient <SpotReservation>(new AmazonDynamoDBClient(), new ConsoleLogger()); var service = new SpotReservationService(databaseClient); List <SpotReservation> spotReservations; if (!string.IsNullOrWhiteSpace(rentalDate)) { validation.AddRange(ReceiptValidation.GetRentalDateValidation(rentalDate)); if (validation.Any()) { response.StatusCode = 400; response.Body = new JObject { { "error", JArray.FromObject(validation) } }.ToString(); return; } spotReservations = service.GetSpotReservations(rentalDate); } else { var vendorId = request.QueryStringParameters != null && request.QueryStringParameters.ContainsKey("vendorId") ? request.QueryStringParameters["vendorId"] : string.Empty; spotReservations = service.GetSpotReservationsByVendor(vendorId) .OrderBy(x => x.RentalDate) .ToList(); } response.Body = JsonConvert.SerializeObject(spotReservations); }
public void Run(APIGatewayProxyRequest request, APIGatewayProxyResponse response, FinanceUser user) { var dbClientCore = new AmazonDynamoDBClient(); var logger = new ConsoleLogger(); var spotClient = new DatabaseClient <Spot>(dbClientCore, logger); var spots = spotClient.ScanAll(new ScanRequest(new Spot().GetTable())) .OrderBy(x => x.Section?.Name) .ThenBy(x => x.Name) .ToList(); var qboClient = new QuickBooksOnlineClient(PrivateAccounting.Constants.LakelandMiPuebloRealmId, new DatabaseClient <QuickBooksOnlineConnection>(dbClientCore, logger), logger); var allActiveCustomers = qboClient .QueryAll <Customer>("select * from customer") .ToDictionary(x => x.Id); var allActiveVendors = new ActiveVendorSearch() .GetActiveVendors(allActiveCustomers, new DatabaseClient <Vendor>(dbClientCore, logger)) .ToList(); var spotReservationCheck = new SpotReservationCheck( spotClient, new DatabaseClient <SpotReservation>(dbClientCore, logger), allActiveVendors, allActiveCustomers ); var rentalDate = request.QueryStringParameters.ContainsKey("rentalDate") ? request.QueryStringParameters["rentalDate"] : string.Empty; var validation = ReceiptValidation.GetRentalDateValidation(rentalDate); if (validation.Any()) { response.StatusCode = 400; response.Body = new JObject { { "error", JArray.FromObject(validation) } }.ToString(); return; } validation = new List <string>(); DateTime.TryParseExact(rentalDate, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var parsedRentalDate); if (parsedRentalDate - DateTime.UtcNow > TimeSpan.FromDays(91)) // Endpoint is cached. The date constraint prevents denial of service causing the cache to be hit and database hits to plateau quickly. { validation.Add("rentalDate can't be greater than 90 days in the future"); } if (parsedRentalDate - DateTime.UtcNow < TimeSpan.FromDays(-1)) { validation.Add("rentalDate can't be in the past"); } if (validation.Any()) { response.StatusCode = 400; response.Body = new JObject { { "error", JArray.FromObject(validation) } }.ToString(); return; } var jsonResponse = new List <PublicSpot>(); foreach (var spot in spots) { var reservation = spotReservationCheck.GetReservation(spot.Id, rentalDate); int?reservedByQuickBooksOnlineId = 0; if (reservation?.Item1 != null) { reservedByQuickBooksOnlineId = reservation.Item1.QuickBooksOnlineId; } if (reservation?.Item2 != null) { reservedByQuickBooksOnlineId = reservation.Item2.QuickBooksOnlineId; } var publicSpot = new PublicSpot { Id = spot.Id, Name = spot.Name, Section = spot.Section, Right = spot.Right, Bottom = spot.Bottom }; if (reservedByQuickBooksOnlineId.HasValue && allActiveCustomers.TryGetValue(reservedByQuickBooksOnlineId, out var customer)) { publicSpot.ReservedBy = customer.DisplayName; } jsonResponse.Add(publicSpot); } response.Body = JsonConvert.SerializeObject(jsonResponse); }