private bool SetShippingMethod(GetExpressCheckoutDetailsResponseDetailsType details) { UserSelectedOptionType userSelectedOptions = details.UserSelectedOptions; bool shippingMethodSet = false; if (userSelectedOptions != null) { string shippingOptionName = userSelectedOptions.ShippingOptionName; if (string.IsNullOrWhiteSpace(shippingOptionName)) { return(false); } HashSet <IShippingMethod> enabledMethods = _shippingMethodUiService.GetEnabledMethods(); IShippingMethod shippingMethod = enabledMethods.FirstOrDefault(method => shippingOptionName.StartsWith(method.TypeName)) ?? enabledMethods.FirstOrDefault(method => shippingOptionName.StartsWith(method.Name)) ?? enabledMethods.FirstOrDefault(method => shippingOptionName.StartsWith(method.DisplayName)); if (shippingMethod != null) { _cartManager.SetShippingMethod(shippingMethod); shippingMethodSet = true; } } return(shippingMethodSet); }
public ActionResult PaymentDetails(string token) { if (token.IsNullOrWhiteSpace()) { return(RedirectToAction("PayPalCancel")); } GetExpressCheckoutDetailsReq req = PayPalHelper.GetGetExpressCheckoutDetailsReq(token); CustomSecurityHeaderType credentials = PayPalHelper.GetPayPalCredentials(); PayPalAPIAAInterfaceClient client = new PayPalAPIAAInterfaceClient(); GetExpressCheckoutDetailsResponseType response = client.GetExpressCheckoutDetails(ref credentials, req); if (response.Errors != null && response.Errors.Length > 0) { throw new Exception("Exception occured when calling PayPal: " + response.Errors[0].LongMessage); } GetExpressCheckoutDetailsResponseDetailsType respDetails = response.GetExpressCheckoutDetailsResponseDetails; Order order = PayPalHelper.UpdateOrderAfterAuthentication(respDetails.Custom, respDetails.PayerInfo.PayerID); var model = new PaymentModel { Order = order, BuyerName = respDetails.PayerInfo.PayerName.FirstName + respDetails.PayerInfo.PayerName.LastName }; Session["CheckoutDetails"] = response; return(View("PaymentDetails", model)); }
private void SetShippingAddress(GetExpressCheckoutDetailsResponseDetailsType details) { PaymentDetailsType paymentDetails = details.PaymentDetails.FirstOrDefault(); if (paymentDetails != null) { _cartManager.SetShippingAddress(paymentDetails.ShipToAddress.GetAddress()); } }
public bool UpdateCart(GetExpressCheckoutDetailsResponseDetailsType details) { _cartManager.SetPaymentMethod(PayPalExpressCheckoutPaymentMethod.MethodSystemName); _cartManager.SetPayPalExpressPayerId(details.PayerInfo.PayerID); SetBillingAddress(details); SetEmail(details); SetShippingAddress(details); return(SetShippingMethod(details)); }
private void SetEmail(GetExpressCheckoutDetailsResponseDetailsType details) { if (string.IsNullOrWhiteSpace(_cart.OrderEmail)) { PayerInfoType payer = details.PayerInfo; if (payer != null && !string.IsNullOrWhiteSpace(payer.Payer)) { _cartManager.SetOrderEmail(payer.Payer); } } }
private void SetBillingAddress(GetExpressCheckoutDetailsResponseDetailsType details) { var address = details.BillingAddress.GetAddress(); if (address != null) { if (string.IsNullOrWhiteSpace(address.PhoneNumber)) { address.PhoneNumber = details.ContactPhone; } } _cartManager.SetBillingAddress(address); }
private void SetShippingAddress(GetExpressCheckoutDetailsResponseDetailsType details) { PaymentDetailsType paymentDetails = details.PaymentDetails.FirstOrDefault(); if (paymentDetails != null) { var address = paymentDetails.ShipToAddress.GetAddress(); if (string.IsNullOrWhiteSpace(address.PhoneNumber)) { address.PhoneNumber = details.ContactPhone; } _cartManager.SetShippingAddress(address); } }
public ProcessPaymentRequest SetCheckoutDetails(ProcessPaymentRequest processPaymentRequest, GetExpressCheckoutDetailsResponseDetailsType checkoutDetails) { int customerId = Convert.ToInt32(Services.WorkContext.CurrentCustomer.Id.ToString()); var customer = _customerService.GetCustomerById(customerId); var settings = Services.Settings.LoadSetting <PayPalExpressPaymentSettings>(Services.StoreContext.CurrentStore.Id); Services.WorkContext.CurrentCustomer = customer; //var cart = customer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList(); var cart = Services.WorkContext.CurrentCustomer.GetCartItems(ShoppingCartType.ShoppingCart, Services.StoreContext.CurrentStore.Id); // get/update billing address string billingFirstName = checkoutDetails.PayerInfo.PayerName.FirstName; string billingLastName = checkoutDetails.PayerInfo.PayerName.LastName; string billingEmail = checkoutDetails.PayerInfo.Payer; string billingAddress1 = checkoutDetails.PayerInfo.Address.Street1; string billingAddress2 = checkoutDetails.PayerInfo.Address.Street2; string billingPhoneNumber = checkoutDetails.PayerInfo.ContactPhone; string billingCity = checkoutDetails.PayerInfo.Address.CityName; int? billingStateProvinceId = null; var billingStateProvince = _stateProvinceService.GetStateProvinceByAbbreviation(checkoutDetails.PayerInfo.Address.StateOrProvince); if (billingStateProvince != null) { billingStateProvinceId = billingStateProvince.Id; } string billingZipPostalCode = checkoutDetails.PayerInfo.Address.PostalCode; int? billingCountryId = null; var billingCountry = _countryService.GetCountryByTwoLetterIsoCode(checkoutDetails.PayerInfo.Address.Country.ToString()); if (billingCountry != null) { billingCountryId = billingCountry.Id; } var billingAddress = customer.Addresses.FindAddress( billingFirstName, billingLastName, billingPhoneNumber, billingEmail, string.Empty, string.Empty, billingAddress1, billingAddress2, billingCity, billingStateProvinceId, billingZipPostalCode, billingCountryId); if (billingAddress == null) { billingAddress = new Core.Domain.Common.Address() { FirstName = billingFirstName, LastName = billingLastName, PhoneNumber = billingPhoneNumber, Email = billingEmail, FaxNumber = string.Empty, Company = string.Empty, Address1 = billingAddress1, Address2 = billingAddress2, City = billingCity, StateProvinceId = billingStateProvinceId, ZipPostalCode = billingZipPostalCode, CountryId = billingCountryId, CreatedOnUtc = DateTime.UtcNow, }; customer.Addresses.Add(billingAddress); } //set default billing address customer.BillingAddress = billingAddress; _customerService.UpdateCustomer(customer); var genericAttributeService = EngineContext.Current.Resolve <IGenericAttributeService>(); genericAttributeService.SaveAttribute <ShippingOption>(customer, SystemCustomerAttributeNames.SelectedShippingOption, null); bool shoppingCartRequiresShipping = cart.RequiresShipping(); if (shoppingCartRequiresShipping) { var paymentDetails = checkoutDetails.PaymentDetails.FirstOrDefault(); string[] shippingFullname = paymentDetails.ShipToAddress.Name.Trim().Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); string shippingFirstName = shippingFullname[0]; string shippingLastName = string.Empty; if (shippingFullname.Length > 1) { shippingLastName = shippingFullname[1]; } string shippingEmail = checkoutDetails.PayerInfo.Payer; string shippingAddress1 = paymentDetails.ShipToAddress.Street1; string shippingAddress2 = paymentDetails.ShipToAddress.Street2; string shippingPhoneNumber = paymentDetails.ShipToAddress.Phone; string shippingCity = paymentDetails.ShipToAddress.CityName; int? shippingStateProvinceId = null; var shippingStateProvince = _stateProvinceService.GetStateProvinceByAbbreviation(paymentDetails.ShipToAddress.StateOrProvince); if (shippingStateProvince != null) { shippingStateProvinceId = shippingStateProvince.Id; } int? shippingCountryId = null; string shippingZipPostalCode = paymentDetails.ShipToAddress.PostalCode; var shippingCountry = _countryService.GetCountryByTwoLetterIsoCode(paymentDetails.ShipToAddress.Country.ToString()); if (shippingCountry != null) { shippingCountryId = shippingCountry.Id; } var shippingAddress = customer.Addresses.FindAddress( shippingFirstName, shippingLastName, shippingPhoneNumber, shippingEmail, string.Empty, string.Empty, shippingAddress1, shippingAddress2, shippingCity, shippingStateProvinceId, shippingZipPostalCode, shippingCountryId); if (shippingAddress == null) { shippingAddress = new Core.Domain.Common.Address() { FirstName = shippingFirstName, LastName = shippingLastName, PhoneNumber = shippingPhoneNumber, Email = shippingEmail, FaxNumber = string.Empty, Company = string.Empty, Address1 = shippingAddress1, Address2 = shippingAddress2, City = shippingCity, StateProvinceId = shippingStateProvinceId, ZipPostalCode = shippingZipPostalCode, CountryId = shippingCountryId, CreatedOnUtc = DateTime.UtcNow, }; customer.Addresses.Add(shippingAddress); } customer.ShippingAddress = shippingAddress; _customerService.UpdateCustomer(customer); } bool isShippingSet = false; GetShippingOptionResponse getShippingOptionResponse = _shippingService.GetShippingOptions(cart, customer.ShippingAddress); if (checkoutDetails.UserSelectedOptions != null) { if (getShippingOptionResponse.Success && getShippingOptionResponse.ShippingOptions.Count > 0) { foreach (var shippingOption in getShippingOptionResponse.ShippingOptions) { if (checkoutDetails.UserSelectedOptions.ShippingOptionName.Contains(shippingOption.Name) && checkoutDetails.UserSelectedOptions.ShippingOptionName.Contains(shippingOption.Description)) { _genericAttributeService.SaveAttribute(Services.WorkContext.CurrentCustomer, SystemCustomerAttributeNames.SelectedShippingOption, shippingOption); isShippingSet = true; break; } } } if (!isShippingSet) { var shippingOption = new ShippingOption(); shippingOption.Name = checkoutDetails.UserSelectedOptions.ShippingOptionName; decimal shippingPrice = settings.DefaultShippingPrice; decimal.TryParse(checkoutDetails.UserSelectedOptions.ShippingOptionAmount.Value, out shippingPrice); shippingOption.Rate = shippingPrice; _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.SelectedShippingOption, shippingOption); } } processPaymentRequest.PaypalPayerId = checkoutDetails.PayerInfo.PayerID; return(processPaymentRequest); }
public ProcessPaymentRequest SetCheckoutDetails(GetExpressCheckoutDetailsResponseDetailsType checkoutDetails) { // get customer & cart //var customer = customer; int customerId = Convert.ToInt32(_workContext.CurrentCustomer.Id.ToString()); var customer = _customerService.GetCustomerById(customerId); _workContext.CurrentCustomer = customer; var cart = customer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList(); // get/update billing address string billingFirstName = checkoutDetails.PayerInfo.PayerName.FirstName; string billingLastName = checkoutDetails.PayerInfo.PayerName.LastName; string billingEmail = checkoutDetails.PayerInfo.Payer; string billingAddress1 = checkoutDetails.PayerInfo.Address.Street1; string billingAddress2 = checkoutDetails.PayerInfo.Address.Street2; string billingPhoneNumber = string.IsNullOrEmpty(checkoutDetails.PayerInfo.ContactPhone) ? checkoutDetails.ContactPhone : checkoutDetails.PayerInfo.ContactPhone; //check if customer has entered the phone number, if not, get the contact phone number string billingCity = checkoutDetails.PayerInfo.Address.CityName; int? billingStateProvinceId = null; var billingStateProvince = _stateProvinceService.GetStateProvinceByAbbreviation(checkoutDetails.PayerInfo.Address.StateOrProvince); if (billingStateProvince != null) { billingStateProvinceId = billingStateProvince.Id; } string billingZipPostalCode = checkoutDetails.PayerInfo.Address.PostalCode; int? billingCountryId = null; var billingCountry = _countryService.GetCountryByTwoLetterIsoCode(checkoutDetails.PayerInfo.Address.Country.ToString()); if (billingCountry != null) { billingCountryId = billingCountry.Id; } var billingAddress = customer.Addresses.ToList().FindAddress( billingFirstName, billingLastName, billingPhoneNumber, billingEmail, string.Empty, string.Empty, billingAddress1, billingAddress2, billingCity, billingStateProvinceId, billingZipPostalCode, billingCountryId, //TODO process custom attributes null); if (billingAddress == null) { billingAddress = new Core.Domain.Common.Address() { FirstName = billingFirstName, LastName = billingLastName, PhoneNumber = billingPhoneNumber, Email = billingEmail, FaxNumber = string.Empty, Company = string.Empty, Address1 = billingAddress1, Address2 = billingAddress2, City = billingCity, StateProvinceId = billingStateProvinceId, ZipPostalCode = billingZipPostalCode, CountryId = billingCountryId, CreatedOnUtc = DateTime.UtcNow, }; customer.Addresses.Add(billingAddress); } //set default billing address customer.BillingAddress = billingAddress; _customerService.UpdateCustomer(customer); _genericAttributeService.SaveAttribute <ShippingOption>(customer, SystemCustomerAttributeNames.SelectedShippingOption, null); bool shoppingCartRequiresShipping = cart.RequiresShipping(); if (shoppingCartRequiresShipping) { var paymentDetails = checkoutDetails.PaymentDetails.FirstOrDefault(); string[] shippingFullname = paymentDetails.ShipToAddress.Name.Trim() .Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); string shippingFirstName = shippingFullname[0]; string shippingLastName = string.Empty; if (shippingFullname.Length > 1) { shippingLastName = shippingFullname[1]; } string shippingEmail = checkoutDetails.PayerInfo.Payer; string shippingAddress1 = paymentDetails.ShipToAddress.Street1; string shippingAddress2 = paymentDetails.ShipToAddress.Street2; string shippingPhoneNumber = string.IsNullOrEmpty(paymentDetails.ShipToAddress.Phone) ? checkoutDetails.ContactPhone : paymentDetails.ShipToAddress.Phone; //check if customer has entered the shipping phone, if not, get the contact phone number string shippingCity = paymentDetails.ShipToAddress.CityName; int? shippingStateProvinceId = null; var shippingStateProvince = _stateProvinceService.GetStateProvinceByAbbreviation( paymentDetails.ShipToAddress.StateOrProvince); if (shippingStateProvince != null) { shippingStateProvinceId = shippingStateProvince.Id; } int? shippingCountryId = null; string shippingZipPostalCode = paymentDetails.ShipToAddress.PostalCode; var shippingCountry = _countryService.GetCountryByTwoLetterIsoCode(paymentDetails.ShipToAddress.Country.ToString()); if (shippingCountry != null) { shippingCountryId = shippingCountry.Id; } var shippingAddress = customer.Addresses.ToList().FindAddress( shippingFirstName, shippingLastName, shippingPhoneNumber, shippingEmail, string.Empty, string.Empty, shippingAddress1, shippingAddress2, shippingCity, shippingStateProvinceId, shippingZipPostalCode, shippingCountryId, //TODO process custom attributes null); if (shippingAddress == null) { shippingAddress = new Core.Domain.Common.Address() { FirstName = shippingFirstName, LastName = shippingLastName, PhoneNumber = shippingPhoneNumber, Email = shippingEmail, FaxNumber = string.Empty, Company = string.Empty, Address1 = shippingAddress1, Address2 = shippingAddress2, City = shippingCity, StateProvinceId = shippingStateProvinceId, ZipPostalCode = shippingZipPostalCode, CountryId = shippingCountryId, CreatedOnUtc = DateTime.UtcNow, }; customer.Addresses.Add(shippingAddress); } //set default shipping address customer.ShippingAddress = shippingAddress; _customerService.UpdateCustomer(customer); } var processPaymentRequest = new ProcessPaymentRequest { CustomerId = customerId }; processPaymentRequest.CustomValues["PaypalToken"] = checkoutDetails.Token; processPaymentRequest.CustomValues["PaypalPayerId"] = checkoutDetails.PayerInfo.PayerID; return(processPaymentRequest); }
private ActionResult ProcessingResult_PayPal(ProcessingResultModel model) { if (model == null) { throw new System.ArgumentNullException("model"); } PaymentResultContext context = new PaymentResultContext(); context.Order = model.order; if (model.success == true) { if (model.token == null) { throw new System.ArgumentNullException("token"); } if (model.payerID == null) { throw new System.ArgumentNullException("payerID"); } GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType(); request.Version = "104.0"; request.Token = model.token; GetExpressCheckoutDetailsReq wrapper = new GetExpressCheckoutDetailsReq(); wrapper.GetExpressCheckoutDetailsRequest = request; System.Collections.Generic.Dictionary <string, string> config = PaymentController.PayPal_CreateConfig(); PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(config); GetExpressCheckoutDetailsResponseType ecResponse = service.GetExpressCheckoutDetails(wrapper); if (ecResponse == null) { throw new System.Exception("checkout details result is null"); } if (ecResponse.Errors != null && ecResponse.Errors.Count > 0) { ecResponse.Errors.ForEach(delegate(ErrorType m) { context.Errors.Add(m.LongMessage); }); } if (ecResponse.Ack == AckCodeType.SUCCESS || ecResponse.Ack == AckCodeType.SUCCESSWITHWARNING) { GetExpressCheckoutDetailsResponseDetailsType details = ecResponse.GetExpressCheckoutDetailsResponseDetails; if (details == null) { throw new System.Exception("details object is null"); } if (string.IsNullOrEmpty(details.InvoiceID)) { throw new System.Exception("invoiceID not found"); } if (details.PaymentDetails == null) { throw new System.Exception("payment details is null"); } System.Collections.Generic.List <PaymentDetailsType> paymentDetails = new System.Collections.Generic.List <PaymentDetailsType>(); foreach (PaymentDetailsType payment in details.PaymentDetails) { paymentDetails.Add(new PaymentDetailsType { NotifyURL = null, PaymentAction = payment.PaymentAction, OrderTotal = payment.OrderTotal }); } DoExpressCheckoutPaymentRequestType paymentRequest = new DoExpressCheckoutPaymentRequestType(); paymentRequest.Version = "104.0"; paymentRequest.DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType { PaymentDetails = paymentDetails, Token = model.token, PayerID = model.payerID }; DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(new DoExpressCheckoutPaymentReq { DoExpressCheckoutPaymentRequest = paymentRequest }); if (doECResponse == null) { throw new System.Exception("payment result is null"); } if (doECResponse.Errors != null && doECResponse.Errors.Count > 0) { doECResponse.Errors.ForEach(delegate(ErrorType m) { context.Errors.Add(m.LongMessage); }); } if (doECResponse.Ack == AckCodeType.SUCCESS || doECResponse.Ack == AckCodeType.SUCCESSWITHWARNING) { ConfirmInvoiceResult invoiceResult = BookingProvider.ConfirmInvoice(details.InvoiceID.Trim()); Tracing.DataTrace.TraceEvent(TraceEventType.Information, 0, "PAYPAL transaction: invoice: '{0}', invoice confirmation: '{1}'", new object[] { details.InvoiceID, invoiceResult.IsSuccess ? "SUCCESS" : "FAILED" }); if (!invoiceResult.IsSuccess) { context.Errors.Add(string.Format("invoice confirmation error: {0}", invoiceResult.ErrorMessage)); } else { context.Success = true; BookingProvider.AcceptInvoice(Convert.ToInt32(context.Order)); } } } } else { context.Errors.Add(PaymentStrings.PaymentCancelled); } return(base.View("_ProcessingResult", context)); }
public static string GetECDetails(string payPalToken, int customerId) { var payPalRefund = new PayPalAPISoapBinding(); var payPalBinding = new PayPalAPIAASoapBinding(); var payerId = string.Empty; var addressStatus = string.Empty; var request = new GetExpressCheckoutDetailsReq(); var requestType = new GetExpressCheckoutDetailsRequestType(); var response = new GetExpressCheckoutDetailsResponseType(); var responseType = new GetExpressCheckoutDetailsResponseDetailsType(); GetPaypalRequirements(out payPalRefund, out payPalBinding); request.GetExpressCheckoutDetailsRequest = requestType; response.GetExpressCheckoutDetailsResponseDetails = responseType; requestType.Token = payPalToken; requestType.Version = API_VER; response = payPalBinding.GetExpressCheckoutDetails(request); var payerInfo = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo; payerId = payerInfo.PayerID; if (string.IsNullOrEmpty(payerId)) // If we don't have a PayerID the transaction must be aborted. { return(string.Empty); } addressStatus = payerInfo.Address.AddressStatus.ToString(); //Is address AVS Confirmed or Unconfirmed? var requireConfirmedAddress = AppLogic.AppConfigBool("PayPal.Express.AVSRequireConfirmedAddress"); if (requireConfirmedAddress && !addressStatus.Equals("Confirmed", StringComparison.OrdinalIgnoreCase)) { return("AVSFAILED"); } var customer = new Customer(customerId, true); customer.UpdateCustomer( email: customer.IsRegistered ? null : payerInfo.Payer, firstName: payerInfo.PayerName.FirstName, lastName: payerInfo.PayerName.LastName, phone: payerInfo.Address.Phone != null ? payerInfo.Address.Phone : string.Empty, okToEmail: false ); //Use the address from PayPal var payPalAddress = Address.FindOrCreateOffSiteAddress( customerId: customerId, city: payerInfo.Address.CityName, stateAbbreviation: AppLogic.GetStateAbbreviation(payerInfo.Address.StateOrProvince, payerInfo.Address.CountryName), postalCode: payerInfo.Address.PostalCode, countryName: payerInfo.Address.CountryName, offSiteSource: AppLogic.ro_PMPayPalExpress, firstName: payerInfo.PayerName.FirstName, lastName: payerInfo.PayerName.LastName, address1: payerInfo.Address.Street1, address2: payerInfo.Address.Street2, phone: payerInfo.Address.Phone != null ? payerInfo.Address.Phone : null ); customer.SetPrimaryAddress(payPalAddress.AddressID, AddressTypes.Billing); customer.SetPrimaryAddress(payPalAddress.AddressID, AddressTypes.Shipping); return(payerId); }
public ProcessPaymentRequest SetCheckoutDetails(GetExpressCheckoutDetailsResponseDetailsType checkoutDetails) { // get customer & cart var customerId = Convert.ToInt32(_workContext.CurrentCustomer.Id.ToString()); var customer = _customerService.GetCustomerById(customerId); _workContext.CurrentCustomer = customer; var cart = _shoppingCartService.GetShoppingCart(customer, ShoppingCartType.ShoppingCart).ToList(); // get/update billing address var billingFirstName = checkoutDetails.PayerInfo.PayerName.FirstName; var billingLastName = checkoutDetails.PayerInfo.PayerName.LastName; var billingEmail = checkoutDetails.PayerInfo.Payer; var billingAddress1 = checkoutDetails.PayerInfo.Address.Street1; var billingAddress2 = checkoutDetails.PayerInfo.Address.Street2; var billingPhoneNumber = checkoutDetails.PayerInfo.ContactPhone; var billingCity = checkoutDetails.PayerInfo.Address.CityName; int?billingStateProvinceId = null; var billingStateProvince = _stateProvinceService.GetStateProvinceByAbbreviation(checkoutDetails.PayerInfo.Address.StateOrProvince); if (billingStateProvince != null) { billingStateProvinceId = billingStateProvince.Id; } var billingZipPostalCode = checkoutDetails.PayerInfo.Address.PostalCode; int?billingCountryId = null; var billingCountry = _countryService.GetCountryByTwoLetterIsoCode(checkoutDetails.PayerInfo.Address.Country.ToString()); if (billingCountry != null) { billingCountryId = billingCountry.Id; } var billingAddress = _addressService.FindAddress(_customerService.GetAddressesByCustomerId(_workContext.CurrentCustomer.Id).ToList(), billingFirstName, billingLastName, billingPhoneNumber, billingEmail, string.Empty, string.Empty, billingAddress1, billingAddress2, billingCity, billingCountry?.Name, billingStateProvinceId, billingZipPostalCode, billingCountryId, null); //TODO process custom attributes if (billingAddress == null) { billingAddress = new Core.Domain.Common.Address { FirstName = billingFirstName, LastName = billingLastName, PhoneNumber = billingPhoneNumber, Email = billingEmail, FaxNumber = string.Empty, Company = string.Empty, Address1 = billingAddress1, Address2 = billingAddress2, City = billingCity, StateProvinceId = billingStateProvinceId, ZipPostalCode = billingZipPostalCode, CountryId = billingCountryId, CreatedOnUtc = DateTime.UtcNow }; _addressService.InsertAddress(billingAddress); _customerService.InsertCustomerAddress(customer, billingAddress); } //set default billing address customer.BillingAddressId = billingAddress.Id; _customerService.UpdateCustomer(customer); _genericAttributeService.SaveAttribute <ShippingOption>(customer, NopCustomerDefaults.SelectedShippingOptionAttribute, null, customer.RegisteredInStoreId); var shoppingCartRequiresShipping = _shoppingCartService.ShoppingCartRequiresShipping(cart); if (shoppingCartRequiresShipping) { var paymentDetails = checkoutDetails.PaymentDetails.FirstOrDefault() ?? new PaymentDetailsType(); var shippingFullname = paymentDetails.ShipToAddress.Name.Trim() .Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); var shippingFirstName = shippingFullname[0]; var shippingLastName = string.Empty; if (shippingFullname.Length > 1) { shippingLastName = shippingFullname[1]; } var shippingEmail = checkoutDetails.PayerInfo.Payer; var shippingAddress1 = paymentDetails.ShipToAddress.Street1; var shippingAddress2 = paymentDetails.ShipToAddress.Street2; var shippingPhoneNumber = paymentDetails.ShipToAddress.Phone; var shippingCity = paymentDetails.ShipToAddress.CityName; int?shippingStateProvinceId = null; var shippingStateProvince = _stateProvinceService.GetStateProvinceByAbbreviation(paymentDetails.ShipToAddress.StateOrProvince); if (shippingStateProvince != null) { shippingStateProvinceId = shippingStateProvince.Id; } int?shippingCountryId = null; var shippingZipPostalCode = paymentDetails.ShipToAddress.PostalCode; var shippingCountry = _countryService.GetCountryByTwoLetterIsoCode(paymentDetails.ShipToAddress.Country.ToString()); if (shippingCountry != null) { shippingCountryId = shippingCountry.Id; } var shippingAddress = _addressService.FindAddress(_customerService.GetAddressesByCustomerId(_workContext.CurrentCustomer.Id).ToList(), shippingFirstName, shippingLastName, shippingPhoneNumber, shippingEmail, string.Empty, string.Empty, shippingAddress1, shippingAddress2, shippingCity, shippingCountry?.Name, shippingStateProvinceId, shippingZipPostalCode, shippingCountryId, null); //TODO process custom attributes if (shippingAddress == null) { shippingAddress = new Core.Domain.Common.Address { FirstName = shippingFirstName, LastName = shippingLastName, PhoneNumber = shippingPhoneNumber, Email = shippingEmail, FaxNumber = string.Empty, Company = string.Empty, Address1 = shippingAddress1, Address2 = shippingAddress2, City = shippingCity, StateProvinceId = shippingStateProvinceId, ZipPostalCode = shippingZipPostalCode, CountryId = shippingCountryId, CreatedOnUtc = DateTime.UtcNow }; _addressService.InsertAddress(shippingAddress); _customerService.InsertCustomerAddress(customer, shippingAddress); } //set default shipping address customer.ShippingAddressId = shippingAddress.Id; _customerService.UpdateCustomer(customer); } var processPaymentRequest = new ProcessPaymentRequest { CustomerId = customerId, CustomValues = { [Defaults.PaypalTokenKey] = checkoutDetails.Token, [Defaults.PaypalPayerIdKey] = checkoutDetails.PayerInfo.PayerID } }; return(processPaymentRequest); }