/// <summary>
 /// Convert Confirm Booking Online Request Dto to payment from Paypal
 /// </summary>
 /// <param name="confirmBookingRequestDto">ConfirmBookingRequestDto</param>
 /// <returns>Payment</returns>
 public static Payment ConvertConfirmBookingOnlineRequestDtoToPaymentFromPaypal(ConfirmOrderRequestDto confirmBookingRequestDto)
 {
     return new Payment
     {
         OrderId = confirmBookingRequestDto.OrderId,
         Amount = confirmBookingRequestDto.Amount,
         Currency = ConvertCurrencyCodeToCurrencyModel(confirmBookingRequestDto.CurrencyCode),
         PaymentTypeEnum = PaymentTypeEnum.Payment,
         PaymentMethodEnum = PaymentMethodEnum.PayPal,
         PaymentSourceEnum = PaymentSourceEnum.Online,
         PaymentName = string.Empty,
         PaymentStatusEnum = PaymentStatusEnum.Created,
         ReceivedDate = confirmBookingRequestDto.ReceivedDate
     };
 }
Beispiel #2
0
        /// <summary>
        /// Confirm and change the state of the bookings as well as collecting the payment information
        /// </summary>
        /// <param name="confirmBooking">Confirm Order Request Dto</param>
        /// <returns>ConfirmOrderResponseDto</returns>
        /// <remarks>
        /// Confirm all the bookings attached to an order
        /// </remarks>
        public ConfirmOrderResponseDto ConfirmOrder(ConfirmOrderRequestDto confirmBooking)
        {
            // Log request
            Log.LogInfo("ConfirmOrder request: {0}", null, confirmBooking);
            Log.LogInfoAsXml(confirmBooking);

            #region Preconditions
            if (confirmBooking == null || string.IsNullOrEmpty(confirmBooking.OrderReferenceNumber))
            {
                return null;
            }
      

            var order = orderManager.GetOrderWithBookingsByKey(orderReference: confirmBooking.OrderReferenceNumber, type: GetOrderWithBookingsByEnum.OrderReference);

            if (order == null || order.Bookings == null || !order.Bookings.Any())
            {
                return null;
            }
          
            var firstBooking = order.Bookings.FirstOrDefault();

            var business = businessManager.GetBusiness(firstBooking.BusinessId);

            if (business == null)
            {
                return null;
            }
            #endregion

            var isCommitSucceeded = false;
            using (var tx = new BusinessTransaction())
            {   
                Payment payment = null;

                //At this point we just handle credit card and Paypal
                switch (confirmBooking.PaymentMethod)
                {
                    case PaymentMethodEnumDto.CreditCard:
                        payment =
                            DataTransferObjectsConverter.ConvertConfirmBookingOnlineRequestDtoToPayment(
                                confirmBooking);
                        break;
                    case PaymentMethodEnumDto.PayPal:
                        payment =
                            DataTransferObjectsConverter.ConvertConfirmBookingOnlineRequestDtoToPaymentFromPaypal(
                                confirmBooking);
                        break;
                    case PaymentMethodEnumDto.AccountTransfer:
                        // This means possibly it is expedia already paid for
                        payment = paymentManager.SetupOtaPayment(order, business, confirmBooking.ReceivedDate);
                        break;
                }

                if (payment != null && payment.IsValid())
                {
                    payment.OrderId = order.Id.Value;

                    //For the moment we use the business working currency
                    //Because ABS does not supply the currency in the availability offers
                    if (payment.Currency == null)
                    {
                        payment.Currency = new Currency(business.WorkingCurrencyCode);
                    }

                    paymentManager.CreatePaymentForOrder(payment, order.Bookings.Count > 0 ? order.Bookings.FirstOrDefault().BusinessId : 0);
                }

                bool areFeesCreated = false;

                foreach (var booking in order.Bookings)
                {
                    if (confirmBooking.Guest != null)
                    {
                        Guest guest = Mapper.Map<Guest>(confirmBooking.Guest);

                        if (guest.TryIsValid())
                        {
                            // Modify or Create the Guest
                            if (booking.Guest != null)
                            {
                                if (!booking.Guest.Id.HasValue)
                                {
                                    guestManager.Create(guest);
                                }
                                else
                                {
                                    guest.Id = booking.Guest.Id;
                                    guest.BusinessId = booking.BusinessId;
                                    guestManager.Modify(guest);
                                }
                            }
                        }
                    }

                    if (areFeesCreated == false)
                    {
                        bookingItemManager.CreateBookingFees(booking);
                        areFeesCreated = true;
                    }

                    bookingManager.ConfirmTentativeBooking(
                        booking.Id.Value,
                        booking.BusinessId,
                        confirmBooking.ChannelReference,
                        confirmBooking.CCToken,
                        confirmBooking.CCTokenSource);

                    if (booking.IsOverBooking)
                    {
                        int emailId = emailManager.SendOverbookingEmail(business, order, booking, confirmBooking.ChannelReference);

                        Log.LogInfo(
                            "Over Booking. Split product/inventory availability found for Hotel Shortname={0}, room type id={1}, check-in date={2}, check-out date={3}, email Id = {4}",
                            null, booking.BusinessShortName, booking.RoomTypeId,
                            booking.StartDate.ToString("ddd d MMM, yyyy"), booking.EndDate.ToString("ddd d MMM, yyyy"),
                            emailId);
                    }
                }

                

                tx.Commit();
                isCommitSucceeded = true;
            }

            if (isCommitSucceeded)
            {
                orderManager.SendConfirmationEmails(order);
            }

            var confirmBookingResponseDto = new ConfirmOrderResponseDto { OrderReferenceNumber = confirmBooking.OrderReferenceNumber };

            // Log response
            Log.LogInfo("ConfirmOrder response: {0}", null, confirmBookingResponseDto);
            Log.LogInfoAsXml(confirmBookingResponseDto);

            return confirmBookingResponseDto;
        }
        /// <summary>
        /// Convert Confirm Booking Online Request Dto to payment
        /// </summary>
        /// <param name="confirmBookingRequestDto">ConfirmBookingRequestDto</param>
        /// <returns>Payment</returns>
        public static Payment ConvertConfirmBookingOnlineRequestDtoToPayment(ConfirmOrderRequestDto confirmBookingRequestDto)
        {
            CardTypeEnum cardType = (CardTypeEnum)Enum.Parse(typeof(CardTypeEnum), confirmBookingRequestDto.CardType);

            return new Payment
            {
                OrderId = confirmBookingRequestDto.OrderId,
                Amount = confirmBookingRequestDto.Amount,
                CardLast4Digits = confirmBookingRequestDto.CardLast4Digits,
                CardType = new CardType { Code = cardType.GetCode()},
                Currency = ConvertCurrencyCodeToCurrencyModel(confirmBookingRequestDto.CurrencyCode),
                PaymentTypeEnum = PaymentTypeEnum.Payment,
                PaymentMethodEnum = PaymentMethodEnum.CreditCard,
                PaymentSourceEnum = PaymentSourceEnum.Online,
                PaymentName = confirmBookingRequestDto.CardOwner,
                PaymentStatusEnum = PaymentStatusEnum.Created,
                ReceivedDate = confirmBookingRequestDto.ReceivedDate
            };
        }