예제 #1
0
        public virtual async Task CompletePayment(EnterpriseManagerClient entMgr, SecurityManagerClient secMgr, IdentityManagerClient idMgr, string entApiKey,
                                                  string username, string methodId, string customerName, string plan, int trialPeriodDays)
        {
            State.CustomerName = customerName;

            State.PaymentMethodID = methodId;

            // var completeResp = await entMgr.Post<CompleteStripeSubscriptionRequest, CompleteStripeSubscriptionResponse>($"billing/{entApiKey}/stripe/subscription",
            var completeResp = await entMgr.CompleteStripeSubscription(entApiKey,
                                                                       new CompleteStripeSubscriptionRequest()
            {
                CustomerName    = State.CustomerName,
                PaymentMethodID = methodId,
                Plan            = plan,
                TrialPeriodDays = trialPeriodDays,
                Username        = username
            });

            State.PaymentStatus = completeResp.Status;

            if (State.PaymentStatus)
            {
                State.PurchasedPlanLookup = plan;

                var resp = await secMgr.SetIdentityThirdPartyData(entApiKey, username, new Dictionary <string, string>()
                {
                    { "LCU-USER-BILLING.TermsOfService", DateTimeOffset.UtcNow.ToString() },
                    { "LCU-USER-BILLING.EnterpriseAgreement", DateTimeOffset.UtcNow.ToString() }
                });

                var planOption = this.State.Plans.First(p => p.Lookup == plan);

                var licenseType = planOption.Metadata["LicenseType"].ToString();

                var token = planOption.JSONConvert <LicenseAccessToken>();

                token.EnterpriseAPIKey = entApiKey;

                token.Lookup = licenseType;

                token.AccessStartDate = DateTime.Now;

                token.TrialPeriodDays = trialPeriodDays;

                token.Username = username;

                var setLicenseAccessResp = await idMgr.IssueLicenseAccess(token, entApiKey);

                State.PaymentStatus = setLicenseAccessResp.Status;

                State.SuccessRedirect = licenseType == "lcu" ? "/workspace/new" : "https://forecast.fathym-it.com/";
            }
        }
        public virtual async Task <Status> SetLicenseAccess(IdentityManagerClient idMgr, string entApiKey, string username, int trialLength, bool isLocked, bool isReset)
        {
            var response = await idMgr.IssueLicenseAccess(new LicenseAccessToken()
            {
                IsLocked        = isLocked,
                IsReset         = isReset,
                TrialPeriodDays = trialLength,
                Username        = username
            }, entApiKey);

            return(response.Status);
        }