コード例 #1
0
        /// <summary>
        /// Builds a Microsoft Partner Center order from a list of purchase line items.
        /// </summary>
        /// <param name="purchaseLineItems">The purchase line items.</param>
        /// <param name="billingCycle">The order billing cycle.</param>
        /// <returns>The Partner Center Order.</returns>
        private Order BuildPartnerCenterOrder(IEnumerable <PurchaseLineItemWithOffer> purchaseLineItems, BillingCycleType billingCycle)
        {
            int lineItemNumber = 0;
            ICollection <OrderLineItem> partnerCenterOrderLineItems = new List <OrderLineItem>();

            // Build the Partner Center order line items
            foreach (PurchaseLineItemWithOffer lineItem in purchaseLineItems)
            {
                // add the line items to the partner center order and calculate the price to charge
                partnerCenterOrderLineItems.Add(new OrderLineItem()
                {
                    OfferId        = lineItem.PartnerOffer.MicrosoftOfferId,
                    Quantity       = lineItem.PurchaseLineItem.Quantity,
                    LineItemNumber = lineItemNumber++
                });
            }

            // Get the store billing cycle and update the order
            PartnerCenter.Models.Offers.BillingCycleType orderBillingCycle;

            switch (billingCycle)
            {
            case BillingCycleType.Annual:
                orderBillingCycle = PartnerCenter.Models.Offers.BillingCycleType.Annual;
                break;

            case BillingCycleType.Monthly:
                orderBillingCycle = PartnerCenter.Models.Offers.BillingCycleType.Monthly;
                break;

            default:
                throw new NotImplementedException($"Billing cycle {billingCycle} is not implemented");
            }

            // Bundle the order line items into a partner center order
            return(new Order()
            {
                ReferenceCustomerId = CustomerId,
                BillingCycle = orderBillingCycle,
                LineItems = partnerCenterOrderLineItems
            });
        }
コード例 #2
0
        /// <summary>
        /// Calculates the amount to charge for buying an extra additional seat for the remainder of a subscription's lease.
        /// </summary>
        /// <param name="expiryDate">The subscription's expiry date.</param>
        /// <param name="ratePerSeat">The subscription's price per seat, either yearly or mothly depending on the billing cycle.</param>
        /// <param name="billingCycle">The billing cycle.</param>
        /// <returns>The prorated amount to charge for the new extra seat.</returns>
        public static decimal CalculateProratedSeatCharge(DateTime expiryDate, decimal ratePerSeat, BillingCycleType billingCycle)
        {
            DateTime rightNow = DateTime.UtcNow;

            expiryDate = expiryDate.ToUniversalTime();

            // Determine the total yearly price per seat
            decimal yearlyRatePerSeat;

            switch (billingCycle)
            {
            case BillingCycleType.Annual:
                yearlyRatePerSeat = ratePerSeat;
                break;

            case BillingCycleType.Monthly:
                yearlyRatePerSeat = ratePerSeat * 12m;
                break;

            default:
                throw new NotImplementedException($"Billing cycle {billingCycle} is not implemented");
            }

            // Calculate the daily price per seat
            decimal dailyChargePerSeat = yearlyRatePerSeat / 365m;

            // Round up the remaining days in case there was a fraction and ensure it does not exceed 365 days
            decimal remainingDaysTillExpiry = Math.Ceiling(Convert.ToDecimal((expiryDate - rightNow).TotalDays));

            remainingDaysTillExpiry = Math.Min(remainingDaysTillExpiry, 365);

            return(remainingDaysTillExpiry * dailyChargePerSeat);
        }
コード例 #3
0
 /// <summary>
 /// Gets the order collection behavior given a billing cycle type.
 /// </summary>
 /// <param name="billingCycleType">The billing cycle type.</param>
 /// <returns>The order collection by billing cycle type.</returns>
 public IOrderCollectionByBillingCycleType ByBillingCycleType(BillingCycleType billingCycleType)
 {
     return(new OrderCollectionByBillingCycleTypeOperations(Partner, Context, billingCycleType));
 }