/// <summary>
        /// Gets a paypal express checkout result
        /// </summary>
        /// <param name="token">paypal express checkout token</param>
        /// <returns>Paypal payer</returns>
        public PaypalPayer GetExpressCheckout(string token)
        {
            InitSettings();
            GetExpressCheckoutDetailsReq         req     = new GetExpressCheckoutDetailsReq();
            GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType();

            req.GetExpressCheckoutDetailsRequest = request;

            request.Token   = token;
            request.Version = this.APIVersion;

            GetExpressCheckoutDetailsResponseType response = service2.GetExpressCheckoutDetails(req);

            string error;

            if (!PaypalHelper.CheckSuccess(response, out error))
            {
                throw new NopException(error);
            }

            PaypalPayer payer = new PaypalPayer();

            payer.PayerEmail        = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
            payer.FirstName         = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.FirstName;
            payer.LastName          = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.LastName;
            payer.CompanyName       = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerBusiness;
            payer.Address1          = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street1;
            payer.Address2          = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street2;
            payer.City              = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CityName;
            payer.State             = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.StateOrProvince;
            payer.Zipcode           = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
            payer.Phone             = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.ContactPhone;
            payer.PaypalCountryName = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CountryName;
            payer.CountryCode       = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Country.ToString();
            payer.PayerID           = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
            payer.Token             = response.GetExpressCheckoutDetailsResponseDetails.Token;
            return(payer);
        }
        /// <summary>
        /// Gets a paypal express checkout result
        /// </summary>
        /// <param name="token">paypal express checkout token</param>
        /// <returns>Paypal payer</returns>
        public PaypalPayer GetExpressCheckout(string token)
        {
            InitSettings();
            GetExpressCheckoutDetailsReq req = new GetExpressCheckoutDetailsReq();
            GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType();
            req.GetExpressCheckoutDetailsRequest = request;

            request.Token = token;
            request.Version = this.APIVersion;

            GetExpressCheckoutDetailsResponseType response = service2.GetExpressCheckoutDetails(req);

            string error;
            if (!PaypalHelper.CheckSuccess(response, out error))
                throw new NopException(error);

            PaypalPayer payer = new PaypalPayer();
            payer.PayerEmail = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
            payer.FirstName = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.FirstName;
            payer.LastName = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.LastName;
            payer.CompanyName = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerBusiness;
            payer.Address1 = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street1;
            payer.Address2 = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street2;
            payer.City = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CityName;
            payer.State = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.StateOrProvince;
            payer.Zipcode = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
            payer.Phone = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.ContactPhone;
            payer.PaypalCountryName = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CountryName;
            payer.CountryCode = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Country.ToString();
            payer.PayerID = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
            payer.Token = response.GetExpressCheckoutDetailsResponseDetails.Token;
            return payer;
        }
        protected override void OnInit(EventArgs e)
        {
            PayPalExpressPaymentProcessor payPalExpress = new PayPalExpressPaymentProcessor();
            try
            {
                token = CommonHelper.QueryString("token");
                payer = payPalExpress.GetExpressCheckout(token);
                if (string.IsNullOrEmpty(payer.PayerID))
                    throw new NopException("Payer ID is not set");

                OrderSummaryControl.VendorId = int.Parse(payer.VendorId);
                OrderSummaryControl.BindData();
            }
            catch (Exception Ex)
            {
                LogService.InsertLog(LogTypeEnum.OrderError, Ex.Message, String.Empty);
            }
            finally
            {
                base.OnInit(e);
            }
        }
        /// <summary>
        /// Gets a paypal express checkout result
        /// </summary>
        /// <param name="token">paypal express checkout token</param>
        /// <returns>Paypal payer</returns>
        public PaypalPayer GetExpressCheckout(string token)
        {
            InitSettings();
            GetExpressCheckoutDetailsReq req = new GetExpressCheckoutDetailsReq();
            GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType();
            req.GetExpressCheckoutDetailsRequest = request;

            request.Token = token;
            request.Version = this.APIVersion;

            GetExpressCheckoutDetailsResponseType response = service2.GetExpressCheckoutDetails(req);

            string error;
            ILogService logService = IoC.Resolve<ILogService>();

            if (!PaypalHelper.CheckSuccess(response, out error)) {
                //first we need to log the error for our own good.  We can trouble shoot if
                //we determine the issue is occuring here.  So ... first thing's first.
                foreach(ErrorType errorses in response.Errors){
                    System.Text.StringBuilder sbErrors = new System.Text.StringBuilder();

                    sbErrors.AppendLine(errorses.ErrorCode);
                    sbErrors.AppendLine(errorses.LongMessage);
                    sbErrors.AppendLine(response.ToString());

                    logService.InsertLog(LogTypeEnum.OrderError, sbErrors.ToString(), "Paypal GetExpresCheckout Failure");
                }

                logService.InsertLog(LogTypeEnum.OrderError, response.Ack.ToString(), "Paypal GetExpressCheckout Failure");

                //we throw the user to the custom error page with this.
                throw new NopException(error);
            }

            PaypalPayer payer = new PaypalPayer();
            payer.PayerEmail = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
            payer.FirstName = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.FirstName;
            payer.LastName = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.LastName;
            payer.CompanyName = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerBusiness;
            payer.Address1 = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street1;
            payer.Address2 = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street2;
            payer.City = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CityName;
            payer.State = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.StateOrProvince;
            payer.Zipcode = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
            payer.Phone = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.ContactPhone;
            payer.PaypalCountryName = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CountryName;
            payer.CountryCode = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Country.ToString();
            payer.PayerID = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
            payer.VendorId = response.GetExpressCheckoutDetailsResponseDetails.Custom.Split(Convert.ToChar(":"))[0];
            payer.CustomerId = response.GetExpressCheckoutDetailsResponseDetails.Custom.Split(Convert.ToChar(":"))[1];
            payer.Note = response.GetExpressCheckoutDetailsResponseDetails.PaymentDetails[0].NoteText == null ? String.Empty : response.GetExpressCheckoutDetailsResponseDetails.PaymentDetails[0].NoteText;
            payer.Token = response.GetExpressCheckoutDetailsResponseDetails.Token;
            payer.PaypalVendorAccount = response.GetExpressCheckoutDetailsResponseDetails.PaymentDetails[0].SellerDetails.PayPalAccountID;

            return payer;
        }