/// <summary>
        ///     Maps <see cref="AdjustmentLineItemReference" /> to <see cref="IInvoiceLineItem" />.
        /// </summary>
        /// <param name="adj">
        ///     The adj.
        /// </param>
        /// <returns>
        ///     The <see cref="IInvoiceLineItem" />.
        /// </returns>
        public static IInvoiceLineItem ToInvoiceLineItem(this AdjustmentLineItemReference adj)
        {
            // Default sku
            var sku = Guid.NewGuid().ToString();

            // Get line item type
            var lineItemType = StringToLineItemType(adj.LineItemType);

            if (lineItemType == LineItemType.Product)
            {
                // Product use sku supplied for create new one
                if (!string.IsNullOrEmpty(adj.Sku) && adj.Sku != "adj")
                {
                    sku = adj.Sku;
                }
            }

            // Create invoicelineitem object
            var item = new InvoiceLineItem(lineItemType, adj.Name, sku, 1, adj.Price);

            // See if this adjustment has extended data
            if (adj.ExtendedData != null)
            {
                // If so, add them to the InvoiceLineItem
                foreach (var ed in adj.ExtendedData)
                {
                    item.ExtendedData.SetValue(ed.Key, ed.Value);
                }
            }

            if (adj.IsTaxable)
            {
                item.ExtendedData.SetValue(Constants.ExtendedDataKeys.Taxable, true.ToString());
            }

            item.ExtendedData.SetValue(Constants.ExtendedDataKeys.Adjustment, adj.LineItemType);

            if (adj.Key.Equals(Guid.Empty))
            {
                item.ExtendedData.SetValue("userName", adj.UserName);
                item.ExtendedData.SetValue("email", adj.Email);
            }
            else
            {
                item.Key = adj.Key;
            }

            return(item);
        }
示例#2
0
        /// <summary>
        /// Maps <see cref="AdjustmentLineItemReference"/> to <see cref="IInvoiceLineItem"/>.
        /// </summary>
        /// <param name="adj">
        /// The adj.
        /// </param>
        /// <returns>
        /// The <see cref="IInvoiceLineItem"/>.
        /// </returns>
        public static IInvoiceLineItem ToInvoiceLineItem(this AdjustmentLineItemReference adj)
        {
            var item = new InvoiceLineItem(LineItemType.Adjustment, adj.Name, Guid.NewGuid().ToString(), 1, adj.Price);

            if (adj.Key.Equals(Guid.Empty))
            {
                item.ExtendedData.SetValue("userName", adj.UserName);
                item.ExtendedData.SetValue("email", adj.Email);
            }
            else
            {
                item.Key = adj.Key;
            }

            return(item);
        }