Need the location in nop4.2 of where (method) PayPal Standard gets the Order or Cart Total for payment processing.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 anos atrás
Can someone please point me to the Method that calculates the Order SubTotal for PayPal Standard in NopCommerce V4.2?

I need to check this total to decide on a few other steps...

Tks!
4 anos atrás
Have a look at the GetShoppingCartSubTotal methods.

This can be found in Nop.Services > Orders > OrderTotalCalculationService > GetShoppingCartSubTotal


Hope this will help you.
4 anos atrás
Zambroff ITOS wrote:
Have a look at the GetShoppingCartSubTotal methods.
This can be found in Nop.Services > Orders > OrderTotalCalculationService > GetShoppingCartSubTotal
Hope this will help you.


During Checkout, PayPal gets the Cart Total from a specific location. Specifically, I am referring to the Cart Total location when this Checkbox is checked.  

4 anos atrás
webzest wrote:

During Checkout, PayPal gets the Cart Total from a specific location. Specifically, I am referring to the Cart Total location when this Checkbox is checked.  




Have a look at the AddItemsParameters method found in the PayPalStandardPaymentProcessor.cs file. The items and totals are passed in through the PostProcessPaymentRequest object.


private void AddItemsParameters(IDictionary<string, string> parameters, PostProcessPaymentRequest postProcessPaymentRequest)
        {
            //upload order items
            parameters.Add("cmd", "_cart");
            parameters.Add("upload", "1");

            var cartTotal = decimal.Zero;
            var roundedCartTotal = decimal.Zero;
            var itemCount = 1;

            //add shopping cart items
            foreach (var item in postProcessPaymentRequest.Order.OrderItems)
            {
                var roundedItemPrice = Math.Round(item.UnitPriceExclTax, 2);

                //add query parameters
                parameters.Add($"item_name_{itemCount}", item.Product.Name);
                parameters.Add($"amount_{itemCount}", roundedItemPrice.ToString("0.00", CultureInfo.InvariantCulture));
                parameters.Add($"quantity_{itemCount}", item.Quantity.ToString());

                cartTotal += item.PriceExclTax;
                roundedCartTotal += roundedItemPrice * item.Quantity;
                itemCount++;
            }

            //add checkout attributes as order items
            var checkoutAttributeValues = _checkoutAttributeParser.ParseCheckoutAttributeValues(postProcessPaymentRequest.Order.CheckoutAttributesXml);
            foreach (var attributeValue in checkoutAttributeValues)
            {
                var attributePrice = _taxService.GetCheckoutAttributePrice(attributeValue, false, postProcessPaymentRequest.Order.Customer);
                var roundedAttributePrice = Math.Round(attributePrice, 2);

                //add query parameters
                if (attributeValue.CheckoutAttribute == null)
                    continue;

                parameters.Add($"item_name_{itemCount}", attributeValue.CheckoutAttribute.Name);
                parameters.Add($"amount_{itemCount}", roundedAttributePrice.ToString("0.00", CultureInfo.InvariantCulture));
                parameters.Add($"quantity_{itemCount}", "1");

                cartTotal += attributePrice;
                roundedCartTotal += roundedAttributePrice;
                itemCount++;
            }

            //add shipping fee as a separate order item, if it has price
            var roundedShippingPrice = Math.Round(postProcessPaymentRequest.Order.OrderShippingExclTax, 2);
            if (roundedShippingPrice > decimal.Zero)
            {
                parameters.Add($"item_name_{itemCount}", "Shipping fee");
                parameters.Add($"amount_{itemCount}", roundedShippingPrice.ToString("0.00", CultureInfo.InvariantCulture));
                parameters.Add($"quantity_{itemCount}", "1");

                cartTotal += postProcessPaymentRequest.Order.OrderShippingExclTax;
                roundedCartTotal += roundedShippingPrice;
                itemCount++;
            }

            //add payment method additional fee as a separate order item, if it has price
            var roundedPaymentMethodPrice = Math.Round(postProcessPaymentRequest.Order.PaymentMethodAdditionalFeeExclTax, 2);
            if (roundedPaymentMethodPrice > decimal.Zero)
            {
                parameters.Add($"item_name_{itemCount}", "Payment method fee");
                parameters.Add($"amount_{itemCount}", roundedPaymentMethodPrice.ToString("0.00", CultureInfo.InvariantCulture));
                parameters.Add($"quantity_{itemCount}", "1");

                cartTotal += postProcessPaymentRequest.Order.PaymentMethodAdditionalFeeExclTax;
                roundedCartTotal += roundedPaymentMethodPrice;
                itemCount++;
            }

            //add tax as a separate order item, if it has positive amount
            var roundedTaxAmount = Math.Round(postProcessPaymentRequest.Order.OrderTax, 2);
            if (roundedTaxAmount > decimal.Zero)
            {
                parameters.Add($"item_name_{itemCount}", "Tax amount");
                parameters.Add($"amount_{itemCount}", roundedTaxAmount.ToString("0.00", CultureInfo.InvariantCulture));
                parameters.Add($"quantity_{itemCount}", "1");

                cartTotal += postProcessPaymentRequest.Order.OrderTax;
                roundedCartTotal += roundedTaxAmount;
            }

            if (cartTotal > postProcessPaymentRequest.Order.OrderTotal)
            {
                //get the difference between what the order total is and what it should be and use that as the "discount"
                var discountTotal = Math.Round(cartTotal - postProcessPaymentRequest.Order.OrderTotal, 2);
                roundedCartTotal -= discountTotal;

                //gift card or rewarded point amount applied to cart in nopCommerce - shows in PayPal as "discount"
                parameters.Add("discount_amount_cart", discountTotal.ToString("0.00", CultureInfo.InvariantCulture));
            }

            //save order total that actually sent to PayPal (used for PDT order total validation)
            _genericAttributeService.SaveAttribute(postProcessPaymentRequest.Order, PayPalHelper.OrderTotalSentToPayPal, roundedCartTotal);
        }
4 anos atrás
I added my logic and added my extra fee according to the Cart totals and it is properly reflected in the PayPal parameter; however, the number that is actually transferred to PayPal differs from what I am seeing in debug mode.

4 anos atrás
Could you advise how you are adding the additional fee?

Note that the actual amount passed to PayPal is not actually passed as a single total but rather a list of items with individual amounts.


Have a look at the PostProcessPayment method in PayPalStandardPaymentProcessor.cs

Specifically look at the parameters variable prior to sending to PayPal and if the totals of all the parameters match to your postProcessPaymentRequest.Order.OrderTotal value.



//remove null values from parameters
                parameters = parameters.Where(parameter => !string.IsNullOrEmpty(parameter.Value))
                    .ToDictionary(parameter => parameter.Key, parameter => parameter.Value);

                //ensure redirect URL doesn't exceed 2K chars to avoid "too long URL" exception
                var redirectUrl = QueryHelpers.AddQueryString(baseUrl, parameters);
                if (redirectUrl.Length <= 2048)
                {
                    _httpContextAccessor.HttpContext.Response.Redirect(redirectUrl);
                    return;
                }
4 anos atrás
I am updating the cartTotal and roundedCartTotal values in the AddItemsParameters method...

        private void AddItemsParameters(IDictionary<string, string> parameters, PostProcessPaymentRequest postProcessPaymentRequest)
        {
            //upload order items
            parameters.Add("cmd", "_cart");
            parameters.Add("upload", "1");

            var cartTotal = decimal.Zero;
            var roundedCartTotal = decimal.Zero;
            var itemCount = 1;

            //add shopping cart items
            foreach (var item in postProcessPaymentRequest.Order.OrderItems)
            {
                var roundedItemPrice = Math.Round(item.UnitPriceExclTax, 2);

                //add query parameters
                parameters.Add($"item_name_{itemCount}", item.Product.Name);
                parameters.Add($"amount_{itemCount}", roundedItemPrice.ToString("0.00", CultureInfo.InvariantCulture));
                parameters.Add($"quantity_{itemCount}", item.Quantity.ToString());

                cartTotal += item.PriceExclTax;
                roundedCartTotal += roundedItemPrice * item.Quantity;
                itemCount++;
            }

            // Update totals if they are less than 20.
            if (cartTotal < 20)
            {
                cartTotal += 2;
                roundedCartTotal += 2;
            }
4 anos atrás
webzest wrote:
I am updating the cartTotal and roundedCartTotal values in the AddItemsParameters method...

        private void AddItemsParameters(IDictionary<string, string> parameters, PostProcessPaymentRequest postProcessPaymentRequest)
        {
            //upload order items
            parameters.Add("cmd", "_cart");
            parameters.Add("upload", "1");

            var cartTotal = decimal.Zero;
            var roundedCartTotal = decimal.Zero;
            var itemCount = 1;

            //add shopping cart items
            foreach (var item in postProcessPaymentRequest.Order.OrderItems)
            {
                var roundedItemPrice = Math.Round(item.UnitPriceExclTax, 2);

                //add query parameters
                parameters.Add($"item_name_{itemCount}", item.Product.Name);
                parameters.Add($"amount_{itemCount}", roundedItemPrice.ToString("0.00", CultureInfo.InvariantCulture));
                parameters.Add($"quantity_{itemCount}", item.Quantity.ToString());

                cartTotal += item.PriceExclTax;
                roundedCartTotal += roundedItemPrice * item.Quantity;
                itemCount++;
            }

            // Update totals if they are less than 20.
            if (cartTotal < 20)
            {
                cartTotal += 2;
                roundedCartTotal += 2;
            }




The parameters that are sent to PayPal are being set prior to you updating the totals.


This is the amount sent to PayPal:

parameters.Add($"amount_{itemCount}", roundedItemPrice.ToString("0.00", CultureInfo.InvariantCulture));



One way of achieving what you are trying to do is adding a new item to be sent to PayPal.

Example:

            var cartTotal = decimal.Zero;
            var roundedCartTotal = decimal.Zero;
            var itemCount = 1;

            //add shopping cart items
            foreach (var item in postProcessPaymentRequest.Order.OrderItems)
            {
                var roundedItemPrice = Math.Round(item.UnitPriceExclTax, 2);

                //add query parameters
                parameters.Add($"item_name_{itemCount}", item.Product.Name);
                parameters.Add($"amount_{itemCount}", roundedItemPrice.ToString("0.00", CultureInfo.InvariantCulture));
                parameters.Add($"quantity_{itemCount}", item.Quantity.ToString());

                cartTotal += item.PriceExclTax;
                roundedCartTotal += roundedItemPrice * item.Quantity;
                itemCount++;
            }

            if (cartTotal < 20)
            {
                var additionalPrice = 2.00m;

                //add query parameters
                parameters.Add($"item_name_{itemCount}", YOUR_ITEM_NAME_HERE);
                parameters.Add($"amount_{itemCount}", additionalPrice.ToString("0.00", CultureInfo.InvariantCulture));
                parameters.Add($"quantity_{itemCount}", "1");

                cartTotal += additionalPrice;
                roundedCartTotal += additionalPrice;
                itemCount++;
            }


The correct way of performing this should be through a plugin, but the above should work.
4 anos atrás
Yes, indeed; that worked.
I would like to explore the plugin approach as well because I need to also check the shipping or pick-up status and exclude the extra fee if UPS is the shipping mode or if the client will pick-up the item from our Greenhouse.  If either one of these is true, then no extra fee; otherwise add the fee.
Can I still do this from our current approach while I investigate the plug-in path?
4 anos atrás
Have a look at this plugin, should support what you looking for.

https://www.nopcommerce.com/p/3540/shipping-rules-foxnetsoftcom.aspx


One hack of getting around this from your current approach would be to set up a distinct fee for pickup in store and UPS shipping and check for this fee in the shipping fee parameter, you would have to insure that all other shipping methods have a different fee.

The other option would be to develop a plugin yourself or have someone develop it for you.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.