Ejemplo n.º 1
0
        public async Task CanCreateACheckoutWithMerchantCompletes()
        {
            var checkouts = new Checkouts(SezzleConfig, AuthResponse);

            var checkout         = new Checkout();
            var amount           = 1000;
            var currencyCode     = "USD";
            var orderReferenceId = DateTime.UtcNow.Ticks.ToString();

            checkout.AmountInCents       = amount;
            checkout.CurrencyCode        = currencyCode;
            checkout.OrderDescription    = "Test checkout";
            checkout.OrderReferenceId    = orderReferenceId;
            checkout.CheckoutCancelUrl   = "https://test.sezzle.com/cancel";
            checkout.CheckoutCompleteUrl = "https://test.sezzle.com/complete";
            checkout.CustomerDetails     = new CustomerDetails("TestFirst", "TestLast", "*****@*****.**");
            checkout.BillingAddress      = new Address("TestFirst TestLast", "1516 W. Lake St", "Minneapolis", "MN", "55408", "US");
            checkout.ShippingAddress     = new Address("TestFirst TestLast", "1516 W. Lake St", "Minneapolis", "MN", "55408", "US");
            checkout.Items = new List <Item> {
                new Item("Test T-Shirt", "ABC123", 1, new Price(amount, currencyCode))
            };
            checkout.MerchantCompletes    = true;
            checkout.RequiresShippingInfo = false;

            var checkoutResponse = await checkouts.Post(checkout);

            Assert.IsNotNull(checkoutResponse);

            Console.WriteLine("Order reference id: {0}", orderReferenceId);
            Console.WriteLine(JsonConvert.SerializeObject(checkoutResponse, Formatting.Indented));

            Assert.IsNotNull(checkoutResponse.CheckoutUrl);
            Assert.IsNotEmpty(checkoutResponse.CheckoutUrl);
            Assert.AreNotEqual(400, checkoutResponse.Status);
        }
Ejemplo n.º 2
0
        public override int GetHashCode()
        {
            int hashCode = -958586851;

            if (Context != null)
            {
                hashCode += Context.GetHashCode();
            }

            if (Errors != null)
            {
                hashCode += Errors.GetHashCode();
            }

            if (Checkouts != null)
            {
                hashCode += Checkouts.GetHashCode();
            }

            if (Cursor != null)
            {
                hashCode += Cursor.GetHashCode();
            }

            return(hashCode);
        }
Ejemplo n.º 3
0
        public async Task <(Dictionary <string, List <Checkout> > checkouts, List <Territory> territories)> Backup()
        {
            var checkout = await Checkouts.ToListAsync();

            var territories = await Territorys.ToListAsync();

            return(checkout.OrderBy(c => c.TerritoryId).GroupBy(c => c.TerritoryId).ToDictionary(c => c.Key, c => c.ToList()), territories);
        }
Ejemplo n.º 4
0
        public async Task UpdateCheckout(Checkout checkout)
        {
            var existing = await Checkouts.SingleAsync(c => c.CheckoutId == checkout.CheckoutId && c.TerritoryId == checkout.TerritoryId);

            Checkouts.Remove(existing);
            Checkouts.Add(checkout);

            await SaveChangesAsync();
        }
Ejemplo n.º 5
0
        private void LoadCheckoutsCallback(ServiceLoadResult <Checkout> result)
        {
            if (result.Error != null)
            {
                // handle error
            }
            else if (!result.Cancelled)
            {
                this.Checkouts = result.Entities as ICollection <Checkout>;

                SelectedCheckout = Checkouts.FirstOrDefault();
            }
        }
Ejemplo n.º 6
0
        public async Task CanCompleteACheckoutWithMerchantCompletes()
        {
            // TODO: Mark this test as ignored and require a parameter to send the order reference id into it
            var orderReferenceId = "636773928435687781";
            var checkouts        = new Checkouts(SezzleConfig, AuthResponse);

            // Now let's try completing it
            var completeResponse = await checkouts.Complete(orderReferenceId);

            // Per Sezzle, an empty response body is success
            Assert.IsNotNull(completeResponse);
            Assert.AreEqual(HttpStatusCode.OK, completeResponse.HttpStatusCode);
        }
Ejemplo n.º 7
0
        public void CheckoutItem(int id, int libraryCardId)
        {
            if (IsCheckedOut(id))
            {
                return;
            }

            var item = _context.LibraryAsset
                       .Include(a => a.Status)
                       .FirstOrDefault(a => a.Id == id);

            _context.Update(item);

            item.Status = _context.Status
                          .FirstOrDefault(a => a.Name == "Checked Out");

            var now = DateTime.Now;

            var libraryCard = _context.LibraryCards
                              .Include(c => c.Checkouts)
                              .FirstOrDefault(a => a.Id == libraryCardId);

            if (libraryCard == null)
            {
                return;
            }

            var checkout = new Checkouts
            {
                LibraryAsset = item,
                LibraryCard  = libraryCard,
                Since        = now,
                Until        = GetDefaultCheckoutTime(now)
            };

            _context.Add(checkout);

            var checkoutHistory = new CheckoutHistory
            {
                CheckedOut   = now,
                LibraryAsset = item,
                LibraryCard  = libraryCard
            };

            _context.Add(checkoutHistory);
            _context.SaveChanges();
        }
Ejemplo n.º 8
0
        /// <summary> Returns a document from a user to the LMS </summary>
        /// <returns> Result of returning doc as message </returns>
        public string ReturnDoc(int docID)
        {
            Checkouts checkout = SDM.LMS.GetCheckout(PersonID, docID);
            Document  doc      = SDM.LMS.GetDoc(docID);

            // User has fine
            if (SDM.LMS.GetUserFineForDoc(PersonID, docID) > 0)
            {
                return(SDM.Strings.USER_HAVE_FINE);
            }

            SDM.LMS.RemoveCheckout(docID, PersonID);
            SDM.LMS.ModifyAV(docID, doc.Title, doc.Autors, doc.Price, doc.Quantity + 1, doc.Tags);
            SDM.LMS.NotifyNextUser(docID, SDM.Strings.MAIL_BOOK_AVAILIBLE_TITLE, SDM.Strings.MAIL_BOOK_AVAILIBLE_TEXT(doc.Title, SDM.Strings.DOC_TYPES[doc.DocType]));

            return(SDM.Strings.SUCCESSFUL_RETURN + " " + doc.Title + "!");
        }
Ejemplo n.º 9
0
        public static string GetCommaSeparatedItemIdsFromCheckout(Checkouts checkout)
        {
            List <string> strings = new List <string> {
            };

            if (checkout.entries.Length == 0)
            {
                return("");
            }

            for (int i = 0; i < checkout.entries.Length; i++)
            {
                string itemurl = checkout.entries[i].item;
                strings.Add(itemurl.Substring(itemurl.LastIndexOf("/") + 1));
            }

            return(string.Join(",", strings));
        }
Ejemplo n.º 10
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            return(obj is SearchTerminalCheckoutsResponse other &&
                   ((Context == null && other.Context == null) || (Context?.Equals(other.Context) == true)) &&
                   ((Errors == null && other.Errors == null) || (Errors?.Equals(other.Errors) == true)) &&
                   ((Checkouts == null && other.Checkouts == null) || (Checkouts?.Equals(other.Checkouts) == true)) &&
                   ((Cursor == null && other.Cursor == null) || (Cursor?.Equals(other.Cursor) == true)));
        }
Ejemplo n.º 11
0
        public void checkOutItem(int assetId, int libraryCardId)
        {
            if (isCheckOut(assetId))
            {
                //If item has been checkout
                //Here can do smtg to notify user
                return;
            }
            var item = _context.libraryAssets
                       .FirstOrDefault(a => a.id == assetId);

            updateAsset(assetId, "Checked Out");

            var libraryCard = _context.libraryCards
                              .Include(c => c.checkOut)
                              .FirstOrDefault(c => c.id == libraryCardId);

            var timeNow = DateTime.Now;

            var checkOut = new Checkouts
            {
                LibraryAsset = item,
                LibraryCard  = libraryCard,
                since        = timeNow,
                until        = getDefaultCheckoutTime(timeNow),
            };

            _context.Add(checkOut);

            var checkOutHis = new CheckoutHistory
            {
                libraryAsset = item,
                LibraryCard  = libraryCard,
                checkOut     = timeNow,
                //checkIn =
                //Check in would be null for this i supposed
                //since item just got checked out and
                //we dont know when user will return
            };

            _context.Add(checkOutHis);
            _context.SaveChanges();
        }
Ejemplo n.º 12
0
        // Update methods
        public void CheckOutItem(int assetId, int libraryCardId)
        {
            if (IsCheckedOut(assetId))
            {
                return;
            }

            // Update library asset status to Checked out
            var item = _context.LibraryAssets
                       .FirstOrDefault(asset => asset.Id == assetId);

            UpdateAssetStatus(assetId, "Checked Out");

            // Grab the library card and date time to create a new checkout
            var libraryCard = _context.LibraryCards
                              .Include(card => card.Checkouts)
                              .FirstOrDefault(card => card.Id == libraryCardId);

            var now = DateTime.Now;

            // Create a new checkout and add it to the db
            var checkout = new Checkouts
            {
                LibraryAsset = item,
                LibraryCard  = libraryCard,
                Since        = now,
                Until        = GetDefaultCheckoutTime(now)
            };

            _context.Add(checkout);

            // Create a new checkout history and add that as well
            var checkoutHistory = new CheckoutHistory
            {
                CheckedOut   = now,
                LibraryAsset = item,
                LibraryCard  = libraryCard
            };

            _context.Add(checkoutHistory);
            _context.SaveChanges();
        }
        public void ChecKOutItem(int assetId, int libraryCardId)
        {
            if (IsCheckedOut(assetId))
            {
                return;
                //Add logic here to handle feedback to the user;
            }

            var item = _context.LibraryAssets
                       .FirstOrDefault(a => a.Id == assetId);

            UpdateAssestStatus(assetId, "Checked Out");

            var libraryCard = _context.LibraryCards
                              .Include(card => card.Checkouts)
                              .FirstOrDefault(card => card.Id == libraryCardId);

            var now = DateTime.Now;

            var checkout = new Checkouts
            {
                LibraryAsset = item,
                LibraryCard  = libraryCard,
                Since        = now,
                Until        = GetDefaultCheckoutTime(now)
            };

            _context.Add(checkout);

            var checkoutHistory = new CheckoutHistory
            {
                CheckOut     = now,
                LibraryAsset = item,
                LibraryCard  = libraryCard
            };

            _context.Add(checkoutHistory);

            _context.SaveChanges();
        }
Ejemplo n.º 14
0
        public void CheckOutItem(int assetId, int libraryCardId)
        {
            if (IsCheckedOut(assetId))
            {
                return;
            }

            var item = _context.LibraryAssets.Include(c => c.Status).First(c => c.Id == assetId);

            _context.Update(item);

            //item.Status = _context.Statuses
            //    .FirstOrDefault(s => s.Name == "Checked Out");

            UpdateAssetStatus(assetId, "Checked Out");

            var now = DateTime.Now;

            var libraryCard = _context.LibraryCards.Include(card => card.Checkouts).FirstOrDefault(card => card.Id == libraryCardId);

            var checkout = new Checkouts
            {
                LibraryAsset = item,
                LibraryCard  = libraryCard,
                Since        = now,
                Until        = GetDefaultCheckoutTime(now)
            };

            _context.Add(checkout);
            var checkoutHistory = new CheckoutHistory
            {
                CheckedOut   = now,
                LibraryAsset = item,
                LibraryCard  = libraryCard
            };

            _context.Add(checkoutHistory);
            _context.SaveChanges();
        }
Ejemplo n.º 15
0
        public void CheckOutItem(int assetId, int libraryCardId)
        {
            if (IsCheckedOut(assetId))
            {
                return;
                //add logic here to feedback to the user
            }
            var Item = _context.LibraryAssets
                       .FirstOrDefault(i => i.ID == assetId);

            UpdateAsset(assetId, "Checked Out");

            var libryCard = _context.LibraryCards
                            .FirstOrDefault(h => h.Id == libraryCardId);

            var now = DateTime.Now;

            var checkout = new Checkouts
            {
                LibraryAsset = Item,
                LibraryCard  = libryCard,
                Since        = now,
                Until        = GetDefaultCheckOutTime(now)
            };

            _context.Add(checkout);

            var checkOutHistory = new CheckoutHistory
            {
                LibraryAsset = Item,
                LibraryCard  = libryCard,
                CheckedOut   = now,
            };

            _context.Add(checkOutHistory);

            _context.SaveChanges();
        }
Ejemplo n.º 16
0
 partial void Insertcheckouts(Checkouts instance);
Ejemplo n.º 17
0
        public async Task <IActionResult> CheckoutBook([FromRoute] int id, [FromBody] CheckoutViewModel checkoutBook)
        {
            var errorMessage = new ErrorMessageViewModel();
            var error        = new { Error = errorMessage };
            var userId       = "";

            if (!ModelState.IsValid)
            {
                errorMessage.Message = "The model is missing required fields";
                return(Json(error));
            }

            if (User == null)
            {
                errorMessage.Message = "Could not find user for claims";
                return(Json(error));
            }

            try
            {
                userId = User.Claims.Where(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").SingleOrDefault().Value;
            }
            catch (Exception exception)
            {
                errorMessage.Message = "User Id was not found";
                return(Json(error));
            }

            // Get book and check out
            Documents book = db.Documents.Where(e => e.DocumentId == id).SingleOrDefault();

            if (book == null)
            {
                errorMessage.Message = "Could not find book";
                return(Json(error));
            }

            book.CheckedOut      = true;
            db.Entry(book).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (Exception exception)
            {
                errorMessage.Message = "Could not check out book";
                return(Json(error));
            }

            // Add book to checked out in database
            var checkedOutBook = new Checkouts
            {
                BookId      = id,
                UserId      = userId,
                Email       = checkoutBook.Email,
                Name        = checkoutBook.Name,
                PhoneNumber = checkoutBook.PhoneNumber,
                ReturnDate  = checkoutBook.ReturnDate,
                CheckedOut  = true
            };

            db.Checkouts.Add(checkedOutBook);

            try
            {
                db.SaveChanges();
            }
            catch (Exception exception)
            {
                errorMessage.Message = "Could not add checked out book to database";
                return(Json(error));
            }

            return(Ok(checkedOutBook));
        }
Ejemplo n.º 18
0
        public void PostReturn([FromBody] Checkouts cvalue, int userid, int userstat, int itemid)
        {
            IReturn addReturn = new ProcessReturns();

            addReturn.AddReturn(cvalue, userid, userstat, itemid);
        }
Ejemplo n.º 19
0
 public void AddItem(IEnumerable<ICheckoutable> newItems)
 {
   //add list of books
   Checkouts.AddRange(newItems);
 }
Ejemplo n.º 20
0
 private void LoadCheckouts()
 {
     Checkouts.Clear();
     BookDataService.LoadCheckouts(LoadCheckoutsCallback, null);
 }
Ejemplo n.º 21
0
 partial void Updatecheckouts(Checkouts instance);
Ejemplo n.º 22
0
        public void Put(int id, [FromBody] Checkouts cvalue)
        {
            IUpdate updateCheckout = new Update();

            updateCheckout.UpdateCheckOut(id, cvalue);
        }
Ejemplo n.º 23
0
 partial void Deletecheckouts(Checkouts instance);
 public void Add(Checkouts newCheckout)
 {
     _context.Add(newCheckout);
     _context.SaveChanges();
 }
Ejemplo n.º 25
0
 public void AddItem(ICheckoutable newItem)
 {
   Checkouts.Add(newItem);
 }