public virtual async Task CompletePayment(IEnterprisesBillingManagerService entBillingMgr, ISecurityDataTokenService secMgr, IIdentityAccessService idMgr, string entLookup, string username, string methodId, string customerName, string plan, int trialPeriodDays, string projectId) { State.CustomerName = customerName; State.PaymentMethodID = methodId; var planOption = this.State.Plans.First(p => p.Lookup == plan); var licenseTypeCore = planOption.Metadata["LicenseType"].ToString(); var licenseTypes = planOption.Metadata.ContainsKey("LicenseTypeOverrides") ? planOption.Metadata["LicenseTypeOverrides"].ToString().Split('|', StringSplitOptions.RemoveEmptyEntries) : new[] { licenseTypeCore }; var completeResp = await entBillingMgr.CompleteStripeSubscription( new CompleteStripeSubscriptionRequest() { CustomerName = State.CustomerName, PaymentMethodID = methodId, Plan = plan, TrialPeriodDays = trialPeriodDays, Username = username }, entLookup, licenseTypeCore); State.PaymentStatus = completeResp.Status; if (State.PaymentStatus.Code == 0) { State.PurchasedPlanLookup = plan; var tosResp = await secMgr.SetDataToken(new DataToken() { Lookup = "LCU-USER-BILLING.TermsOfService", Name = "LCU-USER-BILLING.TermsOfService", Description = "Billing Terms of Service", Value = DateTimeOffset.UtcNow.ToString(), }, entLookup, email : username, projectId : Guid.Parse(projectId)); var eaResp = await secMgr.SetDataToken(new DataToken() { Lookup = "LCU-USER-BILLING.EnterpriseAgreement", Name = "LCU-USER-BILLING.EnterpriseAgreement", Description = "Billing Enterprise Agreement", Value = DateTimeOffset.UtcNow.ToString(), }, entLookup, email : username, projectId : Guid.Parse(projectId)); var licenseResponse = await idMgr.IssueLicense(new License() { Details = JsonConvert.SerializeObject(planOption.Metadata), ExpirationDate = DateTimeOffset.Now.AddYears(50), IsLocked = false }, entLookup, username, projectId, plan, licenseTypeCore); State.PaymentStatus = licenseResponse.Status; State.SubscriptionID = completeResp.SubscriptionID; State.SuccessRedirect = planOption.Metadata["SuccessRedirect"].ToString(); } else { //TODO handle when payment fails but subscription is assigned } }