AddError() public method

Add error
public AddError ( string error ) : void
error string Error
return void
        protected ProcessPaymentResult AuthorizeOrSale(ProcessPaymentRequest processPaymentRequest, bool authorizeOnly)
        {
            var result = new ProcessPaymentResult();


            var customer = _customerService.GetCustomerById(processPaymentRequest.CustomerId);

            if (customer == null)
            {
                throw new Exception("Customer cannot be loaded");
            }

            var req = new DoDirectPaymentReq();

            req.DoDirectPaymentRequest         = new DoDirectPaymentRequestType();
            req.DoDirectPaymentRequest.Version = GetApiVersion();
            var details = new DoDirectPaymentRequestDetailsType();

            req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = details;
            details.IPAddress = _webHelper.GetCurrentIpAddress() ?? "";
            if (authorizeOnly)
            {
                details.PaymentAction = PaymentActionCodeType.AUTHORIZATION;
            }
            else
            {
                details.PaymentAction = PaymentActionCodeType.SALE;
            }
            //credit card
            details.CreditCard = new CreditCardDetailsType();
            details.CreditCard.CreditCardNumber = processPaymentRequest.CreditCardNumber;
            details.CreditCard.CreditCardType   = GetPaypalCreditCardType(processPaymentRequest.CreditCardType);
            details.CreditCard.ExpMonth         = processPaymentRequest.CreditCardExpireMonth;
            details.CreditCard.ExpYear          = processPaymentRequest.CreditCardExpireYear;
            details.CreditCard.CVV2             = processPaymentRequest.CreditCardCvv2;

            //details.CreditCard.CardOwner = new PayerInfoType();
            //details.CreditCard.CardOwner.PayerCountry = GetPaypalCountryCodeType(customer.BillingAddress.Country);
            ////billing address
            //details.CreditCard.CardOwner.Address = new AddressType();
            //details.CreditCard.CardOwner.Address.Street1 = customer.BillingAddress.Address1;
            //details.CreditCard.CardOwner.Address.Street2 = customer.BillingAddress.Address2;
            //details.CreditCard.CardOwner.Address.CityName = customer.BillingAddress.City;
            //if (customer.BillingAddress.StateProvince != null)
            //    details.CreditCard.CardOwner.Address.StateOrProvince = customer.BillingAddress.StateProvince.Abbreviation;
            //else
            //    details.CreditCard.CardOwner.Address.StateOrProvince = "CA";
            //details.CreditCard.CardOwner.Address.Country = GetPaypalCountryCodeType(customer.BillingAddress.Country);
            //details.CreditCard.CardOwner.Address.PostalCode = customer.BillingAddress.ZipPostalCode;
            //details.CreditCard.CardOwner.Payer = customer.BillingAddress.Email;
            //details.CreditCard.CardOwner.PayerName = new PersonNameType();
            //details.CreditCard.CardOwner.PayerName.FirstName = customer.BillingAddress.FirstName;
            //details.CreditCard.CardOwner.PayerName.LastName = customer.BillingAddress.LastName;

            //order totals
            var payPalCurrency = PaypalHelper.GetPaypalCurrency("USD");

            details.PaymentDetails                       = new PaymentDetailsType();
            details.PaymentDetails.OrderTotal            = new BasicAmountType();
            details.PaymentDetails.OrderTotal.value      = Math.Round(processPaymentRequest.OrderTotal, 2).ToString("N", new CultureInfo("en-us"));
            details.PaymentDetails.OrderTotal.currencyID = payPalCurrency;
            details.PaymentDetails.Custom                = processPaymentRequest.OrderGuid.ToString();
            details.PaymentDetails.ButtonSource          = "EGSWPaymentButton";

            ////shipping
            //if (customer.ShippingAddress != null)
            //{
            //    if (customer.ShippingAddress.StateProvince != null && customer.ShippingAddress.Country != null)
            //    {
            //        var shippingAddress = new AddressType();
            //        shippingAddress.Name = customer.ShippingAddress.FirstName + " " + customer.ShippingAddress.LastName;
            //        shippingAddress.Street1 = customer.ShippingAddress.Address1;
            //        shippingAddress.Street2 = customer.ShippingAddress.Address2;
            //        shippingAddress.CityName = customer.ShippingAddress.City;
            //        shippingAddress.StateOrProvince = customer.ShippingAddress.StateProvince.Abbreviation;
            //        shippingAddress.PostalCode = customer.ShippingAddress.ZipPostalCode;
            //        shippingAddress.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), customer.ShippingAddress.Country.TwoLetterIsoCode, true);
            //        details.PaymentDetails.ShipToAddress = shippingAddress;
            //    }
            //}

            //send request
            var service = GetService();
            DoDirectPaymentResponseType response = service.DoDirectPayment(req);

            string error;
            bool   success = PaypalHelper.CheckSuccess(response, out error);

            if (success)
            {
                result.AvsResult = response.AVSCode;
                result.AuthorizationTransactionCode = response.CVV2Code;
                if (authorizeOnly)
                {
                    result.AuthorizationTransactionId     = response.TransactionID;
                    result.AuthorizationTransactionResult = response.Ack.ToString();

                    result.NewPaymentStatus = PaymentStatus.Authorized;
                }
                else
                {
                    result.CaptureTransactionId     = response.TransactionID;
                    result.CaptureTransactionResult = response.Ack.ToString();

                    result.NewPaymentStatus = PaymentStatus.Paid;
                }
            }
            else
            {
                result.AddError(error);
            }
            return(result);
        }
        protected ProcessPaymentResult AuthorizeOrSale(ProcessPaymentRequest processPaymentRequest, bool authorizeOnly)
        {
            var result = new ProcessPaymentResult();

            var customer = _customerService.GetCustomerById(processPaymentRequest.CustomerId);
            if (customer == null)
                throw new Exception("Customer cannot be loaded");

            var req = new DoDirectPaymentReq();
            req.DoDirectPaymentRequest = new DoDirectPaymentRequestType();
            req.DoDirectPaymentRequest.Version = GetApiVersion();
            var details = new DoDirectPaymentRequestDetailsType();
            req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = details;
            details.IPAddress = _webHelper.GetCurrentIpAddress() ?? "";
            if (authorizeOnly)
                details.PaymentAction = PaymentActionCodeType.AUTHORIZATION;
            else
                details.PaymentAction = PaymentActionCodeType.SALE;
            //credit card
            details.CreditCard = new CreditCardDetailsType();
            details.CreditCard.CreditCardNumber = processPaymentRequest.CreditCardNumber;
            details.CreditCard.CreditCardType = GetPaypalCreditCardType(processPaymentRequest.CreditCardType);
            details.CreditCard.ExpMonth = processPaymentRequest.CreditCardExpireMonth;
            details.CreditCard.ExpYear = processPaymentRequest.CreditCardExpireYear;
            details.CreditCard.CVV2 = processPaymentRequest.CreditCardCvv2;

            //details.CreditCard.CardOwner = new PayerInfoType();
            //details.CreditCard.CardOwner.PayerCountry = GetPaypalCountryCodeType(customer.BillingAddress.Country);
            ////billing address
            //details.CreditCard.CardOwner.Address = new AddressType();
            //details.CreditCard.CardOwner.Address.Street1 = customer.BillingAddress.Address1;
            //details.CreditCard.CardOwner.Address.Street2 = customer.BillingAddress.Address2;
            //details.CreditCard.CardOwner.Address.CityName = customer.BillingAddress.City;
            //if (customer.BillingAddress.StateProvince != null)
            //    details.CreditCard.CardOwner.Address.StateOrProvince = customer.BillingAddress.StateProvince.Abbreviation;
            //else
            //    details.CreditCard.CardOwner.Address.StateOrProvince = "CA";
            //details.CreditCard.CardOwner.Address.Country = GetPaypalCountryCodeType(customer.BillingAddress.Country);
            //details.CreditCard.CardOwner.Address.PostalCode = customer.BillingAddress.ZipPostalCode;
            //details.CreditCard.CardOwner.Payer = customer.BillingAddress.Email;
            //details.CreditCard.CardOwner.PayerName = new PersonNameType();
            //details.CreditCard.CardOwner.PayerName.FirstName = customer.BillingAddress.FirstName;
            //details.CreditCard.CardOwner.PayerName.LastName = customer.BillingAddress.LastName;

            //order totals
            var payPalCurrency = PaypalHelper.GetPaypalCurrency("USD");
            details.PaymentDetails = new PaymentDetailsType();
            details.PaymentDetails.OrderTotal = new BasicAmountType();
            details.PaymentDetails.OrderTotal.value = Math.Round(processPaymentRequest.OrderTotal, 2).ToString("N", new CultureInfo("en-us"));
            details.PaymentDetails.OrderTotal.currencyID = payPalCurrency;
            details.PaymentDetails.Custom = processPaymentRequest.OrderGuid.ToString();
            details.PaymentDetails.ButtonSource = "EGSWPaymentButton";

            ////shipping
            //if (customer.ShippingAddress != null)
            //{
            //    if (customer.ShippingAddress.StateProvince != null && customer.ShippingAddress.Country != null)
            //    {
            //        var shippingAddress = new AddressType();
            //        shippingAddress.Name = customer.ShippingAddress.FirstName + " " + customer.ShippingAddress.LastName;
            //        shippingAddress.Street1 = customer.ShippingAddress.Address1;
            //        shippingAddress.Street2 = customer.ShippingAddress.Address2;
            //        shippingAddress.CityName = customer.ShippingAddress.City;
            //        shippingAddress.StateOrProvince = customer.ShippingAddress.StateProvince.Abbreviation;
            //        shippingAddress.PostalCode = customer.ShippingAddress.ZipPostalCode;
            //        shippingAddress.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), customer.ShippingAddress.Country.TwoLetterIsoCode, true);
            //        details.PaymentDetails.ShipToAddress = shippingAddress;
            //    }
            //}

            //send request
            var service = GetService();
            DoDirectPaymentResponseType response = service.DoDirectPayment(req);

            string error;
            bool success = PaypalHelper.CheckSuccess(response, out error);
            if (success)
            {
                result.AvsResult = response.AVSCode;
                result.AuthorizationTransactionCode = response.CVV2Code;
                if (authorizeOnly)
                {
                    result.AuthorizationTransactionId = response.TransactionID;
                    result.AuthorizationTransactionResult = response.Ack.ToString();

                    result.NewPaymentStatus = PaymentStatus.Authorized;
                }
                else
                {
                    result.CaptureTransactionId = response.TransactionID;
                    result.CaptureTransactionResult = response.Ack.ToString();

                    result.NewPaymentStatus = PaymentStatus.Paid;
                }
            }
            else
            {
                result.AddError(error);
            }
            return result;
        }