Session Lost-about the PayPal Express

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 лет назад
the session lost  is about the payment,we pay for with the PayPal Express(PayPal Express plugin 2.4),once the we login paypal,and goto our website,the session will lost...who can Help me?

public ActionResult GetDetails(string token)
        {
            _logger.Information(_workContext.CurrentCustomer.Id + "-PayExpress:start GetDetails(" + token + ").");
            var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.PayPalExpress") as PayPalExpressCheckoutPaymentProcessor;
            if (processor == null ||
                !processor.IsPaymentMethodActive(_paymentSettings) || !processor.PluginDescriptor.Installed)
                throw new NopException("PayPal Express Checkout module cannot be loaded");

            var resp = processor.GetExpressCheckoutDetails(token);
            if (resp == null)
            {
                _logger.Error(_workContext.CurrentCustomer.Id + "-PayExpress-Error:processor.GetExpressCheckoutDetails(token) is null." + token);
            }
            if (resp.Ack == AckCodeType.Success)
            {
                var paymentInfo = this.Session["OrderPaymentInfo"] as ProcessPaymentRequest;
                if (this.Session["OrderPaymentInfo"] == null)
                {
                    _logger.Error(_workContext.CurrentCustomer.Id + "-PayExpress-Error:Session[OrderPaymentInfo] is null");
                }
                //paymentInfo = processor.SetCheckoutDetails(paymentInfo, resp.GetExpressCheckoutDetailsResponseDetails);
                //this.Session["OrderPaymentInfo"] = paymentInfo;
                //_workContext.CurrentCustomer = _customerService.GetCustomerById(paymentInfo.CustomerId);
                //_customerService.UpdateCustomer(_workContext.CurrentCustomer);

                if (!_workContext.CurrentCustomer.IsRegistered())
                {
                    PayerInfoType payerInfo = resp.GetExpressCheckoutDetailsResponseDetails.PayerInfo;

                    _logger.Information("PayExpress-PayerInfo.payerInfo.Payer=" + payerInfo.Payer +
                        ";payerInfo.PayerBusiness=" + payerInfo.PayerBusiness +
                        ";payerInfo.Address.CountryName=" + payerInfo.Address.CountryName +
                        ";payerInfo.Address.Street1=" + payerInfo.Address.Street1 +
                        ";payerInfo.Address.Street2=" + payerInfo.Address.Street2 +
                        ";payerInfo.Address.CityName=" + payerInfo.Address.CityName+
                        ";payerInfo.PayerName.FirstName=" + payerInfo.PayerName.FirstName+
                        ";payerInfo.PayerName.LastName=" + payerInfo.PayerName.LastName+
                        ";payerInfo.Address.Phone=" + payerInfo.Address.Phone+
                        ";payerInfo.Address.StateOrProvince=" + payerInfo.Address.StateOrProvince+
                        ";payerInfo.Address.PostalCode=" + payerInfo.Address.PostalCode);

                    var customer = _customerService.GetCustomerByUsername(payerInfo.Payer);
                    if (customer != null)/*customer exists*/
                    {
                        //update payer's customer Id
                        paymentInfo.CustomerId = customer.Id;
                        this.Session["OrderPaymentInfo"] = paymentInfo;
                        //migrate shopping cart
                        _shoppingCartService.MigrateShoppingCart(_workContext.CurrentCustomer, customer);
                        //login customer now
                        _authenticationService.SignIn(customer, true);
                        _logger.Information(_workContext.CurrentCustomer.Id + "-PayExpress:Customer is exists,logined");
                    }
                    else
                    {
                        _logger.Information(_workContext.CurrentCustomer.Id + "-PayExpress:Customer is not exists,start to create");
                        /*Save a new record*/
                        var newCustomer = _workContext.CurrentCustomer;
                        newCustomer.Email = payerInfo.Payer;
                        newCustomer.Username = payerInfo.Payer;
                        string saltKey = _encryptionService.CreateSaltKey(5);
                        newCustomer.PasswordSalt = saltKey;
                        newCustomer.Password = _encryptionService.CreatePasswordHash(newCustomer.CustomerGuid.ToString().Substring(0, 4), saltKey, _customerSettings.HashedPasswordFormat);
                        newCustomer.PasswordFormat = PasswordFormat.Hashed;
                        newCustomer.Active = true;

                        Address billingAddress = new Address();
                        Address shippingAddress = new Address();
                        if (!_workContext.CurrentCustomer.IsRegistered())//unlogined
                        {
                            //add billingAddress
                            var country_new = new Country();
                            int countryId = getCountryId(payerInfo.Address.CountryName);
                            billingAddress.Address1 = payerInfo.Address.Street1;
                            billingAddress.Address2 = payerInfo.Address.Street2;
                            billingAddress.City = payerInfo.Address.CityName;
                            billingAddress.Company = payerInfo.PayerBusiness;
                            if (countryId > 0)
                            {
                                billingAddress.CountryId = countryId;
                            }
                            else
                            {
                                country_new.AllowsBilling = true;
                                country_new.AllowsShipping = true;
                                country_new.Name = payerInfo.Address.CountryName;
                                country_new.Published = true;
                                //country_new.RestrictedShippingMethods=
                                billingAddress.Country = country_new;
                                billingAddress.CountryId = country_new.Id;
                            }
                            billingAddress.CreatedOnUtc = DateTime.UtcNow;
                            billingAddress.Email = payerInfo.Payer;
                            billingAddress.FirstName = payerInfo.PayerName.FirstName;
                            billingAddress.LastName = payerInfo.PayerName.LastName;
                            billingAddress.PhoneNumber = payerInfo.Address.Phone;
                            var stateProvinceBill = getStateProvince(payerInfo.Address.StateOrProvince);
                            StateProvince stateProvince_new = new StateProvince();
                            if (stateProvinceBill != null)
                            {
                                billingAddress.StateProvince = stateProvinceBill;
                                billingAddress.StateProvinceId = billingAddress.StateProvince.Id;
                            }
                            else
                            {
                                stateProvince_new.Abbreviation = payerInfo.Address.StateOrProvince;
                                stateProvince_new.CountryId = (int)billingAddress.CountryId;
                                stateProvince_new.Name = payerInfo.Address.StateOrProvince;
                                stateProvince_new.Published = true;

                                billingAddress.StateProvince = stateProvince_new;
                                billingAddress.StateProvinceId = stateProvince_new.Id;
                            }


                            billingAddress.ZipPostalCode = payerInfo.Address.PostalCode;

                            //add shippingAddress
                            shippingAddress.Address1 = payerInfo.Address.Street1;
                            shippingAddress.Address2 = payerInfo.Address.Street2;
                            shippingAddress.City = payerInfo.Address.CityName;
                            shippingAddress.Company = payerInfo.PayerBusiness;

                            if (countryId > 0)
                            {
                                shippingAddress.CountryId = countryId;
                            }
                            else
                            {

                                country_new.AllowsBilling = true;
                                country_new.AllowsShipping = true;
                                country_new.Name = payerInfo.Address.CountryName;
                                country_new.Published = true;
                                //country_new.RestrictedShippingMethods=
                                shippingAddress.Country = country_new;
                                shippingAddress.CountryId = country_new.Id;
                            }
                            shippingAddress.CreatedOnUtc = DateTime.UtcNow;
                            shippingAddress.Email = payerInfo.Payer;
                            shippingAddress.FirstName = payerInfo.PayerName.FirstName;
                            shippingAddress.LastName = payerInfo.PayerName.LastName;
                            shippingAddress.PhoneNumber = payerInfo.Address.Phone;
                            var stateProvinceShipping = getStateProvince(payerInfo.Address.StateOrProvince);
                            if (stateProvinceShipping != null)
                            {
                                shippingAddress.StateProvince = stateProvinceShipping;
                                shippingAddress.StateProvinceId = billingAddress.StateProvince.Id;
                            }
                            else
                            {
                                stateProvince_new.Abbreviation = payerInfo.Address.StateOrProvince;
                                stateProvince_new.CountryId = (int)shippingAddress.CountryId;
                                stateProvince_new.Name = payerInfo.Address.StateOrProvince;
                                stateProvince_new.Published = true;

                                shippingAddress.StateProvince = stateProvince_new;
                                shippingAddress.StateProvinceId = stateProvince_new.Id;
                            }
                            shippingAddress.ZipPostalCode = payerInfo.Address.PostalCode;

                            newCustomer.Addresses.Add(billingAddress);
                            newCustomer.Addresses.Add(shippingAddress);
                            newCustomer.SetBillingAddress(billingAddress);
                            newCustomer.SetShippingAddress(shippingAddress);
                        }

                        _workContext.CurrentCustomer = newCustomer;
                        _customerService.UpdateCustomer(_workContext.CurrentCustomer);

                        //add to 'Registered' role
                        var registeredRole = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.Registered);
                        if (registeredRole == null)
                            throw new NopException("'Registered' role could not be loaded");
                        _workContext.CurrentCustomer.CustomerRoles.Add(registeredRole);
                        //remove from 'Guests' role
                        var guestRole = _workContext.CurrentCustomer.CustomerRoles.FirstOrDefault(cr => cr.SystemName == SystemCustomerRoleNames.Guests);
                        if (guestRole != null)
                            _workContext.CurrentCustomer.CustomerRoles.Remove(guestRole);

                        //Add reward points for customer registration (if enabled)
                        if (_rewardPointsSettings.Enabled &&
                            _rewardPointsSettings.PointsForRegistration > 0)
                            _workContext.CurrentCustomer.AddRewardPointsHistoryEntry(_rewardPointsSettings.PointsForRegistration, "Registered as customer");

                        //migrate shopping cart
                        _shoppingCartService.MigrateShoppingCart(_workContext.CurrentCustomer, _workContext.CurrentCustomer);
                        //send customer welcome message
                        _workflowMessageService.SendCustomerWelcomeMessageForAutoCreateUser(_workContext.CurrentCustomer, _workContext.WorkingLanguage.Id);
                        //login customer now
                        _authenticationService.SignIn(_workContext.CurrentCustomer, true);
                        _logger.Information(_workContext.CurrentCustomer.Id + "-PayExpress:Customer is not exists,customer created");
                    }
                    return RedirectToRoute("CheckoutShippingMethodPEC");
                }

                return RedirectToRoute("CheckoutConfirmPEC");

            }

            return Content("We are sorry - an error occured processing you order<br />");
        }

9 лет назад
I'm getting the same problem with 3.1
What was causing the issue for you?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.