protected override Task <ICommandResult> Handle(UpdateTransactionCommand command)
        {
            List <TransactionDetail> transactionDetailList = new List <TransactionDetail>();
            var transaction = _transactionRepository.Get(command.TransactionId);

            if (transaction != null && transaction.CreatedBy != null && transaction.ChannelId != Channels.Feel)
            {
                var user = _userRepository.GetByAltId(transaction.CreatedBy);
                user.PhoneCode   = command.DeliveryDetail[0].PhoneCode;
                user.PhoneNumber = command.DeliveryDetail[0].PhoneNumber;
                User upadateUserResult = _userRepository.Save(user);
            }
            var     transactionDetails = AutoMapper.Mapper.Map <IEnumerable <FIL.Contracts.DataModels.TransactionDetail> >(_transactionDetailRepository.GetByTransactionId(command.TransactionId));
            var     eventTicketAttributeIds = transactionDetails.Select(s => s.EventTicketAttributeId).Distinct();
            var     eventTicketAttributes = AutoMapper.Mapper.Map <IEnumerable <Contracts.Models.EventTicketAttribute> >(_eventTicketAttributeRepository.GetByIds(eventTicketAttributeIds));
            var     ticketFeeDetails = AutoMapper.Mapper.Map <IEnumerable <Contracts.Models.TicketFeeDetail> >(_ticketFeeDetailRepository.GetByEventTicketAttributeIds(eventTicketAttributeIds));
            var     isItinerary = TransactionType.Regular;
            decimal totalConvenienceCharge = 0, smsCharges = 0, totalServiceCharge = 0, totalDeliveryCharge = 0, grossTicketAmount = 0, transactionFee = 0, transactionFeeValue = 0, transactionFeeValueTypeId = 0, creditCardSurcharge = 0, creditCardSurchargeValue = 0, creditCardSurchargeValueTypeId = 0;

            Channels ChannelID = transaction.ChannelId;

            foreach (var transactionDetail in transactionDetails)
            {
                TransactionDetail transactionDetailMapper = transactionDetail;
                var eventTicketAttribute  = eventTicketAttributes.Where(w => w.Id == transactionDetail.EventTicketAttributeId).FirstOrDefault();
                var ticketFeeDetailList   = ticketFeeDetails.Where(w => w.EventTicketAttributeId == eventTicketAttribute.Id);
                var commandDeliveryDetail = command.DeliveryDetail.Where(w => w.EventTicketAttributeId == eventTicketAttribute.Id).FirstOrDefault();
                grossTicketAmount += transactionDetail.PricePerTicket * transactionDetail.TotalTickets;
            }

            foreach (var transactionDetail in transactionDetails)
            {
                TransactionDetail transactionDetailMapper = transactionDetail;
                if (transactionDetail.TransactionType == TransactionType.Itinerary)
                {
                    isItinerary = TransactionType.Itinerary;
                }
                var eventTicketAttribute = eventTicketAttributes.Where(w => w.Id == transactionDetail.EventTicketAttributeId).FirstOrDefault();
                var ticketFeeDetailList  = ticketFeeDetails.Where(w => w.EventTicketAttributeId == eventTicketAttribute.Id).OrderBy(o => o.FeeId);

                // Convert TicketFeeDetails into geo currency...
                if (ChannelID == Channels.Feel)
                {
                    _geoCurrency.UpdateTicketFeeDetails(ticketFeeDetailList.ToList(), command.TargetCurrencyCode, eventTicketAttribute.CurrencyId);
                }
                var     commandDeliveryDetail = command.DeliveryDetail.Where(w => w.EventTicketAttributeId == eventTicketAttribute.Id).FirstOrDefault();
                decimal prevConvenienceCharges = 0;
                decimal DeliveryCharge = 0, ServiceCharge = 0, ConvenienceCharge = 0;
                decimal convenienceCharges = 0, serviceCharge = 0, pahCharge = 0, unitLevelSMSCharge = 0, unitLevelTransactionFee = 0;
                foreach (var ticketFeeDetail in ticketFeeDetailList)
                {
                    if (ticketFeeDetail.FeeId == (int)FeeType.ConvenienceCharge)
                    {
                        if (ticketFeeDetail.ValueTypeId == (int)ValueTypes.Percentage)
                        {
                            convenienceCharges     = ((ticketFeeDetail.Value * (transactionDetail.PricePerTicket * transactionDetail.TotalTickets)) / 100);
                            prevConvenienceCharges = convenienceCharges;
                        }
                        else if (ticketFeeDetail.ValueTypeId == (int)ValueTypes.Flat)
                        {
                            convenienceCharges     = ticketFeeDetail.Value * transactionDetail.TotalTickets;
                            prevConvenienceCharges = convenienceCharges;
                        }
                    }

                    if (ticketFeeDetail.FeeId == (int)FeeType.SMSCharge)
                    {
                        smsCharges = ticketFeeDetail.Value;
                    }

                    if (ticketFeeDetail.FeeId == (int)FeeType.TransactionFee)
                    {
                        transactionFeeValue       = ticketFeeDetail.Value;
                        transactionFeeValueTypeId = ticketFeeDetail.ValueTypeId;
                    }

                    if (ticketFeeDetail.FeeId == (int)FeeType.CreditCardSurcharge)
                    {
                        creditCardSurchargeValue       = ticketFeeDetail.Value;
                        creditCardSurchargeValueTypeId = ticketFeeDetail.ValueTypeId;
                    }

                    if (transactionFeeValueTypeId == (int)ValueTypes.Percentage)
                    {
                        transactionFee = ((transactionFeeValue * (totalConvenienceCharge + smsCharges)) / 100);
                    }
                    else if (transactionFeeValueTypeId == (int)ValueTypes.Flat)
                    {
                        transactionFee = transactionFeeValue;
                    }

                    if (creditCardSurchargeValueTypeId == (int)ValueTypes.Percentage)
                    {
                        creditCardSurcharge = ((creditCardSurchargeValue * (grossTicketAmount + transactionFee)) / 100);
                    }
                    else if (creditCardSurchargeValue == (int)ValueTypes.Flat)
                    {
                        creditCardSurcharge = creditCardSurchargeValue;
                    }
                    unitLevelSMSCharge      = (smsCharges / transactionDetails.Count());
                    unitLevelTransactionFee = ((transactionFee + creditCardSurcharge) / transactionDetails.Count());
                    ConvenienceCharge       = convenienceCharges + unitLevelSMSCharge + unitLevelTransactionFee;

                    if (ticketFeeDetail.FeeId == (int)FeeType.ServiceCharge)
                    {
                        if (ticketFeeDetail.ValueTypeId == (int)ValueTypes.Percentage)
                        {
                            serviceCharge          = ((ticketFeeDetail.Value * prevConvenienceCharges) / 100);
                            prevConvenienceCharges = 0;
                        }
                        else if (ticketFeeDetail.ValueTypeId == (int)ValueTypes.Flat)
                        {
                            serviceCharge = ticketFeeDetail.Value * transactionDetail.TotalTickets;
                        }
                    }
                    ServiceCharge = serviceCharge;

                    if (commandDeliveryDetail.DeliveryTypeId == DeliveryTypes.PrintAtHome && ticketFeeDetail.FeeId == (int)FeeType.PrintAtHomeCharge)
                    {
                        pahCharge = ticketFeeDetail.Value;
                    }
                    DeliveryCharge = pahCharge;
                }
                transactionDetailMapper.ConvenienceCharges = ConvenienceCharge;
                transactionDetailMapper.ServiceCharge      = ServiceCharge;
                transactionDetailMapper.DeliveryCharges    = DeliveryCharge;
                totalDeliveryCharge    += DeliveryCharge;
                totalServiceCharge     += ServiceCharge;
                totalConvenienceCharge += ConvenienceCharge;
                transactionDetailList.Add(transactionDetailMapper);
            }

            if (transactionFeeValueTypeId == (int)ValueTypes.Percentage)
            {
                transactionFee = ((transactionFeeValue * (totalConvenienceCharge + smsCharges)) / 100);
            }
            else if (transactionFeeValueTypeId == (int)ValueTypes.Flat)
            {
                transactionFee = transactionFeeValue;
            }

            if (creditCardSurchargeValueTypeId == (int)ValueTypes.Percentage)
            {
                creditCardSurcharge = ((creditCardSurchargeValue * (grossTicketAmount + transactionFee)) / 100);
            }
            else if (creditCardSurchargeValue == (int)ValueTypes.Flat)
            {
                creditCardSurcharge = creditCardSurchargeValue;
            }

            if (transactionFee > 0)
            {
                transaction.ConvenienceCharges = transactionFee + creditCardSurcharge;
                transaction.ServiceCharge      = totalServiceCharge;
                transaction.DeliveryCharges    = totalDeliveryCharge;
                transaction.GrossTicketAmount  = grossTicketAmount;
                transaction.NetTicketAmount    = ((grossTicketAmount + transactionFee + creditCardSurcharge) - transaction.DiscountAmount);
            }
            else
            {
                transaction.ConvenienceCharges = totalConvenienceCharge + transactionFee + creditCardSurcharge;
                transaction.ServiceCharge      = totalServiceCharge;
                transaction.DeliveryCharges    = totalDeliveryCharge;
                transaction.GrossTicketAmount  = grossTicketAmount;
                transaction.NetTicketAmount    = ((grossTicketAmount + totalConvenienceCharge + totalServiceCharge + totalDeliveryCharge + transactionFee + creditCardSurcharge) - transaction.DiscountAmount);
            }
            if (ChannelID == Channels.Feel)
            {
                _geoCurrency.UpdateTransactionUpdates(transaction, command.TargetCurrencyCode);
            }
            FIL.Contracts.DataModels.Transaction transactionResult = _transactionRepository.Save(transaction);
            foreach (var transactionDetail in transactionDetailList)
            {
                TransactionDetail transactionDetailResult = _transactionDetailRepository.Save(transactionDetail);
                try
                {
                    if (ChannelID == Channels.Feel)
                    {
                        var currentETA = command.EventTicketAttributeList.Where(s => s.Id == transactionDetail.EventTicketAttributeId && (transactionDetail.TicketTypeId != null ? (TicketType)transactionDetail.TicketTypeId : TicketType.Regular) == s.TicketType).FirstOrDefault();
                        if (currentETA != null && currentETA.GuestDetails != null)
                        {
                            foreach (FIL.Contracts.Commands.Transaction.GuestUserDetail currentGuestDetail in currentETA.GuestDetails)
                            {
                                _saveGuestUserProvider.SaveGuestUsers(currentGuestDetail, transactionDetail);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.Log(Logging.Enums.LogCategory.Error, e);
                }
            }

            var transactionDeliveryDetails = _transactionDeliveryDetailRepository.GetByTransactionDetailIds(transactionDetails.Select(s => s.Id).Distinct());

            foreach (var deliveryDetail in command.DeliveryDetail)
            {
                var transactionDeliveryDetail = transactionDeliveryDetails.Where(w => w.TransactionDetailId == transactionDetails.Where(c => c.EventTicketAttributeId == deliveryDetail.EventTicketAttributeId).Select(s => s.Id).FirstOrDefault()).FirstOrDefault();
                if (transactionDeliveryDetail == null)
                {
                    _transactionDeliveryDetailRepository.Save(new TransactionDeliveryDetail
                    {
                        TransactionDetailId = transactionDetails.Where(w => w.EventTicketAttributeId == deliveryDetail.EventTicketAttributeId).Select(s => s.Id).FirstOrDefault(),
                        DeliveryTypeId      = deliveryDetail.DeliveryTypeId,
                        PickupBy            = Convert.ToInt16(string.IsNullOrWhiteSpace(deliveryDetail.RepresentativeFirstName) ? 0 : 1),
                        SecondaryName       = $"{deliveryDetail.FirstName} {deliveryDetail.LastName}",
                        SecondaryContact    = $"{deliveryDetail.PhoneCode}-{deliveryDetail.PhoneNumber}",
                        SecondaryEmail      = deliveryDetail.DeliveryTypeId == DeliveryTypes.Courier ? deliveryDetail.Email : deliveryDetail.Email,
                        PickUpAddress       = command.PickUpAddress
                    });
                }
                else
                {
                    transactionDeliveryDetail.SecondaryName    = $"{deliveryDetail.FirstName} {deliveryDetail.LastName}";
                    transactionDeliveryDetail.SecondaryContact = $"{deliveryDetail.PhoneCode}-{deliveryDetail.PhoneNumber}";
                    transactionDeliveryDetail.SecondaryEmail   = deliveryDetail.DeliveryTypeId == DeliveryTypes.Courier ? deliveryDetail.Email : deliveryDetail.Email;
                    transactionDeliveryDetail.PickUpAddress    = command.PickUpAddress;
                    _transactionDeliveryDetailRepository.Save(transactionDeliveryDetail);
                }
            }
            var transactionresult = _transactionRepository.Get(command.TransactionId);

            UpdateTransactionCommandResult updateTransactionCommandResult = new UpdateTransactionCommandResult();

            updateTransactionCommandResult.Id                 = transactionresult.Id;
            updateTransactionCommandResult.CurrencyId         = transactionresult.CurrencyId;
            updateTransactionCommandResult.GrossTicketAmount  = transactionresult.GrossTicketAmount;
            updateTransactionCommandResult.DeliveryCharges    = transactionresult.DeliveryCharges;
            updateTransactionCommandResult.ConvenienceCharges = transactionresult.ConvenienceCharges;
            updateTransactionCommandResult.ServiceCharge      = transactionresult.ServiceCharge;
            updateTransactionCommandResult.DiscountAmount     = transactionresult.DiscountAmount;
            updateTransactionCommandResult.NetTicketAmount    = transactionresult.NetTicketAmount;

            return(Task.FromResult <ICommandResult>(updateTransactionCommandResult));
        }
Exemplo n.º 2
0
        protected override async Task <ICommandResult> Handle(ReserveTimeSlotCommand command)
        {
            ReserveTimeSlotCommandResult results = new ReserveTimeSlotCommandResult();
            ReserveTimeSlotReqestModel   reserveTimelotRequestModel = new ReserveTimeSlotReqestModel();

            IEnumerable <long> eventTicketAttributeIds = command.EventTicketAttributeList.Select(s => s.Id).Distinct();
            IEnumerable <Contracts.Models.EventTicketAttribute> eventTicketAttributes = AutoMapper.Mapper.Map <IEnumerable <Contracts.Models.EventTicketAttribute> >(_eventTicketAttributeRepository.GetByIds(eventTicketAttributeIds));

            var allETD = _eventTicketDetailRepository.GetByEventTicketDetailsIds(eventTicketAttributes.Select(s => s.EventTicketDetailId).Distinct()).Distinct();
            var allTC  = _ticketCategoryRepository.GetByTicketCategoryIds(allETD.Select(s => s.TicketCategoryId).Distinct()).Distinct();
            var allED  = _eventDetailRepository.GetByIds(allETD.Select(s => s.EventDetailId).Distinct()).Distinct().FirstOrDefault();
            var citySightEventDetails        = _citySightSeeingEventDetailMappingRepository.GetByEventDetailId(allED.Id);
            var citySightSeeingTickets       = _citySightSeeingTicketRepository.Get(citySightEventDetails.CitySightSeeingTicketId);
            var citySightSeeingTicketDetails = _citySightSeeingTicketDetailRepository.GetByTicketId(citySightSeeingTickets.TicketId);
            var citySightSeeingLocations     = _citySightSeeingLocationRepository.Get(citySightSeeingTickets.CitySightSeeingLocationId);

            var locationDetail = await _googleMapApi.GetLatLongFromAddress(citySightSeeingLocations.Name);

            string tz = ""; DateTime fromDate = DateTime.Now;; var offset = "";

            if (locationDetail.Success)
            {
                double lat = Convert.ToDouble(locationDetail.Result.lat);
                double lng = Convert.ToDouble(locationDetail.Result.lng);
                tz = TimeZoneLookup.GetTimeZone(lat, lng).Result;
                TimeZoneInfo tzi       = TZConvert.GetTimeZoneInfo(tz);
                var          visitDate = command.EventTicketAttributeList[0].VisitDate;
                var          timeSlot  = command.EventTicketAttributeList[0].TimeSlot;
                var          utcOffset = tzi.BaseUtcOffset.ToString().Split(":")[0];
                var          minutes   = Convert.ToInt64(tzi.BaseUtcOffset.ToString().Split(":")[1]);
                if (utcOffset.Contains("-"))
                {
                    var hours = Convert.ToInt64((tzi.BaseUtcOffset.ToString().Split(":")[0]).Split("-")[1]);
                    visitDate = visitDate.AddHours(hours).AddMinutes(minutes);
                    offset    = utcOffset;
                }
                else
                {
                    var hours = Convert.ToInt64((tzi.BaseUtcOffset.ToString().Split(":")[0]));
                    visitDate = visitDate.AddHours(-hours).AddMinutes(-minutes);
                    offset    = "+" + utcOffset;
                }
                var formattedDateTime = visitDate.Year + "-" + visitDate.Month + "-" + visitDate.Day + "T" + timeSlot;
                fromDate = Convert.ToDateTime(formattedDateTime);
            }

            var duration = citySightSeeingTicketDetails.Duration;

            reserveTimelotRequestModel.request_type = "reserve";
            TimeSlotData timeSlotData = new TimeSlotData();

            timeSlotData.distributor_id  = _settings.GetConfigSetting <string>(SettingKeys.Integration.CitySightSeeing.DistributorId);
            timeSlotData.ticket_id       = citySightSeeingTickets.TicketId;
            timeSlotData.pickup_point_id = (citySightSeeingTicketDetails.PickupPoints != null && citySightSeeingTicketDetails.PickupPoints != "") ? citySightSeeingTicketDetails.PickupPoints : "";

            DateTime endDate = DateTime.Now;
            List <BookingTimeSlotDetail> bookingTimeSlotDetailList = new List <BookingTimeSlotDetail>();

            foreach (Contracts.Commands.Transaction.EventTicketAttribute ticketAttributes in command.EventTicketAttributeList)
            {
                BookingTimeSlotDetail bookingTimeSlotDetail = new BookingTimeSlotDetail();
                var currentTA = ticketAttributes;
                Contracts.Models.EventTicketAttribute checkoutCommandEventTicketAttribute = eventTicketAttributes.Where(w => w.Id == ticketAttributes.Id).FirstOrDefault();
                EventTicketDetail eventTicketDetail = allETD.Where(s => s.Id == checkoutCommandEventTicketAttribute.EventTicketDetailId).FirstOrDefault();
                var ticketCategoryId = allTC.Where(s => s.Id == eventTicketDetail.TicketCategoryId).FirstOrDefault();
                bookingTimeSlotDetail.count = ticketAttributes.TotalTickets;
                var formattedTicketCat = ticketCategoryId.Name.Split("(");
                bookingTimeSlotDetail.ticket_type   = formattedTicketCat[0].ToUpper();
                bookingTimeSlotDetail.extra_options = null;
                bookingTimeSlotDetailList.Add(bookingTimeSlotDetail);
            }
            if (duration.Contains("day"))
            {
                string[] day = duration.Split("day");
                endDate = fromDate.AddDays(Convert.ToDouble(day[0]));
            }
            if (duration.Contains("hour"))
            {
                string[] hour = duration.Split("hour");
                endDate = fromDate.AddHours(Convert.ToDouble(hour[0]));
            }
            var fromDate_with_time_slot = Convert.ToDateTime(fromDate.ToString() + offset);
            var endDate_with_time_slot  = Convert.ToDateTime(endDate.ToString() + offset);

            timeSlotData.from_date_time     = fromDate_with_time_slot;
            timeSlotData.to_date_time       = endDate_with_time_slot;
            timeSlotData.booking_details    = bookingTimeSlotDetailList;
            reserveTimelotRequestModel.data = timeSlotData;
            reserveTimelotRequestModel.data.distributor_reference = RandomDigits(10);
            var response = Mapper <TimeSlotResponseModel> .MapFromJson(await ReserveBooking(reserveTimelotRequestModel));

            if (response != null && response.data.booking_status == "Reserved")
            {
                results.Success  = true;
                results.FromTime = fromDate.ToString() + offset;
                results.EndTime  = endDate.ToString() + offset;
                results.Reservation_reference   = response.data.reservation_reference;
                results.Reservation_valid_until = response.data.reservation_valid_until;
                results.Distributor_reference   = response.data.distributor_reference;
                results.TicketId = citySightSeeingTicketDetails.TicketId;
                results.TimeSlot = command.EventTicketAttributeList[0].TimeSlot;
            }
            else
            {
                results.Success = false;
            }
            return(results);
        }
Exemplo n.º 3
0
        protected override async Task <ICommandResult> Handle(CheckoutCommand command)
        {
            CheckoutCommandResult GuestCheckoutCommandResult = new CheckoutCommandResult();

            IEnumerable <long> eventTicketAttributeIds = command.EventTicketAttributeList.Select(s => s.Id).Distinct();
            IEnumerable <Contracts.Models.EventTicketAttribute> eventTicketAttributes = AutoMapper.Mapper.Map <IEnumerable <Contracts.Models.EventTicketAttribute> >(_eventTicketAttributeRepository.GetByIds(eventTicketAttributeIds));

            try
            {
                // Ticket Limit Check Provider
                var ticketLimit = _ticketLimitProvider.CheckTicketLimit(command);
                if (!ticketLimit.Success)
                {
                    return(ticketLimit);
                }

                Contracts.Models.Country country = new Contracts.Models.Country();
                if (!command.IsLoginCheckout)
                {
                    country = AutoMapper.Mapper.Map <Contracts.Models.Country>(_countryRepository.GetByAltId(command.GuestUser.PhoneCode));
                }

                // User Provider
                var user = _userProvider.GetCheckoutUser(command, country);
                if (command.SiteId == Site.RASVSite)
                {
                    await _mediator.Publish(new FIL.Api.Events.Event.HubSpot.VisitorInfoEvent(user));
                }

                // Save Transaction Provider
                var transactionResult = _saveTransactionProvider.SaveTransaction(command, eventTicketAttributes, user);
                if (!transactionResult.Success && transactionResult.IsTransactionLimitExceed)
                {
                    return(transactionResult);
                }

                //// TODO: XXX: HUB: This can still be called
                //// but the front end should call API when things are added to the cart (or removed)
                //// where if they are logged in, or HubspotUtk is not empty, it posts to a command to save to DB
                //// That there is a temp cart (with the hubspot vid saved).  If they buy, delete the row, if not, its checked with
                //// ticket release as well, marked as cart abandoned and then deleted.
                if (command.ISRasv)
                {
                    try
                    {
                        await _mediator.Publish(new CartInfoEvent(new Contracts.Models.CartTrack
                        {
                            Email = user.Email,
                            FirstName = user.FirstName,
                            LastName = user.LastName,
                            Phone = user.PhoneNumber,
                            EventDetailId = transactionResult.CartBookingModel,
                            TicketDateOfPurchase = transactionResult.Transaction.CreatedUtc,
                            IsMailOpt = command.GuestUser.IsMailOpt != null ? (bool)command.GuestUser.IsMailOpt : false,
                        }));
                    }
                    catch (Exception e)
                    {
                        _logger.Log(Logging.Enums.LogCategory.Error, e);
                    }
                }

                var aSIBookingResponse = new ASIBookingResponse();
                if (command.IsASI != null && (bool)command.IsASI) // IF ASI CART
                {
                    foreach (var eta in command.EventTicketAttributeList)
                    {
                        var timeSlot = _aSIMonumentTimeSlotMappingRepository.GetByASIMonumentIdAndTimeId(eta.ASIAvailability.MonumentId, eta.ASIAvailability.Id);
                        if (timeSlot == null)
                        {
                            var ASIMonumentTimeSlotMapping = new ASIMonumentTimeSlotMapping
                            {
                                ASIMonumentId = eta.ASIAvailability.MonumentId,
                                TimeSlotId    = eta.ASIAvailability.Id,
                                Name          = eta.ASIAvailability.Name,
                                StartTime     = eta.ASIAvailability.StartTime,
                                EndTime       = eta.ASIAvailability.EndTime,
                                IsEnabled     = true,
                                CreatedBy     = command.ModifiedBy,
                                CreatedUtc    = DateTime.UtcNow,
                                ModifiedBy    = command.ModifiedBy,
                                UpdatedBy     = command.ModifiedBy,
                                UpdatedUtc    = DateTime.UtcNow
                            };
                            _aSIMonumentTimeSlotMappingRepository.Save(ASIMonumentTimeSlotMapping);
                        }
                        var @event = _eventRepository.GetByAltId(Guid.Parse(eta.eventAltId));

                        var eventTimeSlot = _eventTimeSlotMappingRepository.GetByEventIdandTimeSlotId(@event.Id, eta.ASIAvailability.Id);
                        if (eventTimeSlot == null)
                        {
                            eventTimeSlot = _eventTimeSlotMappingRepository.Save(new Contracts.DataModels.ASI.EventTimeSlotMapping
                            {
                                EventId    = @event.Id,
                                TimeSlotId = eta.ASIAvailability.Id,
                                Name       = eta.ASIAvailability.Name,
                                StartTime  = eta.ASIAvailability.StartTime,
                                EndTime    = eta.ASIAvailability.EndTime,
                                IsEnabled  = true,
                                CreatedUtc = DateTime.UtcNow,
                                UpdatedUtc = DateTime.UtcNow,
                                CreatedBy  = Guid.NewGuid()
                            });
                        }
                        eta.VisitTimeId = (int?)eventTimeSlot.Id;
                    }

                    aSIBookingResponse = await _iASIBookingProvider.saveASIData(new ASIBooking
                    {
                        EventTicketAttributeList = command.EventTicketAttributeList,
                        TransactionId            = transactionResult.Id,
                    });
                }
                if (transactionResult != null && transactionResult.Transaction != null && user != null)
                {
                    return(new CheckoutCommandResult
                    {
                        Success = true,
                        Id = transactionResult.Id,
                        TransactionAltId = transactionResult.Transaction.AltId,
                        Transaction = transactionResult.Transaction,
                        User = AutoMapper.Mapper.Map <FIL.Contracts.Models.User>(user),
                        IsTransactionLimitExceed = false,
                        IsTicketCategorySoldOut = false,
                        IsASI = command.IsASI == null ? false : command.IsASI,
                        ASIBookingResponse = aSIBookingResponse,
                        IsPaymentByPass = transactionResult.IsPaymentByPass,
                        StripeAccount = transactionResult.StripeAccount
                    });
                }
                else
                {
                    return(new CheckoutCommandResult
                    {
                        Success = false,
                        Id = 0,
                        TransactionAltId = Guid.NewGuid(),
                        IsTransactionLimitExceed = false,
                        IsTicketCategorySoldOut = false,
                        IsASI = command.IsASI == null ? false : command.IsASI,
                    });
                }
            }
            catch (Exception exception)
            {
                _logger.Log(Logging.Enums.LogCategory.Error, exception);
                return(new CheckoutCommandResult
                {
                    Success = false,
                    Id = 0,
                    TransactionAltId = Guid.NewGuid(),
                    IsTransactionLimitExceed = false,
                    IsTicketCategorySoldOut = false,
                    IsASI = command.IsASI == null ? false : command.IsASI,
                });
            }
        }
Exemplo n.º 4
0
        protected override async Task <ICommandResult> Handle(CreateOrderCommand command)
        {
            CreateOrderCommandResult commandResults = new CreateOrderCommandResult();
            var user = _userRepository.GetByAltId(command.UserAltId);
            var eventTicketAttributeIds = command.EventTicketAttributeList.Select(s => s.Id).Distinct();
            var eventTicketAttributes   = AutoMapper.Mapper.Map <IEnumerable <Contracts.Models.EventTicketAttribute> >(_eventTicketAttributeRepository.GetByIds(eventTicketAttributeIds));
            var allEventTicketDetails   = AutoMapper.Mapper.Map <IEnumerable <Contracts.Models.EventTicketDetail> >(_eventTicketDetailRepository.GetByIds(eventTicketAttributes.Select(s => s.EventTicketDetailId))).ToList();
            var tiqetEventDetail        = _tiqetEventDetailMappingRepository.GetByEventDetailId(allEventTicketDetails[0].EventDetailId);

            CreateOrderRequestModel requestModel   = new CreateOrderRequestModel();
            CustomerDetails         customerDetail = new CustomerDetails();
            List <Variants>         variants       = new List <Variants>();

            foreach (var ticketAttributes in command.EventTicketAttributeList)
            {
                var      eventTicketAttribute   = eventTicketAttributes.Where(w => w.Id == ticketAttributes.Id).FirstOrDefault();
                var      eventTicketDetail      = allEventTicketDetails.Where(w => w.Id == eventTicketAttribute.EventTicketDetailId).FirstOrDefault();;
                var      tiqetEventTicketDetail = _tiqetEventTicketDetailMappingRepository.GetByEventTicketDetailId(eventTicketDetail.Id);
                var      tiqetVariant           = _tiqetVariantDetailRepository.Get(tiqetEventTicketDetail.TiqetVariantDetailId);
                Variants variant = new Variants();
                variant.variant_id = Convert.ToInt32(tiqetVariant.VariantId);
                variant.count      = ticketAttributes.TotalTickets;
                variants.Add(variant);
            }
            var item = command.EventTicketAttributeList[0];

            requestModel.product_id = Convert.ToInt32(tiqetEventDetail.ProductId);
            requestModel.day        = item.VisitDate.ToString("yyyy-MM-dd");
            if (item.TimeSlot != null && item.TimeSlot != "")
            {
                requestModel.timeslot = item.TimeSlot;
            }
            customerDetail.email          = _settings.GetConfigSetting <string>(SettingKeys.Integration.Tiqets.CustomerEmail);
            customerDetail.firstname      = user.FirstName;
            customerDetail.lastname       = user.LastName;
            customerDetail.phone          = _settings.GetConfigSetting <string>(SettingKeys.Integration.Tiqets.CustomerPhone);
            requestModel.customer_details = customerDetail;
            requestModel.variants         = variants;
            var responseData = await CreateOrderAsync(requestModel);

            var responseJson = Mapper <CreateOrderResponseModel> .MapFromJson(responseData);

            if (responseJson.success)
            {
                commandResults.Success         = true;
                commandResults.OrderRefernceId = responseJson.order_reference_id;
                commandResults.PaymentToken    = responseJson.payment_confirmation_token;
            }
            else
            {
                commandResults.Success         = false;
                commandResults.OrderRefernceId = null;
                commandResults.PaymentToken    = null;
            }
            return(commandResults);
        }