예제 #1
0
        public FulfillOrderResponse FulfillOrder(FulfillOrderRequest request)
        {
            FulfillOrderResponse response = new FulfillOrderResponse();

            dynamic zuoraResp    = new ExpandoObject();
            var     subscription = SubscriptionManager.Get(request.Account.AccountNumber);

            if (subscription != null)
            {
                zuoraResp = SubscriptionManager.Amend(request, subscription);
            }
            else
            {
                zuoraResp = SubscriptionManager.Create(request);
            }

            if (zuoraResp.Errors.Count == 0)
            {
                response.AccountNumber           = zuoraResp.AccountNumber;
                request.Account.AccountNumber    = zuoraResp.AccountNumber;
                request.Order.SubscriptionNumber = zuoraResp.SubscriptionNumber;
                response.SubscriptionNumber      = zuoraResp.SubscriptionNumber;
                response.InvoiceNumber           = zuoraResp.InvoiceNumber;
                response.InvoiceId           = zuoraResp.InvoiceId;
                response.AccountId           = zuoraResp.AccountId;
                response.InvoiceTotalAmount  = zuoraResp.TotalAmount;
                response.InvoiceTaxAmount    = zuoraResp.Tax;
                response.InvoiceBalance      = zuoraResp.Balance;
                response.BillToContactId     = zuoraResp.BillToId;
                response.SoldToContactId     = zuoraResp.SoldToId;
                response.InvoiceLineItems    = request.Order.LineItems;
                response.Entitlements        = ProvisionManager.Provision(request);
                response.CloudLicenseServers = request.GetDevices();

                response.Successful = true;
                var ase = new AzureStorageEntity(response.SubscriptionNumber, response.AccountNumber, response.ToJsonString());
                new AzureSaveToTableStorageCommand(storageName).
                Execute(ase);
            }
            else
            {
                response.Successful = false;
                response.Errors     = zuoraResp.Errors;
            }


            return(response);
        }
예제 #2
0
        public FulfillOrderResponse RenewOrder(FulfillOrderRequest request)
        {
            FulfillOrderResponse response = new FulfillOrderResponse();

            dynamic zuoraResp    = new ExpandoObject();
            var     subscription = SubscriptionManager.Get(request.Account.AccountNumber);

            if (subscription != null)
            {
                zuoraResp = SubscriptionManager.Amend(request, subscription);
            }
            else
            {
            }


            if (zuoraResp.Errors.Count == 0)
            {
                response.AccountNumber           = zuoraResp.AccountNumber;
                request.Account.AccountNumber    = zuoraResp.AccountNumber;
                request.Order.SubscriptionNumber = zuoraResp.SubscriptionNumber;
                response.SubscriptionNumber      = zuoraResp.SubscriptionNumber;
                response.InvoiceNumber           = zuoraResp.InvoiceNumber;
                response.InvoiceId          = zuoraResp.InvoiceId;
                response.AccountId          = zuoraResp.AccountId;
                response.InvoiceTotalAmount = zuoraResp.TotalAmount;
                response.InvoiceTaxAmount   = zuoraResp.Tax;
                response.InvoiceBalance     = zuoraResp.Balance;

                response.Entitlements        = ProvisionManager.Provision(request);
                response.CloudLicenseServers = request.GetDevices();
                response.Successful          = true;

                if (StorageManager != null)
                {
                    StorageManager.Save <OrderDetail>(null);
                }
            }
            else
            {
                response.Successful = false;
                response.Errors     = zuoraResp.Errors;
            }


            return(response);
        }
        List <string> GetLicensServers(FulfillOrderRequest request)
        {
            List <string> LicenseServers = new List <string>();

            LicenseServers = flexeraClient.GetLicenseServers(request.Account.AccountNumber);
            var licenServerItems = request.Order.LineItems.Where(l => l.IsCloudLicenseServer).ToList();

            foreach (var ls in licenServerItems)
            {
                var device = flexeraClient.CreateLicenseServer(request.Account.AccountNumber,
                                                               request.Account.CompanyName,
                                                               ls.EntitlementFamily, ls.Quantity, LicenseServers.Count);
                LicenseServers.AddRange(device);
            }

            return(LicenseServers);
        }
 List <OrderEntitlementLineItem> GetLineEntitlementLineItems(FulfillOrderRequest request, string entitlementFamily, bool networked)
 {
     return((from i in request.Order.LineItems
             where i.EntitlementFamily == entitlementFamily
             & i.IsCloudLicenseServer == false
             & i.DeployToCloudLicenseServer == networked
             & (i.IsPerpetualLicense == true ||
                i.IsMaintenanceItem == true)
             select new OrderEntitlementLineItem
     {
         PartNumber = i.PartNo,
         Quantity = i.Quantity,
         EffectiveDate = i.EffectiveDate,
         ExpirationDate = i.ExpirationDate,
         ProductRatePlanChargeId = i.ProductRatePlanChargeId,
         IsPerpertual = i.IsPerpetualLicense,
         Term = request.Order.Term,
         LicenseManagerId = i.CloudLicenseServerName,
     }).ToList());
 }
예제 #5
0
 public dynamic Amend(FulfillOrderRequest request, dynamic existingSubscription)
 {
     return(zuoraClient.UpdateSubscription(request, existingSubscription));
 }
예제 #6
0
 public dynamic Create(FulfillOrderRequest request)
 {
     return(zuoraClient.CreateSubscription(request));
 }
        public List <EntitlementResponse> Provision(FulfillOrderRequest request)
        {
            var resultEntitlements = new List <EntitlementResponse>();

            var entitlementList = flexeraClient.GetEntitlements(request.Account.AccountNumber);

            List <string> LicenseServers = GetLicensServers(request);

            var productFamilies = request.Order.LineItems.Select(c => new { c.EntitlementFamily, c.IsSingleSeat,
                                                                            c.DeployToCloudLicenseServer }).Distinct();

            foreach (var p in productFamilies)
            {
                var ocsProductFamily = p.EntitlementFamily + (p.DeployToCloudLicenseServer ? "_Networked" : "_Local");
                if (!string.IsNullOrWhiteSpace(p.EntitlementFamily))
                {
                    var orderEntitlement = new OrderEntitlement();
                    orderEntitlement.EntitlementFamily = p.EntitlementFamily;

                    orderEntitlement.LineItems = GetLineEntitlementLineItems(request, p.EntitlementFamily, p.DeployToCloudLicenseServer);

                    if (orderEntitlement.LineItems.Count > 0)
                    {
                        var qty     = orderEntitlement.LineItems[0].Quantity;
                        var entResp = new EntitlementResponse();

                        //if (p.IsSingleSeat)
                        //    entResp.EntitlementId = flexeraClient.CreateEntitlement(request.Account.AccountNumber, p.EntitlementFamily);
                        //else
                        entResp.EntitlementId = GetProductFamilyEntitlementId(entitlementList, request.Account.AccountNumber,
                                                                              request.Account.CompanyName, ocsProductFamily);

                        entResp.EntitlementFamily = p.EntitlementFamily;

                        entResp.EntitlementLineItems = new List <EntitlementLineItemResponse>();

                        foreach (var li in orderEntitlement.LineItems)
                        {
                            var entLiResp = new EntitlementLineItemResponse();

                            var existingLineItem = (from i in entitlementList
                                                    from j in i.LineItems
                                                    where j.PartNumber == li.PartNumber
                                                    select j).FirstOrDefault();

                            if (existingLineItem != null)
                            {
                                existingLineItem.ProductRatePlanChargeId = li.ProductRatePlanChargeId;
                                existingLineItem.Quantity += qty;
                                entLiResp = flexeraClient.Update(existingLineItem);
                            }
                            else
                            {
                                if (request.RequestType == FulfillmentRequestType.Renewal)
                                {
                                    if (li.IsPerpertual)
                                    {
                                        li.Quantity = qty;
                                        flexeraClient.Update(li);
                                    }
                                    else
                                    {
                                        flexeraClient.ExpireLineItem(entResp.EntitlementId, li.ActivationId);
                                        li.Quantity = qty;
                                        entLiResp   = flexeraClient.AddLineItemToEntitlement(entResp.EntitlementId, li);
                                    }
                                }
                                else
                                {
                                    li.Quantity = qty;
                                    entLiResp   = flexeraClient.AddLineItemToEntitlement(entResp.EntitlementId, li);
                                }
                            }

                            if (p.DeployToCloudLicenseServer)
                            {
                                entLiResp.CloudLicenseServerId = li.LicenseManagerId;


                                if (LicenseServers.Count > 0)
                                {
                                    var cls = LicenseServers.FirstOrDefault(ls => ls == entLiResp.CloudLicenseServerId);
                                    if (string.IsNullOrWhiteSpace(cls))
                                    {
                                        cls = LicenseServers.Last();
                                    }

                                    flexeraClient.AddEntitlementLineItemToLicenseServer(entLiResp, cls);
                                    entLiResp.CloudLicenseServerId = cls;
                                }
                            }
                            entResp.EntitlementLineItems.Add(entLiResp);
                        }
                        resultEntitlements.Add(entResp);
                    }
                }
            }

            request.setDevices(LicenseServers);

            return(resultEntitlements);
        }
 public FulfillOrderResponse Post(FulfillOrderRequest request)
 {
     return(Service.FulfillOrder(request));
 }