Example #1
0
        /// <summary>
        /// Get all PayPal line items
        /// </summary>
        /// <param name="postProcessPaymentRequest">Post process paymenmt request object</param>
        /// <param name="checkoutAttributeValues">List with checkout attribute values</param>
        /// <param name="cartTotal">Receives the calculated cart total amount</param>
        /// <returns>All items for PayPal Standard API</returns>
        public List <PayPalLineItem> GetLineItems(PostProcessPaymentRequest postProcessPaymentRequest, out decimal cartTotal)
        {
            cartTotal = decimal.Zero;

            var order = postProcessPaymentRequest.Order;
            var lst   = new List <PayPalLineItem>();

            // order items
            foreach (var orderItem in order.OrderItems)
            {
                var item = new PayPalLineItem()
                {
                    Type     = PayPalItemType.CartItem,
                    Name     = orderItem.Product.GetLocalized(x => x.Name),
                    Quantity = orderItem.Quantity,
                    Amount   = orderItem.UnitPriceExclTax
                };
                lst.Add(item);

                cartTotal += orderItem.PriceExclTax;
            }

            // checkout attributes.... are included in order total
            //foreach (var caValue in checkoutAttributeValues)
            //{
            //	var attributePrice = _taxService.GetCheckoutAttributePrice(caValue, false, order.Customer);

            //	if (attributePrice > decimal.Zero && caValue.CheckoutAttribute != null)
            //	{
            //		var item = new PayPalLineItem()
            //		{
            //			Type = PayPalItemType.CheckoutAttribute,
            //			Name = caValue.CheckoutAttribute.GetLocalized(x => x.Name),
            //			Quantity = 1,
            //			Amount = attributePrice
            //		};
            //		lst.Add(item);

            //		cartTotal += attributePrice;
            //	}
            //}

            // shipping
            if (order.OrderShippingExclTax > decimal.Zero)
            {
                var item = new PayPalLineItem()
                {
                    Type     = PayPalItemType.Shipping,
                    Name     = T("Plugins.Payments.PayPalStandard.ShippingFee").Text,
                    Quantity = 1,
                    Amount   = order.OrderShippingExclTax
                };
                lst.Add(item);

                cartTotal += order.OrderShippingExclTax;
            }

            // payment fee
            if (order.PaymentMethodAdditionalFeeExclTax > decimal.Zero)
            {
                var item = new PayPalLineItem()
                {
                    Type     = PayPalItemType.PaymentFee,
                    Name     = T("Plugins.Payments.PayPalStandard.PaymentMethodFee").Text,
                    Quantity = 1,
                    Amount   = order.PaymentMethodAdditionalFeeExclTax
                };
                lst.Add(item);

                cartTotal += order.PaymentMethodAdditionalFeeExclTax;
            }

            // tax
            if (order.OrderTax > decimal.Zero)
            {
                var item = new PayPalLineItem()
                {
                    Type     = PayPalItemType.Tax,
                    Name     = T("Plugins.Payments.PayPalStandard.SalesTax").Text,
                    Quantity = 1,
                    Amount   = order.OrderTax
                };
                lst.Add(item);

                cartTotal += order.OrderTax;
            }

            return(lst);
        }
        /// <summary>
        /// Get all PayPal line items
        /// </summary>
        /// <param name="postProcessPaymentRequest">Post process paymenmt request object</param>
        /// <param name="checkoutAttributeValues">List with checkout attribute values</param>
        /// <param name="cartTotal">Receives the calculated cart total amount</param>
        /// <returns>All items for PayPal Standard API</returns>
        public List <PayPalLineItem> GetLineItems(PostProcessPaymentRequest postProcessPaymentRequest, out decimal cartTotal)
        {
            cartTotal = decimal.Zero;

            var order = postProcessPaymentRequest.Order;
            var lst   = new List <PayPalLineItem>();

            // Order items... checkout attributes are included in order total
            foreach (var orderItem in order.OrderItems)
            {
                var item = new PayPalLineItem
                {
                    Type     = PayPalItemType.CartItem,
                    Name     = orderItem.Product.GetLocalized(x => x.Name),
                    Quantity = orderItem.Quantity,
                    Amount   = orderItem.UnitPriceExclTax
                };
                lst.Add(item);

                cartTotal += orderItem.PriceExclTax;
            }

            // Shipping
            if (order.OrderShippingExclTax > decimal.Zero)
            {
                var item = new PayPalLineItem
                {
                    Type     = PayPalItemType.Shipping,
                    Name     = T("Plugins.Payments.PayPalStandard.ShippingFee").Text,
                    Quantity = 1,
                    Amount   = order.OrderShippingExclTax
                };
                lst.Add(item);

                cartTotal += order.OrderShippingExclTax;
            }

            // Payment fee
            if (order.PaymentMethodAdditionalFeeExclTax > decimal.Zero)
            {
                var item = new PayPalLineItem
                {
                    Type     = PayPalItemType.PaymentFee,
                    Name     = T("Plugins.Payments.PayPal.PaymentMethodFee").Text,
                    Quantity = 1,
                    Amount   = order.PaymentMethodAdditionalFeeExclTax
                };
                lst.Add(item);

                cartTotal += order.PaymentMethodAdditionalFeeExclTax;
            }

            // Tax
            if (order.OrderTax > decimal.Zero)
            {
                var item = new PayPalLineItem
                {
                    Type     = PayPalItemType.Tax,
                    Name     = T("Plugins.Payments.PayPalStandard.SalesTax").Text,
                    Quantity = 1,
                    Amount   = order.OrderTax
                };
                lst.Add(item);

                cartTotal += order.OrderTax;
            }

            return(lst);
        }