/// <summary>
        /// Special method which Sets paypal express checkout
        /// using the cart.  This method also allows for the items to be included
        /// which will appear in the paypal checkout page.
        /// </summary>
        /// <param name="OrderTotal">Order total</param>
        /// <param name="ReturnURL">Return URL</param>
        /// <param name="CancelURL">Cancel URL</param>
        /// <returns>Express checkout URL</returns>
        public string SetExpressCheckout(ShoppingCart Cart, decimal OrderTotal,
            string ReturnURL, string CancelURL, string NotifyURL, string noteToSeller)
        {
            InitSettings();
            TransactMode transactionMode = GetCurrentTransactionMode();

            SetExpressCheckoutReq req = new SetExpressCheckoutReq();
            req.SetExpressCheckoutRequest = new SetExpressCheckoutRequestType();
            req.SetExpressCheckoutRequest.Version = this.APIVersion;

            SetExpressCheckoutRequestDetailsType details = new SetExpressCheckoutRequestDetailsType();

            details.PaymentDetails = new PaymentDetailsType[1];

            details.AllowNote = "1";

            PaymentDetailsType payDetails = new PaymentDetailsType();
            details.BrandName = "Sewbie";
            details.OrderTotal = new BasicAmountType();
            details.OrderTotal.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency);
            details.OrderTotal.Value = OrderTotal.ToString("N", new CultureInfo("en-us"));

            details.Custom = Cart[0].VendorID.ToString() + ":" + Cart[0].CustomerSession.CustomerId;

            decimal discountAmount = 0, subTotalWithoutDiscount = 0, subTotalWithDiscount = 0;
            NopCommerce.BusinessLogic.Promo.Discounts.Discount appliedDiscount = new NopCommerce.BusinessLogic.Promo.Discounts.Discount();
            string scError = IoC.Resolve<IShoppingCartService>().GetShoppingCartSubTotal(Cart, NopCommerce.BusinessLogic.NopContext.Current.User, out discountAmount, out appliedDiscount, out subTotalWithoutDiscount, out subTotalWithDiscount);
            //TODO: We may need to put an error check in here.
            payDetails.ItemTotal = new BasicAmountType();
            payDetails.ItemTotal.Value = subTotalWithoutDiscount.ToString("N", new CultureInfo("en-us"));
            payDetails.ItemTotal.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency);

            payDetails.TaxTotal = new BasicAmountType();
            payDetails.TaxTotal.Value = 0.ToString("N", new CultureInfo("en-us"));
            payDetails.TaxTotal.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency);

            decimal shippingAmount = 0;
            payDetails.ShippingTotal = new BasicAmountType();
            foreach (ShoppingCartItem sci in Cart)
            {
                shippingAmount = shippingAmount + sci.AdditionalShippingCharge;
            }
            payDetails.ShippingTotal.Value = shippingAmount.ToString("N", new CultureInfo("en-us"));
            payDetails.ShippingTotal.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency);

            payDetails.HandlingTotal = new BasicAmountType();
            payDetails.HandlingTotal.Value = 0.ToString("N", new CultureInfo("en-us"));
            payDetails.HandlingTotal.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency);

            payDetails.InsuranceTotal = new BasicAmountType();
            payDetails.InsuranceTotal.Value = 0.ToString("N", new CultureInfo("en-us"));
            payDetails.InsuranceTotal.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency);

            //payDetails.ShipToAddress.Name = "";
            //payDetails.ShipToAddress.Street1 = "";
            //payDetails.ShipToAddress.Street2 = "";
            //payDetails.ShipToAddress.CityName = "";
            //payDetails.ShipToAddress.PostalCode = "";
            //payDetails.ShipToAddress.StateOrProvince = "";

            payDetails.NoteText = noteToSeller.Length > 0? noteToSeller:String.Empty;

            payDetails.SellerDetails = new SellerDetailsType();
            payDetails.SellerDetails.PayPalAccountID = Cart[0].Vendor.PaypalEmailAddress;

            payDetails.PaymentDetailsItem = new PaymentDetailsItemType[Cart.TotalProducts];

            payDetails.NotifyURL = NotifyURL;

            int itemCounter = 0;
            foreach (ShoppingCartItem sci in Cart)
            {
               PaymentDetailsItemType item = new PaymentDetailsItemType();
               item.Name = sci.ProductVariant.Product.Name;
               item.Number = sci.ProductVariant.Product.ProductId.ToString();
               item.Description = sci.ProductVariant.Product.ShortDescription;

               item.Amount = new BasicAmountType();
               item.Amount.Value = sci.ProductVariant.Price.ToString("N", new CultureInfo("en-us"));
               item.Amount.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency);

               item.Quantity = sci.Quantity.ToString();

               item.Tax = new BasicAmountType();
               item.Tax.Value = 0.ToString("N", new CultureInfo("en-us"));;
               item.Tax.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency);

               payDetails.PaymentDetailsItem[itemCounter] = item;

               itemCounter++;
            }

            details.PaymentDetails[0] = payDetails;

            details.PaymentAction = PaymentActionCodeType.Sale;
            details.PaymentActionSpecified = true;
            details.ReturnURL = ReturnURL;
            details.CancelURL = CancelURL;
            req.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails = details;

            SetExpressCheckoutResponseType response = service2.SetExpressCheckout(req);
            string error;
            if (PaypalHelper.CheckSuccess(response, out error))
                return GetPaypalUrl(response.Token);
            throw new NopException(error);
        }
        /// <summary>
        /// Do paypal express checkout
        /// </summary>
        /// <param name="paymentInfo">Payment info required for an order processing</param>
        /// <param name="orderGuid">Unique order identifier</param>
        /// <param name="processPaymentResult">Process payment result</param>
        public void DoExpressCheckout(PaymentInfo paymentInfo, 
            Guid orderGuid,  ProcessPaymentResult processPaymentResult)
        {
            InitSettings();
            TransactMode transactionMode = GetCurrentTransactionMode();

            DoExpressCheckoutPaymentReq req = new DoExpressCheckoutPaymentReq();
            DoExpressCheckoutPaymentRequestType request = new DoExpressCheckoutPaymentRequestType();
            req.DoExpressCheckoutPaymentRequest = request;
            request.Version = this.APIVersion;
            DoExpressCheckoutPaymentRequestDetailsType details = new DoExpressCheckoutPaymentRequestDetailsType();
            request.DoExpressCheckoutPaymentRequestDetails = details;
            if (transactionMode == TransactMode.Authorize)
                details.PaymentAction = PaymentActionCodeType.Authorization;
            else
                details.PaymentAction = PaymentActionCodeType.Sale;
            details.PaymentActionSpecified = true;
            details.Token = paymentInfo.PaypalToken;
            details.PayerID = paymentInfo.PaypalPayerId;

            details.PaymentDetails = new PaymentDetailsType[1];
            PaymentDetailsType paymentDetails1 = new PaymentDetailsType();
            details.PaymentDetails[0] = paymentDetails1;
            paymentDetails1.OrderTotal = new BasicAmountType();
            paymentDetails1.OrderTotal.Value = paymentInfo.OrderTotal.ToString("N", new CultureInfo("en-us"));
            paymentDetails1.OrderTotal.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency);
            paymentDetails1.Custom = orderGuid.ToString();
            paymentDetails1.ButtonSource = "nopCommerceCart";

            DoExpressCheckoutPaymentResponseType response = service2.DoExpressCheckoutPayment(req);
            string error;
            if (!PaypalHelper.CheckSuccess(response, out error))
                throw new NopException(error);

            if (response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo != null &&
                response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0] != null)
            {
                processPaymentResult.AuthorizationTransactionId = response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID;
                processPaymentResult.AuthorizationTransactionResult = response.Ack.ToString();

                if (transactionMode == TransactMode.Authorize)
                    processPaymentResult.PaymentStatus = PaymentStatusEnum.Authorized;
                else
                    processPaymentResult.PaymentStatus = PaymentStatusEnum.Paid;
            }
            else
            {
                throw new NopException("response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo is null");
            }
        }
        /// <summary>
        /// Do paypal express checkout
        /// </summary>
        /// <param name="Token">Paypal express checkout token</param>
        /// <param name="PayerID">Paypal payer identifier</param>
        /// <param name="OrderTotal">Order total</param>
        /// <param name="processPaymentResult">Process payment result</param>
        public void DoExpressCheckout(string Token, string PayerID, decimal OrderTotal, ProcessPaymentResult processPaymentResult)
        {
            InitSettings();
            TransactMode transactionMode = GetCurrentTransactionMode();

            DoExpressCheckoutPaymentReq req = new DoExpressCheckoutPaymentReq();
            DoExpressCheckoutPaymentRequestType request = new DoExpressCheckoutPaymentRequestType();
            req.DoExpressCheckoutPaymentRequest = request;
            request.Version = this.APIVersion;
            DoExpressCheckoutPaymentRequestDetailsType details = new DoExpressCheckoutPaymentRequestDetailsType();
            request.DoExpressCheckoutPaymentRequestDetails = details;
            PaymentDetailsType paymentDetails = new PaymentDetailsType();
            details.PaymentDetails = paymentDetails;
            if (transactionMode == TransactMode.Authorize)
                details.PaymentAction = PaymentActionCodeType.Authorization;
            else
                details.PaymentAction = PaymentActionCodeType.Sale;
            details.Token = Token;
            details.PayerID = PayerID;
            paymentDetails.OrderTotal = new BasicAmountType();
            paymentDetails.OrderTotal.Value = OrderTotal.ToString("N", new CultureInfo("en-us"));
            paymentDetails.OrderTotal.currencyID = PaypalHelper.GetPaypalCurrency(CurrencyManager.PrimaryStoreCurrency);
            paymentDetails.ButtonSource = "nopCommerceCart";

            DoExpressCheckoutPaymentResponseType response = service2.DoExpressCheckoutPayment(req);
            string error;
            if (!PaypalHelper.CheckSuccess(response, out error))
                throw new NopException(error);

            processPaymentResult.AuthorizationTransactionID =  response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.TransactionID;
            processPaymentResult.AuthorizationTransactionResult = response.Ack.ToString();
            //processPaymentResult.AuthorizationDate = response.Timestamp;
            //processPaymentResult.AuthorizationDate = DateTime.Now;

            if (transactionMode == TransactMode.Authorize)
                processPaymentResult.PaymentStatus = PaymentStatusEnum.Authorized;
            else
                processPaymentResult.PaymentStatus = PaymentStatusEnum.Paid;            
        }