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!
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);
}
//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;
}
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;
}
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;
}
parameters.Add($"amount_{itemCount}", roundedItemPrice.ToString("0.00", CultureInfo.InvariantCulture));
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++;
}