예제 #1
0
        public void TestInitiateCheckout()
        {
            Guid userId = new Guid("92A8AA97-294C-487F-8B82-4DA9836C1136");
            User user   = DbCommonManager.GetUser(userId);

            Configuration config      = new Configuration();
            PayUManager   payUManager = new PayUManager(config);

            CheckoutRequest cr = new CheckoutRequest();

            cr.User          = user;
            cr.CheckoutItems = new CheckoutItems();
            cr.CheckoutItems.TotalCalcPrice = 135;

            List <CheckoutItem> cil = new List <CheckoutItem>();
            CheckoutItem        ci  = new CheckoutItem();

            ci.SID  = 1;
            ci.Qty  = 1;
            ci.ID   = 1;
            ci.IPID = 1;
            cil.Add(ci);

            cr.CheckoutItems.Items = cil.ToArray();

            CheckoutResponse response = payUManager.InitiateCheckout(cr);
        }
예제 #2
0
        public void Get_Checkout_Total_Cost_WithDiscount()
        {//check the cost for the checkout items
            //some of the items with offer
            IList <KeyValuePair <int, OfferFlags> > lstProductOffer;

            lstProductOffer = new List <KeyValuePair <int, OfferFlags> >()
            {
                new KeyValuePair <int, OfferFlags>(1, OfferFlags.BuyOneGetOneFree),
                new KeyValuePair <int, OfferFlags>(2, OfferFlags.ThreeForTwo)
            };

            var cart = new CheckoutProcesor(_lstCheckItem, _lstProduct);
            var item = new CheckoutItem()
            {
                CheckoutItemId = 1, ProductId = 1, Quantity = 1
            };

            cart.AddItem(item);
            item = new CheckoutItem()
            {
                CheckoutItemId = 2, ProductId = 2, Quantity = 2
            };
            cart.AddItem(item);
            item = new CheckoutItem()
            {
                CheckoutItemId = 3, ProductId = 1, Quantity = 1
            };
            cart.AddItem(item);
            var tot = cart.GetTotalCost(lstProductOffer);

            Assert.AreEqual(1.1M, tot);
        }
예제 #3
0
        //Carregar os itens da compra (Mensalidade)
        private List <CheckoutItem> carregarProdutos(AssociadoContribuicao OAssociadoContribuicao)
        {
            List <CheckoutItem> listaItens = new List <CheckoutItem>();

            CheckoutItem OItemCompra = new CheckoutItem();

            OItemCompra.flagEntrega = false;

            OItemCompra.idTipoItem = TipoItemConst.MENSALIDADE;

            OItemCompra.idItem = OAssociadoContribuicao.id;

            OItemCompra.nomeItem = OAssociadoContribuicao.Contribuicao.descricao;

            OItemCompra.descricaoItem = String.Format("Pagamento de Mensalidade referente ao perído de {0}", OAssociadoContribuicao.Contribuicao.anoInicioVigencia.ToString());

            OItemCompra.qtdeItem = 1;

            OItemCompra.valorUnitario = OAssociadoContribuicao.valorAtual;

            OItemCompra.pathImagem = "";

            listaItens.Add(OItemCompra);

            return(listaItens);
        }
예제 #4
0
 public void Post([FromBody] List <BasketHelper> customerBasket)
 {
     _context.CheckoutItem.RemoveRange(_context.CheckoutItem);
     for (int i = 0; i < customerBasket.Count(); i++)
     {
         CheckoutItem _checkoutItem = new CheckoutItem
         {
             ItemName  = customerBasket[i].ItemName,
             ItemPrice = customerBasket[i].ItemPrice,
             ItemBrand = customerBasket[i].ItemBrand,
             ItemType  = customerBasket[i].ItemType,
             Pic       = customerBasket[i].Pic,
             Quantity  = customerBasket[i].Quantity
         };
         if (_checkoutItem.Quantity > 1)
         {
             _checkoutItem.ItemPriceTotal = _checkoutItem.ItemPrice * _checkoutItem.Quantity;
         }
         else
         {
             _checkoutItem.ItemPriceTotal = _checkoutItem.ItemPrice;
         }
         decimal.Round(_checkoutItem.ItemPriceTotal, 2);
         _context.CheckoutItem.Add(_checkoutItem);
         _context.SaveChanges();
     }
 }
예제 #5
0
        private void btnAddBarcode_Click(object sender, EventArgs e)
        {
            lblBarcodeError.Hide();

            string barcode = txtBarcode.Text.Trim();

            if (string.IsNullOrEmpty(barcode))
            {
                NotifySelectionError(Properties.Resources.BARCODE_REQUIRED);
            }
            else if (!IsValidBarcode(barcode))
            {
                NotifySelectionError(Properties.Resources.ALPHANUMERIC_CHARS_ONLY);
            }
            else
            {
                CheckoutItem item = FindByBarcode(barcode);

                if (item == null)
                {
                    NotifySelectionError("Item not found");
                }
                else if (IsItemInSelectionList(item))
                {
                    NotifySelectionError("Item already added");
                }
                else
                {
                    checkoutInfo.AddItem(item);

                    txtBarcode.Text = "";
                }
            }
        }
예제 #6
0
        public async Task <ActionResult <CheckoutItem> > PostCheckoutItem(CheckoutItem item)
        {
            _context.CheckoutItems.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetCheckoutItem), new { id = item.Id }, item));
        }
        private decimal CalculateTotalForItemWithDiscount(CheckoutItem item)
        {
            if (item.Product.DiscountRule.Quantity <= 0)
            {
                throw new ArgumentOutOfRangeException("Cannot add a discount with negative or zero quantity");
            }

            if (item.Product.DiscountRule.Price < 0)
            {
                throw new ArgumentOutOfRangeException("Cannot add a discount with negative price");
            }

            var totalPrice = 0m;

            if (item.Product.DiscountRule.Quantity == 1)
            {
                // In this case, the discount is applied on the total number or quantity of products
                totalPrice += item.Quantity * item.Product.DiscountRule.Price;
            }
            else
            {
                // calculate the number of items subject to discount based on the discount rule's number of discounts
                var nbrOfDiscounts = Math.Floor(item.Quantity / item.Product.DiscountRule.Quantity);
                totalPrice += nbrOfDiscounts * item.Product.DiscountRule.Price;

                // calculate the number of elements excluded from discount
                var remaining = item.Quantity - nbrOfDiscounts * item.Product.DiscountRule.Quantity;
                totalPrice += remaining * item.Product.UnitPrice;
            }

            return(totalPrice);
        }
예제 #8
0
        private static void ShoppingCart()
        {
            IList <ICheckoutItem> _lstCheckItem = new List <ICheckoutItem>();
            IList <IProduct>      _lstProduct   = new List <IProduct>();

            //set up store products
            _lstProduct = SetupProducts();

            //check out items
            var cart = new CheckoutProcesor(_lstCheckItem, _lstProduct);
            var item = new CheckoutItem()
            {
                CheckoutItemId = 1, ProductId = 1, Quantity = 1
            };

            cart.AddItem(item);

            item = new CheckoutItem()
            {
                CheckoutItemId = 2, ProductId = 2, Quantity = 1
            };
            cart.AddItem(item);

            //get the cost for the checkout items
            var tot = cart.GetTotalCost();

            Console.WriteLine($"Total number of the items checked out and the cost: {cart.GetTotalItems().Count}  {tot.ToString("C")}.");
        }
예제 #9
0
        public void Test_CanRemoveItemFromCheckout()
        {
            var checkoutService = Subject();

            // First add the item to the checkout
            checkoutService.AddItemToCheckout(3, 4, MeasurmentUnits.POUND, null);

            // Setting-up the CheckoutRepository mock object to imitate getting an exapmle checkoutItem
            var testItem = new CheckoutItem
            {
                Id      = 1,
                Product = new Product {
                    Sku = 3
                },
                Quantity = 4
            };

            _checkoutRepoMock.Setup(r => r.GetCheckoutItem(1)).Returns(testItem);

            // Perform delete through the checkoutService
            checkoutService.DeleteItemFromCheckout(1);

            // Verify that the checkoutService called the repository mock object; otherwise MockException is thrown.
            // this is to verify that the checkoutService will call the real repository for removing the item.
            _checkoutRepoMock.Verify(r => r.DeleteItem(testItem));
        }
예제 #10
0
        private void LoadFromDB()
        {
            var cmd = DbConnection.CreateCommand();

            cmd.CommandText = "select ci.InventoryID, c.CheckoutID, c.CheckoutDate, b.Title, b.ISBN, ci.DueDate, ci.RenewalCount, " +
                              "a.Fname, a.Minit, a.Lname " +
                              "from CHECKOUT c " +
                              "join CHECKOUT_ITEM ci on ci.CheckoutID = c.CheckoutID " +
                              "join INVENTORY i on i.Barcode = ci.InventoryID " +
                              "join BOOK b on b.ISBN = i.BookID " +
                              "join BOOK_AUTHOR ba on ba.BookID = b.ISBN " +
                              "join AUTHOR a on a.ID = ba.AuthorID " +
                              "where c.MemberID = @memberId " +
                              "and ReturnedDate is null " +
                              "order by c.CheckoutDate desc, Title desc";
            cmd.Parameters.AddWithValue("memberId", MemberDetails.MemberId);

            Hashtable recordHash = new Hashtable();

            using (var reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    var InventoryID = reader.GetString(0);
                    var CheckoutID  = reader.GetInt32(1);

                    var key = string.Format("{0}:{1}", InventoryID, CheckoutID);

                    var item = (CheckoutItem)recordHash[key];

                    if (item == null)
                    {
                        item = new CheckoutItem()
                        {
                            InventoryID    = InventoryID,
                            CheckoutID     = CheckoutID,
                            CheckedoutDate = reader.GetDateTime(2).ToString(DATE_COLUMN_FORMAT),
                            Title          = reader.GetString(3),
                            ISBN           = reader.GetString(4),
                            DueDate        = reader.GetDateTime(5).ToString(DATE_COLUMN_FORMAT),
                            RenewalCount   = reader.GetInt32(6)
                        };

                        recordHash[key] = item;
                    }

                    item.Authors.Add(new Author()
                    {
                        Firstname     = reader.GetString(7),
                        MiddleInitial = (reader.IsDBNull(8) ? null : reader.GetString(8)),
                        Lastname      = reader.GetString(9)
                    });
                }
            }

            foreach (var record in recordHash.Values)
            {
                checkoutList.Add((CheckoutItem)record);
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,BookId,CheckoutId,Returned")] CheckoutItem checkoutItem)
        {
            if (id != checkoutItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(checkoutItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CheckoutItemExists(checkoutItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"]     = new SelectList(_context.Book, "Id", "Id", checkoutItem.BookId);
            ViewData["CheckoutId"] = new SelectList(_context.Checkout, "Id", "Id", checkoutItem.CheckoutId);
            return(View(checkoutItem));
        }
        public void TestItemCanBeIdentifiedBySKU()
        {
            // Arrange
            ICheckoutItem item;

            // Act
            item = new CheckoutItem("A", 50);

            // Assert
            Assert.AreEqual("A", item.SKU);
        }
예제 #13
0
        public async Task <IActionResult> PutCheckoutItem(long id, CheckoutItem item)
        {
            if (id != item.Id)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
예제 #14
0
        public void TestPayItemsWithDiscountPositive()
        {
            var apple = new Item {
                Name = "Apple", Price = 30
            };
            var banana = new Item {
                Name = "Banana", Price = 50
            };
            var peach = new Item {
                Name = "Peach", Price = 60
            };

            checkout.AddItem(2, apple);
            checkout.AddItem(7, banana);
            checkout.AddItem(4, peach);

            var discountApple = new Discount {
                Name = "2 for 45", Quantity = 2, Price = 45
            };
            var discountBanana = new Discount {
                Name = "3 for 130", Quantity = 3, Price = 130
            };
            var discountPeach = new Discount {
                Name = "5 for 40", Quantity = 5, Price = 40
            };

            discountCollection.Add(apple, discountApple);
            discountCollection.Add(banana, discountBanana);
            discountCollection.Add(peach, discountPeach);
            var checkoutBill = checkout.PayItems();

            var paidApple = new CheckoutItem(apple, discountApple)
            {
                Amount           = 2, Price = 45,
                AppliedDiscounts = 1
            };

            var paidBanana = new CheckoutItem(banana, discountBanana)
            {
                Amount           = 7, Price = 310,
                AppliedDiscounts = 2
            };
            var paidPeach = new CheckoutItem(peach, discountPeach)
            {
                Amount           = 4, Price = 240,
                AppliedDiscounts = 0
            };

            Assert.True(checkoutBill.Items.Contains(paidApple));
            Assert.True(checkoutBill.Items.Contains(paidBanana));
            Assert.True(checkoutBill.Items.Contains(paidPeach));
            Assert.AreEqual(595, checkoutBill.Total);
        }
        public async Task <IActionResult> Create([Bind("Id,BookId,CheckoutId,Returned")] CheckoutItem checkoutItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(checkoutItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"]     = new SelectList(_context.Book, "Id", "Id", checkoutItem.BookId);
            ViewData["CheckoutId"] = new SelectList(_context.Checkout, "Id", "Id", checkoutItem.CheckoutId);
            return(View(checkoutItem));
        }
        public void WhenScanSingleItem_ThenItemShouldBeInstantiated(char itemCode, decimal itemPrice)
        {
            ICheckout     checkout             = Mocker.CreateInstance <Checkout>();
            ICheckoutItem expectedCheckoutItem = new CheckoutItem(itemCode, itemPrice);

            Mocker.GetMock <IItemLookup>()
            .Setup(scanner => scanner.Lookup(itemCode))
            .Returns(expectedCheckoutItem);

            var item = checkout.AppendItem(itemCode);

            item.ItemCode.Should().Be(itemCode);
            item.ItemPrice.Should().Be(itemPrice);
        }
예제 #17
0
        private CheckoutItem FindByBarcode(string barcode)
        {
            var cmd = DbConnection.CreateCommand();

            cmd.CommandText = "select b.ISBN, b.Title, a.ID, a.Fname, a.Minit, a.Lname " +
                              "from BOOK b " +
                              "join INVENTORY i on i.BookID = b.ISBN " +
                              "join BOOK_AUTHOR ba on ba.BookID = b.ISBN " +
                              "join AUTHOR a on a.ID = ba.AuthorID " +
                              "where barcode = @barcode";
            cmd.Parameters.AddWithValue("barcode", barcode);
            Hashtable t = new Hashtable();

            string ISBN = null;

            using (var reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    ISBN = reader.GetString(0);

                    var item = (CheckoutItem)t[ISBN];

                    if (item == null)
                    {
                        item = new CheckoutItem
                        {
                            ISBN    = ISBN,
                            Title   = reader.GetString(1),
                            Barcode = barcode
                        };

                        t.Add(ISBN, item);
                    }

                    item.Authors.Add(new Author()
                    {
                        ID            = reader.GetInt32(2),
                        Firstname     = reader.GetString(3),
                        MiddleInitial = (reader.IsDBNull(4) ? null : reader.GetString(4)),
                        Lastname      = reader.GetString(5)
                    });
                }
            }

            return(ISBN == null ? null : (CheckoutItem)t[ISBN]);
        }
예제 #18
0
        public static void TestCheckout()
        {
            List <CheckoutItem> cil = new List <CheckoutItem>();
            CheckoutItem        ci  = new CheckoutItem();

            ci.SID       = 1;
            ci.Qty       = 1;
            ci.ID        = 1;
            ci.IPID      = 1;
            ci.CalcPrice = 135;
            cil.Add(ci);

            JsonSerializerHelper jsh = new JsonSerializerHelper();
            string serializedItems   = jsh.Serialize(ci);

            //cr.Items = cil.ToArray();
        }
예제 #19
0
        public void ItemWithoutSpecialPrice_Test()
        {
            //Arrange


            //Act
            var A99Product = new CheckoutItem("A99", 0.50);
            var B15Product = new CheckoutItem("B15", 0.30);
            var C40Product = new CheckoutItem("C40", 0.60);


            _checkoutService.ScanItem(A99Product);
            _checkoutService.ScanItem(B15Product);
            _checkoutService.ScanItem(C40Product);
            //Assert
            Assert.AreEqual(1.40, _checkoutService.GetTotal());
        }
예제 #20
0
        public void PriceCalculationLogic_MultipleQuantity_NoOffers()
        {
            //Arrange
            ISpecialOfferRepository specialOfferRepository = Substitute.For <ISpecialOfferRepository>();

            CheckoutItem checkoutItem = new CheckoutItem {
                Price = 0.5M, Quantity = 4
            };

            PriceCalculationLogic priceCalculationLogic = new PriceCalculationLogic(specialOfferRepository);

            //Act
            var price = priceCalculationLogic.GetPrice(checkoutItem);

            //Assert
            Assert.AreEqual(2m, price);
        }
예제 #21
0
        public void Get_Checkout_Total_Cost()
        {//check the cost for the checkout items
            var cart = new CheckoutProcesor(_lstCheckItem, _lstProduct);
            var item = new CheckoutItem()
            {
                CheckoutItemId = 1, ProductId = 1, Quantity = 1
            };

            cart.AddItem(item);
            item = new CheckoutItem()
            {
                CheckoutItemId = 2, ProductId = 2, Quantity = 2
            };
            cart.AddItem(item);
            var tot = cart.GetTotalCost();

            Assert.AreEqual(1.1M, tot);
        }
예제 #22
0
        public static Status ValidateItem(CheckoutItem purchaseItem)
        {
            Decimal hundred = 100.00M;
            Status  status  = Status.Success;

            List <StoreItem> availableStoreItems = GetAvailableStoreItems(purchaseItem.SID);

            if (availableStoreItems == null || availableStoreItems.Count <= 0)
            {
                status = Status.InvalidInput;
                return(status);
            }

            StoreItem storeItem = availableStoreItems.Find(si => si.ID == purchaseItem.ID);

            if (storeItem == null)
            {
                status = Status.InvalidItem;
                return(status);
            }
            ItemPrice itemPrice = storeItem.PriceList.Find(ip => ip.ID == purchaseItem.IPID);

            if (itemPrice == null)
            {
                status = Status.InvalidItem;
                return(status);
            }
            if (itemPrice.Price <= 0)
            {
                status = Status.InvalidPrice;
                return(status);
            }

            Decimal itemDiscount = CalculateDiscount(itemPrice.Price, storeItem);

            if (itemDiscount >= hundred)
            {
                status = Status.InvalidPrice;
                return(status);
            }
            Decimal discountedPrice = itemPrice.Price - itemDiscount;

            return(discountedPrice == purchaseItem.CalcPrice? Status.Success: Status.InvalidPrice);
        }
예제 #23
0
        private bool RenewItem(CheckoutItem item, DateTime newDueDate)
        {
            var cmd = DbConnection.CreateCommand();

            //be very specific on the match to ensure it wasn't updated ahead of us
            cmd.CommandText = "update CHECKOUT_ITEM set RenewalCount = @NewRenewalCount, DueDate = @NewDueDate, RenewedDate = @RenewedDate " +
                              "where CheckoutID = @CheckoutID and InventoryID = @InventoryID and RenewalCount = @RenewalCount and ReturnedDate is null";

            cmd.Parameters.AddWithValue("NewRenewalCount", item.RenewalCount + 1);
            cmd.Parameters.AddWithValue("NewDueDate", newDueDate);
            cmd.Parameters.AddWithValue("RenewedDate", DateTime.Now);
            cmd.Parameters.AddWithValue("CheckoutID", item.CheckoutID);
            cmd.Parameters.AddWithValue("InventoryID", item.InventoryID);
            cmd.Parameters.AddWithValue("RenewalCount", item.RenewalCount);

            int recordsUpdated = cmd.ExecuteNonQuery();

            return(recordsUpdated == 1);
        }
예제 #24
0
        /// <summary>
        ///     Pay the added items (with discounts) (<see cref="AddItem" />) and get a <see cref="CheckoutBill" />.
        /// </summary>
        /// <returns>The <see cref="CheckoutBill" />.</returns>
        public CheckoutBill PayItems()
        {
            var checkoutBill = new CheckoutBill();

            foreach (var(item, amount) in items)
            {
                var discount = GetDiscount(item);
                var(price, appliedDiscounts) = CalculatePrice(amount, item, discount);

                var checkoutItem = new CheckoutItem(item, discount)
                {
                    Amount           = amount, Price = price,
                    AppliedDiscounts = appliedDiscounts
                };
                checkoutBill.Items.Add(checkoutItem);
            }

            return(checkoutBill);
        }
        public void AddItem(Product product, decimal quantity, MeasurmentUnits buyUnit, DiscountRule discountRule)
        {
            product.DiscountRule = discountRule;

            // create a CheckoutItem object from the provided parameters
            var checkoutItem = new CheckoutItem
            {
                Product  = product,
                Quantity = quantity,
                BuyUnit  = buyUnit,
                Price    = product.UnitPrice * quantity
            };

            // Set a unique ID and increment the static counter
            checkoutItem.Id = _id;
            Interlocked.Increment(ref _id);

            // add the item to the checkout list
            _checkoutItems.Add(checkoutItem);
        }
예제 #26
0
        private static void ShoppingCartWithOffer()
        {
            IList <ICheckoutItem> _lstCheckItem = new List <ICheckoutItem>();
            IList <IProduct>      _lstProduct   = new List <IProduct>();

            //set up store products
            _lstProduct = SetupProducts();

            //set up offers
            IList <KeyValuePair <int, OfferFlags> > lstProductOffer;

            lstProductOffer = new List <KeyValuePair <int, OfferFlags> >()
            {
                new KeyValuePair <int, OfferFlags>(1, OfferFlags.BuyOneGetOneFree),
                new KeyValuePair <int, OfferFlags>(2, OfferFlags.ThreeForTwo)
            };

            //check out items
            var cart = new CheckoutProcesor(_lstCheckItem, _lstProduct);
            var item = new CheckoutItem()
            {
                CheckoutItemId = 1, ProductId = 1, Quantity = 1
            };

            cart.AddItem(item);
            item = new CheckoutItem()
            {
                CheckoutItemId = 2, ProductId = 2, Quantity = 1
            };
            cart.AddItem(item);
            item = new CheckoutItem()
            {
                CheckoutItemId = 3, ProductId = 1, Quantity = 1
            };
            cart.AddItem(item);

            //get the cost for the checkout items with the offers
            var tot = cart.GetTotalCost(lstProductOffer);

            Console.WriteLine($"Total number of the items checked out with offers and the cost: {cart.GetTotalItems().Count}  {tot.ToString("C")}.");
        }
        public void TestItemCanBeIdentifiedBySKU()
        {
            // Arrange
            var collection = new CheckOutItemCollection();
            var a          = new CheckoutItem("A", 50);
            var b          = new CheckoutItem("B", 30);
            var c          = new CheckoutItem("C", 20);
            var d          = new CheckoutItem("D", 15);

            // Act
            collection.Add(a);
            collection.Add(b);
            collection.Add(c);
            collection.Add(d);

            // Assert
            Assert.AreEqual("A", collection["A"].SKU);
            Assert.AreEqual("B", collection["B"].SKU);
            Assert.AreEqual("C", collection["C"].SKU);
            Assert.AreEqual("D", collection["D"].SKU);
        }
예제 #28
0
        public void Scan(string sku)
        {
            if (string.IsNullOrEmpty(sku))
            {
                throw new Exception("SKU cannot be NULL or Empty");
            }

            var product = _productService.GetProductBySku(sku.Trim());

            if (product == null)
            {
                throw new Exception($"Product not found for SKU : {sku}");
            }

            var checkoutItem = new CheckoutItem {
                Product    = product,
                ItemNumber = _items.Count + 1
            };

            _items.Add(checkoutItem);
        }
예제 #29
0
        public void CheckoutExpress()
        {
            checkoutoptions.Process = CheckoutType.Express;
            var itemId      = Request.Form["ItemId"];
            var itemName    = Request.Form["ItemName"];
            var unitPrice   = decimal.Parse(Request.Form["UnitPrice"]);
            var quantity    = int.Parse(Request.Form["Quantity"]);
            var discount    = decimal.Parse(Request.Form["Discount"]);
            var deliveryFee = decimal.Parse(Request.Form["DeliveryFee"]);
            var handlingFee = decimal.Parse(Request.Form["HandlingFee"]);
            var tax1        = decimal.Parse(Request.Form["Tax1"]);
            var tax2        = decimal.Parse(Request.Form["Tax2"]);

            CheckoutItem checkoutitem = new CheckoutItem(itemId, itemName, unitPrice, quantity, tax1, tax2, discount, handlingFee, deliveryFee);

            checkoutoptions.OrderId      = "12-34"; //"YOUR_UNIQUE_ID_FOR_THIS_ORDER";  //can also be set null
            checkoutoptions.ExpiresAfter = 2880;    //"NUMBER_OF_MINUTES_BEFORE_THE_ORDER_EXPIRES"; //setting null means it never expires
            var url = CheckoutHelper.GetCheckoutUrl(checkoutoptions, checkoutitem);

            Response.Redirect(url);
        }
예제 #30
0
        public static void InitiateCheckout()
        {
            Guid userId = new Guid("92A8AA97-294C-487F-8B82-4DA9836C1136");
            User user   = DbCommonManager.GetUser(userId);

            Configuration config = new Configuration();

            config.PayUFailureUrl = "FailureUrl";
            config.PayUSuccessUrl = "SuccessUrl";
            config.PayUSalt       = "Salt";
            config.PayUKey        = "Key";

            PayUManager payUManager = new PayUManager(config);

            CheckoutRequest cr = new CheckoutRequest();

            cr.User                    = user;
            cr.DeliveryAddress         = new OrderDeliveryAddressMap();
            cr.DeliveryAddress.City    = "Bangalore";
            cr.DeliveryAddress.ZipCode = "560068";
            cr.DeliveryAddress.State   = "Karnataka";
            cr.DeliveryAddress.Address = "No 204 Sunnyvale apartment, 15th main road, AECS layout block A, Singasandra/Kudlu";

            CheckoutItems coi = new CheckoutItems();

            cr.CheckoutItems = coi;
            List <CheckoutItem> cil = new List <CheckoutItem>();
            CheckoutItem        ci  = new CheckoutItem();

            ci.SID       = 1;
            ci.Qty       = 1;
            ci.ID        = 1;
            ci.IPID      = 1;
            ci.CalcPrice = 135;
            cil.Add(ci);
            cr.CheckoutItems.Items          = cil.ToArray();
            cr.CheckoutItems.TotalCalcPrice = 135;

            CheckoutResponse response = payUManager.InitiateCheckout(cr);
        }