/// <summary>
        /// Create an Order
        /// </summary>
        /// <param name="defaultDomain">default domain of the reseller</param>
        /// <param name="appId">appid that is registered for this application in Partner Center</param>
        /// <param name="key">Key for this application in Partner Center</param>
        /// <param name="customerMicrosoftId">Microsoft Id of the customer</param>
        /// <param name="resellerMicrosoftId">Microsoft Id of the reseller</param>
        public static void CreateOrder(string defaultDomain, string appId, string key, string customerMicrosoftId,
                                       string resellerMicrosoftId)
        {
            // Get Active Directory token first
            AuthorizationToken adAuthorizationToken = Reseller.GetAD_Token(defaultDomain, appId, key);

            // Using the ADToken get the sales agent token
            AuthorizationToken saAuthorizationToken = Reseller.GetSA_Token(adAuthorizationToken);

            // Get the Reseller Cid, you can cache this value
            string resellerCid = Reseller.GetCid(resellerMicrosoftId, saAuthorizationToken.AccessToken);

            // You can cache this value too
            var customerCid = Customer.GetCustomerCid(customerMicrosoftId, resellerMicrosoftId,
                                                      saAuthorizationToken.AccessToken);

            // Populate a multi line item order
            var existingCustomerOrder = Order.PopulateOrderFromConsole(customerCid);
            // Place the order and subscription uri and entitlement uri are returned per each line item
            var existingCustomerPlacedOrder = Order.PlaceOrder(existingCustomerOrder, resellerCid,
                                                               saAuthorizationToken.AccessToken);

            foreach (var line_Item in existingCustomerPlacedOrder.line_items)
            {
                Console.WriteLine("Subscription: {0}", line_Item.resulting_subscription_uri);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates a virtual machine in a new Azure subscription for a new customer.
        /// </summary>
        /// <param name="defaultDomain">default domain of the reseller</param>
        /// <param name="ptrCtrAppId">appId for this program that is registered in the Partner Center</param>
        /// <param name="ptrCtrAppSecret">app secret for this program that is registered in the Partner Center</param>
        /// <param name="resellerMicrosoftId">cid of the reseller</param>
        /// <param name="azureAppId">appId for this program that is registered in the reseller azure directory and configured for pre-consent</param>
        /// <param name="credentialName">Internet or network address label of entry in credential manager</param>
        public static void CreateVirtualMachineInNewSubscription(string defaultDomain, string ptrCtrAppId, string ptrCtrAppSecret,
                                                                 string resellerMicrosoftId, string azureAppId, string credentialName)
        {
            // Get Active Directory token first
            AuthorizationToken adAuthorizationToken = Reseller.GetAD_Token(defaultDomain, ptrCtrAppId, ptrCtrAppSecret);

            // Using the ADToken get the sales agent token
            AuthorizationToken saAuthorizationToken = Reseller.GetSA_Token(adAuthorizationToken);

            // Get the Reseller Cid, you can cache this value
            string resellerCid = Reseller.GetCid(resellerMicrosoftId, saAuthorizationToken.AccessToken);

            var s = Stream.CreateStream(resellerCid, saAuthorizationToken.AccessToken);

            string newCustomerMicrosoftId = Orchestrator.CreateCustomer(defaultDomain, ptrCtrAppId, ptrCtrAppSecret, resellerMicrosoftId);
            string newSubscriptionId      = Orchestrator.CreateOrderWithAzureTip(defaultDomain, ptrCtrAppId, ptrCtrAppSecret, newCustomerMicrosoftId, resellerMicrosoftId);

            bool continueProcess = Stream.WaitForSubscriptionEvent(resellerCid, saAuthorizationToken.AccessToken, newSubscriptionId, StreamEvents.Subscription.Provisioned);

            if (continueProcess)
            {
                CreateAzureVirtualMachine(azureAppId, credentialName, newCustomerMicrosoftId, newSubscriptionId);
            }

            Stream.DeleteStream(resellerCid, saAuthorizationToken.AccessToken);
        }
Beispiel #3
0
        /// <summary>
        /// List all customers for the reseller, loops through them and delete one by one.
        /// </summary>
        /// <param name="defaultDomain">default domain of the reseller</param>
        /// <param name="appId">appid that is registered for this application in Azure Active Directory (AAD)</param>
        /// <param name="key">Key for this application in Azure Active Directory</param>
        /// <param name="customerMicrosoftId">Microsoft Id of the customer</param>
        /// <param name="resellerMicrosoftId">Microsoft Id of the reseller</param>
        public static void ListAndDeleteAllCustomers(string defaultDomain, string appId, string key,
                                                     string resellerMicrosoftId, string customerMicrosoftId)
        {
            // Get Active Directory token first
            AuthorizationToken adAuthorizationToken = Reseller.GetAD_Token(defaultDomain, appId, key);

            // Using the ADToken get the sales agent token
            AuthorizationToken saAuthorizationToken = Reseller.GetSA_Token(adAuthorizationToken);

            // Get the Reseller Cid, you can cache this value
            string resellerCid = Reseller.GetCid(resellerMicrosoftId, saAuthorizationToken.AccessToken);

            var customers = Customer.GetAllCustomers(resellerMicrosoftId, adAuthorizationToken.AccessToken);

            foreach (var customer in customers.value)
            {
                Console.WriteLine("\nCustomer Info");
                Console.WriteLine("\tCustomer Id\t: {0}", customer.customerContextId);
                Console.WriteLine("\tName\t: {0}", customer.displayName);
                var existingCustomerCid = Customer.GetCustomerCid(customer.customerContextId, resellerMicrosoftId,
                                                                  saAuthorizationToken.AccessToken);
                Console.WriteLine("Deleting Customer " + customer.displayName);
                Customer.DeleteCustomer(resellerCid, existingCustomerCid, saAuthorizationToken.AccessToken);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Transition an Office 365 subscription to another (Office 365 Enterprise E1) SKU.
        /// Creates a subscription stream and gather events from the stream and show them on console.
        /// </summary>
        /// <param name="subscriptionId">Subscription Id</param>
        /// <param name="defaultDomain">default domain of the reseller</param>
        /// <param name="appId">appid that is registered for this application in Azure Active Directory (AAD)</param>
        /// <param name="key">Key for this application in Azure Active Directory</param>
        /// <param name="customerMicrosoftId">Microsoft Id of the customer</param>
        /// <param name="resellerMicrosoftId">Microsoft Id of the reseller</param>
        public static void TransitionToNewSKU(string subscriptionId, string defaultDomain, string appId, string key,
                                              string customerMicrosoftId, string resellerMicrosoftId)
        {
            // Get Active Directory token first
            AuthorizationToken adAuthorizationToken = Reseller.GetAD_Token(defaultDomain, appId, key);

            // Using the ADToken get the sales agent token
            AuthorizationToken saAuthorizationToken = Reseller.GetSA_Token(adAuthorizationToken);

            // Get the Reseller Cid, you can cache this value
            string resellerCid = Reseller.GetCid(resellerMicrosoftId, saAuthorizationToken.AccessToken);

            // You can cache this value too
            var customerCid = Customer.GetCustomerCid(customerMicrosoftId, resellerMicrosoftId,
                                                      saAuthorizationToken.AccessToken);

            // Correlation Id to be used for this scenaario
            var correlationId = Guid.NewGuid().ToString();

            // Offer Uri for an Office 365 Enterprise E1 subscription
            string newOfferUri = PromptForOfferUri();

            Subscription.Transition(subscriptionId, customerCid, newOfferUri, resellerCid,
                                    saAuthorizationToken.AccessToken);

            WaitForSuccessfulTransition(resellerCid, subscriptionId, saAuthorizationToken.AccessToken);
        }
Beispiel #5
0
        /// <summary>
        /// Create an Order for Azure in Integration Sandbox
        /// </summary>
        /// <param name="defaultDomain">default domain of the reseller</param>
        /// <param name="appId">appid that is registered for this application in Azure Active Directory (AAD)</param>
        /// <param name="key">Key for this application in Azure Active Directory</param>
        /// <param name="customerMicrosoftId">Microsoft Id of the customer</param>
        /// <param name="resellerMicrosoftId">Microsoft Id of the reseller</param>
        /// <returns></returns>
        public static string CreateOrderWithAzureTip(string defaultDomain, string appId, string key,
                                                     string customerMicrosoftId, string resellerMicrosoftId)
        {
            string result = String.Empty;

            // Get Active Directory token first
            AuthorizationToken adAuthorizationToken = Reseller.GetAD_Token(defaultDomain, appId, key);

            // Using the ADToken get the sales agent token
            AuthorizationToken saAuthorizationToken = Reseller.GetSA_Token(adAuthorizationToken);

            // Get the Reseller Cid, you can cache this value
            string resellerCid = Reseller.GetCid(resellerMicrosoftId, saAuthorizationToken.AccessToken);

            // You can cache this value too
            var customerCid = Customer.GetCustomerCid(customerMicrosoftId, resellerMicrosoftId,
                                                      saAuthorizationToken.AccessToken);

            // Populate an Azure in TIP order
            var newOrder = Order.PopulateAzureOrderInTIP(customerCid);
            // Place the order and subscription uri and entitlement uri are returned per each line item
            var existingCustomerPlacedOrder = Order.PlaceOrder(newOrder, resellerCid,
                                                               saAuthorizationToken.AccessToken);

            foreach (var line_Item in existingCustomerPlacedOrder.line_items)
            {
                var subscription = Subscription.GetSubscriptionByUri(line_Item.resulting_subscription_uri,
                                                                     saAuthorizationToken.AccessToken);
                result = subscription.Id;
                Console.WriteLine("Subscription: {0}", subscription.Id);
            }

            return(result);
        }
        /// <summary>
        /// Get all orders placed by the reseller for this customer
        /// </summary>
        /// <param name="defaultDomain">default domain of the reseller</param>
        /// <param name="appId">appid that is registered for this application in Partner Center</param>
        /// <param name="key">Key for this application in Partner Center</param>
        /// <param name="customerMicrosoftId">Microsoft Id of the customer</param>
        /// <param name="resellerMicrosoftId">Microsoft Id of the reseller</param>
        /// <returns>object that contains orders</returns>
        public static dynamic GetOrderById(string defaultDomain, string appId, string key, string orderId,
                                           string resellerMicrosoftId)
        {
            // Get Active Directory token first
            AuthorizationToken adAuthorizationToken = Reseller.GetAD_Token(defaultDomain, appId, key);

            // Using the ADToken get the sales agent token
            AuthorizationToken saAuthorizationToken = Reseller.GetSA_Token(adAuthorizationToken);

            // Get the Reseller Cid, you can cache this value
            string resellerCid = Reseller.GetCid(resellerMicrosoftId, saAuthorizationToken.AccessToken);

            return(Order.GetOrderById(resellerCid, orderId, saAuthorizationToken.AccessToken));
        }
        /// <summary>
        /// Create a customer
        /// </summary>
        /// <param name="defaultDomain">default domain of the reseller</param>
        /// <param name="appId">appid that is registered for this application in Partner Center</param>
        /// <param name="key">Key for this application in Partner Center</param>
        /// <param name="resellerMicrosoftId">Microsoft Id of the reseller</param>
        public static void CreateCustomer(string defaultDomain, string appId, string key, string resellerMicrosoftId)
        {
            // Get Active Directory token first
            AuthorizationToken adAuthorizationToken = Reseller.GetAD_Token(defaultDomain, appId, key);

            // Using the ADToken get the sales agent token
            AuthorizationToken saAuthorizationToken = Reseller.GetSA_Token(adAuthorizationToken);

            // Get the Reseller Cid, you can cache this value
            string resellerCid = Reseller.GetCid(resellerMicrosoftId, saAuthorizationToken.AccessToken);

            // Get input from the console application for creating a new customer
            var customer = Customer.PopulateCustomerFromConsole();

            // This is the created customer object that contains the cid, the microsoft tenant id etc
            var createdCustomer = Customer.CreateCustomer(customer, resellerCid, saAuthorizationToken.AccessToken);
        }
Beispiel #8
0
        /// <summary>
        /// Gets the customer entity for the given customer id
        /// </summary>
        /// <param name="defaultDomain">default domain of the reseller</param>
        /// <param name="customerMicrosoftId">Microsoft Id of the customer</param>
        /// <param name="resellerMicrosoftId">Microsoft Id of the reseller</param>
        /// <returns>customer object</returns>
        public static dynamic GetCustomer(string defaultDomain, string appId, string key, string customerMicrosoftId,
                                          string resellerMicrosoftId)
        {
            // Get Active Directory token first
            AuthorizationToken adAuthorizationToken = Reseller.GetAD_Token(defaultDomain, appId, key);

            // Using the ADToken get the sales agent token
            AuthorizationToken saAuthorizationToken = Reseller.GetSA_Token(adAuthorizationToken);

            var existingCustomerCid = Customer.GetCustomerCid(customerMicrosoftId, resellerMicrosoftId,
                                                              saAuthorizationToken.AccessToken);
            // Get Customer token
            AuthorizationToken customerAuthorizationToken = Customer.GetCustomer_Token(existingCustomerCid,
                                                                                       adAuthorizationToken);

            return(Customer.GetCustomer(existingCustomerCid, customerAuthorizationToken.AccessToken));
        }
Beispiel #9
0
        /// <summary>
        /// Get all subscriptions placed by the reseller for the customer
        /// </summary>
        /// <param name="defaultDomain">default domain of the reseller</param>
        /// <param name="appId">appid that is registered for this application in Azure Active Directory (AAD)</param>
        /// <param name="key">Key for this application in Azure Active Directory</param>
        /// <param name="customerMicrosoftId">Microsoft Id of the customer</param>
        /// <param name="resellerMicrosoftId">Microsoft Id of the reseller</param>
        /// <returns>object that contains all of the subscriptions</returns>
        public static dynamic GetSubscriptions(string defaultDomain, string appId, string key,
                                               string customerMicrosoftId, string resellerMicrosoftId)
        {
            // Get Active Directory token first
            AuthorizationToken adAuthorizationToken = Reseller.GetAD_Token(defaultDomain, appId, key);

            // Using the ADToken get the sales agent token
            AuthorizationToken saAuthorizationToken = Reseller.GetSA_Token(adAuthorizationToken);

            // Get the Reseller Cid, you can cache this value
            string resellerCid = Reseller.GetCid(resellerMicrosoftId, saAuthorizationToken.AccessToken);

            // You can cache this value too
            var customerCid = Customer.GetCustomerCid(customerMicrosoftId, resellerMicrosoftId,
                                                      saAuthorizationToken.AccessToken);

            return(Subscription.GetSubscriptions(customerCid, resellerCid, saAuthorizationToken.AccessToken));
        }
Beispiel #10
0
        /// <summary>
        /// Create a new customer
        /// </summary>
        /// <param name="defaultDomain">default domain of the reseller</param>
        /// <param name="appId">appid that is registered for this application in Azure Active Directory (AAD)</param>
        /// <param name="key">Key for this application in Azure Active Directory</param>
        /// <param name="resellerMicrosoftId">Microsoft Id of the reseller</param>
        /// <returns></returns>
        internal static string CreateCustomer(string defaultDomain, string appId, string key,
                                              string resellerMicrosoftId)
        {
            // Get Active Directory token first
            AuthorizationToken adAuthorizationToken = Reseller.GetAD_Token(defaultDomain, appId, key);

            // Using the ADToken get the sales agent token
            AuthorizationToken saAuthorizationToken = Reseller.GetSA_Token(adAuthorizationToken);

            // Get the Reseller Cid, you can cache this value
            string resellerCid = Reseller.GetCid(resellerMicrosoftId, saAuthorizationToken.AccessToken);
            // Get input from the console application for creating a new customer
            var customer = Customer.PopulateCustomerFromConsole();

            // This is the created customer object that contains the cid, the microsoft tenant id etc
            var createdCustomer = Customer.CreateCustomer(customer, resellerCid, saAuthorizationToken.AccessToken);

            if (createdCustomer == null)
            {
                throw new Exception("Error creating customer");
            }
            string newCustomerMicrosoftId = createdCustomer.customer.identity.data.tid;

            // Populate a multi line item order
            var newCustomerOrder = Order.PopulateOrderWithMultipleLineItems(createdCustomer.customer.id);

            // Place the order and subscription uri and entitlement uri are returned per each line item
            var newCustomerPlacedOrder = Order.PlaceOrder(newCustomerOrder, resellerCid, saAuthorizationToken.AccessToken);

            foreach (var line_Item in newCustomerPlacedOrder.line_items)
            {
                var subscription = Subscription.GetSubscriptionByUri(line_Item.resulting_subscription_uri, saAuthorizationToken.AccessToken);
                Console.WriteLine("Subscription: {0}", subscription.Id);
            }

            return(newCustomerMicrosoftId);
        }
Beispiel #11
0
        static void Main()
        {
            Console.Write("\nHave you updated the app.config, with the settings from https://partnercenter.microsoft.com (y/n)? ");
            string response = Console.ReadLine().Trim().ToUpperInvariant();

            if (response != "Y" && response != "YES")
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("\nUpdate AppId, Key, MicrosoftId, DefaultDomain in the app.config and run the app again");

                Console.ResetColor();
                Console.Write("\n\n\nHit enter to exit the app now");
                Console.ReadLine();
                return;
            }

            // This is the Microsoft ID of the reseller
            // Please work with your Admin Agent to get it from https://partnercenter.microsoft.com/en-us/pc/AccountSettings/TenantProfile
            string microsoftId = ConfigurationManager.AppSettings["MicrosoftId"];

            // This is the default domain of the reseller
            // Please work with your Admin Agent to get it from https://partnercenter.microsoft.com/en-us/pc/AccountSettings/TenantProfile
            string defaultDomain = ConfigurationManager.AppSettings["DefaultDomain"];

            // This is the appid that is registered for this application in Azure Active Directory (AAD)
            // Please work with your Admin Agent to get it from  https://partnercenter.microsoft.com/en-us/pc/ApiIntegration/Overview
            string appId = ConfigurationManager.AppSettings["AppId"];

            // This is the key for this application in Azure Active Directory
            // This is only available at the time your admin agent has created a new app at https://partnercenter.microsoft.com/en-us/pc/ApiIntegration/Overview
            // You could alternatively goto Azure Active Directory and generate a new key, and use that.
            string key = ConfigurationManager.AppSettings["Key"];

            try
            {
                // Get Active Directory token first
                adAuthorizationToken = Reseller.GetAD_Token(defaultDomain, appId, key);

                // Using the ADToken get the sales agent token
                saAuthorizationToken = Reseller.GetSA_Token(adAuthorizationToken);

                // Get the Reseller Cid, you can cache this value
                string resellerCid = Reseller.GetCid(microsoftId, saAuthorizationToken.AccessToken);

#if CREATE_CUSTOMER_SCENARIO
                // Get input from the console application for creating a new customer
                var customer = Customer.PopulateCustomerFromConsole();

                // This is the created customer object that contains the cid, the microsoft tenant id etc
                var createdCustomer = Customer.CreateCustomer(customer, resellerCid, saAuthorizationToken.AccessToken);

                // Populate a multi line item order
                var newCustomerOrder = Order.PopulateOrderWithMultipleLineItems(createdCustomer.customer.id);

                // Place the order and subscription uri and entitlement uri are returned per each line item
                var newCustomerPlacedOrder = Order.PlaceOrder(newCustomerOrder, resellerCid, saAuthorizationToken.AccessToken);

                foreach (var line_Item in newCustomerPlacedOrder.line_items)
                {
                    var subscription = Subscription.GetSubscriptionByUri(line_Item.resulting_subscription_uri, saAuthorizationToken.AccessToken);
                    Console.WriteLine("Subscription: {0}", subscription.Id);
                }
#endif
#if true
                string ExistingCustomerMicrosoftId = ConfigurationManager.AppSettings["ExistingCustomerMicrosoftId"];

                // You can cache this value too
                var existingCustomerCid = Customer.GetCustomerCid(ExistingCustomerMicrosoftId, microsoftId, saAuthorizationToken.AccessToken);

                customerAuthorizationToken = Customer.GetCustomer_Token(existingCustomerCid, adAuthorizationToken);

                // get the customer entity
                var customer = Customer.GetCustomer(existingCustomerCid, customerAuthorizationToken.AccessToken);

                // Get all subscriptions placed by the reseller for the customer
                var subscriptions = Subscription.GetSubscriptions(existingCustomerCid, resellerCid, saAuthorizationToken.AccessToken);

                // Get all orders placed by the reseller for this customer
                var orders = Order.GetOrders(existingCustomerCid, resellerCid, saAuthorizationToken.AccessToken);

                // Populate a multi line item order
                var existingCustomerOrder = Order.PopulateOrderFromConsole(existingCustomerCid);

                // Place the order and subscription uri and entitlement uri are returned per each line item
                var existingCustomerPlacedOrder = Order.PlaceOrder(existingCustomerOrder, resellerCid, saAuthorizationToken.AccessToken);

                foreach (var line_Item in existingCustomerPlacedOrder.line_items)
                {
                    var subscription = Subscription.GetSubscriptionByUri(line_Item.resulting_subscription_uri, saAuthorizationToken.AccessToken);
                    Console.WriteLine("Subscription: {0}", subscription.Id);
                }
#endif
            }
            catch (System.FieldAccessException)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("\n\n\n Looks like you are debugging the application.  Inorder to fix this exception: "
                                  + "\n 1. In Visual Studio, Right Click on the Project Microsoft.CSP.Api.V1.Samples"
                                  + "\n 2. Select the Debug Tab"
                                  + "\n 3. Uncheck the option \"Enable the Visual Studio hosting process\" (it is at the bottom of the page)"
                                  + "\n 4. Save the changes (File -> Save Selected Items)"
                                  + "\n 5. Debug the app now.");
                Console.Write("Make sure you copy/remember the above steps before exiting the app.");
            }
            catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("\n Make sure the app.config has all the right settings.  The defaults in the app.config won't work."
                                  + "\n If the settings are correct, its possible you are hitting a service error.  Try again."
                                  + "\n If the error persists, contact support");
            }


            Console.ResetColor();
            Console.Write("\n\n\nHit enter to exit the app...");
            Console.ReadLine();
        }
Beispiel #12
0
        /// <summary>
        /// Get a customer's usage information for the last 1 month, calculates the total cost using RateCard API
        /// and Suspends the subscription if the total cost is more than the credit limit.
        /// </summary>
        /// <param name="defaultDomain">default domain of the reseller</param>
        /// <param name="appId">appid that is registered for this application in Azure Active Directory (AAD)</param>
        /// <param name="key">Key for this application in Azure Active Directory</param>
        /// <param name="customerMicrosoftId">Microsoft Id of the customer</param>
        /// <param name="resellerMicrosoftId">Microsoft Id of the reseller</param>
        public static void GetRateCardAndUsage(string defaultDomain, string appId, string key,
                                               string customerMicrosoftId, string resellerMicrosoftId)
        {
            var correlationId = Guid.NewGuid().ToString();
            // Get Active Directory token first
            AuthorizationToken adAuthorizationToken = Reseller.GetAD_Token(defaultDomain, appId, key);

            // Using the ADToken get the sales agent token
            AuthorizationToken saAuthorizationToken = Reseller.GetSA_Token(adAuthorizationToken);

            // Get the Reseller Cid, you can cache this value
            string resellerCid = Reseller.GetCid(resellerMicrosoftId, saAuthorizationToken.AccessToken);

            // You can cache this value too
            var customerCid = Customer.GetCustomerCid(customerMicrosoftId, resellerMicrosoftId,
                                                      saAuthorizationToken.AccessToken);

            // Get Customer token
            AuthorizationToken customerAuthorizationToken = Customer.GetCustomer_Token(customerCid, adAuthorizationToken);

            // Gets the RateCard to get the prices
            var rateCard = RateCard.GetRateCard(resellerCid, saAuthorizationToken.AccessToken);

            var startTime = String.Format("{0:u}", DateTime.Today.AddDays(-30));
            var endTime   = String.Format("{0:u}", DateTime.Today.AddDays(-1));

            // Get all of a Customer's entitlements
            var entitlements = Usage.GetEntitlements(customerCid, customerAuthorizationToken.AccessToken);

            try
            {
                foreach (var entitlement in entitlements.items)
                {
                    // Get the usage for the given entitlement for the last 1 month
                    var usageRecords = Usage.GetUsageRecords(resellerCid, entitlement.id, saAuthorizationToken.AccessToken,
                                                             startTime, endTime);

                    if (usageRecords.items.Count > 0)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                        Console.WriteLine("================================================================================");
                        Console.WriteLine("\nPrices for Entitlement: {0}", entitlement.id);
                        Console.WriteLine("================================================================================");

                        double totalCost = 0;
                        // Looping through the usage records to calculate the cost of each item
                        foreach (UsageType usageRecord in usageRecords.items)
                        {
                            string meterId = usageRecord.meter_id;

                            // Gets the price corresponding to the given meterId from the ratecard.
                            Console.WriteLine("\nMeter Name\t\t: {0}", usageRecord.meter_name);
                            double includedQty = Usage.GetIncludedQuantityByMeterID(rateCard, meterId);
                            Console.WriteLine("Included Quantity\t\t: {0}", includedQty);
                            double consumedQty = (double)usageRecord.quantity;
                            Console.WriteLine("Consumed Quantity\t\t: {0}", consumedQty);
                            double ratableUsage = Usage.GetRatableUsage(consumedQty, includedQty);
                            double cost         = Usage.computeRatedUsagePerMeter(Usage.GetRatesForMeterID(rateCard, meterId), ratableUsage);
                            Console.WriteLine("Cost\t\t: {0}", cost);
                            totalCost += cost;
                        }
                        Console.WriteLine("\nTOTAL COST:  {0}", totalCost);
                        // Setting the credit limit below the total cost for testing this scenario
                        double creditLimit = 100;
                        // Suspends the subscription if the total cost is above the credit limit.
                        if (totalCost > creditLimit)
                        {
                            var subscription = Subscription.GetSubscriptionByUri(entitlement.billing_subscription_uri,
                                                                                 saAuthorizationToken.AccessToken);
                            Subscription.SuspendSubscription(subscription.id, resellerCid, saAuthorizationToken.AccessToken);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }