public void CanWeSubscribe() { Account acc = zth.MakeTestAccount(); Contact con = zth.MakeTestContact(); PaymentMethod pay = zth.MakeTestPaymentMethod(); String productRatePlanId = zth.CreateRatePlanToSubscribe(); PreviewOptions po = new PreviewOptions(); SubscribeOptions so = new SubscribeOptions(); ProductRatePlanHolder prph = new ProductRatePlanHolder(); ProductRatePlan prp = new ProductRatePlan(); prp.Id = productRatePlanId; prph.ProductRatePlan = prp; ResponseHolder queryRes = zs.Query("SELECT id, ChargeModel FROM ProductRatePlanCharge WHERE productrateplanid = '" + productRatePlanId + "'"); ProductRatePlanCharge prpc = (ProductRatePlanCharge)queryRes.Objects[0]; prpc.DefaultQuantity = 11; ProductRatePlanChargeHolder prpch = new ProductRatePlanChargeHolder(); prpch.ProductRatePlanCharge = prpc; prph.ProductRatePlanCharges = new List<ProductRatePlanChargeHolder> { prpch }; SubscribeResponseHolder subResp = sm.Subscribe(acc, con, pay, new List<ProductRatePlanHolder> { prph }, zth.MakeTestSubscription(), po, so); Assert.True(subResp.Success); }
//Get the product catalog from Zuora public List<ProductHolder> GetProductCatalog() { DateTime time = DateTime.Now.ToZuoraTime().Date; string format = "yyyy-MM-ddTHH:mm:ss"; string curDate = time.ToString(format); String productQueryString = "SELECT Id, Name, Description FROM Product WHERE EffectiveStartDate <= " + curDate + " AND EffectiveEndDate >" + curDate; ResponseHolder productQRes = zs.Query(productQueryString); String productRatePlanQueryString = "SELECT Id, Name, Description, ProductId FROM ProductRatePlan WHERE EffectiveStartDate <= " + curDate + " AND EffectiveEndDate >" + curDate; ResponseHolder productRatePlanQRes = zs.Query(productRatePlanQueryString); String productRatePlanChargeQueryString = "SELECT Id, Name, ProductRatePlanId, ChargeModel, ChargeType FROM ProductRatePlanCharge"; ResponseHolder productRatePlanChargeQRes = zs.Query(productRatePlanChargeQueryString); String productRatePlanChargeTierQueryString = "SELECT Id, Price, ProductRatePlanChargeId FROM ProductRatePlanChargeTier"; ResponseHolder productRatePlanChargeTierQRes = zs.Query(productRatePlanChargeTierQueryString); List<ProductHolder> products = new List<ProductHolder>(); Dictionary<String, List<ProductRatePlan>> productRatePlans = new Dictionary<String, List<ProductRatePlan>>(); Dictionary<String, List<ProductRatePlanCharge>> productRatePlanCharges = new Dictionary<String, List<ProductRatePlanCharge>>(); Dictionary<String, List<ProductRatePlanChargeTier>> productRatePlanChargeTiers = new Dictionary<String, List<ProductRatePlanChargeTier>>(); foreach (zObject t in productRatePlanChargeTierQRes.Objects) { ProductRatePlanChargeTier prpct = (ProductRatePlanChargeTier)t; List<ProductRatePlanChargeTier> tempList; productRatePlanChargeTiers.TryGetValue(prpct.ProductRatePlanChargeId, out tempList); if(tempList == null) { productRatePlanChargeTiers.Add(prpct.ProductRatePlanChargeId, new List<ProductRatePlanChargeTier>{prpct}); } else{ tempList.Add(prpct); productRatePlanChargeTiers.Remove(prpct.ProductRatePlanChargeId); productRatePlanChargeTiers.Add(prpct.ProductRatePlanChargeId, tempList); } } foreach(zObject c in productRatePlanChargeQRes.Objects) { ProductRatePlanCharge prpc = (ProductRatePlanCharge)c; List<ProductRatePlanCharge> tempList; productRatePlanCharges.TryGetValue(prpc.ProductRatePlanId, out tempList); if(tempList == null) { productRatePlanCharges.Add(prpc.ProductRatePlanId, new List<ProductRatePlanCharge>{prpc}); } else{ tempList.Add(prpc); productRatePlanCharges.Remove(prpc.ProductRatePlanId); productRatePlanCharges.Add(prpc.ProductRatePlanId, tempList); } } foreach(zObject r in productRatePlanQRes.Objects) { ProductRatePlan prp = (ProductRatePlan)r; List<ProductRatePlan> tempList; productRatePlans.TryGetValue(prp.ProductId, out tempList); if(tempList == null) { productRatePlans.Add(prp.ProductId, new List<ProductRatePlan>{prp}); } else{ tempList.Add(prp); productRatePlans.Remove(prp.ProductId); productRatePlans.Add(prp.ProductId, tempList); } } foreach (zObject z in productQRes.Objects) { Product prod = (Product) z; ProductHolder prodHolder = new ProductHolder(); prodHolder.Product = prod; //get the rate plans for each product List<ProductRatePlan> ratePlanList = new List<ProductRatePlan>(); List<ProductRatePlanHolder> ratePlanHolders = new List<ProductRatePlanHolder>(); if (productRatePlans.TryGetValue(prod.Id, out ratePlanList)) { foreach (ProductRatePlan prp in ratePlanList) { ProductRatePlanHolder prph = new ProductRatePlanHolder(); prph.ProductRatePlan = prp; //get the charges for each rate plan List<ProductRatePlanCharge> prpcList = new List<ProductRatePlanCharge>(); List<ProductRatePlanChargeHolder> chargeHolders = new List<ProductRatePlanChargeHolder>(); if (productRatePlanCharges.TryGetValue(prp.Id, out prpcList)) { foreach (ProductRatePlanCharge prpc in prpcList) { ProductRatePlanChargeHolder prpch = new ProductRatePlanChargeHolder(); prpch.ProductRatePlanCharge = prpc; //get the tiers for each charge List<ProductRatePlanChargeTier> prpctList = new List<ProductRatePlanChargeTier>(); productRatePlanChargeTiers.TryGetValue(prpc.Id, out prpctList); prpch.ProductRatePlanChargeTiers = prpctList; chargeHolders.Add(prpch); } } prph.ProductRatePlanCharges = chargeHolders; ratePlanHolders.Add(prph); } } prodHolder.ProductRatePlans = ratePlanHolders; products.Add(prodHolder); } var productsJSON = new JavaScriptSerializer().Serialize(products); string myFile = cachePath; System.IO.StreamWriter fh = new System.IO.StreamWriter(myFile); fh.WriteLine(productsJSON); fh.Close(); return ReadCache(); }
public void CanWeSubscribeToMultipleRatePlansWithExistingAccount() { String accId = zth.MakeSubscription(true).SubRes.AccountId; String productRatePlanId = zth.CreateRatePlanToSubscribe(); PreviewOptions po = new PreviewOptions(); SubscribeOptions so = new SubscribeOptions(); ProductRatePlanHolder prph = new ProductRatePlanHolder(); ProductRatePlan prp = new ProductRatePlan(); prp.Id = productRatePlanId; prph.ProductRatePlan = prp; ResponseHolder queryRes = zs.Query("SELECT id, ChargeModel FROM ProductRatePlanCharge WHERE productrateplanid = '" + productRatePlanId + "'"); ProductRatePlanCharge prpc = (ProductRatePlanCharge)queryRes.Objects[0]; prpc.DefaultQuantity = 11; ProductRatePlanChargeHolder prpch = new ProductRatePlanChargeHolder(); prpch.ProductRatePlanCharge = prpc; prph.ProductRatePlanCharges = new List<ProductRatePlanChargeHolder> { prpch }; SubscribeResponseHolder subResp = sm.SubscribeWithExisitingAccount(accId, new List<ProductRatePlanHolder> { prph, prph }, zth.MakeTestSubscription(), po, so); Assert.True(subResp.Success); }