Exemplo n.º 1
0
        /// <summary>
        /// Checkout a device
        /// </summary>
        /// <param name="checkOut"></param>
        /// <returns></returns>
        public async Task <bool> CheckOutAsync(CheckOutDTO checkOut)
        {
            var device = await unitOfWork.DeviceRepository.FindByIdAsync(checkOut.Id);

            if (device == null || device.IsDeleted)
            {
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(device.CurrentUser))
            {
                var log = new Log
                {
                    LogTime  = DateTime.Now,
                    LogType  = (int)LogType.CheckOut,
                    UserName = device.CurrentUser,
                    DeviceId = device.Id
                };
                await unitOfWork.LogRepository.AddAsync(log).ConfigureAwait(false);
            }

            device.CurrentUser = string.Empty;
            device.Remarks     = string.Empty;
            await unitOfWork.DeviceRepository.UpdateAsync(device.Id, device).ConfigureAwait(false);


            await unitOfWork.CompleteAsync().ConfigureAwait(false);

            return(true);
        }
Exemplo n.º 2
0
        public OperationDetails AddOrder(string userId, string userIp, string userAgent, Langs l, Currency currency)
        {
            Order       order       = new Order();
            CheckOutDTO checkOutDTO = checkOutService.GetSessionOrder(userId, Langs.English, Currency.Rial);

            order.ShippingCost       = checkOutDTO.ShippingCost;
            order.Status             = OrderStates.pending;
            order.UserId             = userId;
            order.CouponCode         = checkOutDTO.Coupon.Code;
            order.CouponValue        = checkOutDTO.Coupon.Value;
            order.CouponIsPercentage = checkOutDTO.Coupon.IsPercentage;
            order.UserAgent          = userAgent;
            order.UserIpAddress      = userIp;
            order.CreationDate       = DateTime.Now;
            order.DateModified       = DateTime.Now;
            order.SubTotal           = checkOutDTO.SubTotalCost;
            order.Total               = checkOutDTO.TotalCost;
            order.ArabicBillingName   = GetMethodName((long)checkOutDTO.SelectedBillingMethod, Langs.Arabic);
            order.EnglishBillingName  = GetMethodName((long)checkOutDTO.SelectedBillingMethod, Langs.English);
            order.ArabicShippingName  = GetMethodName((long)checkOutDTO.ShippingMethod, Langs.Arabic);
            order.EnglishShippingName = GetMethodName((long)checkOutDTO.ShippingMethod, Langs.English);

            if (checkOutDTO.ShippingMethod == ShippingMethods.WithCompany)
            {
                long coid = checkOutDTO.SelectShippingCompany.Id;
                order.ArabicCompanyName = unitOfWork.ShippingCompanyDescriptionRepository
                                          .Get(c => c.ShippingCompanyId == coid && c.LanguageId == (long)Langs.Arabic).FirstOrDefault().Name;
                order.EnglishCompanyName = unitOfWork.ShippingCompanyDescriptionRepository
                                           .Get(c => c.ShippingCompanyId == coid && c.LanguageId == (long)Langs.English).FirstOrDefault().Name;
            }

            order.OrderItems      = AddOrderItems(checkOutDTO.CheckOutItems);
            order.ShippingAddress =
                AddOrderShippingAddress(addressService.GetAddressById(checkOutDTO.SelectedShippingAddressId));
            order.BillingAddress =
                AddOrderBillingAddress(addressService.GetAddressById(checkOutDTO.SelectedBillingAddressId));
            order = unitOfWork.OrderRepository.Insert(order);
            string billingMetaDesc = unitOfWork.ShippingBillingMethodRepository
                                     .GetByID((long)checkOutDTO.SelectedBillingMethod)
                                     .ShippingBillingMethodDescriptions.FirstOrDefault(c => c.LanguageId == (long)Langs.English).MetaDescription;

            cartService.RemoveAll(checkOutDTO.UserId);
            unitOfWork.Save();
            ChangeState(OrderStates.pending, billingMetaDesc, true, order.Id);
            //unitOfWork.Save();
            CheckOut userCheckOut = unitOfWork.CheckOutRepository.GetByID(order.UserId);

            unitOfWork.CheckOutRepository.Delete(userCheckOut);
            unitOfWork.Save();
            return(new OperationDetails(true, "تمت الإضافة بنجاح", order.Id.ToString()));
        }
Exemplo n.º 3
0
        private async Task CheckOut()
        {
            // Arrange
            var client     = _factory.CreateClient();
            var checkInUrl = "/api/Tracker/CheckOut";

            // Act
            var checkOut = new CheckOutDTO()
            {
                Id = "123456789"
            };
            var json     = JsonConvert.SerializeObject(checkOut);
            var content  = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await client.PostAsync(checkInUrl, content).ConfigureAwait(false);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Exemplo n.º 4
0
        public CheckOutDTO GetSessionOrder(string userId, Langs l, Currency currency)
        {
            CheckOutDTO chickOutDTO  = new CheckOutDTO();
            CheckOut    userCheckOut = GetUserCheckOut(userId);

            chickOutDTO.ShippingMethod            = (ShippingMethods)userCheckOut.SelectedShippingMethod;
            chickOutDTO.SelectedBillingMethod     = (BillingMethods)userCheckOut.SelectedBillingMethod;
            chickOutDTO.SelectedBillingAddressId  = userCheckOut.SelectedBillingAddress;
            chickOutDTO.SelectedShippingAddressId = userCheckOut.SelectedShippingAddress;
            chickOutDTO.SelectShippingCompany     = GetShippingCompanies(l, currency).
                                                    Where(c => userCheckOut.SelectedShippingCompany != null && c.Id == userCheckOut.SelectedShippingCompany).FirstOrDefault();
            chickOutDTO.Step            = userCheckOut.Step;
            chickOutDTO.Coupon          = couponService.GetCoupon(userCheckOut.CouponCode, l, currency);
            chickOutDTO.IsSameAddresses = userCheckOut.IsSame;

            chickOutDTO.CurrencyName = Utils.getCurrencyName(currency, l);

            chickOutDTO.UserId             = userId;
            chickOutDTO.AvailableAddresses = addressService.GetUserAddresses(userId);
            chickOutDTO.CheckOutItems      = ToOrderItemDTO(cartService.GetCartProducts(userId, l, currency), l, currency);

            if (chickOutDTO.AvailableAddresses.Count == 1)
            {
                SetShippingAddress(userId, chickOutDTO.AvailableAddresses[0].Id);
                SetBillingAddress(userId, chickOutDTO.AvailableAddresses[0].Id);
                chickOutDTO.SelectedShippingAddressId = chickOutDTO.AvailableAddresses[0].Id;
                chickOutDTO.SelectedBillingAddressId  = chickOutDTO.AvailableAddresses[0].Id;
            }

            chickOutDTO.CreationDate      = DateTime.Now;
            chickOutDTO.ShippingCompanies = GetShippingCompanies(l, currency);
            if (chickOutDTO.ShippingMethod == ShippingMethods.WithCompany)
            {
                chickOutDTO.ShippingCost = chickOutDTO.SelectShippingCompany.ShippingCost;
            }
            chickOutDTO.BillingMethods  = GetBillingMethods(l);
            chickOutDTO.ShippingMethods = GetShippingMethods(l);
            chickOutDTO.SubTotalCost    = GetSubTotalCost(chickOutDTO.CheckOutItems);

            return(chickOutDTO);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> CheckOut([FromBody] CheckOutDTO checkOutDTO)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var checkInResult = await _trackerBusiness.CheckOutAsync(checkOutDTO).ConfigureAwait(false);

                if (!checkInResult)
                {
                    return(BadRequest(new { Message = "Unable to checkout device." }));
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message + ex.StackTrace);
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Exemplo n.º 6
0
        public Payment CreatePayment(APIContext apiContext, string redirectUrl, CheckOutDTO dto)
        {
            // ADD CART ITEMS
            var itemList = new ItemList()
            {
                items = new List <Item>()
            };

            foreach (var item in dto.CheckOutItems)
            {
                itemList.items.Add(new Item()
                {
                    name        = item.Name,
                    currency    = "USD",
                    price       = item.UnitPrice.ToString(),
                    quantity    = item.Quantity.ToString(),
                    sku         = item.SKU,
                    description = item.Name
                });
            }

            // CHECK COUPON
            if (dto.Coupon.Code != "")
            {
                itemList.items.Add(new Item()
                {
                    name     = "Coupon Discount:" + dto.Coupon.ValueDisplay,
                    quantity = "1",
                    sku      = dto.Coupon.Code,
                    price    = dto.CouponDiscount.ToString(),
                    currency = "USD"
                });
            }

            // CALCULATE AMOUNTS
            var details = new Details()
            {
                subtotal = dto.SubTotalCostDiscounted.ToString(),
                shipping = dto.ShippingCost.ToString(),
            };

            var amount = new Amount()
            {
                currency = "USD",
                total    = dto.TotalCost.ToString(), // Total must be equal to sum of shipping, tax and subtotal.
                details  = details
            };

            // SET TRANSACTION
            var transactionList = new List <Transaction>();

            transactionList.Add(new Transaction()
            {
                description    = "Cart Checkout from romazonia.com",
                invoice_number = dto.InvoiceId,
                amount         = amount,
                item_list      = itemList
            });

            // CREATE PAYER
            var payer = new Payer()
            {
                payment_method = "paypal"
            };

            // CREATE URLS
            var redirUrls = new RedirectUrls()
            {
                cancel_url = redirectUrl,
                return_url = redirectUrl
            };

            // CREATE PAYMENT
            Payment payment = new Payment()
            {
                intent        = "sale",
                payer         = payer,
                transactions  = transactionList,
                redirect_urls = redirUrls
            };

            // RETURN PAYMENT
            return(payment.Create(apiContext));

            //
            //var profile = new WebProfile
            //{
            //    name = "My web experience profile",
            //    presentation = new Presentation
            //    {
            //        brand_name = "My brand name",
            //        locale_code = "US",
            //        logo_image = "https://www.paypalobjects.com/webstatic/i/ex_ce2/logo/logo_paypal_106x28.png",
            //        return_url_label="Back to romazonia.com"
            //    },
            //    input_fields = new InputFields
            //    {
            //        address_override=1,
            //        no_shipping =0
            //    }
            //};
            //var itemList = new ItemList() { items = new List<Item>() };
            //foreach (var item in dto.CheckOutItems)
            //{
            //    itemList.items.Add(new Item()
            //    {
            //        name = item.Name,
            //        currency = "USD",
            //        price = item.UnitPrice.ToString(),
            //        quantity = item.Quantity.ToString(),
            //        sku = item.SKU,
            //        description = item.Name
            //    });
            //}

            //AddressDTO billingAddress=dto.AvailableAddresses.Where(c=>c.Id==dto.SelectedBillingAddressId).SingleOrDefault();

            //Address paypalBillingAddress = new Address()
            //{
            //    city = billingAddress.City,
            //    country_code = billingAddress.Country,
            //    line1 = billingAddress.Address1,
            //    phone = billingAddress.Phone,
            //    postal_code = billingAddress.PostCode
            //};

            //AddressDTO shippingAddress = dto.AvailableAddresses.Where(c => c.Id == dto.SelectedShippingAddressId).SingleOrDefault();

            //ShippingAddress paypalShippingAddress = new ShippingAddress()
            //{
            //    city = shippingAddress.City,
            //    country_code = shippingAddress.Country,
            //    line1 = shippingAddress.Address1,
            //    phone = shippingAddress.Phone,
            //    postal_code = shippingAddress.PostCode
            //};

            ////itemList.shipping_address = paypalShippingAddress;

            //var payer = new Payer() { payment_method = "paypal" };
            //var redirUrls = new RedirectUrls()
            //{
            //    cancel_url = redirectUrl,
            //    return_url = redirectUrl
            //};
            //var details = new Details()
            //{
            //    subtotal = dto.SubTotalCost.ToString(),
            //    shipping=dto.ShippingCost.ToString(),
            //};

            //var amount = new Amount()
            //{
            //    currency = "USD",
            //    total = dto.TotalCost.ToString(), // Total must be equal to sum of shipping, tax and subtotal.
            //    details = details
            //};

            //var transactionList = new List<Transaction>();

            //transactionList.Add(new Transaction()
            //{
            //    description = "Checkout from romazonia.com",
            //    invoice_number = dto.InvoiceId,
            //    amount = amount,
            //    item_list = itemList
            //});

            //Payment payment = new Payment()
            //{
            //    //experience_profile_id = profile.id,
            //    intent = "sale",
            //    payer = payer,
            //    transactions = transactionList,
            //    redirect_urls = redirUrls
            //};
            //return payment.Create(apiContext);
        }