Updating _workContext.CurrentCustomer

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
I'm developing a PayPal Express payment module.  In the controller on the return in trying to update _workContext.CurrentCustomer with checkout details returned from PayPal and then redirect to the checkout confirmation page:

       var paymentInfo = this.Session["OrderPaymentInfo"] as ProcessPaymentRequest;
                paymentInfo = processor.SetCheckoutDetails(paymentInfo, resp.GetExpressCheckoutDetailsResponseDetails);
                this.Session["OrderPaymentInfo"] = paymentInfo;
                _workContext.CurrentCustomer = paymentInfo.Customer;
                return RedirectToRoute("CheckoutConfirm");


So, the  payment method has been explicitly set:
_workContext.CurrentCustomer.SelectedPaymentMethodSystemName = "Payments.PayPalExpress";


but, when I get into CheckoutController methods Confirm or ConfirmOrder, the value is null again.  Am I missing something.  How can I persist this value into CheckoutController methods?
12 years ago
viperguynaz wrote:
I'm developing a PayPal Express payment module.  In the controller on the return in trying to update _workContext.CurrentCustomer with checkout details returned from PayPal and then redirect to the checkout confirmation page:

       var paymentInfo = this.Session["OrderPaymentInfo"] as ProcessPaymentRequest;
                paymentInfo = processor.SetCheckoutDetails(paymentInfo, resp.GetExpressCheckoutDetailsResponseDetails);
                this.Session["OrderPaymentInfo"] = paymentInfo;
                _workContext.CurrentCustomer = paymentInfo.Customer;
                return RedirectToRoute("CheckoutConfirm");


So, the  payment method has been explicitly set:
_workContext.CurrentCustomer.SelectedPaymentMethodSystemName = "Payments.PayPalExpress";


but, when I get into CheckoutController methods Confirm or ConfirmOrder, the value is null again.  Am I missing something.  How can I persist this value into CheckoutController methods?


Hey Don,

Review the CheckoutController. I've taken some code from the controller that you might be interested in.


        [HttpPost, ActionName("PaymentMethod")]
        [FormValueRequired("nextstep")]
        [ValidateInput(false)]
        public ActionResult SelectPaymentMethod(string paymentmethod, CheckoutPaymentMethodModel model)
        {
            //validation
            var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
            if (cart.Count == 0)
                return RedirectToRoute("ShoppingCart");

            if (_orderSettings.OnePageCheckoutEnabled)
                return RedirectToRoute("CheckoutOnePage");

            if ((_workContext.CurrentCustomer.IsGuest() && !_orderSettings.AnonymousCheckoutAllowed))
                return new HttpUnauthorizedResult();

            //Check whether payment workflow is required
            bool isPaymentWorkflowRequired = IsPaymentWorkflowRequired(cart);
            if (!isPaymentWorkflowRequired)
            {
                _workContext.CurrentCustomer.SelectedPaymentMethodSystemName = "";
                _customerService.UpdateCustomer(_workContext.CurrentCustomer);
                return RedirectToRoute("CheckoutPaymentInfo");
            }
            //payment method
            if (String.IsNullOrEmpty(paymentmethod))
                return PaymentMethod();

            //reward points
            _workContext.CurrentCustomer.UseRewardPointsDuringCheckout = model.UseRewardPoints;
            _customerService.UpdateCustomer(_workContext.CurrentCustomer);

            var paymentMethodInst = _paymentService.LoadPaymentMethodBySystemName(paymentmethod);
            if (paymentMethodInst == null || !paymentMethodInst.IsPaymentMethodActive(_paymentSettings))
                return PaymentMethod();

            //save
            _workContext.CurrentCustomer.SelectedPaymentMethodSystemName = paymentmethod;
            _customerService.UpdateCustomer(_workContext.CurrentCustomer);

            return RedirectToRoute("CheckoutPaymentInfo");
        }
12 years ago
Thanks Skyler - I've tried setting the value explicitly and using UpdateCustomer just like below:

 _workContext.CurrentCustomer.SelectedPaymentMethodSystemName = "Payments.PayPalExpress";
_customerService.UpdateCustomer(_workContext.CurrentCustomer);

return RedirectToRoute("CheckoutConfirm");


but I still get a null value in  _workContext.CurrentCustomer.SelectedPaymentMethodSystemName after the redirect - very confusing because I'm also setting the ShippingAddress in  _workContext.CurrentCustomer and it is persisting.  Going to have to dig a little deeper...ugh :-(
12 years ago
viperguynaz wrote:
Thanks Skyler - I've tried setting the value explicitly and using UpdateCustomer just like below:

 _workContext.CurrentCustomer.SelectedPaymentMethodSystemName = "Payments.PayPalExpress";
_customerService.UpdateCustomer(_workContext.CurrentCustomer);

return RedirectToRoute("CheckoutConfirm");


but I still get a null value in  _workContext.CurrentCustomer.SelectedPaymentMethodSystemName after the redirect - very confusing because I'm also setting the ShippingAddress in  _workContext.CurrentCustomer and it is persisting.  Going to have to dig a little deeper...ugh :-(


Are you seeing the value persisted in the database?
12 years ago
thanks Skyler!  I actually moved the setter and UpdateCustomer to the first Controller method - "SubmitButton" - and the value is persisting to the DB now and redirecting properly with a callback to the plug-in's ProcessPayment implementation.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.