예제 #1
0
        public PaymentRequestValidationResponse ValidatePosPaymentRequest(PosBdo pos, string posUserUid)
        {
            if (pos.ValidateUrl == null)
            {
                throw new ArgumentNullException("POS does not have ValidateUrl to validate request from it");
            }

            PaymentRequestValidationResponse response = null;

            try
            {
                //var validationUri = new Uri(pos.ValidateUrl.ToString() + posUserUid);
                string url = pos.ValidateUrl.ToString();
                url = url.EndsWith("/") || url.EndsWith("=") ? String.Concat(url, posUserUid) : String.Concat(url, "/", posUserUid);
                var validationUri = new Uri(url);
                Logger.InfoFormat("Validating request payment from POS: `{0}`", validationUri.ToString());
                response = _communicationBll.GetJsonResponse <PaymentRequestValidationResponse>(validationUri);
                if (response == null)
                {
                    throw new BadResponseException("Got NULL response from POS on request validation");
                }

                if (response.RequestedAmountMinor < 1)
                {
                    throw new IncorrectPaymentParamersException("Payment request amount (minor) should be greater than 0");
                }

                if (String.IsNullOrEmpty(response.ProductName))
                {
                    throw new IncorrectPaymentParamersException("Payment request must specify product name");
                }

                ValidateCurrencyCode(response.CurrencyCode, pos);

                // model.Locations = posResponse.Locations ?? new List<ProductServiceLocation>();
                foreach (var l in response.Locations)
                {
                    if (String.IsNullOrEmpty(l.LatLng) == false)
                    {
                        l.LatLngCoordinates = BllFactory.Current.HelperBll.ParseLatLng(l.LatLng, MapTypes.GoogleMap);
                    }
                }

                return(response);
            }
            catch (InvalidCastException icex)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw;
            }
        }
예제 #2
0
        public ProductBdo SaveProductInformationFromPos(string posUserUid, PaymentRequestValidationResponse posResponse, ProductCheckoutModel checkout)
        {
            if (posResponse == null)
            {
                throw new ArgumentNullException("Response from POS is NULL");
            }

            ProductBdo product = new ProductBdo();
            PosBdo     pos     = new PosBdo();

            // TODO: use automapper
            Mapper.CreateMap <PaymentRequestValidationResponse, ProductBdo>()
            .ForMember(dest => dest.ProductPrice,
                       orig => orig.MapFrom(x => x.RequestedAmountMinor / 100m))
            .ForMember(dest => dest.ValidTill,
                       orig => orig.MapFrom(x => BllFactory.Current.HelperBll.ConvertFromUnixTimestamp(x.ProductValidTillTm)));

            product = Mapper.Map <ProductBdo>(posResponse);

            if (checkout.LocationId > 0)
            {
                var location = posResponse.Locations.FirstOrDefault(x => x.Id == checkout.LocationId);
                if (location == null)
                {
                    throw new ArgumentOutOfRangeException("LocationId", "Incorrect POS service location!");
                }

                product.PosName             = location.Name;
                product.PosCity             = location.City;
                product.PosAddress          = location.Address;
                product.PhoneForReservation = location.PhoneReservation;
                product.EmailForReservation = location.EmailReservation;
            }



            product.CustomerName  = checkout.CustomerName;
            product.CustomerEmail = checkout.CustomerEmail;
            product.CustomerPhone = checkout.CustomerPhone;
            product.Remarks       = checkout.Remarks;

            product.PaymentSystem = checkout.PaymentSystem;
            product.ProductUid    = Guid.NewGuid().ToString("N");
            product.PosUserUid    = posUserUid;
            product.PaySystemUid  = Guid.NewGuid().ToString("N");

            Logger.Debug("Saving product information from POS and customer form");
            Logger.DebugFormat("  Pass product duration to save: `{0}`", product.ProductDuration);
            Logger.Debug(DumpBll.Dump(product));

            return(_productsDal.SaveProductInformationFromPos(product, pos));
        }
예제 #3
0
        public JsonResult Validate(string id)
        {
            var resp = new PaymentRequestValidationResponse();

            try
            {
                var      product = _products.First(x => x.ProductUid == id);
                string[] errors  = new string[0];

                resp.Status               = true;
                resp.Message              = "Ok";
                resp.Errors               = errors;
                resp.ProductName          = product.ProductName;
                resp.RequestedAmountMinor = (int)(product.ProductPrice * 100);
                resp.CurrencyCode         = "EUR";
                resp.Locations            = new List <ProductServiceLocation>();
                resp.Locations.Add(new ProductServiceLocation {
                    Id = 666001, Name = "LocalShop", City = "Computer", Address = "127.0.0.1"
                });
                //return Json(new PaymentRequestValidationResponse
                //{
                //    Status = true,
                //    Message = "Ok",
                //    Errors = errors,
                //    RequestedAmountMinor = 666,
                //    CurrencyCode = "EUR",
                //    ProductName = "Massage #2",
                //    ProductDescription = "Very good and sensitive"
                //});
            }
            catch (Exception ex)
            {
                resp.Status = false;
                resp.Errors = new string[] { ex.Message };
            }
            return(Json(resp));
        }