public static async Task<List<Plan>> Get4FakePlans() { List<Plan> plans = new List<Plan>(); Plan plan = new Plan(); plan.Id = 1; plan.Name = "Plan1"; plan.Duration = 10; plan.MaxBandwidth = 1; plan.MaxQuotaSHared = 2; plan.MaxStorage = 3; plan.Price = 0; plans.Add(plan); Plan plan2 = new Plan(); plan2.Id = 2; plan2.Name = "Plan2"; plan2.Duration = 30; plan2.MaxBandwidth = 2; plan2.MaxQuotaSHared = 3; plan2.MaxStorage = 4; plan2.Price = (float)9.99; plans.Add(plan2); Plan plan3 = new Plan(); plan3.Id = 3; plan3.Name = "Plan3"; plan3.Duration = 60; plan3.MaxBandwidth = 3; plan3.MaxQuotaSHared = 4; plan3.MaxStorage = 5; plan3.Price = (float)14.99; plans.Add(plan3); Plan plan4 = new Plan(); plan4.Id = 4; plan4.Name = "Plan4"; plan4.Duration = 90; plan4.MaxBandwidth = 4; plan4.MaxQuotaSHared = 5; plan4.MaxStorage = 6; plan4.Price = (float)19.99; plans.Add(plan4); return plans; }
public async void BuyProductByName(Plan plan) { ListingInformation allProducts = await CurrentApp.LoadListingInformationAsync(); ProductListing productListing = null; if (!allProducts.ProductListings.TryGetValue(plan.Name, out productListing)) { _informerManagerLocator.InformerManager.AddMessage("Error", "Can't find this plan in market, sorry for this inconvenience"); PlanPurchased(this, new EventArgs(), null); } else { try { /********************************/ // DON'T DO THIS WITH TRUE APP var licensetest = CurrentApp.LicenseInformation.ProductLicenses[plan.Name]; if (licensetest.IsConsumable && licensetest.IsActive) { CurrentApp.ReportProductFulfillment(licensetest.ProductId); } /*******************************/ string result = await CurrentApp.RequestProductPurchaseAsync(productListing.ProductId, false); var license = CurrentApp.LicenseInformation.ProductLicenses[plan.Name]; if (license.IsConsumable && license.IsActive) { CurrentApp.ReportProductFulfillment(license.ProductId); //Pour envoyer un avis de reception chiffré /*string receiptXml = await CurrentApp.GetProductReceiptAsync(license.ProductId); await SendReceipt(receiptXml);*/ } PlanPurchased(this, new EventArgs(), plan); } catch (Exception) { if (PlanPurchased != null) { PlanPurchased(this, new EventArgs(), null); } } } }
public async Task<Plan> CreatePlan(Plan plan, string adminToken) { HttpClient client = new HttpClient(); client.BaseAddress = this.BaseAddress; var content = JsonConvert.SerializeObject(plan); HttpContent httpContent = new StringContent(content, Encoding.UTF8, "application/json"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Add("Token", adminToken); HttpResponseMessage response = await client.PostAsync(client.BaseAddress, httpContent); string responseContent = await response.Content.ReadAsStringAsync(); try { response.EnsureSuccessStatusCode(); } catch (Exception) { if (ErrorReceived != null) { var newError = new Error(true, responseContent); this.ErrorReceived(this, new ErrorEventArgs(newError)); } } Plan result = null; try { result = JsonConvert.DeserializeObject<Plan>(responseContent); } catch (Exception) { if (ErrorReceived != null) { var newError = new Error(true, responseContent); this.ErrorReceived(this, new ErrorEventArgs(newError)); } } return result; }
async void _inAppPurchaseManager_PlanPurchased(object sender, EventArgs e, Plan plan) { if (plan != null) { _user.PlanId = plan.Id; } else { _user.PlanId = 1; } _user.RegistrationPaidPlanDate = DateTime.Now; _user = await _userApi.UpdateUser(_user); if (_user != null) { AuthorizeAccess(); _inAppPurchaseManager.PlanPurchased -= _inAppPurchaseManager_PlanPurchased; if (UndeterminateLoading != null) { UndeterminateLoading(this, new EventArgs(), false); } } }
public async Task<Plan> GetPlanById(int planId) { Plan plan2 = new Plan(); //TODO change from Mock to Real //List<Plan> plans = await GetPlans(); List<Plan> plans = await Mock.PlanMock.Get4FakePlans(); foreach (var plan in plans) { if (plan.Id == planId) { return plan; } } return null; }