/// <summary> /// Create a new subscription. Can be for a new user, or a user who already has another subscription. /// It is important that you store either the SubscriptionAlias that you use to create this subscription, /// or the SubscriptionId that ProfitWell returns in the response, so that you can update/churn this subscription /// at a later date.IMPORTANT: If you are creating multiple subscriptions for the same user, it is important that /// you wait for a response from the API after creating the first subscription before creating subsequent subscriptions. /// </summary> public async Task <CreateSubscriptionResponseModel> CreateSubscriptionAsync(CreateSubscriptionRequestModel model) { try { string json = Newtonsoft.Json.JsonConvert.SerializeObject(model); StringContent stringContent = new StringContent(json, System.Text.Encoding.Default, "application/json"); var result = await client.PostAsync("v2/subscriptions/", stringContent); var jsonResponse = await result.Content.ReadAsStringAsync(); var response = Newtonsoft.Json.JsonConvert.DeserializeObject <CreateSubscriptionResponseModel>(jsonResponse); if (response == null) { response = new CreateSubscriptionResponseModel(); } response.IsSuccessfull = result.IsSuccessStatusCode; return(response); } catch (Exception e) { throw e; } }
/// <summary> /// Create a new subscription. Can be for a new user, or a user who already has another subscription. /// It is important that you store either the SubscriptionAlias that you use to create this subscription, /// or the SubscriptionId that ProfitWell returns in the response, so that you can update/churn this subscription /// at a later date.IMPORTANT: If you are creating multiple subscriptions for the same user, it is important that /// you wait for a response from the API after creating the first subscription before creating subsequent subscriptions. /// </summary> public CreateSubscriptionResponseModel CreateSubscription(CreateSubscriptionRequestModel model) => CreateSubscriptionAsync(model).ConfigureAwait(false).GetAwaiter().GetResult();