public PaymentDetailsType[] GetPaymentDetails(IList <ShoppingCartItem> cart) { var currencyCode = _payPalCurrencyCodeParser.GetCurrencyCodeType(_workContext.WorkingCurrency); decimal orderTotalDiscountAmount; List <DiscountForCaching> appliedDiscounts; int redeemedRewardPoints; decimal redeemedRewardPointsAmount; List <AppliedGiftCard> appliedGiftCards; var orderTotalWithDiscount = _payPalCartItemService.GetCartTotal(cart, out orderTotalDiscountAmount, out appliedDiscounts, out redeemedRewardPoints, out redeemedRewardPointsAmount, out appliedGiftCards); decimal subTotalWithDiscount; decimal subTotalWithoutDiscount; List <DiscountForCaching> subTotalAppliedDiscounts; decimal subTotalDiscountAmount; var itemTotalWithDiscount = _payPalCartItemService.GetCartItemTotal(cart, out subTotalDiscountAmount, out subTotalAppliedDiscounts, out subTotalWithoutDiscount, out subTotalWithDiscount); var giftCardsAmount = appliedGiftCards.Sum(x => x.AmountCanBeUsed); itemTotalWithDiscount = itemTotalWithDiscount - orderTotalDiscountAmount - giftCardsAmount; var taxTotal = _payPalCartItemService.GetTax(cart); var shippingTotal = _payPalCartItemService.GetShippingTotal(cart); var items = GetPaymentDetailsItems(cart); // checkout attributes var customer = cart.GetCustomer(); if (customer != null) { var checkoutAttributesXml = customer.GetAttribute <string>(SystemCustomerAttributeNames.CheckoutAttributes, _genericAttributeService, _storeContext.CurrentStore.Id); var caValues = _checkoutAttributeParser.ParseCheckoutAttributeValues(checkoutAttributesXml); if (caValues != null) { foreach (var caValue in caValues) { if (caValue.PriceAdjustment > 0) { var checkoutAttrItem = new PaymentDetailsItemType { Name = caValue.Name, Amount = caValue.PriceAdjustment.GetBasicAmountType(currencyCode), Quantity = "1" }; items.Add(checkoutAttrItem); } } } } if (orderTotalDiscountAmount > 0 || subTotalDiscountAmount > 0) { var discountItem = new PaymentDetailsItemType { Name = "Discount", Amount = (-orderTotalDiscountAmount + -subTotalDiscountAmount).GetBasicAmountType( currencyCode), Quantity = "1" }; items.Add(discountItem); } foreach (var appliedGiftCard in appliedGiftCards) { var giftCardItem = new PaymentDetailsItemType { Name = string.Format("Gift Card ({0})", appliedGiftCard.GiftCard.GiftCardCouponCode), Amount = (-appliedGiftCard.AmountCanBeUsed).GetBasicAmountType(currencyCode), Quantity = "1" }; items.Add(giftCardItem); } return(new[] { new PaymentDetailsType { OrderTotal = orderTotalWithDiscount.GetBasicAmountType(currencyCode), ItemTotal = itemTotalWithDiscount.GetBasicAmountType(currencyCode), TaxTotal = taxTotal.GetBasicAmountType(currencyCode), ShippingTotal = shippingTotal.GetBasicAmountType(currencyCode), PaymentDetailsItem = items.ToArray(), PaymentAction = _payPalExpressCheckoutPaymentSettings.PaymentAction, PaymentActionSpecified = true, ButtonSource = PayPalHelper.BnCode } }); }
public PaymentDetailsType[] GetPaymentDetails(IList <ShoppingCartItem> cart) { var currencyCode = _payPalCurrencyCodeParser.GetCurrencyCodeType(_workContext.WorkingCurrency); var orderTotalWithDiscount = _payPalCartItemService.GetCartTotal(cart, out var orderTotalDiscountAmount, out _, out _, out _, out var appliedGiftCards); var itemTotalWithDiscount = _payPalCartItemService.GetCartItemTotal(cart, out var subTotalDiscountAmount, out _, out _, out _); var giftCardsAmount = appliedGiftCards.Sum(x => x.AmountCanBeUsed); itemTotalWithDiscount = itemTotalWithDiscount - orderTotalDiscountAmount - giftCardsAmount; var taxTotal = _payPalCartItemService.GetTax(cart); var shippingTotal = _payPalCartItemService.GetShippingTotal(cart); var items = GetPaymentDetailsItems(cart); // checkout attributes var customer = _workContext.CurrentCustomer; if (customer != null) { var checkoutAttributesXml = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.CheckoutAttributes, _storeContext.CurrentStore.Id); var caValues = _checkoutAttributeParser.ParseCheckoutAttributeValues(checkoutAttributesXml); if (caValues != null) { foreach (var caValue in caValues) { if (caValue.PriceAdjustment <= 0) { continue; } var checkoutAttrItem = new PaymentDetailsItemType { Name = caValue.Name, Amount = caValue.PriceAdjustment.GetBasicAmountType(currencyCode), Quantity = "1" }; items.Add(checkoutAttrItem); } } } if (orderTotalDiscountAmount > 0 || subTotalDiscountAmount > 0) { var discountItem = new PaymentDetailsItemType { Name = "Discount", Amount = (-orderTotalDiscountAmount + -subTotalDiscountAmount).GetBasicAmountType(currencyCode), Quantity = "1" }; items.Add(discountItem); } foreach (var appliedGiftCard in appliedGiftCards) { var giftCardItem = new PaymentDetailsItemType { Name = $"Gift Card ({appliedGiftCard.GiftCard.GiftCardCouponCode})", Amount = (-appliedGiftCard.AmountCanBeUsed).GetBasicAmountType(currencyCode), Quantity = "1" }; items.Add(giftCardItem); } return(new[] { new PaymentDetailsType { OrderTotal = orderTotalWithDiscount.GetBasicAmountType(currencyCode), ItemTotal = itemTotalWithDiscount.GetBasicAmountType(currencyCode), TaxTotal = taxTotal.GetBasicAmountType(currencyCode), ShippingTotal = shippingTotal.GetBasicAmountType(currencyCode), PaymentDetailsItem = items.ToArray(), PaymentAction = _payPalExpressCheckoutPaymentSettings.PaymentAction, PaymentActionSpecified = true, ButtonSource = PayPalHelper.BnCode } }); }