示例#1
0
        public IActionResult Index(int productId)
        {
            var shoe = _shoesService.GetShoeById(productId);

            shoe.Sizes = _quantityService.GetAllSizesById(productId);

            var allBrandsVm = _brandServices.GetAllBrands();

            dynamic mymodel = new ExpandoObject();

            mymodel.Shoe  = shoe;
            mymodel.Brand = allBrandsVm;

            return(View(mymodel));
        }
示例#2
0
        public IActionResult GetShoeById(int id)
        {
            var shoe = _shoesService.GetShoeById(id);

            return(Ok(shoe));
        }
示例#3
0
        public ActionResult CheckoutKlarna(int size, int shoeId)
        {
            dynamic myModel = new ExpandoObject();
            var     _shoe   = shoeService.GetShoeById(shoeId);

            myModel.Shoe = _shoe;
            myModel.Size = size;

            using var client   = new HttpClient();
            client.BaseAddress = new Uri(baseURL);
            client.DefaultRequestHeaders.Add("Authorization", "Basic " + _config["KlarnaAuth"]);

            var price = _shoe.Price * 100;

            var request = new HttpRequestMessage(HttpMethod.Post, $"checkout/v3/orders");

            var order_Lines = new KlarnaPost.Order_Lines()
            {
                type                  = "physical",
                reference             = "1337-GBG",
                name                  = _shoe.Name,
                quantity              = 1,
                quantity_unit         = "pcs",
                unit_price            = price,
                tax_rate              = 2500,
                total_amount          = price,
                total_discount_amount = 0,
                total_tax_amount      = 0.2m * price
            };

            KlarnaPost.Order_Lines[] order_lines_array = new KlarnaPost.Order_Lines[] { order_Lines };

            var merchant = new KlarnaPost.Merchant_Urls()
            {
                terms        = @"https://www.example.com/terms.html",
                checkout     = @"https://www.example.com/checkout.html",
                confirmation = @"https://*****:*****@"https://www.example.com/api/push"
            };

            var root = new KlarnaPost.Rootobject()
            {
                purchase_country  = "SE",
                purchase_currency = "SEK",
                locale            = "en-GB",
                order_amount      = order_Lines.total_amount,
                order_tax_amount  = order_Lines.total_tax_amount,
                order_lines       = order_lines_array,
                merchant_urls     = merchant
            };

            var jsonContent = JsonConvert.SerializeObject(root, Formatting.Indented);

            request.Content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
            Debug.WriteLine(jsonContent);

            var result = client.SendAsync(request);

            var resultString = result.Result.Content.ReadAsStringAsync();

            Debug.WriteLine(resultString.Result);

            var klarna = JsonConvert.DeserializeObject <Rootobject>(resultString.Result);

            Debug.WriteLine(klarna);

            klarna.merchant_urls.confirmation = $"https://localhost:44383/OrderConfirmed/{klarna.order_id}";
            myModel.Klarna = klarna;

            return(View("Klarna", klarna));
        }