public async Task <Result> UpdateSubscriptionAsync(int quantity, string externalId, string servicePlanId) { var customer = await _dataService.CompanyService.ExternalGetAsync(externalId); var param = new UpdateSubscriptionParam { CustomerId = new Guid(customer.ApplicationCustomerID), SubscriptionId = new Guid(customer.ApplicationSubscriptionId), UnitsPerLicense = quantity, }; _client.UpdateSubscription(param); return(new Result(true, null)); }
public UpdateSubscriptionResponse UpdateSubscription(UpdateSubscriptionParam param) { var request = new RestRequest(Url.GetSubscriptionUrl, Method.PUT) { RequestFormat = DataFormat.Json }; request.AddUrlSegment("customer_id", param.CustomerId.ToString()); request.AddUrlSegment("subscription_id", param.SubscriptionId.ToString()); var data = CreateUpdateSubscriptionParam(param); var jsonData = request.JsonSerializer.Serialize(data); request.AddBody(data); var url = _client.BuildUri(request); request = ConstructRequestHeader(request, url.PathAndQuery, jsonData); var res = _client.Execute <UpdateSubscriptionResult>(request); if (res.StatusCode != System.Net.HttpStatusCode.OK) { throw new TrendMicroApiException(res.StatusCode, res.StatusDescription, res.ErrorMessage, res.ErrorException); } return(new UpdateSubscriptionResponse { SubscriptionId = res.Data.subscription_id, Name = res.Data.name, Enabled = res.Data.enabled, IsAutoRenawal = res.Data.is_auto_renewal, AutoRenawalMonth = res.Data.auto_renawal_month, ExpirationNotification = res.Data.expiration_notification, ServiceUrl = res.Data.service_url, Licenses = res.Data.licenses.Select(x => new License { AcCode = x.ac_code, ProductId = x.product_id, LicenseStartDate = x.license_start_date, LicenseExpirationDate = x.license_expiration_date, StartChargeDate = x.start_charge_date, GracePeriod = x.grace_period, Units = x.units, Enabled = x.enabled }).ToList() }); }
private object CreateUpdateSubscriptionParam(UpdateSubscriptionParam param) => new { units_per_license = param.UnitsPerLicense, license_expiration_date = param.LicenseExpirationDate };