private FormOfPayment[] AddFormOfPayment(OFly.Models.FormOfPaymentInfo formOfPaymentInfo)
 {
     List<FormOfPayment> payments = new List<FormOfPayment>();
     FormOfPayment fop = new FormOfPayment();
     //fop.Key = "jwt2mcK1Qp27I2xfpcCtAw==";//Key can be different
     fop.Type = "Credit";
     fop.Type = formOfPaymentInfo.IsCreditCard;
     CreditCard cc = new CreditCard()
     {
         BillingAddress = new typeStructuredAddress()
         {
             AddressName = "Home",
             Street = new string[] { formOfPaymentInfo.Address },
             City = formOfPaymentInfo.City,
             State = new State()
             {
                 Value = formOfPaymentInfo.State
             },
             PostalCode = formOfPaymentInfo.PostalCode,
             Country = formOfPaymentInfo.Country
         },
         ExpDate = formOfPaymentInfo.CardExpirationYear + "-" + formOfPaymentInfo.CardExpirationMonth,
         //Key = "GAJOYrVu4hGShsrlYIhwmw==",
         Number = formOfPaymentInfo.CardNumber,
         //BankCountryCode = "US",
         CVV = formOfPaymentInfo.CvvOrCvc,
         Type = "VI"
     };
     fop.Item = cc;
     payments.Add(fop);
     return payments.ToArray();
 }
        public static string AirPricingSolutionConvertToXML(OFly.AirService.AirPricingSolution airPricingSolution)
        {
            try
            {

                var stringwriter = new System.IO.StringWriter();
                var serializer = new XmlSerializer(airPricingSolution.GetType());
                serializer.Serialize(stringwriter, airPricingSolution);
                return stringwriter.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public AirCreateReservationRsp AirBookingReservationRequest(OFly.AirService.AirPricingSolution airPricingSolution, OFly.AirService.AirItinerary airItinerary, string CommissionOrDiscount, string Amount, List<OFly.Models.BookingTravellerInfos> TravellerList, OFly.Models.FormOfPaymentInfo formOfPaymentInfo)
        {
            AirCreateReservationReq request = new AirCreateReservationReq();
            AirCreateReservationRsp airCreateReservationRsp = new AirCreateReservationRsp();

            try
            {

                OFly.AirService.AirPricingSolution aps = airPricingSolution;
                List<OFly.AirService.typeBaseAirSegment> segmentList = airItinerary.AirSegment.ToList();
                List<OFly.AirService.AirPricingInfo> pricingInfo = aps.AirPricingInfo.ToList();
                List<ActionStatus> actionStatus = new List<ActionStatus>();
                List<BookingTraveler> bookingTraveler = new List<BookingTraveler>();

                request.AuthorizedBy = "user";
                request.ProviderCode = segmentList[0].ProviderCode;
                request.RetainReservation = typeRetainReservation.Both;
                request.TargetBranch = OFly.Utilities.CommonUtility.GetConfigValue(OFly.Utilities.ProjectConstants.G_TARGET_BRANCH);

                BillingPointOfSaleInfo billSaleInfo = new BillingPointOfSaleInfo();
                billSaleInfo.OriginApplication = ConfigurationManager.AppSettings["OriginApplication"];
                request.BillingPointOfSaleInfo = billSaleInfo;

                AirPricingSolution apsu = new AirPricingSolution();

                //  converted SegmentList from AirService to UniversalRecordService
                string SegmentListXMLString = SegmentListConvertToXML(segmentList);
                List<typeBaseAirSegment> tbas = LoadFromXMLToSegmentList(SegmentListXMLString);


                //  converted PriceInfoList from AirService to UniversalRecordService
                string PricingInfoXMLString = PricingInfoListConvertToXML(pricingInfo);
                List<AirPricingInfo> api = LoadFromXMLToPricingInfo(PricingInfoXMLString);

                ////    need to add dynamic travelers as per textbox
                bookingTraveler = BookingTravelerList(TravellerList);
                request.BookingTraveler = bookingTraveler.ToArray();


                //apsu.AirItinerarySolutionRef
                apsu.AirPricingInfo = api.ToArray();
                //apsu.AirPricingResultMessage
                apsu.AirSegment = tbas.ToArray();
                apsu.AirSegmentRef = null;
                apsu.ApproximateBasePrice = aps.ApproximateBasePrice;
                apsu.ApproximateFees = aps.ApproximateFees;
                apsu.ApproximateTaxes = aps.ApproximateTaxes;
                apsu.ApproximateTotalPrice = aps.ApproximateTotalPrice;
                //apsu.AvailableSSR
                apsu.BasePrice = aps.BasePrice;
                apsu.CompleteItinerary = aps.CompleteItinerary;
                //apsu.Connection
                apsu.EquivalentBasePrice = aps.EquivalentBasePrice;
                apsu.FareNote = null;
                apsu.FareNoteRef = null;
                //apsu.FeeInfo
                apsu.Fees = aps.Fees;
                //apsu.HostToken
                //apsu.Itinerary
                apsu.ItinerarySpecified = aps.ItinerarySpecified;
                //apsu.Journey
                apsu.Key = aps.Key;
                //apsu.LegRef
                //apsu.MetaData
                //apsu.OptionalServices
                //apsu.PricingDetails
                apsu.QuoteDate = aps.QuoteDate;
                apsu.QuoteDateSpecified = aps.QuoteDateSpecified;
                apsu.Services = aps.Services;
                apsu.Taxes = aps.Taxes;
                //apsu.TaxInfo
                apsu.TotalPrice = aps.TotalPrice;


                request.AirPricingSolution = apsu;

                ////  Applying Commission/Discount if applicable.
                //if (CommissionOrDiscount != null && CommissionOrDiscount != "" && Amount != null && Amount != "")
                //{
                //    List<ManualFareAdjustment> fareAdjustmentList = new List<ManualFareAdjustment>();

                //    ManualFareAdjustment adjustment = new ManualFareAdjustment();

                //    if (CommissionOrDiscount == "Amount")
                //    {
                //        adjustment.AdjustmentType = typeAdjustmentType.Amount;
                //    }
                //    else
                //    {
                //        adjustment.AdjustmentType = typeAdjustmentType.Percentage;
                //    }

                //    adjustment.AppliedOn = typeAdjustmentTarget.Base;
                //    adjustment.Value = Convert.ToInt32(Amount);
                //    adjustment.PassengerRef = "1";
                //    fareAdjustmentList.Add(adjustment);

                //    api[0].AirPricingModifiers = new AirPricingModifiers()
                //    {
                //        ManualFareAdjustment = fareAdjustmentList.ToArray()
                //    };
                //}

                actionStatus.Add(new ActionStatus { Type = ActionStatusType.ACTIVE, TicketDate = "T*", ProviderCode = request.ProviderCode });
                request.ActionStatus = actionStatus.ToArray();

                request.FormOfPayment = AddFormOfPayment(formOfPaymentInfo);

                AirCreateReservationPortTypeClient client = new AirCreateReservationPortTypeClient("AirCreateReservationPort", OFly.Utilities.WsdlService.AIR_ENDPOINT);

                client.ClientCredentials.UserName.UserName = OFly.Utilities.Helper.RetrunUsername();
                client.ClientCredentials.UserName.Password = OFly.Utilities.Helper.ReturnPassword();


                var httpHeaders = OFly.Utilities.Helper.ReturnHttpHeader();
                client.Endpoint.EndpointBehaviors.Add(new HttpHeadersEndpointBehavior(httpHeaders));

                SupportedVersions supportedVersions = new SupportedVersions();
                supportedVersions.airVersion = "air_v31_0";
                airCreateReservationRsp = client.service(supportedVersions, request);

                return airCreateReservationRsp;
            }
            catch (Exception se)
            {
                throw se;
            }
        }